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

2018-08-21 Thread Tom de Vries
Hi,

That solution is limited: it does not show the extra information in the
dump from an executable (which is the only way to see how things look
like post-linking).

Is your concern leaking compiler internals into the dwarf info?

Thanks,
- Tom

On 08/21/2018 06:53 AM, Jason Merrill wrote:
> How about adding this name to a -dA comment instead of the actual dwarf?
> 
> On Tue, Aug 21, 2018, 12:59 AM Richard Biener  > 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 = 0x7fffda90 "\005"
> > D.4278 = 
> > ...
> >
> > 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  mailto:tdevr...@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)
> > 

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

2018-08-21 Thread Tom de Vries
On 08/20/2018 02:59 PM, Richard Biener 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's a hypothetical DWARF attribute, that I would have preferred to use
instead of DW_AT_name.

>> 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:
>> ...
>>  DIE0: 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:
>> ...
>>  DIE0: 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 = 0x7fffda90 "\005"
>> D.4278 = 
>> ...
>>
>> Any comments?
> 
> The idea is OK I guess but I'd call it -gforce-named-dies instead
> of -greadable-dwarf.

Done.

>  It also goes only half-way since it doesn't
> add names to DECL_NAMELESS vars.

I've tried to add that.

> There doesn't seem to be a convenient place to 
> 

?

>> Thanks,
>> - Tom
>>
>> [debug] Add -greadable-dwarf
>>
>> 2018-08-15  Tom de Vries  
>>
>>  * 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.
> 

Done.

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

Done.

>>  add_src_coords_attributes (die, decl);
>>  
>>if (!no_linkage_name)
>>  add_linkage_name (die, decl);
>>  }
>> +  else if (flag_readable_dwarf && decl_name == NULL)
>> +{

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

2018-08-21 Thread Richard Biener
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  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:
> > > ...
> > >  DIE0: 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:
> > > ...
> > >  DIE0: 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 = 0x7fffda90 "\005"
> > > D.4278 = 
> > > ...
> > >
> > > 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  
> > >
> > >   * 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,
> 

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

2018-08-21 Thread Jason Merrill
How about adding this name to a -dA comment instead of the actual dwarf?

On Tue, Aug 21, 2018, 12:59 AM Richard Biener  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:
> > ...
> >  DIE0: 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:
> > ...
> >  DIE0: 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 = 0x7fffda90 "\005"
> > D.4278 = 
> > ...
> >
> > 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  
> >
> >   * 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 

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

2018-08-20 Thread Richard Biener
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:
> ...
>  DIE0: 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:
> ...
>  DIE0: 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 = 0x7fffda90 "\005"
> D.4278 = 
> ...
> 
> 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  
> 
>   * 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?