diff mbox

[debug] Introduce -fno-debug-types-section flag

Message ID 1301394032.24103.11.camel@springer.wildebeest.org
State New
Headers show

Commit Message

Mark Wielaard March 29, 2011, 10:20 a.m. UTC
Hi,

Some dwarf consumers (dwarves, systemtap and dwarflint) grok Dwarf V4,
but not yet the new .debug_types section. To make it easier to use these
tools with -gdwarf-4 this patch introduces a new
-fno-debug-types-section flag and guards all code that is type unit
specific with use_debug_types instead of a generic dwarf_version >= 4
flag. IMHO this makes the code also slightly more readable. And it
re-enables the usage of -feliminate-dwarf2-dups with -gdwarf-4. Although
admittedly the value of that is probably pretty low. I found it helpful
in debugging some issues with dwarf consumers and DW_FORM_ref_addr
usage.

2011-03-29  Mark Wielaard  <mjw@redhat.com>

    * common.opt (fdebug-types-section): New flag.
    * doc/invoke.texi: Document new -fno-debug-types-section flag.
    * dwarf2out.c (use_debug_types): New define.
    (struct die_struct): Mark die_id with GTY desc use_debug_types.
    (print_die): Guard output of type unit signatures using
    use_debug_types.
    (build_abbrev_table): Replace assert of dwarf_version >= 4
    with assert on use_debug_types.
    (size_of_die): Likewise.
    (unmark_dies): Likewise.
    (value_format): Decide AT_ref_external form on use_debug_types.
    (output_die): Replace dwarf_version version check guard with
    use_debug_types where appropriate.
    (modified_type_die): Likewise.
    (gen_reference_type_die): Likewise.
    (dwarf2out_start_source_file): Likewise.
    (dwarf2out_end_source_file): Likewise.
    (prune_unused_types_walk_attribs): Likewise.
    (dwarf2out_finish): Likewise.

Bootstrapped on x86_64 GNU/Linux, no regressions.

Thanks,

Mark

Comments

Cary Coutant March 29, 2011, 6:04 p.m. UTC | #1
> Some dwarf consumers (dwarves, systemtap and dwarflint) grok Dwarf V4,
> but not yet the new .debug_types section. To make it easier to use these
> tools with -gdwarf-4 this patch introduces a new
> -fno-debug-types-section flag and guards all code that is type unit
> specific with use_debug_types instead of a generic dwarf_version >= 4
> flag. IMHO this makes the code also slightly more readable. And it
> re-enables the usage of -feliminate-dwarf2-dups with -gdwarf-4. Although
> admittedly the value of that is probably pretty low. I found it helpful
> in debugging some issues with dwarf consumers and DW_FORM_ref_addr
> usage.

I can't approve the patch, but I think it's a good option to have and
the patch looks good to me.

-cary
Richard Henderson March 30, 2011, 5:32 p.m. UTC | #2
On 03/29/2011 03:20 AM, Mark Wielaard wrote:
> 2011-03-29  Mark Wielaard  <mjw@redhat.com>
> 
>     * common.opt (fdebug-types-section): New flag.
>     * doc/invoke.texi: Document new -fno-debug-types-section flag.
>     * dwarf2out.c (use_debug_types): New define.
>     (struct die_struct): Mark die_id with GTY desc use_debug_types.
>     (print_die): Guard output of type unit signatures using
>     use_debug_types.
>     (build_abbrev_table): Replace assert of dwarf_version >= 4
>     with assert on use_debug_types.
>     (size_of_die): Likewise.
>     (unmark_dies): Likewise.
>     (value_format): Decide AT_ref_external form on use_debug_types.
>     (output_die): Replace dwarf_version version check guard with
>     use_debug_types where appropriate.
>     (modified_type_die): Likewise.
>     (gen_reference_type_die): Likewise.
>     (dwarf2out_start_source_file): Likewise.
>     (dwarf2out_end_source_file): Likewise.
>     (prune_unused_types_walk_attribs): Likewise.
>     (dwarf2out_finish): Likewise.
> 

Ok.


r~
diff mbox

Patch

diff --git a/gcc/common.opt b/gcc/common.opt
index 88ae101..213645c 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1012,6 +1012,10 @@  femit-class-debug-always
 Common Report Var(flag_emit_class_debug_always) Init(0)
 Do not suppress C++ class debug information.
 
