Commit | Line | Data |
---|---|---|
88b9d363 | 1 | # Copyright 2021-2022 Free Software Foundation, Inc. |
1e7fcccb AB |
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\\}" | |
1fd999d9 AB |
102 | |
103 | # Now copy the executable, and remove the .debug_str section. This | |
104 | # creates an executable with an invalid DWARF configuration. GDB | |
105 | # should give an error when trying to read the debug information from | |
106 | # this executable. | |
107 | set binfile_no_debug_str "${binfile}-no-debug-str" | |
108 | set args "--remove-section .debug_str $binfile ${binfile_no_debug_str}" | |
109 | if {[run_on_host "objcopy" [gdb_find_objcopy] "$args"]} { | |
110 | perror "failed to run objcopy" | |
111 | return -1 | |
112 | } | |
113 | ||
114 | # Restart GDB, but don't load an executable. When we do load the | |
115 | # executable we're going to get an error, which we check for below. | |
116 | clean_restart | |
117 | ||
118 | # This pattern is hit when GDB does not use -readnow (i.e. the default | |
119 | # behaviour). | |
120 | set pattern1 \ | |
121 | [multi_line \ | |
122 | "Reading symbols from \[^\r\n\]+" \ | |
123 | "Dwarf Error: DW_FORM_strp used without required section" \ | |
124 | "\\(No debugging symbols \[^\r\n\]+\\)"] | |
125 | ||
126 | # This pattern is hit when GDB does use -readnow (e.g. running with | |
127 | # --target_board=readnow). | |
128 | set pattern2 \ | |
129 | [multi_line \ | |
130 | "Reading symbols from \[^\r\n\]+" \ | |
131 | "Expanding full symbols from \[^\r\n\]+" \ | |
132 | "Dwarf Error: DW_FORM_strp used without required section"] | |
133 | ||
134 | # Load the executable, we expect an error from the DWARF parser. | |
135 | gdb_test_multiple "file $binfile_no_debug_str" "file $testfile" { | |
136 | -wrap -re $pattern1 { | |
137 | pass $gdb_test_name | |
138 | } | |
139 | -re -wrap "$pattern2" { | |
140 | pass $gdb_test_name | |
141 | } | |
142 | } |