c++ - 如何在 C++ 汇编代码中查找 VPTR?

标签 c++ linux gcc code-generation vptr

class Base {
 public:
  Base() {}
  virtual void Get() { }
};

class Derivered : public Base {
 public:
  virtual void Get() { }
};

int main() {
  Base* base = new Derivered();
  base->Get();
  return 0;
}

我使用gcc 5.4.0编译代码,使用objdump -S a.out反汇编二进制文件。我想找到 Base 的 vptr,但只显示一个未知地址 0x80487d4。最大地址数是0x80487b7,我看不懂。 命令列表:g++ test.cpp -O0; objdump -S a.out

080486fe <_ZN4BaseC1Ev>:
 80486fe:   55                      push   %ebp
 80486ff:   89 e5                   mov    %esp,%ebp
 8048701:   ba d4 87 04 08          mov    $0x80487d4,%edx
 8048706:   8b 45 08                mov    0x8(%ebp),%eax
 8048709:   89 10                   mov    %edx,(%eax)

最佳答案

080486fe <_ZN4BaseC1Ev>:
  80486fe:   55                      push   %ebp
  80486ff:   89 e5                   mov    %esp,%ebp
  8048701:   ba d4 87 04 08          mov    $0x80487d4,%edx
  8048706:   8b 45 08                mov    0x8(%ebp),%eax
  8048709:   89 10                   mov    %edx,(%eax)

是...

push %ebp             ;- save frame pointer
mov %esp, %ebp        ;- mov esp-> ebp -ebp is frame pointer
mov $0x80487d4, %edx  ; load vptr address into edx
mov 0x8(%ebp), %eax   ; ld eax with address of this
mov %edx,(%eax)       ; store vptr in this byte 0

关于c++ - 如何在 C++ 汇编代码中查找 VPTR?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45938445/

相关文章:

linux - bash 子 shell 与 vanilla 命令执行

java - 如何使用单个命令在 UNIX 文件系统中提取 JAR 并使用 JAR 命令指定其目标目录?

c - gcc - 在 bss 中编写和执行代码 - 设置权限标志

c++ - free() 后面紧跟 NULL 赋值怎么会导致悬空指针?

c++ - 带 TTL 的数据结构

linux - 如何区分同一文件的两个部分?

gcc - 无法读取符号 : Archive has no index; run ranlib to add one

linux - 在远程Linux服务器上运行本地GCC

时间:2019-03-17 标签:c++coroutinesfinal_suspendforpromise_type

c++ - 我如何更改我的合并算法以接受 C++ 中的不同参数?