This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] dwarf2read.c (read_typedef): Guard against self-referential typedefs.


Hi.

I was playing with a version of GCC that emitted self-referential typedefs.
E.g., readelf -w showed:

 <1><70>: Abbrev Number: 5 (DW_TAG_typedef)
    <71>   DW_AT_name        : T	
    <73>   DW_AT_decl_file   : 1	
    <74>   DW_AT_decl_line   : 5	
    <75>   DW_AT_type        : <0x70>	


This put check_typedef into an infinite loop.
I will check this in in a few days if there are no objections.

2011-12-27  Doug Evans  <dje@google.com>

	* dwarf2read.c (read_typedef): Guard against self-referential typedefs.

Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.588
diff -u -p -r1.588 dwarf2read.c
--- dwarf2read.c	27 Dec 2011 23:41:59 -0000	1.588
+++ dwarf2read.c	28 Dec 2011 00:01:56 -0000
@@ -8836,14 +8836,26 @@ read_typedef (struct die_info *die, stru
 {
   struct objfile *objfile = cu->objfile;
   const char *name = NULL;
-  struct type *this_type;
+  struct type *this_type, *target_type;
 
   name = dwarf2_full_name (NULL, die, cu);
   this_type = init_type (TYPE_CODE_TYPEDEF, 0,
 			 TYPE_FLAG_TARGET_STUB, NULL, objfile);
   TYPE_NAME (this_type) = (char *) name;
   set_die_type (die, this_type, cu);
-  TYPE_TARGET_TYPE (this_type) = die_type (die, cu);
+  target_type = die_type (die, cu);
+  if (target_type != this_type)
+    TYPE_TARGET_TYPE (this_type) = target_type;
+  else
+    {
+      /* Self-referential typedefs are, it seems, not allowed by the DWARF
+	 spec and cause infinite loops in GDB.  */
+      complaint (&symfile_complaints,
+		 _("Self-referential DW_TAG_typedef "
+		   "- DIE at 0x%x [in module %s]"),
+		 die->offset, cu->objfile->name);
+      TYPE_TARGET_TYPE (this_type) = NULL;
+    }
   return this_type;
 }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]