diff mbox

Fix up DW_AT_accessibility (PR debug/45124)

Message ID 20100729171246.GJ18378@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek July 29, 2010, 5:12 p.m. UTC
Hi!

On Thu, Jul 29, 2010 at 10:11:13AM -0600, Tom Tromey wrote:
> >>>>> "Jason" == Jason Merrill <jason@redhat.com> writes:
> 
> Jakub> For compatibility with GDB, I believe all we can do is add more
> Jakub> DW_AT_accessibility attributes and keep emitting where we were
> Jakub> (uselessly) emitting before.
> 
> Jason> Is that really necessary?  What does GDB do with these attributes?
> 
> I believe GDB only uses them when printing, to show the accessibility of
> fields in a type.

In that case it is probably just better to follow the standard (after
confirming on dwarf-discuss).
It is a little bit more complicated though, because it appears DWARF2 is
incompatible in this with DWARF3+ (in DWARF2 it says DW_TAG_inheritance
has DW_ACCESS_private default unconditionally).

2010-07-29  Jakub Jelinek  <jakub@redhat.com>

	PR debug/45124
	* dwarf2out.c (add_accessibility_attribute): Assume
	DW_ACCESS_private as the default for dwarf_version > 2
	and DW_TAG_class_type parent.
	(gen_inheritance_die): Assume DW_ACCESS_public as the default
	for dwarf_version > 2 and parent other than DW_TAG_class_type.



	Jakub

Comments

Jason Merrill July 29, 2010, 5:13 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

--- gcc/dwarf2out.c.jj	2010-07-29 18:55:48.663604621 +0200
+++ gcc/dwarf2out.c	2010-07-29 19:05:20.946228742 +0200
@@ -15832,10 +15832,22 @@  add_AT_location_description (dw_die_ref 
 static void
 add_accessibility_attribute (dw_die_ref die, tree decl)
 {
+  /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
+     children, otherwise the default is DW_ACCESS_public.  In DWARF2
+     the default has always been DW_ACCESS_public.  */
   if (TREE_PROTECTED (decl))
     add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
   else if (TREE_PRIVATE (decl))
-    add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
+    {
+      if (dwarf_version == 2
+	  || die->die_parent == NULL
+	  || die->die_parent->die_tag != DW_TAG_class_type)
+	add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
+    }
+  else if (dwarf_version > 2
+	   && die->die_parent
+	   && die->die_parent->die_tag == DW_TAG_class_type)
+    add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
 }
 
 /* Attach the specialized form of location attribute used for data members of
@@ -19552,10 +19564,20 @@  gen_inheritance_die (tree binfo, tree ac
   if (BINFO_VIRTUAL_P (binfo))
     add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
 
+  /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
+     children, otherwise the default is DW_ACCESS_public.  In DWARF2
+     the default has always been DW_ACCESS_private.  */
   if (access == access_public_node)
-    add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
+    {
+      if (dwarf_version == 2
+	  || context_die->die_tag == DW_TAG_class_type)
+      add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
+    }
   else if (access == access_protected_node)
     add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
+  else if (dwarf_version > 2
+	   && context_die->die_tag != DW_TAG_class_type)
+    add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
 }
 
 /* Generate a DIE for a class member.  */