This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

Re: [RFC][debug] Add -greadable-dwarf


On Tue, 21 Aug 2018, Jason Merrill wrote:

> How about adding this name to a -dA comment instead of the actual dwarf?

That would also work but it requires either sticking that name somewhere
in die_struct or keep a reference to the decl we created a DIE for
in the same struct.  Though we already have die_struct->decl_id which
might be enough info we could even dump unconditionally besides
or in place of the DW_AT_name attribute.

Richard.

> On Tue, Aug 21, 2018, 12:59 AM Richard Biener <rguenther@suse.de> wrote:
> 
> > On Wed, 15 Aug 2018, Tom de Vries wrote:
> >
> > > Hi,
> > >
> > > This patch adds option -greadable-dwarf.  In absence of an DW_AT_comment
> > > attribute,
> >
> > What's a DW_AT_comment attribute?  I don't see this mentioned in the
> > patch.
> >
> > > it sets the DW_AT_name attribute of dies that otherwise do not get
> > > that attribute, to make it easier to figure out what the die is
> > describing.
> > >
> > > The option exports the names of artificial variables:
> > > ...
> > >  DIE    0: DW_TAG_variable (0x7fa934dd54b0)
> > > +  DW_AT_name: "D.1922"
> > >    DW_AT_type: die -> 0 (0x7fa934dd0d70)
> > >    DW_AT_artificial: 1
> > >
> > > ...
> > > which can be traced back to gimple dumps:
> > > ...
> > >   char a[0:D.1922] [value-expr: *a.0];
> > > ...
> > >
> > > Furthermore, it adds names to external references:
> > > ...
> > >  DIE    0: DW_TAG_subprogram (0x7fa88b9650f0)
> > > +DW_AT_name: "main"
> > >  DW_AT_abstract_origin: die -> label: vla_1.c.6719312a + 29
> > (0x7fa88b965140)
> > > ...
> > >
> > > This is an undocumented developer-only option, because using this option
> > may
> > > change behaviour of dwarf consumers, f.i., gdb shows the artificial
> > variables:
> > > ...
> > > (gdb) info locals
> > > a = 0x7fffffffda90 "\005"
> > > D.4278 = <optimized out>
> > > ...
> > >
> > > Any comments?
> >
> > The idea is OK I guess but I'd call it -gforce-named-dies instead
> > of -greadable-dwarf.  It also goes only half-way since it doesn't
> > add names to DECL_NAMELESS vars.
> >
> > There doesn't seem to be a convenient place to
> >
> > > Thanks,
> > > - Tom
> > >
> > > [debug] Add -greadable-dwarf
> > >
> > > 2018-08-15  Tom de Vries  <tdevries@suse.de>
> > >
> > >       * common.opt (greadable-dwarf): Add option.
> > >       * dwarf2out.c (add_name_and_src_coords_attributes): Add param. Add
> > name
> > >       for artifical decls.
> > >       (add_decl_name): New function.
> > >       (dwarf2out_register_external_die): Add name to external reference
> > die.
> > >
> > > ---
> > >  gcc/common.opt  |  5 +++++
> > >  gcc/dwarf2out.c | 24 +++++++++++++++++++++---
> > >  2 files changed, 26 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/gcc/common.opt b/gcc/common.opt
> > > index b2f2215ecc6..6e5e0558e49 100644
> > > --- a/gcc/common.opt
> > > +++ b/gcc/common.opt
> > > @@ -2972,6 +2972,11 @@ gstrict-dwarf
> > >  Common Driver Report Var(dwarf_strict) Init(0)
> > >  Don't emit DWARF additions beyond selected version.
> > >
> > > +greadable-dwarf
> > > +Common Driver Undocumented Report Var(flag_readable_dwarf) Init(0)
> > > +Make generated dwarf more readable, at the cost of space and exposing
> > compiler
> > > +internals.
> > > +
> > >  gtoggle
> > >  Common Driver Report Var(flag_gtoggle)
> > >  Toggle debug information generation.
> > > diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
> > > index 4b63cbd8a1e..8c6b4372874 100644
> > > --- a/gcc/dwarf2out.c
> > > +++ b/gcc/dwarf2out.c
> > > @@ -3824,7 +3824,9 @@ static void add_prototyped_attribute (dw_die_ref,
> > tree);
> > >  static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
> > >  static void add_pure_or_virtual_attribute (dw_die_ref, tree);
> > >  static void add_src_coords_attributes (dw_die_ref, tree);
> > > -static void add_name_and_src_coords_attributes (dw_die_ref, tree, bool
> > = false);
> > > +static void add_name_and_src_coords_attributes (dw_die_ref, tree, bool
> > = false,
> > > +                                             bool = false);
> > > +static void add_decl_name (dw_die_ref, tree);
> > >  static void add_discr_value (dw_die_ref, dw_discr_value *);
> > >  static void add_discr_list (dw_die_ref, dw_discr_list_ref);
> > >  static inline dw_discr_list_ref AT_discr_list (dw_attr_node *);
> > > @@ -6022,6 +6024,8 @@ dwarf2out_register_external_die (tree decl, const
> > char *sym,
> > >    else
> > >      equate_decl_number_to_die (decl, die);
> > >
> > > +  if (flag_readable_dwarf)
> > > +    add_decl_name (die, decl);
> >
> > Please use add_name_and_src_coords_attributes directly.
> >
> > >    /* Add a reference to the DIE providing early debug at $sym + off.  */
> > >    add_AT_external_die_ref (die, DW_AT_abstract_origin, sym, off);
> > >  }
> > > @@ -21269,7 +21273,8 @@ add_linkage_name (dw_die_ref die, tree decl)
> > >
> > >  static void
> > >  add_name_and_src_coords_attributes (dw_die_ref die, tree decl,
> > > -                                 bool no_linkage_name)
> > > +                                 bool no_linkage_name,
> > > +                                 bool no_src_coords_attributes)
> > >  {
> > >    tree decl_name;
> > >
> > > @@ -21279,12 +21284,19 @@ add_name_and_src_coords_attributes (dw_die_ref
> > die, tree decl,
> > >        const char *name = dwarf2_name (decl, 0);
> > >        if (name)
> > >       add_name_attribute (die, name);
> > > -      if (! DECL_ARTIFICIAL (decl))
> > > +      if (!no_src_coords_attributes && ! DECL_ARTIFICIAL (decl))
> >
> > inconsistent spacing after !
> >
> > >       add_src_coords_attributes (die, decl);
> > >
> > >        if (!no_linkage_name)
> > >       add_linkage_name (die, decl);
> > >      }
> > > +  else if (flag_readable_dwarf && decl_name == NULL)
> > > +    {
> > > +      char *buf = XNEWVEC (char, 32);
> > > +      char decl_letter = TREE_CODE (decl) == CONST_DECL ? 'C' : 'D';
> > > +      sprintf (buf, "%c.%u", decl_letter, DECL_UID (decl));
> > > +      add_name_attribute (die, buf);
> >
> > I think you leak 'buf'.
> >
> > > +    }
> > >
> > >  #ifdef VMS_DEBUGGING_INFO
> >
> > how does it interact with this VMS_DEBUGGING_INFO path?
> >
> > >    /* Get the function's name, as described by its RTL.  This may be
> > different
> > > @@ -21298,6 +21310,12 @@ add_name_and_src_coords_attributes (dw_die_ref
> > die, tree decl,
> > >  #endif /* VMS_DEBUGGING_INFO */
> > >  }
> > >
> > > +static void
> > > +add_decl_name (dw_die_ref die, tree decl)
> > > +{
> > > +  add_name_and_src_coords_attributes (die, decl, true, true);
> > > +}
> > > +
> > >  /* Add VALUE as a DW_AT_discr_value attribute to DIE.  */
> > >
> > >  static void
> > >
> > >
> >
> > --
> > Richard Biener <rguenther@suse.de>
> > SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB
> > 21284 (AG Nuernberg)
> >
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)


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