mirror of
https://github.com/Hizenberg469/GDB-tutorial.git
synced 2026-04-19 22:02:23 +03:00
Tutorial Complete
This commit is contained in:
90
GDB-Extra-Features.adoc
Normal file
90
GDB-Extra-Features.adoc
Normal file
@@ -0,0 +1,90 @@
|
||||
= *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>
|
||||
----
|
||||
Reference in New Issue
Block a user