Mention CU offset for <artifical> if verbose

Message ID e28fb7eb-bc71-e597-17f4-0d0c88e18512@suse.de
State New, archived
Headers

Commit Message

Tom de Vries Feb. 8, 2020, 9:16 a.m. UTC
  On 07-02-2020 15:45, Christian Biesinger wrote:
> On Fri, Feb 7, 2020 at 6:34 AM Tom de Vries <tdevries@suse.de> wrote:
> 
> 
>> diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
>> index dafe01d94a..28ade424fd 100644
>> --- a/gdb/dwarf2read.c
>> +++ b/gdb/dwarf2read.c
>> @@ -8020,6 +8020,20 @@ create_partial_symtab (struct dwarf2_per_cu_data *per_cu, const char *name)
>>    struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
>>    dwarf2_psymtab *pst;
>>
>> +  const char *artificial = "<artificial>";
> 
> This may not matter but I'd use static const char artificial[] = "..."
> 

Done.

>> +  if (strcmp (name, artificial) == 0)
>> +    {
>> +      sect_offset cu_offset = per_cu->sect_off;
>> +      const char *cu_offset_str = sect_offset_str (cu_offset);
>> +      const char *sep = "@";
>> +      char *new_name = (char *) xmalloc (strlen (artificial) + strlen (sep)
>> +                                        + strlen (cu_offset_str) + 1);
>> +      strcpy (new_name, artificial);
>> +      strcat (new_name, sep);
>> +      strcat (new_name, cu_offset_str);
> 
> Use concat() instead of malloc/strcpy/strcat?
> 

Done.

Updated patch re-tested and attached.

Thanks,
- Tom
  

Comments

Simon Marchi Feb. 8, 2020, 3:48 p.m. UTC | #1
On 2020-02-08 4:16 a.m., Tom de Vries wrote:
> On 07-02-2020 15:45, Christian Biesinger wrote:
>> On Fri, Feb 7, 2020 at 6:34 AM Tom de Vries <tdevries@suse.de> wrote:
>>
>>
>>> diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
>>> index dafe01d94a..28ade424fd 100644
>>> --- a/gdb/dwarf2read.c
>>> +++ b/gdb/dwarf2read.c
>>> @@ -8020,6 +8020,20 @@ create_partial_symtab (struct dwarf2_per_cu_data *per_cu, const char *name)
>>>    struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
>>>    dwarf2_psymtab *pst;
>>>
>>> +  const char *artificial = "<artificial>";
>>
>> This may not matter but I'd use static const char artificial[] = "..."
>>
> 
> Done.
> 
>>> +  if (strcmp (name, artificial) == 0)
>>> +    {
>>> +      sect_offset cu_offset = per_cu->sect_off;
>>> +      const char *cu_offset_str = sect_offset_str (cu_offset);
>>> +      const char *sep = "@";
>>> +      char *new_name = (char *) xmalloc (strlen (artificial) + strlen (sep)
>>> +                                        + strlen (cu_offset_str) + 1);
>>> +      strcpy (new_name, artificial);
>>> +      strcat (new_name, sep);
>>> +      strcat (new_name, cu_offset_str);
>>
>> Use concat() instead of malloc/strcpy/strcat?
>>
> 
> Done.
> 
> Updated patch re-tested and attached.

Should the string allocated with concat be freed?

Simon
  

Patch

[gdb] Mention CU offset for <artifical> if verbose

Say we're debugging a test-case with CUs with name "<artificial>", meaning
not originating from a single file compilation, and use the verbose setting:
...
$ gdb -iex "set verbose on" -batch cc1
Reading symbols from cc1...
Reading in symbols for <artificial>... \
  and /tmp/trunk/gcc/attribs.c... \
  ...
  and /tmp/trunk/gcc/tree-ssa-reassoc.c... \
  done.
...

From the "/tmp/trunk/gcc/attribs.c" message, it's clear which CU is loaded.  But
that's not the case for the "<artificial>" message.

The message uses the filename field of struct partial_symtab, which is
documented like this:
...
  /* Name of the source file which this partial_symtab defines,
     or if the psymtab is anonymous then a descriptive name for
     debugging purposes, or "".  It must not be NULL.  */
...

So, fix this by setting the filename field to a more descriptive name than
"<artificial>", by appending the CU offset.

This way, we print instead:
...
$ gdb -iex "set verbose on" -batch cc1
Reading symbols from cc1...
Reading in symbols for <artificial>@0x41146d9 \
  and /tmp/trunk/gcc/attribs.c... \
  ... \
  and /tmp/trunk/gcc/tree-ssa-reassoc.c... \
  done.
...

Build and reg-tested on x86_64-linux.

gdb/ChangeLog:

2020-02-07  Tom de Vries  <tdevries@suse.de>

	* dwarf2read.c (create_partial_symtab): Append CU offset to filename
	if it matches "<artificial>".

---
 gdb/dwarf2read.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index dafe01d94a..5acae3eab8 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -8020,6 +8020,10 @@  create_partial_symtab (struct dwarf2_per_cu_data *per_cu, const char *name)
   struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
   dwarf2_psymtab *pst;
 
+  static const char artificial[] = "<artificial>";
+  if (strcmp (name, artificial) == 0)
+    name = concat (artificial, "@", sect_offset_str (per_cu->sect_off), NULL);
+
   pst = new dwarf2_psymtab (name, objfile, 0);
 
   pst->psymtabs_addrmap_supported = true;