]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.dwarf2/dw2-using-debug-str.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / dw2-using-debug-str.exp
1 # Copyright 2021-2024 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 # This test is as much about testing the lib/dwarf.exp DWARF generator
17 # as it is about testing GDB. At the time this test was written, this
18 # was the only test that generated any DWARF using DW_FORM_strp.
19
20 load_lib dwarf.exp
21
22 # This test can only be run on targets which support DWARF-2 and use gas.
23 require dwarf2_support
24
25 standard_testfile .c -dw.S
26
27 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
28 return -1
29 }
30
31 set asm_file [standard_output_file $srcfile2]
32 Dwarf::assemble $asm_file {
33 global srcfile
34
35 cu {} {
36 compile_unit {
37 {language @DW_LANG_C}
38 {name ${srcfile}}
39 } {
40 declare_labels int4_type struct_type
41
42 int4_type: DW_TAG_base_type {
43 {DW_AT_byte_size 4 DW_FORM_sdata}
44 {DW_AT_encoding @DW_ATE_signed}
45 {DW_AT_name integer}
46 }
47
48 struct_type: DW_TAG_structure_type {
49 {DW_AT_name "foo_t" DW_FORM_strp}
50 {DW_AT_byte_size 12 DW_FORM_sdata}
51 } {
52 member {
53 {name "aa" DW_FORM_strp}
54 {type :$int4_type}
55 {data_member_location 0 data1}
56 }
57 member {
58 {name "bb" DW_FORM_strp}
59 {type :$int4_type}
60 {data_member_location 4 data1}
61 }
62 member {
63 {name "cc" DW_FORM_strp}
64 {type :$int4_type}
65 {data_member_location 8 data1}
66 }
67 }
68
69 DW_TAG_variable {
70 {DW_AT_name global_var DW_FORM_strp}
71 {DW_AT_type :$struct_type}
72 {DW_AT_location {
73 DW_OP_addr [gdb_target_symbol global_var]
74 } SPECIAL_expr}
75 {external 1 flag}
76 }
77
78 subprogram {
79 {external 1 flag}
80 {name main DW_FORM_strp}
81 {MACRO_AT_range {main}}
82 }
83 }
84 }
85 }
86
87 if { [prepare_for_testing "failed to prepare" ${testfile} \
88 [list $srcfile $asm_file] {nodebug}] } {
89 return -1
90 }
91
92 if ![runto_main] {
93 return -1
94 }
95
96 # Print the type of global_var. This type information is entirely
97 # fictional, it only exists in the DWARF, but it contains lots of nice
98 # field names, all of which are stored in the .debug_str section.
99 gdb_test "p global_var" " = \\{aa = 0, bb = 0, cc = 0\\}"
100
101 set host_binfile [gdb_remote_download host $binfile]
102
103 # Verify that the executable actually contains a .debug_str section, before
104 # trying to remove it. This can be missing with target boards
105 # cc-with-dwz-m.exp and cc-with-gnu-debuglink.exp. Handle this by
106 # skipping the remainder of the test-case.
107 set debug_str_section "${host_binfile}-debug-str"
108 set args "--dump-section .debug_str=${debug_str_section} $host_binfile"
109 set result [remote_exec host "[gdb_find_objcopy] $args"]
110 set status [lindex $result 0]
111 set output [lindex $result 1]
112 if { $status == 0 && ![string equal $output ""] } {
113 return -1
114 }
115
116 # Now copy the executable, and remove the .debug_str section. This
117 # creates an executable with an invalid DWARF configuration. GDB
118 # should give an error when trying to read the debug information from
119 # this executable.
120 set binfile_no_debug_str "${host_binfile}-no-debug-str"
121 set args "--remove-section .debug_str $host_binfile ${binfile_no_debug_str}"
122 if {[run_on_host "objcopy" [gdb_find_objcopy] "$args"]} {
123 perror "failed to run objcopy"
124 return -1
125 }
126
127 # Restart GDB, but don't load an executable. When we do load the
128 # executable we're going to get an error, which we check for below.
129 clean_restart
130
131 gdb_test_no_output "maint set dwarf synchronous on"
132
133 set line1 "Reading symbols from \[^\r\n\]+"
134 set dwarf_error "Dwarf Error: DW_FORM_strp used without required section"
135
136 # This pattern is hit when GDB does not use -readnow (i.e. the default
137 # behaviour).
138 set pattern1 \
139 [multi_line \
140 $line1 \
141 $dwarf_error \
142 "\\(No debugging symbols \[^\r\n\]+\\)"]
143
144 # This pattern is hit when GDB does use -readnow (e.g. running with
145 # --target_board=readnow).
146 set pattern2 \
147 [multi_line \
148 $line1 \
149 "Expanding full symbols from \[^\r\n\]+" \
150 $dwarf_error]
151
152 # This pattern is hit when gcc adds an index (e.g. running with
153 # --target_board=cc-with-gdb-index).
154 set pattern3 \
155 [multi_line \
156 $line1 \
157 $dwarf_error]
158
159 # Load the executable, we expect an error from the DWARF parser.
160 gdb_test "file $binfile_no_debug_str" "($pattern1|$pattern2|$pattern3)" \
161 "file $testfile"