Skip to content

GDB速查

Command Abbreviation/Shortcut Description
run r Starts the program from the beginning with optional arguments.
break [location] b [location] Sets a breakpoint at the specified location (function name, line number, or address).
tbreak [location] tb [location] Sets a temporary breakpoint at the specified location; it gets deleted once hit.
continue c Continues program execution until the next breakpoint or program termination.
step s Executes the next line of code, stepping into function calls.
next n Executes the next line of code, stepping over function calls.
finish fin Continues execution until the current function returns.
until [location] u [location] Continues execution until a specified location is reached or the current loop ends.
stepi si Executes the next machine instruction, stepping into function calls at the instruction level.
nexti ni Executes the next machine instruction, stepping over function calls at the instruction level.
list [location] l [location] Displays source code around the specified location.
print [expression] p [expression] Evaluates and prints the value of an expression.
display [expression] disp [expression] Automatically displays the value of an expression every time the program stops.
undisplay [display number] undisp [display number] Cancels automatic display of an expression.
info display i disp Lists all automatic displays currently in effect.
set variable [var]=[value] set var [var]=[value] Assigns a new value to a variable in the program being debugged.
call [function(args)] N/A Calls a function in the program with the given arguments.
backtrace bt Displays the call stack (list of active function calls).
frame [frame number] f [frame number] Selects and displays the specified frame in the call stack.
up N/A Moves up one frame in the call stack.
down N/A Moves down one frame in the call stack.
info locals i locals Displays local variables in the current stack frame.
info args i args Displays arguments of the current function.
info variables i var Lists all global and static variable names.
info functions i func Lists all function names.
info breakpoints i b Lists all breakpoints and watchpoints with their statuses.
delete [breakpoint number] d [breakpoint number] Deletes the specified breakpoint or watchpoint.
enable [breakpoint number] en [breakpoint number] Enables a disabled breakpoint or watchpoint.
disable [breakpoint number] dis [breakpoint number] Disables an enabled breakpoint or watchpoint.
clear [location] cl [location] Deletes any breakpoints at the specified location.
watch [expression] N/A Sets a watchpoint that pauses execution when the value of an expression changes.
info watchpoints i watch Lists all watchpoints and their statuses.
awatch [expression] N/A Sets a watchpoint that pauses execution when the value of an expression is read or written.
rwatch [expression] N/A Sets a watchpoint that pauses execution when the value of an expression is read.
info threads i threads Lists all threads in the program.
thread [thread number] N/A Switches the context to the specified thread.
thread apply [thread(s)] [cmd] N/A Applies a command to a list of threads.
set thread [thread number] N/A Sets the default thread for command operations.
signal [signal name/number] N/A Sends a signal to the program being debugged.
handle [signal] [actions] N/A Specifies how GDB handles a signal (e.g., stop, print, pass).
x/[n][f][u] [address] N/A Examines memory at the specified address with options for count (n), format (f), and unit size (u).
set [option] [value] N/A Sets internal GDB variables or configuration options.
show [option] N/A Displays the current value of internal GDB variables or configuration options.
info registers i r Displays the contents of CPU registers.
target remote [host]:[port] N/A Connects to a remote target for debugging over a network or serial connection.
detach N/A Detaches GDB from the debugged process, allowing it to continue independently.
attach [pid] N/A Attaches GDB to a running process with the specified process ID.
quit q Exits GDB.
help [command] h [command] Displays help information for GDB commands.
info [subject] i [subject] Displays information about various debugger states (e.g., info files, info signals).
set args [arguments] N/A Specifies arguments to pass to the program when it starts.
show args N/A Displays the arguments to be passed to the program when it starts.
return [expression] ret [expression] Forces the current function to return immediately, optionally with a specified value.
jump [location] j [location] Sets the execution point to the specified location without executing any intervening code.
info sharedlibrary i shared Lists shared libraries loaded by the program.
load N/A Loads an executable file into GDB without restarting the debugger.
set breakpoint pending [on|off] N/A Controls whether to set breakpoints on future shared library loadings if the breakpoint location is not yet defined.
source [filename] N/A Executes GDB commands from a script file.
define [macro] N/A Defines a sequence of commands as a macro.
info macro [macro] N/A Displays the definition of a macro.
complete [command] N/A Provides command completion suggestions.
macro expand [macro] N/A Expands and displays a macro.
set logging on/off N/A Starts or stops logging of the GDB session to a file (gdb.txt by default).
set pagination off N/A Disables pagination of output, useful for scripting.
info frame N/A Displays detailed information about the selected stack frame.
info source N/A Displays information about the current source file, such as its path and modification time.
maint info sections N/A Displays detailed information about program sections, useful for low-level debugging.
target record N/A Starts recording the execution of the program, allowing reverse debugging.
reverse-step N/A Steps backward one line in the program. Requires recording to be active.
reverse-next N/A Steps backward over one line, stepping over function calls. Requires recording.
reverse-continue N/A Continues execution backward until a breakpoint is hit or the program starts. Requires recording.
set disassembly-flavor [flavor] N/A Sets the assembly syntax for disassembly output (att or intel).
disassemble [address range] disas [address range] Displays the assembly instructions in the specified address range or function.
info line [location] N/A Displays the address and possible breakpoint locations for a source line.
set print pretty [on|off] N/A Controls whether to format complex data types (like structures) in a readable form.
set print elements [number] N/A Limits the number of elements to display when printing arrays or structures.
info files N/A Displays information about the symbol files and executable files used by GDB.
set follow-fork-mode [parent|child] N/A Specifies whether GDB should continue debugging the parent or child process after a fork.
info signals N/A Displays information about how GDB handles various signals.
shell [command] ! [command] Executes a shell command without leaving GDB.
info address [symbol] N/A Displays the memory address of a symbol (variable or function).
start N/A Runs the program until the beginning of main().
set prompt [string] N/A Changes the GDB prompt to a specified string.
complete [text] N/A Lists possible completions for a partially typed command or expression.
apropos [keyword] N/A Searches for commands and variables that include the specified keyword.
maintenance info [topic] N/A Displays internal maintenance information for GDB developers and advanced users.
enable pagination N/A Re-enables pagination after it has been disabled.
set height [number] N/A Sets the number of lines in the display window for pagination purposes.
set width [number] N/A Sets the number of characters per line for output formatting.
set history save [on|off] N/A Controls whether GDB saves the command history to a file between sessions.
show commands N/A Displays the last ten commands from the command history.
edit [location] N/A Opens the source file at the specified location in a text editor defined by the EDITOR environment variable.
set environment [var]=[value] N/A Sets an environment variable for the program being debugged.
unset environment [var] N/A Removes an environment variable for the program being debugged.
info sharedlibrary i shared Displays information about shared libraries loaded by the program.
set substitute-path [from] [to] N/A Replaces the directory path when searching for source files, useful for debugging on different machines or directory structures.
  • 开启 tui 模式:

    • tui enable
    • tui disable
  • 显示当前行: frame

  • 在 tui 模式下切换界面:

    • ctrl + x o