Following are the useful commands to debug:
debug with program arguments:
gdb --args prog arg1 arg2 arg3
Debugging an application with complex configuration files setup in different directories:
compile the program with -g switch, and install it
debug the installed program as follows:
sudo gdb --args prog arg1 arg2 arg3
add break point to function:
b func_foo
add break point to line in file:
b file:line_num
step into:
s
step over:
n
continue program execution:
c
start/restart program:
r
print variable:
p var
x/s str_var
print 10 bytes in hex
x/10x str_var
list program statements being in debug
l
get call stack: (backtrace)
bt
get value of some variable in function call in back in call stack at row 2:
f 2
p var
get all break points (info break):
i b
delete a break point 3:
d 3
watch a variable for change:
wa var
get threads list (info threads):
i th
change to different thread context (e.g. thread 2):
t 2
attaching to an already running process for debugging (first get process id using ps -ef):
at process_id
detaching to debugging process:
det
debugging save state (checkpoint, only for single threaded application):
checkpoint
info checkpoint
restore program state to the checkpoint (e.g. 2):
restart 2
debug with program arguments:
gdb --args prog arg1 arg2 arg3
Debugging an application with complex configuration files setup in different directories:
compile the program with -g switch, and install it
debug the installed program as follows:
sudo gdb --args prog arg1 arg2 arg3
add break point to function:
b func_foo
add break point to line in file:
b file:line_num
step into:
s
step over:
n
continue program execution:
c
start/restart program:
r
print variable:
p var
x/s str_var
print 10 bytes in hex
x/10x str_var
list program statements being in debug
l
get call stack: (backtrace)
bt
get value of some variable in function call in back in call stack at row 2:
f 2
p var
get all break points (info break):
i b
delete a break point 3:
d 3
watch a variable for change:
wa var
get threads list (info threads):
i th
change to different thread context (e.g. thread 2):
t 2
attaching to an already running process for debugging (first get process id using ps -ef):
at process_id
detaching to debugging process:
det
debugging save state (checkpoint, only for single threaded application):
checkpoint
info checkpoint
restore program state to the checkpoint (e.g. 2):
restart 2