[PATCH][gdb/symtab] Fix language of duplicate static minimal symbol

Tom de Vries tdevries@suse.de
Wed Oct 31 09:09:00 GMT 2018


On 10/30/18 10:21 PM, Keith Seitz wrote:
> On 10/30/18 12:11 PM, Tom de Vries wrote:
>> However, when we use gdb to print info on foo, both foos are listed, but we
>> get one symbol mangled and one symbol demangled:
>> ...
>> $ gdb ./a.out -batch -ex "info func foo"
>> All functions matching regular expression "foo":
>>
>> Non-debugging symbols:
>> 0x00000000004004c7  foo()
>> 0x00000000004004dd  _ZL3foov
>> ...
>>
> 
> Good catch!
> >> Build and reg-tested on x86_64-linux.
>>
>> OK for trunk?
> 
> I have just a few comments.
> 
>> 2018-10-30  Tom de Vries  <tdevries@suse.de>
>>
>> 	* symtab.c (symbol_set_names): Call symbol_find_demangled_name
>> 	unconditionally, to get the language of the symbol.
> 
> s/get/set/ ? When reading the patch, I originally wondered how that would help,
> but symbol_find_demangled_name actually *sets* the gsymbol's language if
> it is language_auto.
> 

Typo fixed.

>>
>> 	* gdb.base/msym.c: New test.
>> 	* gdb.base/msym.exp: New file.
>> 	* gdb.base/msym_main.c: New test.
> 
> These entries should be listed under the testsuite ChangeLog, like:
> 
> testsuite/ChangeLog:
> YYYY-MM-DD ....
> 
> 	* gdb.xyz/file1.c: ...
> 	* gdb.xyz/file1.exp: ....
> 
> [https://sourceware.org/gdb/wiki/ContributionChecklist#Properly_Formatted_GNU_ChangeLog]
> 

I have a pre-commit script (for both gcc and gdb) that uses this format,
and puts ChangeLog hunks in the correct ChangeLog file ( more detail
here: https://sourceware.org/ml/gdb-patches/2018-06/msg00351.html ).
Sofar this format has been acceptable for maintainers.

> "msym.c" et al aren't particularly descriptive, though. Can we devise a better,
> more explicit name? Something along the lines of "multiple-language-msyms.exp".
> It's long, but it describes things better. [I'm not saying you should use
> this name, but something other than just "msym.{c,exp}".]
> 

Renamed to msym-lang.exp et al.

> Sorry, some of that is kinda nitpicky.
> 

Np, I'm still kinda new to gdb, all input appreciated.

>> diff --git a/gdb/symtab.c b/gdb/symtab.c
>> index cd27a75e8c..481428f733 100644
>> --- a/gdb/symtab.c
>> +++ b/gdb/symtab.c
>> @@ -818,6 +818,10 @@ symbol_set_names (struct general_symbol_info *gsymbol,
>>    else
>>      linkage_name_copy = linkage_name;
>>  
>> +  /* Set the symbol language.  */
>> +  char *demangled_name = symbol_find_demangled_name (gsymbol,
>> +						     linkage_name_copy);
>> +
>>    entry.mangled = linkage_name_copy;
>>    slot = ((struct demangled_name_entry **)
>>  	  htab_find_slot (per_bfd->demangled_names_hash,
> 
> symbol_find_demangled_name returns a malloc'd string which will leak here unless
> the code goes through the branch. You'll need to save the result into a
> unique_xmalloc_ptr and adjust the code accordingly.
> 

Done, thanks for pointing that out.

> Otherwise, LGTM. Thanks very much for the patch.
> 

And thanks for the review.

Re-tested as attached.

Thanks,
- Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-gdb-symtab-Fix-language-of-duplicate-static-minimal-symbol.patch
Type: text/x-patch
Size: 6998 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20181031/1a87fee4/attachment.bin>


More information about the Gdb-patches mailing list