Starting GDB
gdb
- Start GDB with the specified program.
gdb
- Start GDB with no program specified; you can load a program later.
gdb -p
- Attach GDB to a running process with the specified PID.
Basic Commands
run [args]
- Start the program with optional arguments.
quit
- Exit GDB.
help
- Show help for GDB commands.
info
- Display information about various types (e.g., info registers
).
list
- Display source code around the current line or function.
next
- Step over to the next line of code.
step
- Step into the next function call.
continue
- Resume program execution until the next breakpoint.
finish
- Continue execution until the current function returns.
Breakpoints
break
- Set a breakpoint at the specified location (e.g., break main
or break file.c:10
).
delete
- Delete the breakpoint with the specified number.
clear
- Clear a breakpoint at the specified location.
info breakpoints
- List all breakpoints and their statuses.
disable
- Disable the breakpoint with the specified number.
enable
- Enable the breakpoint with the specified number.
Inspecting Variables
print
- Evaluate and display the value of an expression.
display
- Display the value of an expression each time the program stops.
undisplay
- Stop displaying the expression with the specified number.
info locals
- Display the values of local variables in the current function.
info args
- Display the values of function arguments.
Stack Frames
backtrace
- Display the call stack.
frame
- Select a stack frame by its number.
up
- Move up the call stack to the previous frame.
down
- Move down the call stack to the next frame.
Code Execution
return
- Return from the current function with the specified value.
jump
- Jump to a specified line or function.
Watchpoints
watch
- Set a watchpoint for the specified expression.
rwatch
- Set a read watchpoint for the specified expression.
awatch
- Set an access watchpoint for the specified expression.
delete
- Delete the watchpoint with the specified number.
Threads
info threads
- List all threads.
thread
- Switch to the thread with the specified number.
thread apply all
- Apply a command to all threads (e.g., thread apply all bt
).
Signals
handle
- Set how GDB handles a signal (e.g., handle SIGINT nostop
).
info signals
- Display the current signal handling settings.
Files
file
- Load a different executable file into GDB.
symbol-file
- Load debugging symbols from a specified file.
Scripts
source
- Execute GDB commands from a script file.
Other
set
- Set a GDB variable to a specified value.
show
- Display the value of a GDB variable.
record
- Start recording the program's execution for replay.
restore
- Restore the program's state from a previously recorded state.