GDB
# See also
# General
- Compile with
-gor-ggdbflag to include debug information in the executable gdb --args prog arg1 arg2 arg3to pass arguments- Use
startto execute the program step by step, orrunto just run nextorn- for next instruction.Enterto repeat the last commandp <variable>to print variables,display <variable>to print it continuouslysteporsto step into functions.finishto finish the stepped-into functionbacktraceorbtfor backtracectrl + x, 1ortui enableto enable text text user interface.brto set breakpoints.br some_funcorbr some_file.c:42info argsfor info about program arguments,info breakpointsfor 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.