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]

[rfc] Work around buggy GCC 4.1 namespace dwarf info (GCC PR c++/28460)


Hello,

since recent patches to improve C++ namespace support went in, I'm seeing
large numbers (>150) of C++ test case failures.  It turns out that these
were caused by a bug in G++ 4.1 (GCC PR c++/28460) that generates bogus
DW_TAG_namespace DIEs for the global namespace.

With current GDB these bogus DIEs have the effect that the debugger will
no longer have debug info for any global variable.  This seriously affects
debugging capabilities ...

While the bug is indeed in GCC rather than GDB (and has long since been
fixed), I'm wondering whether it would still make sense for us to work
around the problem, because:
- GCC 4.1 is still in widespread use (e.g. as system compiler in RHEL 5.x
  and SLES 10).
- The impact of the bug seriously affects debugging with current
  mainline GDB.

Note that there is precendent for working around buggy GCC debug info
generation in serious cases already ...

The following patch works around the problem for me.
Tested on powerpc-linux, fixes (most) C++ test case failures.

Any comments?  Does anybody see a simpler way to work around the problem?

Bye,
Ulrich

  
ChangeLog:

	* dwarf2read.c (partial_die_parent_scope): Work around buggy
	GCC 4.1 debug info generation (GCC PR c++/28460).
	(determine_prefix): Likewise.


Index: gdb/dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.370
diff -u -p -r1.370 dwarf2read.c
--- gdb/dwarf2read.c	17 Mar 2010 19:16:02 -0000	1.370
+++ gdb/dwarf2read.c	18 Mar 2010 19:26:51 -0000
@@ -2307,6 +2307,19 @@ partial_die_parent_scope (struct partial
 
   grandparent_scope = partial_die_parent_scope (parent, cu);
 
+  /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
+     DW_TAG_namespace DIEs with a name of "::" for the global namespace.
+     Work around this problem here.  */
+  if (cu->language == language_cplus
+      && parent->tag == DW_TAG_namespace 
+      && strcmp (parent->name, "::") == 0
+      && grandparent_scope == NULL)
+    {
+      parent->scope = NULL;
+      parent->scope_set = 1;
+      return NULL;
+    }
+
   if (parent->tag == DW_TAG_namespace
       || parent->tag == DW_TAG_structure_type
       || parent->tag == DW_TAG_class_type
@@ -9012,6 +9025,12 @@ determine_prefix (struct die_info *die, 
       {
       case DW_TAG_namespace:
 	parent_type = read_type_die (parent, cu);
+	/* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
+	   DW_TAG_namespace DIEs with a name of "::" for the global namespace.
+	   Work around this problem here.  */
+	if (cu->language == language_cplus
+	    && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
+	  return "";
 	/* We give a name to even anonymous namespaces.  */
 	return TYPE_TAG_NAME (parent_type);
       case DW_TAG_class_type:
-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


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