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] DWARF-3+ DW_AT_accessibility defaults #3 (GCC PR debug/45124)


Hi,

so here is a patch which works for everything but regresses gcc-4.5.x
-gdwarf-4, as suggested/allowed by Jakub:
	http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48229#c6

As it has been regression tested enough I will check it in in some time (and
definitely for gdb-7.3).

FSF GDB HEAD without the patch:
             -gdwarf-2 -gdwarf-3 -gdwarf-4
gcc-4.4.fsf  pass      pass      pass
gcc-4.5.fsf  pass      pass      PASS
gcc-4.6.fsf  pass      FAIL      FAIL
gcc-4.7.fsf  pass      FAIL      FAIL
gcc-4.4.fc13           pass
gcc-4.5.fc14           pass
gcc-4.6.fc15           FAIL

FSF GDB HEAD with the patch:
             -gdwarf-2 -gdwarf-3 -gdwarf-4
gcc-4.4.fsf  pass      pass      pass
gcc-4.5.fsf  pass      pass      FAIL
gcc-4.6.fsf  pass      PASS      PASS
gcc-4.7.fsf  pass      PASS      PASS
gcc-4.4.fc13           pass
gcc-4.5.fc14           pass
gcc-4.6.fc15           PASS

GNU gdb (GDB) 7.2.50.20110401-cvs
gcc (GCC) 4.4.6 20110401 (prerelease)
gcc (GCC) 4.5.3 20110401 (prerelease)
gcc (GCC) 4.6.1 20110401 (prerelease)
gcc (GCC) 4.7.0 20110401 (experimental)
gcc-4.4.5-2.fc13
gcc-4.5.1-4.fc14
gcc-4.6.0-0.15.fc15

Only x86_64 host was being tested, the results match for both the default arch
(-m64) and for explicit -m32 arch.

DW_AT_accessibility affects also class's typedefs, these are implemented in
GCCs but not in GDB (GDB PR c++/11757).

The regression for gcc-4.5.x -gdwarf-3 could be fixed in the next gcc-4.5.x
release but no such fix exists now for the filed GCC PR debug/48229.

FSF GCCs default to -gdwarf-2; but they always had an explicit -gdwarf-*
parameter under this test.

Fedora notes:
Fedora GCCs were tested only without any -gdwarf-* parameter, Fedora GCCs
default to -gdwarf-3.  Fedora GDB was not tested for this mail at all.


Thanks,
Jan


gdb/
2011-04-01  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2read.c: Include ctype.h.
	(producer_is_gxx_lt_4_6, dwarf2_default_access_attribute): New
	functions.
	(dwarf2_add_field): Fix new_field->accessibility by calling
	dwarf2_default_access_attribute.  Restructure setting accessibility
	vs. virtuality.
	(dwarf2_add_member_fn): New variable accessibility.  Fix fnp
	is_private and is_protected by calling
	dwarf2_default_access_attribute.

--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -57,6 +57,7 @@
 #include "vec.h"
 #include "c-lang.h"
 #include "valprint.h"
+#include <ctype.h>
 
 #include <fcntl.h>
 #include "gdb_string.h"
@@ -6209,6 +6210,81 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
     }
 }
 
+/* Check for GCC PR debug/45124 fix which is not present in any G++ version up
+   to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
+   during 4.6.0 experimental.  */
+
+static int
+producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
+{
+  const char *cs;
+  int major, minor, release;
+
+  if (cu->producer == NULL)
+    {
+      /* For unknown compilers expect their behavior is DWARF version
+	 compliant.
+
+	 GCC started to support .debug_types sections by -gdwarf-4 since
+	 gcc-4.5.x.  As the .debug_types sections are missing DW_AT_producer
+	 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
+	 combination.  gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
+	 interpreted incorrectly by GDB now - GCC PR debug/48229.  */
+
+      return 0;
+    }
+
+  /* Skip any identifier after "GNU " - such as "C++" or "Java".  */
+
+  if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0)
+    {
+      /* For non-GCC compilers expect their behavior is DWARF version
+	 compliant.  */
+
+      return 0;
+    }
+  cs = &cu->producer[strlen ("GNU ")];
+  while (*cs && !isdigit (*cs))
+    cs++;
+  if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3)
+    {
+      /* Not recognized as GCC.  */
+
+      return 0;
+    }
+
+  return major < 4 || (major == 4 && minor < 6);
+}
+
+/* Return the default accessibility type if it is not overriden by
+   DW_AT_accessibility.  */
+
+static enum dwarf_access_attribute
+dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
+{
+  if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
+    {
+      /* The default DWARF 2 accessibility for members is public, the default
+	 accessibility for inheritance is private.  */
+
+      if (die->tag != DW_TAG_inheritance)
+	return DW_ACCESS_public;
+      else
+	return DW_ACCESS_private;
+    }
+  else
+    {
+      /* DWARF 3+ defines the default accessibility a different way.  The same
+	 rules apply now for DW_TAG_inheritance as for the members and it only
+	 depends on the container kind.  */
+
+      if (die->parent->tag == DW_TAG_class_type)
+	return DW_ACCESS_private;
+      else
+	return DW_ACCESS_public;
+    }
+}
+
 /* Add an aggregate field to the field list.  */
 
 static void
@@ -6239,23 +6315,19 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
     }
   fip->nfields++;
 
-  /* Handle accessibility and virtuality of field.
-     The default accessibility for members is public, the default
-     accessibility for inheritance is private.  */
-  if (die->tag != DW_TAG_inheritance)
-    new_field->accessibility = DW_ACCESS_public;
-  else
-    new_field->accessibility = DW_ACCESS_private;
-  new_field->virtuality = DW_VIRTUALITY_none;
-
   attr = dwarf2_attr (die, DW_AT_accessibility, cu);
   if (attr)
     new_field->accessibility = DW_UNSND (attr);
+  else
+    new_field->accessibility = dwarf2_default_access_attribute (die, cu);
   if (new_field->accessibility != DW_ACCESS_public)
     fip->non_public_fields = 1;
+
   attr = dwarf2_attr (die, DW_AT_virtuality, cu);
   if (attr)
     new_field->virtuality = DW_UNSND (attr);
+  else
+    new_field->virtuality = DW_VIRTUALITY_none;
 
   fp = &new_field->field;
 
@@ -6571,6 +6643,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
   char *fieldname;
   struct nextfnfield *new_fnfield;
   struct type *this_type;
+  enum dwarf_access_attribute accessibility;
 
   if (cu->language == language_ada)
     error (_("unexpected member function in Ada type"));
@@ -6669,16 +6742,17 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
   /* Get accessibility.  */
   attr = dwarf2_attr (die, DW_AT_accessibility, cu);
   if (attr)
+    accessibility = DW_UNSND (attr);
+  else
+    accessibility = dwarf2_default_access_attribute (die, cu);
+  switch (accessibility)
     {
-      switch (DW_UNSND (attr))
-	{
-	case DW_ACCESS_private:
-	  fnp->is_private = 1;
-	  break;
-	case DW_ACCESS_protected:
-	  fnp->is_protected = 1;
-	  break;
-	}
+    case DW_ACCESS_private:
+      fnp->is_private = 1;
+      break;
+    case DW_ACCESS_protected:
+      fnp->is_protected = 1;
+      break;
     }
 
   /* Check for artificial methods.  */


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