在GDB中,如何解决重复的符号 [英] In GDB how do I resolve duplicate symbols
问题描述
(gdb)info var g_reallocCount
所有匹配正则表达式g_reallocCount的变量:
文件sv.c:
long int g_reallocCount;
long int g_reallocCount;
long int g_reallocCount;
long int g_reallocCount;
当我尝试使用print g_reallocCount我只得到一个结果,而不是一个我需要
我相信我有多个符号的原因是我正在更改的静态库链接到多个加载的模块。在这个时候,我不知道是否可以改变这个事实。
谢谢
编辑:由于某种原因,我没有考虑一个更简单的方法,假设c链接。
(gdb)shell nm / path / to / stuff | grep g_reallocCount | cut -d''-f1>> foo
(gdb)shell cat foo | awk'{printp * 0x$ 0}'> foo.gdb
(gdb)source foo.gdb
$ 4 = 0
$ 5 = 0
$ 6 = 0
原始答案,类似前提:
由于缺乏一个更好的主意,您可以尝试复制二进制/库,并使用strip命令剥离调试符号,然后gdb将在info var
中输出符号的地址,您可以使用print * 0xaddr
当调试符号可用时,我会提供一个补丁来打印info var中变量的地址。
如果你想出一个最小的测试用例来重现这个问题,请考虑将它发送到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
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!
这篇关于在GDB中,如何解决重复的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!