开发者

In GDB how do I resolve duplicate symbols

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 ne开发者_如何学JAVAed.

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


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