]> 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-2023 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 if {![dwarf2_support]} {
24 return 0
25 }
26
27 standard_testfile .c -dw.S
28
29 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
30 return -1
31 }
32
33 set asm_file [standard_output_file $srcfile2]
34 Dwarf::assemble $asm_file {
35 global srcfile
36
37 cu {} {
38 compile_unit {
39 {language @DW_LANG_C}
40 {name ${srcfile}}
41 } {
42 declare_labels int4_type struct_type
43
44 int4_type: DW_TAG_base_type {
45 {DW_AT_byte_size 4 DW_FORM_sdata}
46 {DW_AT_encoding @DW_ATE_signed}
47 {DW_AT_name integer}
48 }
49
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}
53 } {
54 member {
55 {name "aa" DW_FORM_strp}
56 {type :$int4_type}
57 {data_member_location 0 data1}
58 }
59 member {
60 {name "bb" DW_FORM_strp}
61 {type :$int4_type}
62 {data_member_location 4 data1}
63 }
64 member {
65 {name "cc" DW_FORM_strp}
66 {type :$int4_type}
67 {data_member_location 8 data1}
68 }
69 }
70
71 DW_TAG_variable {
72 {DW_AT_name global_var DW_FORM_strp}
73 {DW_AT_type :$struct_type}
74 {DW_AT_location {
75 DW_OP_addr [gdb_target_symbol global_var]
76 } SPECIAL_expr}
77 {external 1 flag}
78 }
79
80 subprogram {
81 {external 1 flag}
82 {name main DW_FORM_strp}
83 {MACRO_AT_range {main}}
84 }
85 }
86 }
87 }
88
89 if { [prepare_for_testing "failed to prepare" ${testfile} \
90 [list $srcfile $asm_file] {nodebug}] } {
91 return -1
92 }
93
94 if ![runto_main] {
95 return -1
96 }
97
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\\}"
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 "${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 ""] } {
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 "${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"
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 set line1 "Reading symbols from \[^\r\n\]+"
132 set dwarf_error "Dwarf Error: DW_FORM_strp used without required section"
133
134 # This pattern is hit when GDB does not use -readnow (i.e. the default
135 # behaviour).
136 set pattern1 \
137 [multi_line \
138 $line1 \
139 $dwarf_error \
140 "\\(No debugging symbols \[^\r\n\]+\\)"]
141
142 # This pattern is hit when GDB does use -readnow (e.g. running with
143 # --target_board=readnow).
144 set pattern2 \
145 [multi_line \
146 $line1 \
147 "Expanding full symbols from \[^\r\n\]+" \
148 $dwarf_error]
149
150 # This pattern is hit when gcc adds an index (e.g. running with
151 # --target_board=cc-with-gdb-index).
152 set pattern3 \
153 [multi_line \
154 $line1 \
155 $dwarf_error]
156
157 # Load the executable, we expect an error from the DWARF parser.
158 gdb_test "file $binfile_no_debug_str" "($pattern1|$pattern2|$pattern3)" \
159 "file $testfile"