Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ZTV,ZTS,ZTI mean in the result of gdb x/nfu "vtable_address"?

1. the code

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;
}

2. gdb command

(gdb) x/300xb 0x400b30

0x400b30 is the first address of d's vtable.

3. gdb result

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

4. question

What does _ZTV, _ZTS, _ZTI mean in <_ZTV7Derived>, <_ZTS7Derived>, <_ZTI6Parent>?

like image 500
JellyHan Avatar asked Mar 20 '18 09:03

JellyHan


1 Answers

It is the way the C++ symbol names are mangled by your development platform. You can use the c++filt command line tool from GNU Binutils to find out:

$ c++filt _ZTV7Derived
vtable for Derived
$ c++filt _ZTS7Derived
typeinfo name for Derived
$ c++filt _ZTI6Parent
typeinfo for Parent

More specifically, it is the mangling defined by the Itanium or IA-64 C++ ABI which is also used on x86_64 (because the System V Application Binary Interface - AMD64 Architecture Processor Supplement says so in section 9.1 titled "C++"). See section on "Virtual Tables and RTTI" in the Itanium C++ ABI for the exact mangling details.

like image 60
jotik Avatar answered Sep 28 '22 00:09

jotik