Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch] DWARF-3+ DW_AT_accessibility defaults #2 (GCC PR debug/45124)
@ 2011-03-21 15:47 Jan Kratochvil
  2011-03-21 17:29 ` Tom Tromey
  2011-03-22 10:06 ` revert+new [patch]: " Jan Kratochvil
  0 siblings, 2 replies; 12+ messages in thread
From: Jan Kratochvil @ 2011-03-21 15:47 UTC (permalink / raw)
  To: gdb-patches

Hi,

this is a repost for:
	[patch] Fix DWARF-3+ DW_AT_accessibility default assumption
	http://sourceware.org/ml/gdb-patches/2011-01/msg00507.html
	Re: [patch] Fix DWARF-3+ DW_AT_accessibility default assumption
	http://sourceware.org/ml/gdb-patches/2011-03/msg00546.html
	revert: Re: [patch] Fix DWARF-3+ DW_AT_accessibility default assumption
	http://sourceware.org/ml/gdb-patches/2011-03/msg00586.html

	     FSF GDB HEAD:    former patch:    this patch:
	        dw-2 dw-3        dw-2 dw-3        dw-2 dw-3
	gcc-4.5 pass pass    4.5 pass FAIL    4.5 pass pass
	gcc-4.6 pass FAIL    4.6 pass pass    4.6 pass pass

	(set -x;for gcc in 45 46;do for dwarf in 2 3;do PATH="/your-gcc-dir/gcc${gcc}-root/bin:$PATH" runtest CXX_FOR_TARGET="g++ -gdwarf-${dwarf}" gdb.cp/casts.exp gdb.cp/classes.exp gdb.cp/virtfunc.exp gdb.mi/gdb792.exp gdb.python/py-value.exp ;done;done)

Normally it probably is not of much concern as FSF GCC defaults to -gdwarf-2
where no changes happen.  Just Fedoras+RHELs default to -gdwarf-3 where the
assumed defaults have changed, therefore proposing for FSF GDB to verify
DW_AT_producer - it affects even FSF GCCs when one uses -gdwarf-3 or -gdwarf-4.

Due to the mess I did before waiting for a review.  I believe this fix should
be a gdb-7.3 blocker as gcc-4.6.0 will be released far before gdb-7.4.

I do not provide a special new testcase as the testcases already exist and a
gdb.dwarf2/ code would just carbon-copy the conditionals while it is more
important the conditionals match the real compilers behavior.


Thanks,
Jan


(set -ex;echo 'class C { public: int priv; } c;' | g++ -gdwarf-3 -c -g -o 1.o -x c++ -; readelf -wi 1.o)
old = no DW_AT_accessibility
new = DW_AT_accessibility: 1 (public)
old gcc-4.4.5-6.el6.x86_64     = GNU C++ 4.4.5 20110214 (Red Hat 4.4.5-6)    
old gcc-4.5.1-4.fc14.x86_64    = GNU C++ 4.5.1 20100924 (Red Hat 4.5.1-4)
new gcc-4.6.0-0.14.fc15.x86_64 = GNU C++ 4.6.0 20110318 (Red Hat 4.6.0-0.14)    
new GNU C++ 4.7.0 20110321 (experimental)    
new GNU C++ 4.6.0 20110321 (prerelease) 
old GNU C++ 4.5.3 20110321 (prerelease) 
XXX GNU C++ 4.4.6 20110321 (prerelease) [-gdwarf-3 not supported]


gdb/
2011-03-21  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2read.c (producer_is_gxx_lt_4_6): New function.
	(dwarf2_add_field): Fix new_field->accessibility for
	cu->header.version >= 3 while verifying also producer_is_gxx_lt_4_6.

--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -6209,6 +6209,27 @@ 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 hwile 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 (const char *producer)
+{
+  int major, minor;
+
+  /* Whitespaces are ignored in both PRODUCER and the format string.  */
+  if (sscanf (producer, "GNU C++ %d.%d", &major, &minor) != 2)
+    {
+      /* For non-GCC compilers expect their behavior is DWARF version
+	 compliant.  */
+
+      return 0;
+    }
+
+  return major < 4 || (major == 4 && minor < 6);
+}
+
 /* Add an aggregate field to the field list.  */
 
 static void
