[gdb/symtab] Handle self-reference in inherit_abstract_dies
authorTom de Vries <tdevries@suse.de>
Mon, 28 Aug 2023 14:27:58 +0000 (16:27 +0200)
committerTom de Vries <tdevries@suse.de>
Mon, 28 Aug 2023 14:27:58 +0000 (16:27 +0200)
Building gdb with gcc 7.5.0 and -flto -O2 -flto-partition=one generates a
self-referencing DIE:
...
 <2><91dace>: Abbrev Number: 405 (DW_TAG_label)
    <91dad0>   DW_AT_abstract_origin: <0x91dace>
...

When encountering the self-reference DIE in inherit_abstract_dies we loop
following the abstract origin, effectively hanging gdb.

Fix this by handling self-referencing DIEs in the loop in
inherit_abstract_dies.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
PR symtab/30799
https://sourceware.org/bugzilla/show_bug.cgi?id=30799

gdb/dwarf2/read.c
gdb/testsuite/gdb.dwarf2/self-spec.exp

index eb4cb9ba72e090391120140bd274e335cad5dace..5b32089094d07333a1743ebccae9ef59638e747d 100644 (file)
@@ -9935,8 +9935,15 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
          if (attr == nullptr)
            break;
 
+         die_info *prev_child_origin_die = child_origin_die;
          child_origin_die = follow_die_ref (child_origin_die, attr,
                                             &child_origin_cu);
+
+         if (prev_child_origin_die == child_origin_die)
+           {
+             /* Handle DIE with self-reference.  */
+             break;
+           }
        }
 
       /* If missing DW_AT_abstract_origin, try the corresponding child
index 71e7c1210a6cfeb8f628a3ccfa9ca7af0155d2de..b80f61d3be9ec314cfe2478ab8e3efc5796a02e7 100644 (file)
@@ -14,7 +14,7 @@
 # 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.
+# specification/abstract_origin reference to itself.
 
 load_lib dwarf.exp
 
@@ -27,11 +27,25 @@ set asm_file [standard_output_file $srcfile2]
 Dwarf::assemble $asm_file {
     cu {} {
        compile_unit {{language @DW_LANG_C_plus_plus}} {
+           # Check handling of self-referencing DIE.
            declare_labels c1
            c1: class_type {
                {name c1}
                {specification :$c1}
            }
+
+           # Check handling of self-referencing child DIE.  Regression test
+           # for PR30799.
+           declare_labels f1 abstract_f1 f1_l
+           abstract_f1: subprogram {}
+           f1: subprogram {
+               {MACRO_AT_func {main}}
+               {abstract_origin :$abstract_f1}
+           } {
+               f1_l: label {
+                   {abstract_origin :$f1_l}
+               }
+           }
        }
     }
 }