GDB (or the Gnu Debugger) is the basis of things like the XCode debugger, so it is good to know how to use it in general (as XCode wisely ships with a Debugger Console, your plug into GDB).
Valuable One Liners
whatis var |
prints what kind of variable var is |
info break |
prints all breakpoints in project |
print/d intVar |
prints the value of intVar as an integer (useful when print alone isn't helpful) |
print (ENUM TYPE) intVal |
Looks up the constant in ENUM TYPE for intVal |
Translating an integer to an enum value begs further examination.
Given:
enum PetAnimals
{
dogs = 1,
cats
fish
}
You can, in GDB
(gdb) print (PetAnimals) 2 $1 = cats
In GDB 'hacks'
Printing address of an array
x/x (char*)(var)
For your .gdbinit File
set print object # prints an object's actual class, instead of # its defined type (useful if you're passing # around subclasses as the super's type) # this will show Derived* instead of Base*
Debugging Functions
Printing The Class Name
If you have print object ON this isn't required it will happen automatically if you do whatis
In a situation like this:
Person* me = new Employee(); GDB's whatis command will tell you that me is a Person* (if you have 'print object' off). But we want to know what type it really is - and we don't want to turn 'print object' on - and the following snippet helps with that.
const char* name = typeid(*me).name();
Then print name in GDB.
GDB and Frameworks
Check out GDB/WxWidgets for tips specifically for wxWidgets
Check out GDB/GPC for tips specifically for the Gnu Pascal Compiler
Check out GDB/Carbon for tips on using GDB with Carbon
Documentation/Etc Links
GDB/Docs for documentation + tutorials that we've found
Comments:
Add comments by visiting: GDB/Comments