Site Tools


wiki:gdb-running-and-stepping

Table of Contents

GDB Running and Stepping

Execution control moves through code to find where things break. Run starts the program; stepping commands move line-by-line with different depth.

(gdb) run                       # start program (pauses at breakpoint)
(gdb) run arg1 arg2             # start with command-line arguments
(gdb) run < input.txt           # redirect stdin
(gdb) continue (c)              # resume from breakpoint
(gdb) next (n)                  # next line (skip into function calls)
(gdb) step (s)                  # next line (step into functions)
(gdb) finish                    # run until return from current function
(gdb) until line 25             # run until line 25
(gdb) until                     # run until past current line (for loops)

next executes the next line but does not enter function calls—the whole call executes atomically. step enters functions, pausing on the first line inside. Use next to move quickly; use step when you need to inspect what a function does.

finish runs until the current function returns. Useful when you step into a function and realize you didn't need to debug it—skip back out to the caller without stepping through every line.

until runs until a specific line is reached or until the current line is left (for loops that would otherwise step 1000 times). Without a line number, until moves past the current line—useful inside loops to skip iterations.

Stepping is relative to the current frame (active function). If you step and hit a breakpoint elsewhere, stepping resumes from that breakpoint. backtrace shows which frame you're in.

wiki/gdb-running-and-stepping.md · Last modified: by 127.0.0.1