skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
gdb
This page is read only. You can view the source, but not change it.
# 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. [Basics](/gdb-basics) 2. [Breakpoints](/gdb-breakpoints) 3. [Running and stepping](/gdb-running-and-stepping) 4. [Examining state](/gdb-examining-state) 5. [Inspecting memory](/gdb-inspecting-memory) 6. [Call stack](/gdb-call-stack) 7. [Watching expressions](/gdb-watching-expressions) 8. [Debugging crashes](/gdb-debugging-crashes) 9. [Commands](/gdb-commands) 10. [Configuration](/gdb-configuration) 11. [TUI (Text User Interface)](/gdb-tui) 12. [Advanced features](/gdb-advanced-features)
Page Tools
Show pagesource
Backlinks
Back to top