public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [gdb/symtab] Handle self-reference in inherit_abstract_dies
@ 2023-08-28  6:36 Tom de Vries
  2023-08-28 14:11 ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Tom de Vries @ 2023-08-28  6:36 UTC (permalink / raw)
  To: gdb-patches

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.

PR symtab/30799
https://sourceware.org/bugzilla/show_bug.cgi?id=30799
---
 gdb/dwarf2/read.c                      |  7 +++++++
 gdb/testsuite/gdb.dwarf2/self-spec.exp | 16 +++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index eb4cb9ba72e..5b32089094d 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -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
diff --git a/gdb/testsuite/gdb.dwarf2/self-spec.exp b/gdb/testsuite/gdb.dwarf2/self-spec.exp
index 71e7c1210a6..b80f61d3be9 100644
--- a/gdb/testsuite/gdb.dwarf2/self-spec.exp
+++ b/gdb/testsuite/gdb.dwarf2/self-spec.exp
@@ -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}
+		}
+	    }
 	}
     }
 }

base-commit: 8606b47e94078e77a53f3cd714272c853d2add22
-- 
2.35.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] [gdb/symtab] Handle self-reference in inherit_abstract_dies
  2023-08-28  6:36 [PATCH] [gdb/symtab] Handle self-reference in inherit_abstract_dies Tom de Vries
@ 2023-08-28 14:11 ` Tom Tromey
  2023-08-28 14:32   ` Tom de Vries
  2023-09-04 11:47   ` Tom de Vries
  0 siblings, 2 replies; 4+ messages in thread
From: Tom Tromey @ 2023-08-28 14:11 UTC (permalink / raw)
  To: Tom de Vries via Gdb-patches; +Cc: Tom de Vries

>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> Building gdb with gcc 7.5.0 and -flto -O2 -flto-partition=one generates a
Tom> self-referencing DIE:
Tom> ...
Tom>  <2><91dace>: Abbrev Number: 405 (DW_TAG_label)
Tom>     <91dad0>   DW_AT_abstract_origin: <0x91dace>
Tom> ...

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

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

I wonder if these have ever happened from compiler bugs, or only from
hand-made tests.

Anyway, seems fine.  If we're ever worried about chains of inheritance
that form loops, we can do some kind of tortoise/hare thing.

Approved-By: Tom Tromey <tom@tromey.com>

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] [gdb/symtab] Handle self-reference in inherit_abstract_dies
  2023-08-28 14:11 ` Tom Tromey
@ 2023-08-28 14:32   ` Tom de Vries
  2023-09-04 11:47   ` Tom de Vries
  1 sibling, 0 replies; 4+ messages in thread
From: Tom de Vries @ 2023-08-28 14:32 UTC (permalink / raw)
  To: Tom Tromey, Tom de Vries via Gdb-patches

On 8/28/23 16:11, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Tom> Building gdb with gcc 7.5.0 and -flto -O2 -flto-partition=one generates a
> Tom> self-referencing DIE:
> Tom> ...
> Tom>  <2><91dace>: Abbrev Number: 405 (DW_TAG_label)
> Tom>     <91dad0>   DW_AT_abstract_origin: <0x91dace>
> Tom> ...
> 
> Tom> When encountering the self-reference DIE in inherit_abstract_dies we loop
> Tom> following the abstract origin, effectively hanging gdb.
> 
> Tom> Fix this by handling self-referencing DIEs in the loop in
> Tom> inherit_abstract_dies.
> 
> I wonder if these have ever happened from compiler bugs, or only from
> hand-made tests.
> 

The reported instance is from a compiler bug, manifesting while building 
gdb.

> Anyway, seems fine.  If we're ever worried about chains of inheritance
> that form loops, we can do some kind of tortoise/hare thing.
> 

Ack.

Thanks for the review, committed.

Thanks,
- Tom

> Approved-By: Tom Tromey <tom@tromey.com>
> 
> Tom


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] [gdb/symtab] Handle self-reference in inherit_abstract_dies
  2023-08-28 14:11 ` Tom Tromey
  2023-08-28 14:32   ` Tom de Vries
@ 2023-09-04 11:47   ` Tom de Vries
  1 sibling, 0 replies; 4+ messages in thread
From: Tom de Vries @ 2023-09-04 11:47 UTC (permalink / raw)
  To: Tom Tromey, Tom de Vries via Gdb-patches

On 8/28/23 16:11, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Tom> Building gdb with gcc 7.5.0 and -flto -O2 -flto-partition=one generates a
> Tom> self-referencing DIE:
> Tom> ...
> Tom>  <2><91dace>: Abbrev Number: 405 (DW_TAG_label)
> Tom>     <91dad0>   DW_AT_abstract_origin: <0x91dace>
> Tom> ...
> 
> Tom> When encountering the self-reference DIE in inherit_abstract_dies we loop
> Tom> following the abstract origin, effectively hanging gdb.
> 
> Tom> Fix this by handling self-referencing DIEs in the loop in
> Tom> inherit_abstract_dies.
> 
> I wonder if these have ever happened from compiler bugs, or only from
> hand-made tests.
> 
> Anyway, seems fine.  If we're ever worried about chains of inheritance
> that form loops, we can do some kind of tortoise/hare thing.

FTR, filed as https://sourceware.org/bugzilla/show_bug.cgi?id=30822 .

Thanks,
- Tom


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-09-04 11:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-28  6:36 [PATCH] [gdb/symtab] Handle self-reference in inherit_abstract_dies Tom de Vries
2023-08-28 14:11 ` Tom Tromey
2023-08-28 14:32   ` Tom de Vries
2023-09-04 11:47   ` Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).