diff options
author | Tom de Vries <tdevries@suse.de> | 2023-08-16 23:43:25 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2023-08-16 23:43:25 +0200 |
commit | eeee4389cf3725e729b0a477515afd830b34b9f0 (patch) | |
tree | eed75798355e070fe995ba38cc1d360abfb51721 /gdb/dwarf2 | |
parent | 033bc52bb6190393c8eed80925fa78cc35b40c6d (diff) | |
download | gdb-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/dwarf2')
-rw-r--r-- | gdb/dwarf2/read.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index a64f82b..245117c 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -16375,9 +16375,15 @@ cooked_indexer::scan_attributes (dwarf2_per_cu_data *scanning_per_cu, new_info_ptr, &bytes_read); new_info_ptr += bytes_read; - scan_attributes (scanning_per_cu, new_reader, new_info_ptr, new_info_ptr, - new_abbrev, name, linkage_name, flags, nullptr, - parent_entry, maybe_defer, true); + + if (new_reader->cu == reader->cu && new_info_ptr == watermark_ptr) + { + /* Self-reference, we're done. */ + } + else + scan_attributes (scanning_per_cu, new_reader, new_info_ptr, + new_info_ptr, new_abbrev, name, linkage_name, + flags, nullptr, parent_entry, maybe_defer, true); } } @@ -17888,7 +17894,11 @@ dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) if (!spec) break; + struct die_info *prev_die = die; die = follow_die_ref (die, spec, &cu); + if (die == prev_die) + /* Self-reference, we're done. */ + break; } return NULL; @@ -20540,6 +20550,12 @@ follow_die_ref (struct die_info *src_die, const struct attribute *attr, struct dwarf2_cu *cu = *ref_cu; struct die_info *die; + if (attr->form != DW_FORM_GNU_ref_alt && src_die->sect_off == sect_off) + { + /* Self-reference, we're done. */ + return src_die; + } + die = follow_die_offset (sect_off, (attr->form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz), |