Files
GDB-tutorial/GDB-Extra-Features.adoc
2025-11-14 07:20:58 +05:30

91 lines
1.5 KiB
Plaintext

= *Inspecting the Virtual Table for Inheritance (C++)*
In C++, To inspect whether a pointer to a allocated object is of type
the pointer is declared to a particular class or it is object of a class
which is dervied from the class of which the type of the pointer is.
To check it, we can use the virtualy pointer table of derived class
which can help us in such information.
We can use command:
[source,]
----
info vtbl <pointer-name>
----
[source,]
----
(gdb) info vtbl obj2
vtable for 'Base' @ 0x555555557d48 (subobject @ 0x55555556b6e0):
[0]: 0x5555555552e2 <Derived::VirtualMember()>
(gdb)
----
Code:
[source,]
----
#include <iostream>
class Base {
public:
Base () {
std::cout << "base\n";
}
virtual void VirtualMember () {
}
};
class Derived : public Base {
public:
Derived () {
std::cout << "derived\n";
}
void VirtualMember () {
}
};
int main () {
Base *obj = new Base;
Base *obj2 = new Derived;
return 0;
}
----
=== *GDB Command Debug Levels*
There are different level of debugging information that we can achieve
using the different type of `-g` flag during compilation.
This is mainly to get _macro_ information as these are not added to
debug symbol by default.
Different levels of Debugging symbols:
1. -g0
2. -g1
3. -g2 (default)
4. -g3
5. -ggdb3 (highest level specifically for GDB debugger)
To see the information for all the macro, use command:
[source,]
----
info macros
----
To see the information for particular macro, use command:
[source,]
----
info macro <macro-name>
----