1 # Copyright
2021-2022 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 if {![dwarf2_support
]} {
27 standard_testfile .c
-dw.S
29 if { [prepare_for_testing
"failed to prepare" ${testfile} ${srcfile}] } {
33 set asm_file
[standard_output_file $srcfile2
]
34 Dwarf
::assemble $asm_file
{
42 declare_labels int4_type struct_type
44 int4_type
: DW_TAG_base_type
{
45 {DW_AT_byte_size
4 DW_FORM_sdata
}
46 {DW_AT_encoding @DW_ATE_signed
}
50 struct_type
: DW_TAG_structure_type
{
51 {DW_AT_name
"foo_t" DW_FORM_strp}
52 {DW_AT_byte_size
12 DW_FORM_sdata
}
55 {name "aa" DW_FORM_strp}
57 {data_member_location
0 data1
}
60 {name "bb" DW_FORM_strp}
62 {data_member_location
4 data1
}
65 {name "cc" DW_FORM_strp}
67 {data_member_location
8 data1
}
72 {DW_AT_name global_var DW_FORM_strp
}
73 {DW_AT_type
:$struct_type
}
75 DW_OP_addr
[gdb_target_symbol global_var
]
82 {name main DW_FORM_strp
}
83 {MACRO_AT_range
{main
}}
89 if { [prepare_for_testing
"failed to prepare" ${testfile} \
90 [list $srcfile $asm_file
] {nodebug
}] } {
98 # Print the type of global_var. This type information is entirely
99 # fictional
, it only
exists in the DWARF
, but it contains lots of nice
100 # field names
, all of which are stored in the .debug_str section.
101 gdb_test
"p global_var" " = \\{aa = 0, bb = 0, cc = 0\\}"
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
"${binfile}-debug-str"
108 set args "--dump-section .debug_str=debug_str_section $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
"${binfile}-no-debug-str"
121 set args "--remove-section .debug_str $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 set line1
"Reading symbols from \[^\r\n\]+"
132 set dwarf_error
"Dwarf Error: DW_FORM_strp used without required section"
134 # This pattern is hit when GDB does not use
-readnow
(i.e. the default
140 "\\(No debugging symbols \[^\r\n\]+\\)"]
142 # This pattern is hit when GDB does use
-readnow
(e.g. running with
143 #
--target_board
=readnow
).
147 "Expanding full symbols from \[^\r\n\]+" \
150 # This pattern is hit when gcc adds an index
(e.g. running with
151 #
--target_board
=cc
-with
-gdb
-index
).
157 #
Load the executable
, we expect an error from the DWARF parser.
158 gdb_test
"file $binfile_no_debug_str" "($pattern1|$pattern2|$pattern3)" \