Prerequisites
- Make sure to install the
gdbpackage - Make sure to compile with
-g -gdb3and-O0
Starting
Load the binary with
gdb ./hellband
Setting breakpoints and watches
break <filename>:<line>watch <variable>(breaks on write access)rwatch <variable>(breaks on read access)awatch <variable>(breaks on read and write access)
Querying variables
info variablesto list "All global and static variable names".info localsto list "Local variables of current stack frame" (names and values)info argsto list "Arguments of the current stack frame" (names and values).print <variable>to show a variablevariableexplore <variable>to inspect a variablevariable
Call stack
btto show all frames aka the the call stackselect-frame <n>to select frame numbernfrom the call stack
Program flow
continueto run the program till the end or the next breakpointstepto execute the whole line at oncenextto execute the next atomic part of the linefinishto return to previous frame
Getting fancy
- Consider installing https://github.com/cyrus-and/gdb-dashboard
- Having 2 ssh sessions with one running in gdb
dashboard -output <tty>can be gold cis shorthand forcontinueframeis shorthand forselect-framepis shorthand forprint
Debugging a stuck game
- Open two sessions
- Get one session stuck within a gdb run
- Find the hellband/gdb session with
ps -al - Send from the other session a SIGSEGV with
kill -s SIGSEGV <pid>