@@ -6239,13 +6260,28 @@ 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;
+  if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu->producer))
+    {
+      /* The default DWARF 2 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;
+    }
   else
-    new_field->accessibility = DW_ACCESS_private;
+    {
+      /* DWARF 3+ defines the default accessibility a different way - see
+	 below - than DWARF 2 has defined.  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)
+	new_field->accessibility = DW_ACCESS_private;
+      else
+	new_field->accessibility = DW_ACCESS_public;
+    }
   new_field->virtuality = DW_VIRTUALITY_none;
 
   attr = dwarf2_attr (die, DW_AT_accessibility, cu);


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

* Re: [patch] DWARF-3+ DW_AT_accessibility defaults #2 (GCC PR debug/45124)
  2011-03-21 15:47 [patch] DWARF-3+ DW_AT_accessibility defaults #2 (GCC PR debug/45124) Jan Kratochvil
@ 2011-03-21 17:29 ` Tom Tromey
  2011-03-21 20:15   ` Jan Kratochvil
  2011-03-22 10:06 ` revert+new [patch]: " Jan Kratochvil
  1 sibling, 1 reply; 12+ messages in thread
From: Tom Tromey @ 2011-03-21 17:29 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:

Jan> Normally it probably is not of much concern as FSF GCC defaults to
Jan> -gdwarf-2 where no changes happen.  Just Fedoras+RHELs default to
Jan> -gdwarf-3 where the assumed defaults have changed, therefore
Jan> proposing for FSF GDB to verify DW_AT_producer - it affects even
Jan> FSF GCCs when one uses -gdwarf-3 or -gdwarf-4.

I think this is ok.
I am not really a fan of producer checks, but I couldn't think of
anything better.

Tom


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

* Re: [patch] DWARF-3+ DW_AT_accessibility defaults #2 (GCC PR debug/45124)
  2011-03-21 17:29 ` Tom Tromey
@ 2011-03-21 20:15   ` Jan Kratochvil
  2011-03-21 20:41     ` Tom Tromey
  0 siblings, 1 reply; 12+ messages in thread
From: Jan Kratochvil @ 2011-03-21 20:15 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On Mon, 21 Mar 2011 17:53:43 +0100, Tom Tromey wrote:
> I think this is ok.

Checked in:
	http://sourceware.org/ml/gdb-cvs/2011-03/msg00258.html


> I am not really a fan of producer checks, but I couldn't think of
> anything better.

I was curious I haven't found any GCC/G++ DW_AT_producer check so far.


Thanks,
Jan


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

* Re: [patch] DWARF-3+ DW_AT_accessibility defaults #2 (GCC PR debug/45124)
  2011-03-21 20:15   ` Jan Kratochvil
@ 2011-03-21 20:41     ` Tom Tromey
  0 siblings, 0 replies; 12+ messages in thread
From: Tom Tromey @ 2011-03-21 20:41 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

Tom> I am not really a fan of producer checks, but I couldn't think of
Tom> anything better.

Jan> I was curious I haven't found any GCC/G++ DW_AT_producer check so far.

There are some but they are elsewhere -- see record_producer and then
users of the field that it sets.  Well, ok, I actually just found one,
in arm-tdep.c.

Tom


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

* revert+new [patch]: Re: [patch] DWARF-3+ DW_AT_accessibility defaults #2 (GCC PR debug/45124)
  2011-03-21 15:47 [patch] DWARF-3+ DW_AT_accessibility defaults #2 (GCC PR debug/45124) Jan Kratochvil
  2011-03-21 17:29 ` Tom Tromey
@ 2011-03-22 10:06 ` Jan Kratochvil
  2011-03-22 18:16   ` Tom Tromey
  1 sibling, 1 reply; 12+ messages in thread
From: Jan Kratochvil @ 2011-03-22 10:06 UTC (permalink / raw)
  To: gdb-patches

Hi,

there has been a crash regression for: gdb.dwarf2/dw4-sig-types.exp

The patch has been reverted:
	http://sourceware.org/ml/gdb-cvs/2011-03/msg00264.html

Filed now GCC PR debug/48229:
	DW_TAG_type_unit has no DW_AT_producer
	http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48229

The problem is gcc-4.5.x has wrong DWARF output (GCC PR debug/45124) and it
does not provide any DW_AT_producer.  Therefore proposing GDB would assume
gcc-4.5.x when it sees no DW_AT_producer.  Hopefully GCC is the only DWARF-4
DW_TAG_type_unit producer out there (is it?) and finally hopefully it is the
only DW_TAG_type_unit producer forgetting to output DW_AT_producer.  It would
be probably worth to wait on the resolution of GCC PR debug/48229 before
assuming its implications.

Not sure how I missed the regression, the baseline is a bit floating with
various recent regressions.


Sorry,
Jan


gdb/
2011-03-22  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2read.c (producer_is_gxx_lt_4_6): New function.
	(dwarf2_add_field): Fix new_field->accessibility for
	cu->header.version >= 3 while verifying also producer_is_gxx_lt_4_6.

--- gdb/dwarf2read.c	22 Mar 2011 09:50:42 -0000	1.512
+++ gdb/dwarf2read.c	22 Mar 2011 09:52:44 -0000
@@ -6209,6 +6209,45 @@ dwarf2_record_block_ranges (struct die_i
     }
 }
 
+/* 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)
+{
+  int major, minor;
+
+  if (cu->producer == NULL)
+    {
+      if (cu->per_cu->from_debug_types)
+	{
+	  /* Workaround GCC PR debug/48229 where DW_TAG_type_unit had no
+	     DW_AT_producer in G++ 4.5.x.  G++ 4.4.any could not produce
+	     DWARF-4 (and its DW_TAG_type_unit).  G++ 4.6.0 already provides
+	     DW_AT_producer for DW_TAG_type_unit.  */
+
+	  return 1;
+	}
+
+      /* For unknown compilers expect their behavior is DWARF version
+         compliant.  */
+
+      return 0;
+    }
+
+  /* Whitespaces are ignored in both PRODUCER and the format string.  */
+  if (sscanf (cu->producer, "GNU C++ %d.%d", &major, &minor) != 2)
+    {
+      /* For non-GCC compilers expect their behavior is DWARF version
+	 compliant.  */
+
+      return 0;
+    }
+
+  return major < 4 || (major == 4 && minor < 6);
+}
+
 /* Add an aggregate field to the field list.  */
 
 static void
