Dumping the Vtable

Hi,

Can someone help me with how to dump the vtable and the vptr addresses within it?

Thanks,

Dami

Hi Damilola,

Can someone help me with how to dump the vtable and the vptr addresses
within it?

I'm not sure if this answers your question exactly, but you can pass
"-Xclang -fdump-vtable-layouts" to ask Clang to dump the layout of
generated vtables. For example:

$ cat /tmp/a.cc
struct S {
  virtual void f() {};
};

void f(S * s) {
  s->f();
}
$ bin/clang++ -c /tmp/a.cc -Xclang -fdump-vtable-layouts
Vtable for 'S' (3 entries).
   0 | offset_to_top (0)
   1 | S RTTI
       -- (S, 0) vtable address --
   2 | void S::f()

VTable indices for 'S' (1 entries).
   0 | void S::f()

- Hans

Hi Hans,

Thanks for the reply. I apologize for the unclear question. I am new to using clang and llvm.

I have tried this but the version I have for some reason won’t allow me to use this command line option. Furthermore, I am trying to get this information via the IR and writing a pass to get this information to use at a later point.

-Dami