GNU Debugger Commands
The most common way to debug a program in Linux is to run gdb. gdb has a large number of commands, but you need only a few to find the cause of an error quickly. The table lists the commonly used gdb commands.
|This Command||Does the Following|
|break NUM||Sets a breakpoint at the specified line number, NUM. (The debugger stops at
|bt||Displays a trace of all stack frames. (This command shows you
the sequence of function calls so far.)
|clear FILENAME: NUM||Deletes the breakpoint at a specific line number, NUM, in the source file FILENAME. For example, clear
xdraw.c:8 clears the breakpoint at line 8 of file
|continue||Continues running the program being debugged. (Use this command
after the program stops due to a signal or breakpoint.)
|display EXPR||Displays the value of an expression, EXPR (consisting of variables defined in the
program) each time the program stops.
|file FILE||Loads the specified executable file, FILE, for debugging.|
|help NAME||Displays help on the command named NAME.|
|info break||Displays a list of current breakpoints, including information
on how many times each breakpoint is reached.
|info files||Displays detailed information about the file being
|info func||Displays all function names.|
|info local||Displays information about local variables of the current
|info prog||Displays the execution status of the program being
|info var||Displays all global and static variable names.|
|kill||Ends the program you’re debugging.|
|list||Lists a section of the source code.|
|make||Runs the make utility to rebuild the executable without leaving
|next||Advances one line of source code in the current function
without stepping into other functions.
|print EXPR||Shows the value of the expression EXPR.|
|run||Starts running the currently loaded executable.|
|set variable VAR=VALUE||Sets the value of the variable VAR to
|shell CMD||Executes the Unix command CMD,
without leaving gdb.
|step||Advances one line in the current function, stepping into other
functions, if any.
|watch VAR||Shows the value of the variable named VAR whenever the value changes.|
|where||Displays the call sequence. Use this command to locate where
your program died.
|x/F ADDR||Examines the contents of the memory location at address
ADDR in the format specified by the letter F, which
can be o (octal), x (hex), d (decimal), u (unsigned decimal), t
(binary), f (float), a (address), i (instruction), c (char), or s
(string). You can append a letter indicating the size of data type
to the format letter. Size letters are b (byte), h (halfword, 2
bytes), w (word, 4 bytes), and g (giant, 8 bytes). Typically,
ADDR is the name of a variable or pointer.