在GDB中反汇编重载成员函数-C ++

ult*_*use 3 c++ gdb c++11 c++14

有多个实现特定类的库-我不确定包含哪个库-我也没有make文件。

我想通过反汇编类的成员方法来直接在GDB中确认这一点。

如何在GDB中反汇编重载成员函数?

Emp*_*ian 5

考虑以下测试:

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);
}
Run Code Online (Sandbox Code Playgroud)

使用调试信息进行编译时:

(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.
Run Code Online (Sandbox Code Playgroud)

如果在没有调试信息的情况下进行编译:

(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.
Run Code Online (Sandbox Code Playgroud)