+fdebug-types-section
+Common Report Var(flag_debug_types_section) Init(1)
+Output .debug_types section when using DWARF v4 debuginfo.
+
 fexceptions
 Common Report Var(flag_exceptions) Optimization
 Enable exception handling
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 85bf2b4..928e322 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -312,7 +312,8 @@  Objective-C and Objective-C++ Dialects}.
 -fdump-final-insns=@var{file} @gol
 -fcompare-debug@r{[}=@var{opts}@r{]}  -fcompare-debug-second @gol
 -feliminate-dwarf2-dups -feliminate-unused-debug-types @gol
--feliminate-unused-debug-symbols -femit-class-debug-always @gol
+-feliminate-unused-debug-symbols -femit-class-debug-always
+-fdebug-types-section @gol
 -fmem-report -fpre-ipa-mem-report -fpost-ipa-mem-report -fprofile-arcs @gol
 -frandom-seed=@var{string} -fsched-verbose=@var{n} @gol
 -fsel-sched-verbose -fsel-sched-dump-cfg -fsel-sched-pipelining-verbose @gol
@@ -4585,6 +4586,15 @@  normally emits debugging information for classes because using this
 option will increase the size of debugging information by as much as a
 factor of two.
 
+@item -fno-debug-types-section
+@opindex fno-types-section
+@opindex ftypes-section
+By default when using Dwarf v4 or higher type DIEs will be put into
+their own .debug_types section instead of making them part of the
+.debug_info section.  It is more efficient to put them in a separate
+comdat sections since the linker will then be able to remove duplicates.
+But not all dwarf consumers support .debug_types sections yet.
+
 @item -gstabs+
 @opindex gstabs+
 Produce debugging information in stabs format (if that is supported),
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 7803ab7..6e80a0b 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -5795,6 +5795,16 @@  const struct gcc_debug_hooks dwarf2_debug_hooks =
    representation is done after the entire program has been compiled.
    The types below are used to describe the internal representation.  */
 
+/* Whether to put type DIEs into their own section .debug_types instead
+   of making them part of the .debug_info section.  Only supported for
+   Dwarf V4 or higher and the user didn't disable them through
+   -fno-debug-types-section.  It is more efficient to put them in a
+   separate comdat sections since the linker will then be able to
+   remove duplicates.  But not all tools support .debug_types sections
+   yet.  */
+
+#define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
+
 /* Various DIE's use offsets relative to the beginning of the
    .debug_info section to refer to each other.  */
 
@@ -5853,7 +5863,7 @@  typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
       char * GTY ((tag ("0"))) die_symbol;
       comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
     }
-  GTY ((desc ("dwarf_version >= 4"))) die_id;
+  GTY ((desc ("use_debug_types"))) die_id;
   VEC(dw_attr_node,gc) * die_attr;
   dw_die_ref die_parent;
   dw_die_ref die_child;
@@ -8524,7 +8534,7 @@  print_die (dw_die_ref die, FILE *outfile)
   fprintf (outfile, " offset: %ld", die->die_offset);
   fprintf (outfile, " mark: %d\n", die->die_mark);
 
