# GDB **GDB** (the GNU Debugger) lets you inspect and control a running program: pause execution at any line, examine variables, walk the call stack, and step through code. It works on C, C++, Fortran, and other compiled languages by reading debug symbols embedded during compilation. Instead of scattering `printf` statements and recompiling after every guess, GDB lets you attach to a running process or post-mortem core dump and ask questions directly: what's in this variable, how did we get here, what did the caller pass in? GDB requires debug information to be useful. Compile with `-O0 -g` for reliable debugging (no optimization, keep debug symbols). Binaries compiled with `-O3` and no `-g` are nearly impossible to debug—the optimizer eliminates the structure GDB needs. ```bash $ gcc -O0 -g -o app app.c # compile with debug symbols $ gdb ./app # start debugger (gdb) break main # set breakpoint (gdb) run # run until breakpoint (gdb) next # step over next line (gdb) print variable # print variable value (gdb) quit # exit GDB ``` GDB is command-line based. Commands can be abbreviated (e.g., `b` for `break`, `c` for `continue`, `p` for `print`). Press Enter to repeat the last command. ## Concepts 1. [[gdb-basics|Basics]] 2. [[gdb-breakpoints|Breakpoints]] 3. [[gdb-running-and-stepping|Running and stepping]] 4. [[gdb-examining-state|Examining state]] 5. [[gdb-inspecting-memory|Inspecting memory]] 6. [[gdb-call-stack|Call stack]] 7. [[gdb-watching-expressions|Watching expressions]] 8. [[gdb-debugging-crashes|Debugging crashes]] 9. [[gdb-commands|Commands]] 10. [[gdb-configuration|Configuration]] 11. [[gdb-tui|TUI (Text User Interface)]] 12. [[gdb-advanced-features|Advanced features]]