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

Tom de Vries tdevries@suse.de
Sun Feb 9 11:48:00 GMT 2020


On 08-02-2020 16:48, Simon Marchi wrote:
> 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?

Indeed.

I've done that now by using gdb::unique_xmalloc_ptr<char>. [ FWIW,
there's some code in create_type_unit_group that does something similar,
but there we use std::string and string_printf. ]

Also, I realized that the code was too deep in the call stack, and I've
brought it one level up, to process_psymtab_comp_unit_reader, to make
sure it doesn't trigger for f.i. create_type_unit_group.

Thanks,
- Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-gdb-Mention-CU-offset-for-artifical-if-verbose.patch
Type: text/x-patch
Size: 2318 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20200209/e6992e03/attachment.bin>


More information about the Gdb-patches mailing list