Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In GDB how do I resolve duplicate symbols

Tags:

debugging

gdb

I have a global variable that's name has multiple symbols and I want to print all of them. Example:

(gdb) info var g_reallocCount
All variables matching regular expression "g_reallocCount":

File sv.c:
long int g_reallocCount;
long int g_reallocCount;
long int g_reallocCount;
long int g_reallocCount;

when I try to use "print g_reallocCount" i get only one result, and it is not the one that I need.

I believe that the reason I have multiple symbols is that the static library I am changing is linked to multiple loaded modules. At this time I am not sure whether I can change that fact.

thanks

like image 615
zekethegeke Avatar asked Nov 14 '22 19:11

zekethegeke


1 Answers

Edit: for some reason I failed to consider an easier way initally... assuming c linkage.

(gdb) shell nm /path/to/stuff | grep g_reallocCount | cut -d' ' -f1 >>foo
(gdb) shell cat foo | awk '{print "p *0x" $0}' >foo.gdb
(gdb) source foo.gdb
$4 = 0
$5 = 0
$6 = 0

original answer, similar premise: For lack of a better idea, you can try copying the binary/library and stripping it of debug symbols with the strip command, gdb will then output the address of the symbol in 'info var' and you can print it with print *0xaddr

I'll come up with a patch to print the address of the variable in 'info var', when debug symbols are available.

If you come up with a minimal testcase to reproduce this, please consider sending it to the gdb lists, or attaching it to a bug report.

Thanks!

like image 156
matt Avatar answered Dec 10 '22 03:12

matt