1 # Copyright 2021-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 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.
22 # This test can only be run on targets which support DWARF-2 and use gas.
23 require dwarf2_support
25 standard_testfile .c -dw.S
27 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
31 set asm_file [standard_output_file $srcfile2]
32 Dwarf::assemble $asm_file {
40 declare_labels int4_type struct_type
42 int4_type: DW_TAG_base_type {
43 {DW_AT_byte_size 4 DW_FORM_sdata}
44 {DW_AT_encoding @DW_ATE_signed}
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}
53 {name "aa" DW_FORM_strp}
55 {data_member_location 0 data1}
58 {name "bb" DW_FORM_strp}
60 {data_member_location 4 data1}
63 {name "cc" DW_FORM_strp}
65 {data_member_location 8 data1}
70 {DW_AT_name global_var DW_FORM_strp}
71 {DW_AT_type :$struct_type}
73 DW_OP_addr [gdb_target_symbol global_var]
80 {name main DW_FORM_strp}
81 {MACRO_AT_range {main}}
87 if { [prepare_for_testing "failed to prepare" ${testfile} \
88 [list $srcfile $asm_file] {nodebug}] } {
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\\}"
101 set host_binfile [gdb_remote_download host $binfile]
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 ""] } {
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
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"
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.
131 gdb_test_no_output "maint set dwarf synchronous on"
133 set line1 "Reading symbols from \[^\r\n\]+"
134 set dwarf_error "Dwarf Error: DW_FORM_strp used without required section"
136 # This pattern is hit when GDB does not use -readnow (i.e. the default
142 "\\(No debugging symbols \[^\r\n\]+\\)"]
144 # This pattern is hit when GDB does use -readnow (e.g. running with
145 # --target_board=readnow).
149 "Expanding full symbols from \[^\r\n\]+" \
152 # This pattern is hit when gcc adds an index (e.g. running with
153 # --target_board=cc-with-gdb-index).
159 # Load the executable, we expect an error from the DWARF parser.
160 gdb_test "file $binfile_no_debug_str" "($pattern1|$pattern2|$pattern3)" \