File gdb-symtab-work-around-gas-pr28629.patch of Package gdb
279
1
From 1b878333913343630472f89b4bc42f51b1619308 Mon Sep 17 00:00:00 2001
2
From: Tom de Vries <tdevries@suse.de>
3
Date: Wed, 1 Nov 2023 00:33:12 +0100
4
Subject: [PATCH 1/2] [gdb/symtab] Work around gas PR28629
5
6
When running test-case gdb.tui/tui-layout-asm-short-prog.exp on AlmaLinux 9.2
7
ppc64le, I run into:
8
...
9
FAIL: gdb.tui/tui-layout-asm-short-prog.exp: check asm box contents
10
...
11
12
The problem is that we get:
13
...
14
7 [ No Assembly Available ]
15
...
16
because tui_get_begin_asm_address doesn't succeed.
17
18
In more detail, tui_get_begin_asm_address calls:
19
...
20
find_line_pc (sal.symtab, sal.line, &addr);
21
...
22
with:
23
...
24
(gdb) p *sal.symtab
25
$5 = {next = 0x130393c0, m_compunit = 0x130392f0, m_linetable = 0x0,
26
filename = "tui-layout-asm-short-prog.S",
27
filename_for_id = "$gdb/build/gdb/testsuite/tui-layout-asm-short-prog.S",
28
m_language = language_asm, fullname = 0x0}
29
(gdb) p sal.line
30
$6 = 1
31
...
32
33
The problem is the filename_for_id which is the source file prefixed with the
34
compilation dir rather than the source dir.
35
36
This is due to faulty debug info generated by gas, PR28629:
37
...
38
<1a> DW_AT_name : tui-layout-asm-short-prog.S
39
<1e> DW_AT_comp_dir : $gdb/build/gdb/testsuite
40
<22> DW_AT_producer : GNU AS 2.35.2
41
...
42
43
The DW_AT_name is relative, and it's relative to the DW_AT_comp_dir entry,
44
making the effective name $gdb/build/gdb/testsuite/tui-layout-asm-short-prog.S.
45
46
The bug is fixed starting version 2.38, where we get instead:
47
...
48
<1a> DW_AT_name :
49
$gdb/src/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.S
50
<1e> DW_AT_comp_dir : $gdb/build/gdb/testsuite
51
<22> DW_AT_producer : GNU AS 2.38
52
...
53
54
Work around the faulty debug info by constructing the filename_for_id using
55
the second directory from the directory table in the .debug_line header:
56
...
57
The Directory Table (offset 0x22, lines 2, columns 1):
58
Entry Name
59
0 $gdb/build/gdb/testsuite
60
1 $gdb/src/gdb/testsuite/gdb.tui
61
...
62
63
Note that the used gas contains a backport of commit 3417bfca676 ("GAS:
64
DWARF-5: Ensure that the 0'th entry in the directory table contains the
65
current working directory."), because directory 0 is correct. With the
66
unpatched 2.35.2 release the directory 0 entry is incorrect: it's a copy of
67
entry 1.
68
69
Add a dwarf assembly test-case that reflects the debug info as generated by
70
unpatched gas 2.35.2.
71
72
Tested on x86_64-linux.
73
74
Approved-By: Tom Tromey <tom@tromey.com>
75
---
76
gdb/dwarf2/cu.c | 1 +
77
gdb/dwarf2/cu.h | 1 +
78
gdb/dwarf2/read.c | 37 +++++++-
79
.../gdb.dwarf2/dw2-gas-workaround.exp | 92 +++++++++++++++++++
80
4 files changed, 130 insertions(+), 1 deletion(-)
81
create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-gas-workaround.exp
82
83
diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c
84
index a908ec908cd..f9b05dfc709 100644
85
--- a/gdb/dwarf2/cu.c
86
+++ b/gdb/dwarf2/cu.c
87
88
producer_is_icc_lt_14 (false),
89
producer_is_codewarrior (false),
90
producer_is_clang (false),
91
+ producer_is_gas_lt_2_38 (false),
92
producer_is_gas_2_39 (false),
93
processing_has_namespace_info (false),
94
load_all_dies (false)
95
diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h
96
index 6c611710503..ef8db480e3f 100644
97
--- a/gdb/dwarf2/cu.h
98
+++ b/gdb/dwarf2/cu.h
99
100
bool producer_is_icc_lt_14 : 1;
101
bool producer_is_codewarrior : 1;
102
bool producer_is_clang : 1;
103
+ bool producer_is_gas_lt_2_38 : 1;
104
bool producer_is_gas_2_39 : 1;
105
106
/* When true, the file that we're processing is known to have
107
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
108
index fc4667b782f..50fa302b43a 100644
109
--- a/gdb/dwarf2/read.c
110
+++ b/gdb/dwarf2/read.c
111
112
static int dwarf2_loclist_block_index;
113
static int ada_block_index;
114
115
+static bool producer_is_gas_lt_2_38 (struct dwarf2_cu *cu);
116
+
117
/* Size of .debug_loclists section header for 32-bit DWARF format. */
118
#define LOCLIST_HEADER_SIZE32 12
119
120
121
122
file_and_directory &fnd = find_file_and_directory (die, cu);
123
124
+ /* GAS supports generating dwarf-5 info starting version 2.35. Versions
125
+ 2.35-2.37 generate an incorrect CU name attribute: it's relative,
126
+ implicitly prefixing it with the compilation dir. Work around this by
127
+ prefixing it with the source dir instead. */
128
+ if (cu->header.version == 5 && !IS_ABSOLUTE_PATH (fnd.get_name ())
129
+ && producer_is_gas_lt_2_38 (cu))
130
+ {
131
+ attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
132
+ if (attr != nullptr && attr->form_is_unsigned ())
133
+ {
134
+ sect_offset line_offset = (sect_offset) attr->as_unsigned ();
135
+ line_header_up lh = dwarf_decode_line_header (line_offset, cu,
136
+ fnd.get_comp_dir ());
137
+ if (lh->version == 5 && lh->is_valid_file_index (1))
138
+ {
139
+ std::string dir = lh->include_dir_at (1);
140
+ fnd.set_comp_dir (std::move (dir));
141
+ }
142
+ }
143
+ }
144
+
145
cu->start_compunit_symtab (fnd.get_name (), fnd.intern_comp_dir (objfile),
146
lowpc);
147
148
149
else if (producer_is_clang (cu->producer, &major, &minor))
150
cu->producer_is_clang = true;
151
else if (producer_is_gas (cu->producer, &major, &minor))
152
- cu->producer_is_gas_2_39 = major == 2 && minor == 39;
153
+ {
154
+ cu->producer_is_gas_lt_2_38 = major < 2 || (major == 2 && minor < 38);
155
+ cu->producer_is_gas_2_39 = major == 2 && minor == 39;
156
+ }
157
else
158
{
159
/* For other non-GCC compilers, expect their behavior is DWARF version
160
161
return cu->producer_is_codewarrior;
162
}
163
164
+static bool
165
+producer_is_gas_lt_2_38 (struct dwarf2_cu *cu)
166
+{
167
+ if (!cu->checked_producer)
168
+ check_producer (cu);
169
+
170
+ return cu->producer_is_gas_lt_2_38;
171
+}
172
+
173
static bool
174
producer_is_gas_2_39 (struct dwarf2_cu *cu)
175
{
176
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-gas-workaround.exp b/gdb/testsuite/gdb.dwarf2/dw2-gas-workaround.exp
177
new file mode 100644
178
index 00000000000..ca2b10f23b3
179
--- /dev/null
180
+++ b/gdb/testsuite/gdb.dwarf2/dw2-gas-workaround.exp
181
182
+# Copyright 2023 Free Software Foundation, Inc.
183
+
184
+# This program is free software; you can redistribute it and/or modify
185
+# it under the terms of the GNU General Public License as published by
186
+# the Free Software Foundation; either version 3 of the License, or
187
+# (at your option) any later version.
188
+#
189
+# This program is distributed in the hope that it will be useful,
190
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
191
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
192
+# GNU General Public License for more details.
193
+#
194
+# You should have received a copy of the GNU General Public License
195
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
196
+
197
+# Test line number information in various configurations.
198
+
199
+load_lib dwarf.exp
200
+
201
+# This test can only be run on targets which support DWARF-2 and use gas.
202
+require dwarf2_support
203
+
204
+standard_testfile dw2-lines.c -dw2.S
205
+
206
+with_shared_gdb {
207
+ set func_info_vars [get_func_info bar]
208
+}
209
+
210
+# Helper function.
211
+proc line_for { l } {
212
+ global srcfile
213
+ set line [gdb_get_line_number "$l:" $srcfile]
214
+ return [expr $line + 1]
215
+}
216
+
217
+set asm_file [standard_output_file $srcfile2]
218
+Dwarf::assemble $asm_file {
219
+ declare_labels Llines
220
+ global srcdir subdir srcfile objdir
221
+ global func_info_vars
222
+ foreach var $func_info_vars {
223
+ global $var
224
+ }
225
+
226
+ cu { version 5 } {
227
+ compile_unit {
228
+ {language @DW_LANG_Mips_Assembler}
229
+ {name $srcfile}
230
+ {comp_dir $objdir}
231
+ {stmt_list $Llines DW_FORM_sec_offset}
232
+ {producer "GNU AS 2.35.2"}
233
+ } {
234
+ subprogram {
235
+ {external 1 flag}
236
+ {name bar}
237
+ {low_pc $bar_start addr}
238
+ {high_pc "$bar_start + $bar_len" addr}
239
+ }
240
+ }
241
+ }
242
+
243
+ lines [list version 5] Llines {
244
+ set diridx1 [include_dir "${srcdir}/${subdir}"]
245
+ set diridx2 [include_dir "${srcdir}/${subdir}"]
246
+ file_name "$srcfile" $diridx1
247
+ file_name "$srcfile" $diridx2
248
+
249
+ program {
250
+ DW_LNE_set_address bar_label
251
+ line [line_for bar_label]
252
+ DW_LNS_copy
253
+
254
+ DW_LNE_set_address bar_label_2
255
+ DW_LNE_end_sequence
256
+ }
257
+ }
258
+}
259
+
260
+if { [prepare_for_testing "failed to prepare" ${testfile} \
261
+ [list $srcfile $asm_file] {nodebug}] } {
262
+ return -1
263
+}
264
+
265
+gdb_test_no_output "set debug symtab-create 1"
266
+gdb_test_multiple "ptype bar" "" {
267
+ -re -wrap "$objdir.*" {
268
+ fail $gdb_test_name
269
+ }
270
+ -re -wrap "" {
271
+ pass $gdb_test_name
272
+ }
273
+}
274
275
base-commit: d9951c3c9ea2e542d071710e9706ed505046fe36
276
--
277
2.35.3
278
279