使用 GDB 打印 C++ vtables

2022-01-20 00:00:00 gdb c++

我正在尝试使用 gdb 打印对象的 vtable;我找到了

I'm trying to print an object's vtable using gdb; I found the

show print vt bl on

设置,但我仍然不知道如何打印 vtable - p *object 仍然不打印出来.

setting, but I still don't actually know how to print the vtable - p *object still doesn't print it out.

如何打印 vtable?

How do I print the vtable?

推荐答案


  (gdb) set $i = 0
  (gdb) while $i < 10
     >print $i
     >p /a (*(void ***)obj)[$i]
     >set $i = $i + 1
     >end

其中obj"是您要打印其 vtable 的对象,10 是方法数.

Where "obj" is the object whose vtable you'd like to print, and 10 is the number of methods.

相关文章