-  if (dwarf_version >= 4 && die->die_id.die_type_node)
+  if (use_debug_types && die->die_id.die_type_node)
     {
       print_spaces (outfile);
       fprintf (outfile, "  signature: ");
@@ -8576,13 +8586,13 @@  print_die (dw_die_ref die, FILE *outfile)
 	case dw_val_class_die_ref:
 	  if (AT_ref (a) != NULL)
 	    {
-	      if (dwarf_version >= 4 && AT_ref (a)->die_id.die_type_node)
+	      if (use_debug_types && AT_ref (a)->die_id.die_type_node)
 	        {
 		  fprintf (outfile, "die -> signature: ");
 		  print_signature (outfile,
 		  		   AT_ref (a)->die_id.die_type_node->signature);
                 }
-	      else if (dwarf_version < 4 && AT_ref (a)->die_id.die_symbol)
+	      else if (! use_debug_types && AT_ref (a)->die_id.die_symbol)
 		fprintf (outfile, "die -> label: %s",
 		         AT_ref (a)->die_id.die_symbol);
 	      else
@@ -10539,7 +10549,7 @@  build_abbrev_table (dw_die_ref die)
     if (AT_class (a) == dw_val_class_die_ref
 	&& AT_ref (a)->die_mark == 0)
       {
-	gcc_assert (dwarf_version >= 4 || AT_ref (a)->die_id.die_symbol);
+	gcc_assert (use_debug_types || AT_ref (a)->die_id.die_symbol);
 	set_AT_ref_external (a, 1);
       }
 
@@ -10687,7 +10697,7 @@  size_of_die (dw_die_ref die)
 		 we use DW_FORM_ref_addr.  In DWARF2, DW_FORM_ref_addr
 		 is sized by target address length, whereas in DWARF3
 		 it's always sized as an offset.  */
-	      if (dwarf_version >= 4)
+	      if (use_debug_types)
 		size += DWARF_TYPE_SIGNATURE_SIZE;
 	      else if (dwarf_version == 2)
 		size += DWARF2_ADDR_SIZE;
@@ -10773,7 +10783,7 @@  unmark_dies (dw_die_ref die)
 {
   dw_die_ref c;
 
-  if (dwarf_version < 4)
+  if (! use_debug_types)
     gcc_assert (die->die_mark);
 
   die->die_mark = 0;
@@ -10972,7 +10982,7 @@  value_format (dw_attr_ref a)
       return DW_FORM_flag;
     case dw_val_class_die_ref:
       if (AT_ref_external (a))
-	return dwarf_version >= 4 ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
+	return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
       else
 	return DW_FORM_ref;
     case dw_val_class_fde_ref:
@@ -11182,7 +11192,7 @@  output_die (dw_die_ref die)
 
   /* If someone in another CU might refer to us, set up a symbol for
      them to point to.  */
-  if (dwarf_version < 4 && die->die_id.die_symbol)
+  if (! use_debug_types && die->die_id.die_symbol)
     output_die_symbol (die);
 
   dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
@@ -11321,7 +11331,7 @@  output_die (dw_die_ref die)
 	case dw_val_class_die_ref:
 	  if (AT_ref_external (a))
 	    {
-	      if (dwarf_version >= 4)
+	      if (use_debug_types)
 	        {
 	          comdat_type_node_ref type_node =
 	            AT_ref (a)->die_id.die_type_node;
@@ -12862,7 +12872,7 @@  modified_type_die (tree type, int is_const_type, int is_volatile_type,
     }
   else if (code == REFERENCE_TYPE)
     {
-      if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
+      if (TYPE_REF_IS_RVALUE (type) && use_debug_types)
 	mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
 				type);
       else
@@ -20067,7 +20077,7 @@  gen_reference_type_die (tree type, dw_die_ref context_die)
 {
   dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
 
-  if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
+  if (TYPE_REF_IS_RVALUE (type) && use_debug_types)
     ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
   else
     ref_die = new_die (DW_TAG_reference_type, scope_die, type);
@@ -22153,7 +22163,7 @@  dwarf2out_source_line (unsigned int line, const char *filename,
 static void
 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
 {
-  if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
+  if (flag_eliminate_dwarf2_dups && ! use_debug_types)
     {
       /* Record the beginning of the file for break_out_includes.  */
       dw_die_ref bincl_die;
@@ -22177,7 +22187,7 @@  dwarf2out_start_source_file (unsigned int lineno, const char *filename)
 static void
 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
 {
-  if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
+  if (flag_eliminate_dwarf2_dups && ! use_debug_types)
     /* Record the end of the file for break_out_includes.  */
     new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
 
@@ -22437,7 +22447,7 @@  prune_unused_types_walk_attribs (dw_die_ref die)
 	  /* A reference to another DIE.
 	     Make sure that it will get emitted.
 	     If it was broken out into a comdat group, don't follow it.  */
-          if (dwarf_version < 4
+          if (! use_debug_types
               || a->dw_attr == DW_AT_specification
               || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
 	    prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
@@ -22518,7 +22528,7 @@  prune_unused_types_mark (dw_die_ref die, int dokids)
 	 breaking out types into comdat sections, do this
 	 for all type definitions.  */
       if (die->die_tag == DW_TAG_array_type
-          || (dwarf_version >= 4
+          || (use_debug_types
               && is_type_die (die) && ! is_declaration_die (die)))
 	FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
       else
@@ -23487,11 +23497,11 @@  dwarf2out_finish (const char *filename)
 
   /* Generate separate CUs for each of the include files we've seen.
      They will go into limbo_die_list.  */
-  if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
+  if (flag_eliminate_dwarf2_dups && ! use_debug_types)
     break_out_includes (comp_unit_die ());
 
   /* Generate separate COMDAT sections for type DIEs. */
-  if (dwarf_version >= 4)
+  if (use_debug_types)
     {
       break_out_comdat_types (comp_unit_die ());
 
-- 
1.7.4