gcc main.c -g # -g enables debug symbols
gdb a.outDebug symbols enables additional information in binary like function, variable names
gdb -p <process id>Running:
tui: runs gdb with text user interfacelist: list code that's currently in gdbrun: runs the binarybreak <breakpoint>: create a break point (can be used with line number and function name)info breakpoints: list breakpointsinfo registers: prints info about registersinfo proc mappings: prints memory mapx/s <memory addr>: prints memory as stringstart:break main+startbt: prints backtraceprint <expr>: prints stuff to stdoutc: continues the running of the program, till next break pointn / next: steps to next line in programstep: steps into next linejump *<addr>: resumes program execution from a given address<enter>: repeats previous commands
Debugging without debug symbols:
disassemble <function name / range>: dissassembles the functionlayout asm: prints assembly layoutset disassembly-flavor <intel>: switches assembly to intel
gdb -p <pid>: attach to running processframe / f: prints current line and line number
while ./buggy; do echo Ok; doneb main: creates breakpoint at start of mainb <exit>: creates breakpoint at end of maincommand 2: runs command when breakpoint 2 is hitrun: runs codeend: end recording
command 1: runs command when breakpoint 2 is hitrecord: records code stepscontinue: continues debugging
set pagination off: don't ask for input at end of large outputreverse-stepi: step backwards
https://github.com/hugsy/gef