@@ -6239,13 +6278,28 @@ dwarf2_add_field (struct field_info *fip
     }
   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;
+  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)
+	new_field->accessibility = DW_ACCESS_public;
+      else
+	new_field->accessibility = DW_ACCESS_private;
+    }
   else
-    new_field->accessibility = DW_ACCESS_private;
+    {
+      /* DWARF 3+ defines the default accessibility a different way - see
+	 below - than DWARF 2 has defined.  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)
+	new_field->accessibility = DW_ACCESS_private;
+      else
+	new_field->accessibility = DW_ACCESS_public;
+    }
   new_field->virtuality = DW_VIRTUALITY_none;
 
   attr = dwarf2_attr (die, DW_AT_accessibility, cu);



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

* Re: revert+new [patch]: Re: [patch] DWARF-3+ DW_AT_accessibility defaults #2 (GCC PR debug/45124)
  2011-03-22 10:06 ` revert+new [patch]: " Jan Kratochvil
@ 2011-03-22 18:16   ` Tom Tromey
  2011-03-22 18:32     ` Jan Kratochvil
  0 siblings, 1 reply; 12+ messages in thread
From: Tom Tromey @ 2011-03-22 18:16 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:

Jan> The problem is gcc-4.5.x has wrong DWARF output (GCC PR
Jan> debug/45124) and it does not provide any DW_AT_producer.  Therefore
Jan> proposing GDB would assume gcc-4.5.x when it sees no
Jan> DW_AT_producer.  Hopefully GCC is the only DWARF-4 DW_TAG_type_unit
Jan> producer out there (is it?) and finally hopefully it is the only
Jan> DW_TAG_type_unit producer forgetting to output DW_AT_producer.  It
Jan> would be probably worth to wait on the resolution of GCC PR
Jan> debug/48229 before assuming its implications.

I think this patch seems reasonable.

To be clear, this comment is documented what we hope will be true,
right?

+	  /* Workaround GCC PR debug/48229 where DW_TAG_type_unit had no
+	     DW_AT_producer in G++ 4.5.x.  G++ 4.4.any could not produce
+	     DWARF-4 (and its DW_TAG_type_unit).  G++ 4.6.0 already provides
+	     DW_AT_producer for DW_TAG_type_unit.  */

... since the bug is still open and, I guess, 4.6 snapshots don't emit
this.

Tom


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

* Re: revert+new [patch]: Re: [patch] DWARF-3+ DW_AT_accessibility defaults #2 (GCC PR debug/45124)
  2011-03-22 18:16   ` Tom Tromey
@ 2011-03-22 18:32     ` Jan Kratochvil
  2011-03-23  2:12       ` Dodji Seketeli
  2011-03-28 12:35       ` Jan Kratochvil
  0 siblings, 2 replies; 12+ messages in thread
From: Jan Kratochvil @ 2011-03-22 18:32 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches, Dodji Seketeli

On Tue, 22 Mar 2011 19:10:35 +0100, Tom Tromey wrote:
> To be clear, this comment is documented what we hope will be true,
> right?

Yes.

> +	  /* Workaround GCC PR debug/48229 where DW_TAG_type_unit had no
> +	     DW_AT_producer in G++ 4.5.x.  G++ 4.4.any could not produce
> +	     DWARF-4 (and its DW_TAG_type_unit).  G++ 4.6.0 already provides
> +	     DW_AT_producer for DW_TAG_type_unit.  */
> 
> ... since the bug is still open and, I guess, 4.6 snapshots don't emit
> this.

If GCC 4.6.0 GA still will not produce DW_AT_producer for DW_TAG_type_unit
there will be no way to distinguish what does DW_TAG_type_unit assume as
a default for DW_AT_accessibility.

Dodji, please GCC PR debug/48229 should really be committed for GCC 4.6.0.


Thanks,
Jan


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

* Re: revert+new [patch]: Re: [patch] DWARF-3+ DW_AT_accessibility defaults #2 (GCC PR debug/45124)
  2011-03-22 18:32     ` Jan Kratochvil
@ 2011-03-23  2:12       ` Dodji Seketeli
  2011-03-28 12:35       ` Jan Kratochvil
  1 sibling, 0 replies; 12+ messages in thread
From: Dodji Seketeli @ 2011-03-23  2:12 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Tom Tromey, gdb-patches

Jan Kratochvil <jan.kratochvil@redhat.com> writes:

> Dodji, please GCC PR debug/48229 should really be committed for GCC
> 4.6.0.

I will look into this.

-- 
		Dodji


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

* Re: [patch] DWARF-3+ DW_AT_accessibility defaults #2 (GCC PR debug/45124)
  2011-03-22 18:32     ` Jan Kratochvil
  2011-03-23  2:12       ` Dodji Seketeli
@ 2011-03-28 12:35       ` Jan Kratochvil
  2011-04-01 21:03         ` [patch] DWARF-3+ DW_AT_accessibility defaults #3 " Jan Kratochvil
  1 sibling, 1 reply; 12+ messages in thread
From: Jan Kratochvil @ 2011-03-28 12:35 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches, Dodji Seketeli

On Tue, 22 Mar 2011 19:16:20 +0100, Jan Kratochvil wrote:
> If GCC 4.6.0 GA still will not produce DW_AT_producer for DW_TAG_type_unit
> there will be no way to distinguish what does DW_TAG_type_unit assume as
> a default for DW_AT_accessibility.

which has happened now with 4.6.0 GA.

Posted now:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48229#c5

# It cannot work as GDB often looks up the type without any referrer from
# DW_TAG_compile_unit, such as during the `ptype' GDB command.  A draft patch
# thus has many regressions such as:
# -PASS: gdb.base/nofield.exp: ptype struct not_empty
# +FAIL: gdb.base/nofield.exp: ptype struct not_empty (GDB internal error)
# 
# This means GDB will have to start full read (like -readnow) of CUs till it
# finds some CU referencing the specific type to find its DW_AT_producer.  During
# scan of .debug_info for GDB partial symbols GDB currently skips over subtrees
# of DIEs which reference the type signature for performance reasons, it no
# longer can.
# 
# With .gdb_index there is no GDB partial symbols scan but .gdb_index also
# indexes types by their name and there is no referrer ever seen during the
# `ptype' GDB command.
# 
# So it means performance regression for non-.gdb_index case and a possible new
# extension/version of .gdb_index to handle it.

So any solution is not easy now.  While playing with it one should have:
	[patch] Fix -readnow for -gdwarf-4 unused type units
	http://sourceware.org/ml/gdb-patches/2011-03/msg01119.html


Thanks,
Jan


--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -446,6 +446,11 @@ struct dwarf2_per_cu_data
     /* Data needed by the "quick" functions.  */
     struct dwarf2_per_cu_quick_data *quick;
   } v;
