1 # Copyright 2012-2024 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This test checks that GDB can load DWARF information from two
17 # separate split .DWO files.
21 # We run objcopy locally to split out the .dwo file.
22 require {!is_remote host}
24 # This test can only be run on targets which support DWARF-2 and use gas.
25 require dwarf2_support
27 # We place the entire source code for the test into a single .c file,
28 # but we generate the DWARF in two separate .S files. Each .S is
29 # compiled to a .o, then the DWARF is split into a .dwo file. Finally
30 # the all three .o files are merged into a single executable that will
31 # reference the two .dwo files.
32 standard_testfile .c -1-dw.S -2-cw.S
34 # Generate the first .S file.
35 set asm_file_1 [standard_output_file $srcfile2]
36 Dwarf::assemble $asm_file_1 {
37 global srcfile binfile objdir srcdir subdir
41 declare_labels int4_type lines_table
43 set debug_addr_lbl ".unknown!!"
45 # The information that will be split out into the .dwo file.
48 # Capture a label to the current start of the .debug_addr
49 # section. This will be passed to DW_AT_GNU_addr_base in the
51 set debug_addr_lbl [debug_addr_label]
56 {DW_AT_comp_dir ${objdir}}
57 {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
59 int4_type: DW_TAG_base_type {
60 {DW_AT_byte_size 4 DW_FORM_sdata}
61 {DW_AT_encoding @DW_ATE_signed}
67 {DW_AT_name func DW_FORM_string}
68 {MACRO_AT_func {func}}
69 {DW_AT_type :$int4_type}
71 DW_TAG_formal_parameter {
73 {DW_AT_type :$int4_type}
75 DW_OP_GNU_addr_index [gdb_target_symbol global_param]
82 lines {version 2} lines_table {
83 include_dir "${srcdir}/${subdir}"
84 file_name "$srcfile" 1
87 DW_LNE_set_address $func_start
88 DW_LNS_advance_line 24
91 DW_LNE_set_address line_label_4
95 DW_LNE_set_address $func_end
100 # The information that will remain in the .o file.
103 {DW_AT_GNU_dwo_name ${binfile}-1-dw.dwo DW_FORM_strp}
104 {DW_AT_comp_dir ${objdir}}
105 {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
106 {DW_AT_GNU_addr_base $debug_addr_lbl}
107 {stmt_list $lines_table DW_FORM_sec_offset}
114 # Generate the second .S file.
115 set asm_file_2 [standard_output_file $srcfile3]
116 Dwarf::assemble $asm_file_2 {
117 global srcfile binfile objdir srcdir subdir
119 set debug_addr_lbl ".unknown!!"
121 declare_labels int4_type lines_table
125 # The information that will be split out into the .dwo file.
128 # Capture a label to the current start of the .debug_addr
129 # section. This will be passed to DW_AT_GNU_addr_base in the
130 # non-split CU later.
131 set debug_addr_lbl [debug_addr_label]
134 {language @DW_LANG_C}
136 {DW_AT_comp_dir ${objdir}}
137 {DW_AT_GNU_dwo_id 0x4567 DW_FORM_data8}
139 int4_type: DW_TAG_base_type {
140 {DW_AT_byte_size 4 DW_FORM_sdata}
141 {DW_AT_encoding @DW_ATE_signed}
147 {DW_AT_name main DW_FORM_string}
148 {MACRO_AT_func {main}}
149 {DW_AT_type :$int4_type}
150 {DW_AT_decl_file 1 data1}
151 {DW_AT_decl_line 29 data1}
156 lines {version 2} lines_table {
157 include_dir "${srcdir}/${subdir}"
158 file_name "$srcfile" 1
161 DW_LNE_set_address $main_start
162 DW_LNS_advance_line 32
165 DW_LNE_set_address line_label_1
166 DW_LNS_advance_line 3
169 DW_LNE_set_address line_label_2
170 DW_LNS_advance_line 2
173 DW_LNE_set_address line_label_3
174 DW_LNS_advance_line 2
177 DW_LNE_set_address $main_end
182 # The information that will remain in the .o file.
185 {DW_AT_GNU_dwo_name ${binfile}-2-dw.dwo DW_FORM_strp}
186 {DW_AT_comp_dir ${objdir}}
187 {DW_AT_GNU_dwo_id 0x4567 DW_FORM_data8}
188 {DW_AT_GNU_addr_base $debug_addr_lbl}
189 {stmt_list $lines_table DW_FORM_sec_offset}
196 # Compile all of the input files, split the DWARF into the .dwo files.
197 set obj1 [standard_output_file "${testfile}-1-dw.o"]
198 set obj2 [standard_output_file "${testfile}-2-dw.o"]
199 if [build_executable_and_dwo_files "$testfile.exp" "${binfile}" {nodebug} \
200 [list $asm_file_1 [list nodebug split-dwo] $obj1] \
201 [list $asm_file_2 [list nodebug split-dwo] $obj2] \
202 [list $srcfile [list nodebug]]] {
206 clean_restart $binfile
212 # Do a few basic things to verify we're finding the DWO debug info.
214 gdb_test "ptype main" "type = int \\(\\)"
215 gdb_test "ptype func" "type = int \\(int\\)"
217 gdb_test "frame" "#0 *main \\(\\) at \[^\r\n\]+${srcfile}:$decimal.*" \
220 gdb_test "break func" "Breakpoint.*at.* file .*${srcfile}, line .*"
222 gdb_test "continue" "Breakpoint.* func \\(arg=-1\\).*" \
225 gdb_test "frame" "#0 *func \\(arg=-1\\) at \[^\r\n\]+${srcfile}:$decimal.*" \