[debug-early] handle objects containing variable-length members
diff mbox

Message ID 55281589.9010209@redhat.com
State New
Headers show

Commit Message

Aldy Hernandez April 10, 2015, 6:25 p.m. UTC
The attached patch handles late dwarf annotations to objects containing 
variable-length members.  It fixes the following regressions in the gdb 
testsuite:

 > FAIL: gdb.base/vla-datatypes.exp: print vla_struct_object
 > FAIL: gdb.base/vla-datatypes.exp: print vla_union_object
 > FAIL: gdb.base/vla-datatypes.exp: ptype vla_struct_object
 > FAIL: gdb.base/vla-datatypes.exp: ptype vla_union_object
 > FAIL: gdb.base/vla-datatypes.exp: size of vla_struct_object
 > FAIL: gdb.base/vla-datatypes.exp: size of vla_union_object

I am not convinced this is the last patch to variable-length variables, 
so it may require further refining, but it does get us down to ZERO gdb 
regressions which is A Good Thing (TM).

The only differences I see for trunk and the debug-early branch wrt gdb 
regressions are:

< KFAIL: gdb.cp/oranking.exp: p foo4(&a) (PRMS: gdb/12098)
---
 > KPASS: gdb.cp/oranking.exp: p foo4(&a) (PRMS gdb/12098)
20065c20065
< KFAIL: gdb.cp/oranking.exp: p foo101("abc") (PRMS: gdb/12098)
---
 > KPASS: gdb.cp/oranking.exp: p foo101("abc") (PRMS gdb/12098)
28222c28222

Plus some noise regarding threads.

I don't know what KFAIL/KPASS are, having lived in GCC land too long, 
but I will take a look at those next.

Committed to branch.
Aldy
commit b7cc4054654591a53e7dcc6a33f1ec35a3c5a7f9
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Fri Apr 10 11:16:46 2015 -0700

    Handle late dwarf annotations to objects containing variable-length
    members.

Comments

Mike Stump April 11, 2015, 5:06 a.m. UTC | #1
On Apr 10, 2015, at 11:25 AM, Aldy Hernandez <aldyh@redhat.com> wrote:
> < KFAIL: gdb.cp/oranking.exp: p foo4(&a) (PRMS: gdb/12098)
> ---
> > KPASS: gdb.cp/oranking.exp: p foo4(&a) (PRMS gdb/12098)
> 20065c20065
> < KFAIL: gdb.cp/oranking.exp: p foo101("abc") (PRMS: gdb/12098)
> ---
> > KPASS: gdb.cp/oranking.exp: p foo101("abc") (PRMS gdb/12098)
> 28222c28222
> 
> Plus some noise regarding threads.
> 
> I don't know what KFAIL/KPASS are, having lived in GCC land too long, but I will take a look at those next.

Known pass, known fail.  These are tied to the named PR in the gdb database.  As they are fixed, likely those bugs should be updated to reflect the improvement in gcc, but see the gdb folks for how to do that.

Patch
diff mbox

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 1928846..0976415 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -20470,6 +20470,16 @@  static void
 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
 				enum debug_info_usage usage)
 {
+  /* Fill in the size of variable lengthed fields in late dwarf.  */
+  if (TREE_ASM_WRITTEN (type)
+      && !early_dwarf_dumping)
+    {
+      tree member;
+      for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
+	fill_variable_array_bounds (TREE_TYPE (member));
+      return;
+    }
+
   dw_die_ref type_die = lookup_type_die (type);
   dw_die_ref scope_die = 0;
   int nested = 0;
@@ -20676,13 +20686,15 @@  gen_tagged_type_die (tree type,
       || !is_tagged_type (type))
     return;
 
+  if (TREE_ASM_WRITTEN (type))
+    need_pop = 0;
   /* If this is a nested type whose containing class hasn't been written
      out yet, writing it out will cover this one, too.  This does not apply
      to instantiations of member class templates; they need to be added to
      the containing class as they are generated.  FIXME: This hurts the
      idea of combining type decls from multiple TUs, since we can't predict
      what set of template instantiations we'll get.  */
-  if (TYPE_CONTEXT (type)
+  else if (TYPE_CONTEXT (type)
       && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
       && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
     {
@@ -20810,11 +20822,14 @@  gen_type_die_with_usage (tree type, dw_die_ref context_die,
 
   if (TREE_ASM_WRITTEN (type))
     {
-      /* Variabled-lengthed types may be incomplete even if
+      /* Variable-length types may be incomplete even if
 	 TREE_ASM_WRITTEN.  For such types, fall through to
 	 gen_array_type_die() and possibly fill in
 	 DW_AT_{upper,lower}_bound attributes.  */
-      if (TREE_CODE (type) != ARRAY_TYPE
+      if ((TREE_CODE (type) != ARRAY_TYPE
+	   && TREE_CODE (type) != RECORD_TYPE
+	   && TREE_CODE (type) != UNION_TYPE
+	   && TREE_CODE (type) != QUAL_UNION_TYPE)
 	  || (TYPE_SIZE (type)
 	      && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST))
 	return;
@@ -20870,9 +20885,6 @@  gen_type_die_with_usage (tree type, dw_die_ref context_die,
       break;
 
     case ARRAY_TYPE:
-      gen_array_type_die (type, context_die);
-      break;
-
     case VECTOR_TYPE:
       gen_array_type_die (type, context_die);
       break;