gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 20:02:00 27 4
gpt4 key购买 nike

有多个库实现了一个特定的类——我不确定包含了哪个库——我也没有生成文件。

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

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

最佳答案

考虑这个测试:

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.

关于c++ - 在 GDB 中反汇编重载的成员函数 - C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48219441/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com