diff options
author | Tom de Vries <tdevries@suse.de> | 2018-11-09 11:54:04 +0100 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2018-11-09 11:54:04 +0100 |
commit | 9325300dc283ece6bf6305b912f53114c0895114 (patch) | |
tree | 8e2ed081e8fd2d578fed61a7b527e46223c0eefc /gdb/symtab.c | |
parent | 13daa8e4889a971309f7d46a8d49129cb26088a5 (diff) | |
download | gdb-9325300dc283ece6bf6305b912f53114c0895114.zip gdb-9325300dc283ece6bf6305b912f53114c0895114.tar.gz gdb-9325300dc283ece6bf6305b912f53114c0895114.tar.bz2 |
[gdb/symtab] Fix language of duplicate static minimal symbol
Consider a test-case with source files msym.c:
...
static int foo (void) { return 1; }
...
and msym_main.c:
...
static int foo (void) { return 2; }
int main (void) { return 0; }
..
compiled as c++ with minimal symbols:
...
$ g++ msym_main.c msym.c
...
With objdump -x we find the two foo symbols prefixed with their corresponding
files in the symbol table:
...
0000000000000000 l df *ABS* 0000000000000000 msym_main.c
00000000004004c7 l F .text 000000000000000b _ZL3foov
0000000000000000 l df *ABS* 0000000000000000 msym.c
00000000004004dd l F .text 000000000000000b _ZL3foov
...
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
...
During minimal symbol reading symbol_set_names is called for each symbol.
First, it's called with foo from msym.c, an entry is created in
per_bfd->demangled_names_hash and symbol_find_demangled_name is called, which
has the side effect of setting the language of the symbol to language_cplus.
Then, it's called with foo from msym_main.c. Since
per_bfd->demangled_names_hash already has an entry for that name,
symbol_find_demangled_name is not called, and the language of the symbol
remains language_auto.
Fix this by doing the symbol_find_demangled_name call unconditionally.
Build and reg-tested on x86_64-linux.
gdb/ChangeLog:
2018-11-09 Tom de Vries <tdevries@suse.de>
* symtab.c (symbol_set_names): Call symbol_find_demangled_name
unconditionally, to set the language of the symbol. Manage freeing
returned pointer using gdb::unique_xmalloc_ptr.
gdb/testsuite/ChangeLog:
2018-11-09 Tom de Vries <tdevries@suse.de>
* gdb.base/msym-lang.c: New test.
* gdb.base/msym-lang.exp: New file.
* gdb.base/msym-lang-main.c: New test.
Diffstat (limited to 'gdb/symtab.c')
-rw-r--r-- | gdb/symtab.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/gdb/symtab.c b/gdb/symtab.c index 7649908..2e9e632 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -818,6 +818,11 @@ symbol_set_names (struct general_symbol_info *gsymbol, else linkage_name_copy = linkage_name; + /* Set the symbol language. */ + char *demangled_name_ptr + = symbol_find_demangled_name (gsymbol, linkage_name_copy); + gdb::unique_xmalloc_ptr<char> demangled_name (demangled_name_ptr); + entry.mangled = linkage_name_copy; slot = ((struct demangled_name_entry **) htab_find_slot (per_bfd->demangled_names_hash, @@ -830,9 +835,7 @@ symbol_set_names (struct general_symbol_info *gsymbol, || (gsymbol->language == language_go && (*slot)->demangled[0] == '\0')) { - char *demangled_name = symbol_find_demangled_name (gsymbol, - linkage_name_copy); - int demangled_len = demangled_name ? strlen (demangled_name) : 0; + int demangled_len = demangled_name ? strlen (demangled_name.get ()) : 0; /* Suppose we have demangled_name==NULL, copy_name==0, and linkage_name_copy==linkage_name. In this case, we already have the @@ -870,10 +873,7 @@ symbol_set_names (struct general_symbol_info *gsymbol, } if (demangled_name != NULL) - { - strcpy ((*slot)->demangled, demangled_name); - xfree (demangled_name); - } + strcpy ((*slot)->demangled, demangled_name.get()); else (*slot)->demangled[0] = '\0'; } |