How to display the VTABLE of a C++ class through GCC?
Asked Answered
A

2

14

I understand that a class will have a VTABLE, if it contains at-least one virtual function. I would like to see the contents of the VTABLE. Is there a way to display it ?

Specifically, is there an option in gcc to display the VTABLE of a class?

Aidoneus answered 22/1, 2012 at 7:4 Comment(0)
A
29

If the input file is say layout.cpp, the command gcc -fdump-class-hierarchy layout.cpp will produce a file layout.cpp.class. This file will display the VTABLE along with some other useful information.

Aidoneus answered 11/2, 2012 at 5:45 Comment(4)
Are you sure we should use gcc or we should use g++ for c++Java
Its g++ not gcc.Peppy
"Since GCC version 8.0 at least these two options were replaced: -fdump-class-hierarchy is now -fdump-lang-class -fdump-translation-unit ---> -fdump-lang-raw"Roos
@user362515: Do you know if these options are still available in gcc version 9.0?Plunkett
Q
-1

Assuming it will really have a v-table (this is compiler dependent, and is not required or dictated by the standard) - you can inspect it with your debugger.

Why would you do that? If you're relying on it for anything other than curiosity - then don't.

Quarrel answered 22/1, 2012 at 7:5 Comment(2)
Yes out of curiosity. Is there an option in gcc to display the vtable?Aidoneus
@LinuxPenseur you must mean gdb. I don't know. I know that on Visual Studio I saw it appearing once in a while when I was inspecting classes. I guess it depends on what symbol gcc attaches to it and whether you can find that symbol.Quarrel

© 2022 - 2024 — McMap. All rights reserved.