aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2023-08-16 23:43:25 +0200
committerTom de Vries <tdevries@suse.de>2023-08-16 23:43:25 +0200
commiteeee4389cf3725e729b0a477515afd830b34b9f0 (patch)
treeeed75798355e070fe995ba38cc1d360abfb51721 /gdb/testsuite
parent033bc52bb6190393c8eed80925fa78cc35b40c6d (diff)
downloadgdb-eeee4389cf3725e729b0a477515afd830b34b9f0.zip
gdb-eeee4389cf3725e729b0a477515afd830b34b9f0.tar.gz
gdb-eeee4389cf3725e729b0a477515afd830b34b9f0.tar.bz2
[gdb/symtab] Handle self-reference DIE
While working on a dwarf assembly test-case I accidentally created the following pathological dwarf: ... <1><be>: Abbrev Number: 3 (DW_TAG_class_type) <bf> DW_AT_name : c1 <c2> DW_AT_specification: <0xbe> ... and noticed gdb segfaulting during cooked index creating due to running out of stack. This is a regression from gdb-12, where gdb just hung. Fix this by inhibiting the scan_attributes self-recursion for self-references. The same test-case with -readnow makes gdb hang, so also fix this in dwarf2_attr and follow_die_ref. Note that this doesn't fix the same problems for the more complicated case of: ... <1><be>: Abbrev Number: 3 (DW_TAG_class_type) <bf> DW_AT_name : c1 <c2> DW_AT_specification: <0xc6> <1><c6>: Abbrev Number: 4 (DW_TAG_class_type) <c7> DW_AT_name : c2 <ca> DW_AT_specification: <0xbe> ... but the approach for deciding whether to fix pathological dwarf cases is as per PR27981 comment 3: ... yes if it is cheap/obvious, and no if it is something complicated or expensive. ... and at this point I'm not sure whether fixing this will fall in the first category. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/gdb.dwarf2/self-spec.exp52
1 files changed, 52 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.dwarf2/self-spec.exp b/gdb/testsuite/gdb.dwarf2/self-spec.exp
new file mode 100644
index 0000000..71e7c12
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/self-spec.exp
@@ -0,0 +1,52 @@
+# Copyright 2023 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Check that gdb doesn't hang or segfault on reading a DIE with a
+# specification reference to itself.
+
+load_lib dwarf.exp
+
+require dwarf2_support
+
+standard_testfile main.c .S
+
+# Create the DWARF.
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+ cu {} {
+ compile_unit {{language @DW_LANG_C_plus_plus}} {
+ declare_labels c1
+ c1: class_type {
+ {name c1}
+ {specification :$c1}
+ }
+ }
+ }
+}
+
+if [prepare_for_testing "failed to prepare" $testfile "${asm_file} ${srcfile}" {}] {
+ return -1
+}
+
+set index [have_index $binfile]
+require {string eq $index ""}
+
+require !readnow
+
+gdb_test "maint print objfiles $testfile" \
+ "\r\n *qualified: *c1\r\n.*" \
+ "class c1 in cooked index"
+
+gdb_test "maint expand-symtabs"