有多个库实现了一个特定的类 - 我不确定包含哪个库 - 我也没有make文件。
我想通过查看类的成员方法的反汇编来直接在GDB中确认这一点。
如何在GDB中反汇编重载的成员函数?
答案 0 :(得分:4)
考虑这个测试:
struct Foo {
int Fn(int x) const { return x + 42; }
int Fn(void) const { return 24; }
};
int main()
{
Foo f;
return f.Fn() + f.Fn(1);
}
使用调试信息编译时:
(gdb) info func Fn
All functions matching regular expression "Fn":
File t.cc:
int Foo::Fn() const;
int Foo::Fn(int) const;
(gdb) disas 'Foo::Fn(int) const'
Dump of assembler code for function Foo::Fn(int) const:
0x000000000040051e <+0>: push %rbp
0x000000000040051f <+1>: mov %rsp,%rbp
0x0000000000400522 <+4>: mov %rdi,-0x8(%rbp)
0x0000000000400526 <+8>: mov %esi,-0xc(%rbp)
0x0000000000400529 <+11>: mov -0xc(%rbp),%eax
0x000000000040052c <+14>: add $0x2a,%eax
0x000000000040052f <+17>: pop %rbp
0x0000000000400530 <+18>: retq
End of assembler dump.
编译时没有调试信息:
(gdb) info func Fn
All functions matching regular expression "Fn":
Non-debugging symbols:
0x000000000040051e Foo::Fn(int) const
0x0000000000400532 Foo::Fn() const
(gdb) disas 'Foo::Fn() const'
Dump of assembler code for function _ZNK3Foo2FnEv:
0x0000000000400532 <+0>: push %rbp
0x0000000000400533 <+1>: mov %rsp,%rbp
0x0000000000400536 <+4>: mov %rdi,-0x8(%rbp)
0x000000000040053a <+8>: mov $0x18,%eax
0x000000000040053f <+13>: pop %rbp
0x0000000000400540 <+14>: retq
End of assembler dump.
答案 1 :(得分:3)
如果可执行文件有调试数据,通常可以根据文件名进行检查。 你的命令是
Ovreloaded函数使用名称修改。基本上他们有独特的名字。
但你实际上可以打印功能的地址,例如
p 'A::function(int, bool, bool)'
它会打印类似于&#39; $ 1 = {bool(int,bool,bool)} ....&#39; 现在你应该使用反汇编命令:
disassemble $1
问题,图书馆静态吗?如果它是一个共享库,那么您只需要在可执行文件上使用ldd
实用程序来确定它使用的共享对象。