Use the Tab key whenever you want GDB to fill out the rest of a word. If there is only one possibility, GDB fills in the word, and waits for you to finish the command (or use Return to enter it). For example, if you type (gdb) info bre, and use the Tab key, GDB fills in the rest of the word ‘breakpoints’, since that is the only info subcommand beginning with ‘bre’.
You can either use Return
at this point, to run the info
breakpoints
command, or use the BACKSPACE
key and enter something else, if ‘breakpoints’
does not look like the command you expected. (If you were sure you wanted
info breakpoints
in the first place, you might as well just use Return
immediately after ‘info
bre’, to exploit
command abbreviations rather than command completion). If there is more
than one possibility for the next word when you use the Tab
key, GDB sounds a bell. You can either supply more characters and try again,
or just use the Tab
key a second time; GDB displays all the possible completions for that word.
For example, you might want to set a breakpoint on a subroutine whose name
begins with ‘make_’,
but when you type b
make_ and
use the Tab
key, GDB just sounds the bell. Using the Tab
key again displays all the function names in your program that begin with
those characters. For example, you type (gdb)
b make_ and then
use the Tab
key. GDB sounds the bell; you use the Tab
key again, to see the following display.
IMPORTANT:
M-?
means using the META
key (if there is one, usually the diamond-shaped character is on the key;
else, use ESC)
and the ‘?’
key. This is a command key sequence with which you may or may not be familiar.
Sometimes the string you need, while logically a word, may contain parentheses or other characters that GDB normally excludes from its notion of a word. To permit word completion to work in this situation, you may enclose words in single quote marks in GDB commands.
The most likely situation
where you might need this is in typing the name of a C++ function. This
is because C++ allows function overloading (multiple definitions of the
same function, distinguished by argument type). For example, when you want
to set a breakpoint you may need to distinguish whether you mean the version
of name
that takes an int
parameter, name(int),
or the version that takes a float
parameter, name(float).
To use the word-completion facilities in this situation, type a single
quote, ’, at the beginning
of the function name. This alerts GDB that it may need to consider more
information than usual when you use the Tab
key or M-?
to request word completion, as in the following example.
Use the M-?
command key sequence this point.
In some cases, GDB can tell
that completing a name requires using quotes. When this happens, GDB inserts
the quote for you (while completing as much as it can) if you do not type
the quote in the first place:
Use the Tab
key at this point.GDB alters your input line to the following, and rings
a bell.
In general, GDB can tell
that a quote is needed (and inserts it) if you have not yet started typing
the argument list when you ask for completion on an overloaded symbol.