+
+  /* Track the .debug_info CUs referring to .debug_types CUs, even
+     transitively.  If unknown it is NULL, otherwise it points to
+     a .debug_info CU.  */
+  struct dwarf2_per_cu_data *referrer;
 };
 
 /* Entry in the signatured_types hash table.  */
@@ -2446,8 +2451,22 @@ dw2_expand_all_symtabs (struct objfile *objfile)
 
   dw2_setup (objfile);
 
-  for (i = 0; i < (dwarf2_per_objfile->n_comp_units
-		   + dwarf2_per_objfile->n_type_comp_units); ++i)
+  /* N_TYPE_COMP_UNITS - .debug_types CUs - do not have to be read in as each
+     such PER_CU belongs into one of these cases:
+     (1) per_cu->referrer == NULL
+	 It is an unused DW_TAG_type_unit which no referrers.  Such unit
+	 cannot be read-in even just for a verification by OBJF_READNOW as
+	 producer_is_gxx_lt_4_6 would not know how to read it.
+     (2) per_cu->referrer->cu == NULL
+	 This DW_TAG_type_unit has been already read it before as a dependency
+	 for some DW_TAG_compile_unit.  producer_is_gxx_lt_4_6 would no longer
+	 know how to read it with DW_TAG_compile_unit no longer available.
+	 And also:
+     (3) per_cu->referrer->cu != NULL
+	 We can read this DW_TAG_type_unit but it would be read in the second
+	 time, there is no need to do so.  */
+
+  for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
     {
       struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
 
@@ -6216,6 +6235,83 @@ 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)
+{
+  int major, minor;
+
+  if (cu->producer == NULL && cu->per_cu->from_debug_types)
+    {
+      struct dwarf2_per_cu_data *referrer;
+
+      /* We may get to a .debug_types CU only through a pointer from
+	 a .debug_info CU.  .debug_types CUs without such pointer are skipped
+	 in dw2_expand_all_symtabs.  */
+      referrer = cu->per_cu->referrer;
+      gdb_assert (referrer != NULL);
+
+      /* On a second and further referrer the first referrer stored in
+	 referrer may have its CU already freed.  But that time
+	 DEBUG_TYPES_TYPE_HASH is used to look up the type and the
+	 .debug_types CU is not read in the second time at all.  */
+      gdb_assert (referrer->cu != NULL);
+
+      cu = referrer->cu;
+    }
+
+  if (cu->producer == NULL)
+    {
+      /* For unknown compilers expect their behavior is DWARF version
+         compliant.  */
+
+      return 0;
+    }
+
+  /* Whitespaces are ignored in both PRODUCER and the format string.  */
+  if (sscanf (cu->producer, "GNU C++ %d.%d", &major, &minor) != 2)
+    {
+      /* For non-GCC compilers expect their behavior is DWARF version
+	 compliant.  */
+
+      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
@@ -6246,23 +6342,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;
 
@@ -6578,6 +6670,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"));
@@ -6676,16 +6769,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.  */
@@ -13254,6 +13348,17 @@ static int
 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
 		       struct dwarf2_per_cu_data *per_cu)
 {
+  /* Try to fill-in referrer for .debug_types CUs.  While
+     THIS_CU->CU may become NULL soon it should be already processed by
+     producer_is_gxx_lt_4_6 that time.  */
+  if (per_cu->from_debug_types && per_cu->referrer == NULL)
+    {
+      if (!this_cu->per_cu->from_debug_types)
+	per_cu->referrer = this_cu->per_cu;
+      else
+	per_cu->referrer = this_cu->per_cu->referrer;
+    }
+
   /* We may arrive here during partial symbol reading, if we need full
      DIEs to process an unusual case (e.g. template arguments).  Do
      not queue PER_CU, just tell our caller to load its DIEs.  */


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

* [patch] DWARF-3+ DW_AT_accessibility defaults #3 (GCC PR debug/45124)
  2011-03-28 12:35       ` Jan Kratochvil
@ 2011-04-01 21:03         ` Jan Kratochvil
  2011-04-03 16:28           ` Jan Kratochvil
  2011-04-09 11:21           ` [commit]+[brach commit] " Jan Kratochvil
  0 siblings, 2 replies; 12+ messages in thread
From: Jan Kratochvil @ 2011-04-01 21:03 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey, Dodji Seketeli

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.  */


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

* Re: [patch] DWARF-3+ DW_AT_accessibility defaults #3 (GCC PR debug/45124)
  2011-04-01 21:03         ` [patch] DWARF-3+ DW_AT_accessibility defaults #3 " Jan Kratochvil
@ 2011-04-03 16:28           ` Jan Kratochvil
  2011-04-09 11:21           ` [commit]+[brach commit] " Jan Kratochvil
  1 sibling, 0 replies; 12+ messages in thread
From: Jan Kratochvil @ 2011-04-03 16:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey, Dodji Seketeli

Hi,

the table lied about gcc-4.4.fsf -gdwarf-3 and gcc-4.4.fsf -gdwarf-4.
Such mode is not supported at all (I wrote there "pass"), the results were
missing in the grep output as the testcase compilation had failed and I did
not notice it.  The table really was not made up.


Jan


On Fri, 01 Apr 2011 23:03:45 +0200, Jan Kratochvil wrote:
FSF GDB HEAD without the patch:
             -gdwarf-2 -gdwarf-3 -gdwarf-4
gcc-4.4.fsf  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
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


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

* [commit]+[brach commit] DWARF-3+ DW_AT_accessibility defaults #3 (GCC PR debug/45124)
  2011-04-01 21:03         ` [patch] DWARF-3+ DW_AT_accessibility defaults #3 " Jan Kratochvil
  2011-04-03 16:28           ` Jan Kratochvil
@ 2011-04-09 11:21           ` Jan Kratochvil
  1 sibling, 0 replies; 12+ messages in thread
From: Jan Kratochvil @ 2011-04-09 11:21 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey, Dodji Seketeli, Joel Brobecker

On Fri, 01 Apr 2011 23:03:45 +0200, Jan Kratochvil wrote:
> 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).
[...]
> 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.

Checked it on HEAD and on 7.3:
	http://sourceware.org/ml/gdb-cvs/2011-04/msg00059.html
	http://sourceware.org/ml/gdb-cvs/2011-04/msg00060.html

The 7.3 check in seems to me pre-approved as present on:
	http://sourceware.org/gdb/wiki/GDB_7.3_Release


Thanks,
Jan


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

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

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-21 15:47 [patch] DWARF-3+ DW_AT_accessibility defaults #2 (GCC PR debug/45124) Jan Kratochvil
2011-03-21 17:29 ` Tom Tromey
2011-03-21 20:15   ` Jan Kratochvil
2011-03-21 20:41     ` Tom Tromey
2011-03-22 10:06 ` revert+new [patch]: " Jan Kratochvil
2011-03-22 18:16   ` Tom Tromey
2011-03-22 18:32     ` Jan Kratochvil
2011-03-23  2:12       ` Dodji Seketeli
2011-03-28 12:35       ` Jan Kratochvil
2011-04-01 21:03         ` [patch] DWARF-3+ DW_AT_accessibility defaults #3 " Jan Kratochvil
2011-04-03 16:28           ` Jan Kratochvil
2011-04-09 11:21           ` [commit]+[brach commit] " Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox