Mini tutorial on gdb

Thanks to Matthew:

gdb --args program/to/debug --whatever
break Foo.c:532
# to put a breakpoint at line 532 of Foo.c
run # to run it, until it hits that line
bt # to display the stacktrace (backtrace)
frame 2 # to change the stack frame you're looking at
list # to list the sourcecode for that stack frame
step # to step into the next command for that frame
next # to run the code to the next command
continue # to continue onwards
print bar # to print the contents of variable bar
printf  "%08x", bar # standard printf for bar
delete 2 # to remove the 2nd breakpoint

Obviously, you need to compile things with -g as an argument to GCC.

Tags// , , , ,
More Reading
comments powered by Disqus