作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
class Parent {
public:
virtual void Foo() {}
virtual void FooNotOverridden() {}
};
class Derived : public Parent {
public:
void Foo() override {}
};
int main() {
Parent p1, p2;
Derived d1, d2;
}
(gdb) x/300xb 0x400b30
0x400b30
是d的vtable的首地址。
0x400b30 <_ZTV7Derived>: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x400b38 <_ZTV7Derived+8>: 0x80 0x0b 0x40 0x00 0x00 0x00 0x00 0x00
0x400b40 <_ZTV7Derived+16>: 0x60 0x0a 0x40 0x00 0x00 0x00 0x00 0x00
0x400b48 <_ZTV7Derived+24>: 0x70 0x0a 0x40 0x00 0x00 0x00 0x00 0x00
0x400b50 <_ZTS7Derived>: 0x37 0x44 0x65 0x72 0x69 0x76 0x65 0x64
0x400b58 <_ZTS7Derived+8>: 0x00 0x36 0x50 0x61 0x72 0x65 0x6e 0x74
0x400b60 <_ZTS6Parent+7>: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x400b68 <_ZTI6Parent>: 0x70 0x20 0x60 0x00 0x00 0x00 0x00 0x00
_ZTV、_ZTS、_ZTI在<_ZTV7Derived>
中是什么意思| , <_ZTS7Derived>
, <_ZTI6Parent>
?
最佳答案
这是您的开发平台破坏 C++ 符号名称的方式。您可以使用 GNU Binutils 中的 c++filt
命令行工具找出:
$ c++filt _ZTV7Derived
vtable for Derived
$ c++filt _ZTS7Derived
typeinfo name for Derived
$ c++filt _ZTI6Parent
typeinfo for Parent
更具体地说,它是由 Itanium 或 IA-64 C++ ABI 定义的 mangling,它也在 x86_64 上使用(因为 System V Application Binary Interface - AMD64 Architecture Processor Supplement 在标题为“C++”的第 9.1 节中如此说明)。参见 section on "Virtual Tables and RTTI"在 Itanium C++ ABI 中获取确切的处理细节。
关于c++ - ZTV、ZTS、ZTI 在 gdb x/nfu "vtable_address"的结果中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49381011/
1。代码 class Parent { public: virtual void Foo() {} virtual void FooNotOverridden() {} }; class D
我是一名优秀的程序员,十分优秀!