My first approach to using GDB for debugging is to setup breakpoints. This is done like so-
prompt> gdb ./x_bstree.c
(gdb) #prompt
(gdb) b 123 #break at line 123
(gdb) r #start program
Now your program halts at line 123 of your program. Now you can examine variables in stack or heap using print
. For stack variables just use print <varname>
. For heap variables (pointers) use print <*varname>
. Not sure there is anything special to do for examining stack/heap variables?
Of course to debug multi-threaded applications you would need to make it run in single-threaded mode & then dubug Otherwise it becomes difficult to predict what's happening.
For anything else there is extensive documentation of gdb & many sites also provide gdb cheat sheets