toolchain/share/doc/gdb/Completion.html

227 lines
12 KiB
HTML

<html lang="en">
<head>
<title>Completion - Debugging with GDB</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Debugging with GDB">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Commands.html#Commands" title="Commands">
<link rel="prev" href="Command-Syntax.html#Command-Syntax" title="Command Syntax">
<link rel="next" href="Help.html#Help" title="Help">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Copyright (C) 1988-2019 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Free Software'' and ``Free Software Needs
Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
and with the Back-Cover Texts as in (a) below.
(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
this GNU Manual. Buying copies from GNU Press supports the FSF in
developing GNU and promoting software freedom.''
-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="Completion"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Help.html#Help">Help</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Command-Syntax.html#Command-Syntax">Command Syntax</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Commands.html#Commands">Commands</a>
<hr>
</div>
<h3 class="section">3.2 Command Completion</h3>
<p><a name="index-completion-84"></a><a name="index-word-completion-85"></a><span class="sc">gdb</span> can fill in the rest of a word in a command for you, if there is
only one possibility; it can also show you what the valid possibilities
are for the next word in a command, at any time. This works for <span class="sc">gdb</span>
commands, <span class="sc">gdb</span> subcommands, and the names of symbols in your program.
<p>Press the &lt;TAB&gt; key whenever you want <span class="sc">gdb</span> to fill out the rest
of a word. If there is only one possibility, <span class="sc">gdb</span> fills in the
word, and waits for you to finish the command (or press &lt;RET&gt; to
enter it). For example, if you type
<!-- FIXME "@key" does not distinguish its argument sufficiently to permit -->
<!-- complete accuracy in these examples; space introduced for clarity. -->
<!-- If texinfo enhancements make it unnecessary, it would be nice to -->
<!-- replace " @key" by "@key" in the following... -->
<pre class="smallexample"> (gdb) info bre &lt;TAB&gt;
</pre>
<p class="noindent"><span class="sc">gdb</span> fills in the rest of the word &lsquo;<samp><span class="samp">breakpoints</span></samp>&rsquo;, since that is
the only <code>info</code> subcommand beginning with &lsquo;<samp><span class="samp">bre</span></samp>&rsquo;:
<pre class="smallexample"> (gdb) info breakpoints
</pre>
<p class="noindent">You can either press &lt;RET&gt; at this point, to run the <code>info
breakpoints</code> command, or backspace and enter something else, if
&lsquo;<samp><span class="samp">breakpoints</span></samp>&rsquo; does not look like the command you expected. (If you
were sure you wanted <code>info breakpoints</code> in the first place, you
might as well just type &lt;RET&gt; immediately after &lsquo;<samp><span class="samp">info bre</span></samp>&rsquo;,
to exploit command abbreviations rather than command completion).
<p>If there is more than one possibility for the next word when you press
&lt;TAB&gt;, <span class="sc">gdb</span> sounds a bell. You can either supply more
characters and try again, or just press &lt;TAB&gt; a second time;
<span class="sc">gdb</span> displays all the possible completions for that word. For
example, you might want to set a breakpoint on a subroutine whose name
begins with &lsquo;<samp><span class="samp">make_</span></samp>&rsquo;, but when you type <kbd>b make_&lt;TAB&gt;</kbd> <span class="sc">gdb</span>
just sounds the bell. Typing &lt;TAB&gt; again displays all the
function names in your program that begin with those characters, for
example:
<pre class="smallexample"> (gdb) b make_ &lt;TAB&gt;
<br><span class="sc">gdb</span> sounds bell; press &lt;TAB&gt; again, to see:<br>
make_a_section_from_file make_environ
make_abs_section make_function_type
make_blockvector make_pointer_type
make_cleanup make_reference_type
make_command make_symbol_completion_list
(gdb) b make_
</pre>
<p class="noindent">After displaying the available possibilities, <span class="sc">gdb</span> copies your
partial input (&lsquo;<samp><span class="samp">b make_</span></samp>&rsquo; in the example) so you can finish the
command.
<p>If you just want to see the list of alternatives in the first place, you
can press <kbd>M-?</kbd> rather than pressing &lt;TAB&gt; twice. <kbd>M-?</kbd>
means <kbd>&lt;META&gt; ?</kbd>. You can type this either by holding down a
key designated as the &lt;META&gt; shift on your keyboard (if there is
one) while typing <kbd>?</kbd>, or as &lt;ESC&gt; followed by <kbd>?</kbd>.
<p>If the number of possible completions is large, <span class="sc">gdb</span> will
print as much of the list as it has collected, as well as a message
indicating that the list may be truncated.
<pre class="smallexample"> (gdb) b m&lt;TAB&gt;&lt;TAB&gt;
main
&lt;... the rest of the possible completions ...&gt;
*** List may be truncated, max-completions reached. ***
(gdb) b m
</pre>
<p class="noindent">This behavior can be controlled with the following commands:
<a name="index-set-max_002dcompletions-86"></a>
<dl><dt><code>set max-completions </code><var>limit</var><dt><code>set max-completions unlimited</code><dd>Set the maximum number of completion candidates. <span class="sc">gdb</span> will
stop looking for more completions once it collects this many candidates.
This is useful when completing on things like function names as collecting
all the possible candidates can be time consuming.
The default value is 200. A value of zero disables tab-completion.
Note that setting either no limit or a very large limit can make
completion slow.
<a name="index-show-max_002dcompletions-87"></a><br><dt><code>show max-completions</code><dd>Show the maximum number of candidates that <span class="sc">gdb</span> will collect and show
during completion.
</dl>
<p><a name="index-quotes-in-commands-88"></a><a name="index-completion-of-quoted-strings-89"></a>Sometimes the string you need, while logically a &ldquo;word&rdquo;, may contain
parentheses or other characters that <span class="sc">gdb</span> normally excludes from
its notion of a word. To permit word completion to work in this
situation, you may enclose words in <code>'</code> (single quote marks) in
<span class="sc">gdb</span> commands.
<p>A likely situation where you might need this is in typing an
expression that involves a C<tt>++</tt> symbol name with template
parameters. This is because when completing expressions, GDB treats
the &lsquo;<samp><span class="samp">&lt;</span></samp>&rsquo; character as word delimiter, assuming that it's the
less-than comparison operator (see <a href="C-Operators.html#C-Operators">C and C<tt>++</tt> Operators</a>).
<p>For example, when you want to call a C<tt>++</tt> template function
interactively using the <code>print</code> or <code>call</code> commands, you may
need to distinguish whether you mean the version of <code>name</code> that
was specialized for <code>int</code>, <code>name&lt;int&gt;()</code>, or the version
that was specialized for <code>float</code>, <code>name&lt;float&gt;()</code>. To use
the word-completion facilities in this situation, type a single quote
<code>'</code> at the beginning of the function name. This alerts
<span class="sc">gdb</span> that it may need to consider more information than usual
when you press &lt;TAB&gt; or <kbd>M-?</kbd> to request word completion:
<pre class="smallexample"> (gdb) p 'func&lt; <kbd>M-?</kbd>
func&lt;int&gt;() func&lt;float&gt;()
(gdb) p 'func&lt;
</pre>
<p>When setting breakpoints however (see <a href="Specify-Location.html#Specify-Location">Specify Location</a>), you don't
usually need to type a quote before the function name, because
<span class="sc">gdb</span> understands that you want to set a breakpoint on a
function:
<pre class="smallexample"> (gdb) b func&lt; <kbd>M-?</kbd>
func&lt;int&gt;() func&lt;float&gt;()
(gdb) b func&lt;
</pre>
<p>This is true even in the case of typing the name of C<tt>++</tt> overloaded
functions (multiple definitions of the same function, distinguished by
argument type). For example, when you want to set a breakpoint you
don't need to distinguish whether you mean the version of <code>name</code>
that takes an <code>int</code> parameter, <code>name(int)</code>, or the version
that takes a <code>float</code> parameter, <code>name(float)</code>.
<pre class="smallexample"> (gdb) b bubble( <kbd>M-?</kbd>
bubble(int) bubble(double)
(gdb) b bubble(dou <kbd>M-?</kbd>
bubble(double)
</pre>
<p>See <a href="quoting-names.html#quoting-names">quoting names</a> for a description of other scenarios that
require quoting.
<p>For more information about overloaded functions, see <a href="C-Plus-Plus-Expressions.html#C-Plus-Plus-Expressions">C<tt>++</tt> Expressions</a>. You can use the command <code>set
overload-resolution off</code> to disable overload resolution;
see <a href="Debugging-C-Plus-Plus.html#Debugging-C-Plus-Plus"><span class="sc">gdb</span> Features for C<tt>++</tt></a>.
<p><a name="index-completion-of-structure-field-names-90"></a><a name="index-structure-field-name-completion-91"></a><a name="index-completion-of-union-field-names-92"></a><a name="index-union-field-name-completion-93"></a>When completing in an expression which looks up a field in a
structure, <span class="sc">gdb</span> also tries<a rel="footnote" href="#fn-1" name="fnd-1"><sup>1</sup></a> to
limit completions to the field names available in the type of the
left-hand-side:
<pre class="smallexample"> (gdb) p gdb_stdout.<kbd>M-?</kbd>
magic to_fputs to_rewind
to_data to_isatty to_write
to_delete to_put to_write_async_safe
to_flush to_read
</pre>
<p class="noindent">This is because the <code>gdb_stdout</code> is a variable of the type
<code>struct ui_file</code> that is defined in <span class="sc">gdb</span> sources as
follows:
<pre class="smallexample"> struct ui_file
{
int *magic;
ui_file_flush_ftype *to_flush;
ui_file_write_ftype *to_write;
ui_file_write_async_safe_ftype *to_write_async_safe;
ui_file_fputs_ftype *to_fputs;
ui_file_read_ftype *to_read;
ui_file_delete_ftype *to_delete;
ui_file_isatty_ftype *to_isatty;
ui_file_rewind_ftype *to_rewind;
ui_file_put_ftype *to_put;
void *to_data;
}
</pre>
<div class="footnote">
<hr>
<h4>Footnotes</h4><p class="footnote"><small>[<a name="fn-1" href="#fnd-1">1</a>]</small> The completer can be
confused by certain kinds of invalid expressions. Also, it only
examines the static type of the expression, not the dynamic type.</p>
<hr></div>
</body></html>