GDB Debugger Commands Reference

Core GDB commands — break, run, step, backtrace, watch — with syntax and TUI notes.

Searchable GDB command reference covering breakpoints, stepping, inspection, watchpoints and TUI mode. Look up syntax, shorthand and common usage for the GNU debugger fast.

What is the difference between step and next in GDB?

step (s) executes one source line and descends into any function call it encounters. next (n) executes one source line but treats function calls as a single step, running them to completion without stopping inside.

GDB command quick reference

GDB, the GNU Debugger, lets you inspect and control a running program: pause at breakpoints, step line by line, examine memory and variables, and modify state on the fly. This reference groups the most-used commands by task so you can find the right syntax without paging through the manual.

Most commands have a short alias — b for break, r for run, c for continue, bt for backtrace — shown alongside each entry. Filter the table below by command, alias, or description.

How it works

GDB attaches to a process (by launching it, loading a core file, or attaching to a PID) and uses the host’s debugging facilities (ptrace on Linux) to control execution. Breakpoints work by patching the target instruction with a trap; when hit, control returns to GDB. Watchpoints use hardware debug registers when available, falling back to single-stepping otherwise. The TUI is a curses-based front end layered over the same command engine.

Stepping commands operate at the source-line granularity using the line-number information in the program’s debug symbols (compile with -g). Without symbols you fall back to instruction-level stepping (stepi, nexti) and raw addresses.

Tips and examples

A typical debug session:

gdb ./myprog
(gdb) break main
(gdb) run arg1 arg2
(gdb) next
(gdb) print someVar
(gdb) backtrace
(gdb) watch counter
(gdb) continue

To debug a crash from a core dump: gdb ./myprog core. Then bt full prints a full backtrace with local variables. Use frame N to switch stack frames and info locals to inspect that frame’s variables. Save repetitive setup in a .gdbinit file in the working directory.