GDB
# See also
# General
- Compile with
-g
or-ggdb
flag to include debug information in the executable gdb --args prog arg1 arg2 arg3
to pass arguments- Use
start
to execute the program step by step, orrun
to just run next
orn
- for next instruction.Enter
to repeat the last commandp <variable>
to print variables,display <variable>
to print it continuouslystep
ors
to step into functions.finish
to finish the stepped-into functionbacktrace
orbt
for backtracectrl + x, 1
ortui enable
to enable text text user interface.br
to set breakpoints.br some_func
orbr some_file.c:42
info args
for info about program arguments,info breakpoints
for breakpointsset follow-fork-mode child
- follow the forked process instead of parent when usingfork()
set foo=bar
- change variables at runtime! Isn’t that awesome? But with great power comes great responsibilitycall <expr>
- run arbitrary code. Beware of state mutation, as withset
.
Miscctrl + x, o
to switch views (useful in tui mode).set print pretty on
- to print structs in a more readable way.print *array@size
to print arrays.layout src|regs|split
- switch views.