Cover | Table of Contents
Constant width$echo command.[ ]Constant width$echo command.[ ]^x-g3 and -gdwarf-2 options, GDB understands references to C preprocessor macros. This is particularly helpful for code using macros to simplify complicated gdb [options] [executable [corefile-or-PID]] gdb [options] --args executable [program args ...]
gdbtui command is equivalent to gdb --tui; it invokes GDB with the Text User Interface (TUI). The TUI is described in the later section "."--args--async, --noasync-b baudrate, --baud baudrate--batch--cd dir-c file, --core file-d dir, --directory dir-e file, --exec file-f, --fullname--help--interpreter interp-m, --mapped-n, --nx-nw, --nowindows-p pidnum, -c pidnum, --pid pidnum-q, --quiet, --silent-r, --readnow-s file, --symbols file--se file--statistics-t device, --tty device--tui-x file, --command file--version-w, --windows--write# and continue to the end of the line. GDB executes commands from initialization files and from the command line in the following order:-x option.-nx option to make GDB skip the execution of the initialization files.vi- or Emacs-style commands for editing your command line. The readline library reads the file ~/.inputrc to initialize its settings and options. The details are beyond the scope of this book; see the Bash and GDB documentation or the online Info system for the full story. Here is a sample .inputrc file:set editing-mode vi | Use vi editor commands |
set horizontal-scroll-mode On | Scroll line left/right as cursor moves along it |
control-h: backward-delete-char | Use ^H as backspace character |
set comment-begin # | For Bash, # starts comments |
set expand-tilde On | Expand ~ notation |
"\C-r": redraw-current-line | Make ^R redraw the current input line |
print, GDB saves the value in the value history. You can reference these saved values by their numeric place in the history, preceded with a $. GDB reminds you of this by printing $n = val. For example:$ gdb whizprog ... (gdb) print stopped_early $1 = 0 (gdb) print whiny_users $2 = TRUE (gdb)
$ refers to the most recent value in the value history. This can save considerable typing. If you've just looked at a pointer variable, you can use:(gdb) print *$$$ refers to the next most recent value in the history, and $$n refers to the value n places from the end. (Thus, $n counts from the beginning, while $$n counts from the end.)show values to see the values in the history. Whenever GDB reloads the executable (rereads the symbol table), it clears the value history. This is because the value history may have contained pointers into the symbol table and such pointers become invalid when the symbol table is reloaded.$ and consist of alphanumeric characters and underscores. They should start with a letter or underscore. (Note that values in the value history have names that are numeric.) You might want to use a convenience variable as an array index:(gdb) set $j = 0 (gdb) print data[$j++]
xterm. This can be quite effective, especially since it allows you to do everything from the keyboard.set options and GDB commands are specific to the TUI. These are listed along with the rest of the set options and GDB commands in the later section "," and in the later section "."Alias | Short for ... | Alias | Short for ... |
|---|---|---|---|
bt | backtrace | i | info |
c | continue | l | list |
cont | continue | n | next |
d | delete | ni | nexti |
dir | directory | p | print |
dis | disable | po | print-object |
do | down | r | run |
e | edit | s | step |
f | frame | share | sharedlibrary |
fo | forward-search | si | stepi |
gcore | generate-core-file | u | until |
h | help | where | backtrace |
awatch | Set an expression watchpoint. |
break | Set a breakpoint at a line or function. |
catch | Set a catchpoint to catch an event. |
clear | Clear a given breakpoint. |
commands | Specify commands to run when a breakpoint is reached. |
condition | Supply a condition to a particular breakpoint. |
delete | Delete one or more breakpoints or auto-display expressions. |
disable | Disable one or more breakpoints. |
enable | Enable one or more breakpoints. |
hbreak | Set a hardware-assisted breakpoint. |
ignore | Set the ignore-count of a particular breakpoint. |
rbreak | Set a breakpoint for all functions matching a regular expression. |
rwatch | Set a read watchpoint for an expression. |
tbreak | Set a temporary breakpoint. |
tcatch | Set a temporary catchpoint. |
thbreak | Set a temporary hardware-assisted breakpoint. |
watch | Set an expression watchpoint. |
call | Call a function in the program. |
delete display | Cancel one or more expressions that have been set to display when the program stops. |
delete mem | Delete a memory region. |
disable display | Disable one or more expressions that have been set to display when the program stops. |
disable mem | Disable a memory region. |
disassemble | Disassemble a section of memory. |
display | Print the value of an expression each time the program stops. |
enable display | Enable one or more expressions that have been set to display when the program stops. |
enable mem | Enable a memory region. |
inspect | Same as print. |
mem | Define attributes for a memory region. |
output | Similar to print, but doesn't save the value in history and doesn't print a newline. For scripting. |
print | Print the value of an expression. |
print-object | Cause an Objective C object to print information about itself. |
printf | Print values such as the |
set command accepts a large number of different parameters that control GDB's behavior. Many of the accepted parameters are rather esoteric. The show command displays the values of the same parameters as set accepts. The following section summarizes the parameters and how they affect GDB.set option and set option on are equivalent; they enable the option. Use set option off to disable the option.set annotate level
show annotateannotation_level variable to level. GUI programs that call GDB as a subsidiary process use this variable.set architecture architecture
show architectureset args show args
run command uses this list when it isn't given any arguments. See the entry for run in the later section "."set auto-solib-add show auto-solib-add
off, symbols must be loaded manually with the sharedlibrary command.set auto-solib-limit megs
show auto-solib-limitset backtrace limit count
show backtrace limit
set backtrace past-main
show backtrace past-mainmain( ) function. Such startup code is usually not of interest, thus the default is off.set breakpoint pending val
show breakpoint pendingon, off, or auto. When val is on, GDB automatically creates a pending breakpoint. For auto, it asks you. For off, pending breakpoints are not created.set can-use-hw-watchpoints
info command displays information about the state of the debuggee (as opposed to show, which provides information about internal GDB features, variables, and options). With no arguments, it provides a list of possible features about which information is available.info ... | Information displayed |
|---|---|
address sym | Information about where symbol sym is stored. This is either a memory address or a register name. |
all-registers | Information about all registers, including floating-point registers. |
args | Information about the arguments to the current function (stack frame). |
break [bpnum] | Information about breakpoint bpnum if given, or about all breakpoints if not. |
breakpoints [bpnum] | Same information as the info break command. |
catch | Information on exception handlers active in the current frame. |
classes [regexp] | Information about Objective-C classes that match regexp, or about all classes if regexp is not given. |
display | Information about items in the automatic display list. |
extensions | Information about the correspondence of filename extensions to source code programming languages. |
f [address] | Same information as the info frame command. |
files | Information about the current debugging target, including the current executable, core, and symbol files. |
float | Information about the floating-point hardware. |
frame [address] | With no argument, print information about the current frame. With an address, print information about the frame containing address, but do not make it the current frame. |
functions [regexp] | With no argument, print the names and types of all functions. Otherwise, print information about functions whose names match regexp. |
handle | The list of all signals and how GDB currently treats them. |
line line-spec | The starting and ending address for the code containing the line specified by line-spec. See list in the "" section for a description of line-spec. This sets the default address to the starting address for the given line, so that x/i may be used to examine instructions. |
locals | Information about local variables ( static or automatic) accessible from the current frame. |
macro macroname | Show the definition and source location for the macro |
add-symbol-file file addr [-mapped] [-readnow] add-symbol-file file [-s section address ...]
-mapped and -readnow options are the same as for the file command; see file for more information. You may use -s to name the memory starting at address with the name section. You can provide multiple section/address pairs with multiple -s options.advance bp-specbreak command (see break for the details). This command is like the until command, but it does not skip recursive function calls, and the location doesn't have to be in the current frame.apropos regexgrep); however, it also ignores case when matching.attach pidawatch expressionbacktrace [count]break [bp-spec] break bp-spec if condition
Return to GDB Pocket Reference