1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<!-- Copyright (C) 1988-2021 Free Software Foundation, Inc. 4 5Permission is granted to copy, distribute and/or modify this document 6under the terms of the GNU Free Documentation License, Version 1.3 or 7any later version published by the Free Software Foundation; with the 8Invariant Sections being "Free Software" and "Free Software Needs 9Free Documentation", with the Front-Cover Texts being "A GNU Manual," 10and with the Back-Cover Texts as in (a) below. 11 12(a) The FSF's Back-Cover Text is: "You are free to copy and modify 13this GNU Manual. Buying copies from GNU Press supports the FSF in 14developing GNU and promoting software freedom." --> 15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ --> 16<head> 17<title>Debugging with GDB: Completion</title> 18 19<meta name="description" content="Debugging with GDB: Completion"> 20<meta name="keywords" content="Debugging with GDB: Completion"> 21<meta name="resource-type" content="document"> 22<meta name="distribution" content="global"> 23<meta name="Generator" content="makeinfo"> 24<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 25<link href="index.html#Top" rel="start" title="Top"> 26<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> 27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> 28<link href="Commands.html#Commands" rel="up" title="Commands"> 29<link href="Command-Options.html#Command-Options" rel="next" title="Command Options"> 30<link href="Command-Settings.html#Command-Settings" rel="previous" title="Command Settings"> 31<style type="text/css"> 32<!-- 33a.summary-letter {text-decoration: none} 34blockquote.smallquotation {font-size: smaller} 35div.display {margin-left: 3.2em} 36div.example {margin-left: 3.2em} 37div.indentedblock {margin-left: 3.2em} 38div.lisp {margin-left: 3.2em} 39div.smalldisplay {margin-left: 3.2em} 40div.smallexample {margin-left: 3.2em} 41div.smallindentedblock {margin-left: 3.2em; font-size: smaller} 42div.smalllisp {margin-left: 3.2em} 43kbd {font-style:oblique} 44pre.display {font-family: inherit} 45pre.format {font-family: inherit} 46pre.menu-comment {font-family: serif} 47pre.menu-preformatted {font-family: serif} 48pre.smalldisplay {font-family: inherit; font-size: smaller} 49pre.smallexample {font-size: smaller} 50pre.smallformat {font-family: inherit; font-size: smaller} 51pre.smalllisp {font-size: smaller} 52span.nocodebreak {white-space:nowrap} 53span.nolinebreak {white-space:nowrap} 54span.roman {font-family:serif; font-weight:normal} 55span.sansserif {font-family:sans-serif; font-weight:normal} 56ul.no-bullet {list-style: none} 57--> 58</style> 59 60 61</head> 62 63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> 64<a name="Completion"></a> 65<div class="header"> 66<p> 67Next: <a href="Command-Options.html#Command-Options" accesskey="n" rel="next">Command Options</a>, Previous: <a href="Command-Settings.html#Command-Settings" accesskey="p" rel="previous">Command Settings</a>, Up: <a href="Commands.html#Commands" accesskey="u" rel="up">Commands</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> 68</div> 69<hr> 70<a name="Command-Completion"></a> 71<h3 class="section">3.3 Command Completion</h3> 72 73<a name="index-completion"></a> 74<a name="index-word-completion"></a> 75<p><small>GDB</small> can fill in the rest of a word in a command for you, if there is 76only one possibility; it can also show you what the valid possibilities 77are for the next word in a command, at any time. This works for <small>GDB</small> 78commands, <small>GDB</small> subcommands, command options, and the names of symbols 79in your program. 80</p> 81<p>Press the <tt class="key">TAB</tt> key whenever you want <small>GDB</small> to fill out the rest 82of a word. If there is only one possibility, <small>GDB</small> fills in the 83word, and waits for you to finish the command (or press <tt class="key">RET</tt> to 84enter it). For example, if you type 85</p> 86<div class="smallexample"> 87<pre class="smallexample">(gdb) info bre <span class="key">TAB</span> 88</pre></div> 89 90<p><small>GDB</small> fills in the rest of the word ‘<samp>breakpoints</samp>’, since that is 91the only <code>info</code> subcommand beginning with ‘<samp>bre</samp>’: 92</p> 93<div class="smallexample"> 94<pre class="smallexample">(gdb) info breakpoints 95</pre></div> 96 97<p>You can either press <tt class="key">RET</tt> at this point, to run the <code>info 98breakpoints</code> command, or backspace and enter something else, if 99‘<samp>breakpoints</samp>’ does not look like the command you expected. (If you 100were sure you wanted <code>info breakpoints</code> in the first place, you 101might as well just type <tt class="key">RET</tt> immediately after ‘<samp>info bre</samp>’, 102to exploit command abbreviations rather than command completion). 103</p> 104<p>If there is more than one possibility for the next word when you press 105<tt class="key">TAB</tt>, <small>GDB</small> sounds a bell. You can either supply more 106characters and try again, or just press <tt class="key">TAB</tt> a second time; 107<small>GDB</small> displays all the possible completions for that word. For 108example, you might want to set a breakpoint on a subroutine whose name 109begins with ‘<samp>make_</samp>’, but when you type <kbd>b make_<span class="key">TAB</span></kbd> <small>GDB</small> 110just sounds the bell. Typing <tt class="key">TAB</tt> again displays all the 111function names in your program that begin with those characters, for 112example: 113</p> 114<div class="smallexample"> 115<pre class="smallexample">(gdb) b make_ <span class="key">TAB</span> 116</pre><pre class="smallexample">GDB sounds bell; press <span class="key">TAB</span> again, to see: 117</pre><pre class="smallexample">make_a_section_from_file make_environ 118make_abs_section make_function_type 119make_blockvector make_pointer_type 120make_cleanup make_reference_type 121make_command make_symbol_completion_list 122(gdb) b make_ 123</pre></div> 124 125<p>After displaying the available possibilities, <small>GDB</small> copies your 126partial input (‘<samp>b make_</samp>’ in the example) so you can finish the 127command. 128</p> 129<p>If you just want to see the list of alternatives in the first place, you 130can press <kbd>M-?</kbd> rather than pressing <tt class="key">TAB</tt> twice. <kbd>M-?</kbd> 131means <kbd><span class="key">META</span> ?</kbd>. You can type this either by holding down a 132key designated as the <tt class="key">META</tt> shift on your keyboard (if there is 133one) while typing <kbd>?</kbd>, or as <tt class="key">ESC</tt> followed by <kbd>?</kbd>. 134</p> 135<p>If the number of possible completions is large, <small>GDB</small> will 136print as much of the list as it has collected, as well as a message 137indicating that the list may be truncated. 138</p> 139<div class="smallexample"> 140<pre class="smallexample">(gdb) b m<span class="key">TAB</span><span class="key">TAB</span> 141main 142<... the rest of the possible completions ...> 143*** List may be truncated, max-completions reached. *** 144(gdb) b m 145</pre></div> 146 147<p>This behavior can be controlled with the following commands: 148</p> 149<dl compact="compact"> 150<dd><a name="index-set-max_002dcompletions"></a> 151</dd> 152<dt><code>set max-completions <var>limit</var></code></dt> 153<dt><code>set max-completions unlimited</code></dt> 154<dd><p>Set the maximum number of completion candidates. <small>GDB</small> will 155stop looking for more completions once it collects this many candidates. 156This is useful when completing on things like function names as collecting 157all the possible candidates can be time consuming. 158The default value is 200. A value of zero disables tab-completion. 159Note that setting either no limit or a very large limit can make 160completion slow. 161<a name="index-show-max_002dcompletions"></a> 162</p></dd> 163<dt><code>show max-completions</code></dt> 164<dd><p>Show the maximum number of candidates that <small>GDB</small> will collect and show 165during completion. 166</p></dd> 167</dl> 168 169<a name="index-quotes-in-commands"></a> 170<a name="index-completion-of-quoted-strings"></a> 171<p>Sometimes the string you need, while logically a “word”, may contain 172parentheses or other characters that <small>GDB</small> normally excludes from 173its notion of a word. To permit word completion to work in this 174situation, you may enclose words in <code>'</code> (single quote marks) in 175<small>GDB</small> commands. 176</p> 177<p>A likely situation where you might need this is in typing an 178expression that involves a C<tt>++</tt> symbol name with template 179parameters. This is because when completing expressions, GDB treats 180the ‘<samp><</samp>’ character as word delimiter, assuming that it’s the 181less-than comparison operator (see <a href="C-Operators.html#C-Operators">C and C<tt>++</tt> 182Operators</a>). 183</p> 184<p>For example, when you want to call a C<tt>++</tt> template function 185interactively using the <code>print</code> or <code>call</code> commands, you may 186need to distinguish whether you mean the version of <code>name</code> that 187was specialized for <code>int</code>, <code>name<int>()</code>, or the version 188that was specialized for <code>float</code>, <code>name<float>()</code>. To use 189the word-completion facilities in this situation, type a single quote 190<code>'</code> at the beginning of the function name. This alerts 191<small>GDB</small> that it may need to consider more information than usual 192when you press <tt class="key">TAB</tt> or <kbd>M-?</kbd> to request word completion: 193</p> 194<div class="smallexample"> 195<pre class="smallexample">(gdb) p 'func< <kbd>M-?</kbd> 196func<int>() func<float>() 197(gdb) p 'func< 198</pre></div> 199 200<p>When setting breakpoints however (see <a href="Specify-Location.html#Specify-Location">Specify Location</a>), you don’t 201usually need to type a quote before the function name, because 202<small>GDB</small> understands that you want to set a breakpoint on a 203function: 204</p> 205<div class="smallexample"> 206<pre class="smallexample">(gdb) b func< <kbd>M-?</kbd> 207func<int>() func<float>() 208(gdb) b func< 209</pre></div> 210 211<p>This is true even in the case of typing the name of C<tt>++</tt> overloaded 212functions (multiple definitions of the same function, distinguished by 213argument type). For example, when you want to set a breakpoint you 214don’t need to distinguish whether you mean the version of <code>name</code> 215that takes an <code>int</code> parameter, <code>name(int)</code>, or the version 216that takes a <code>float</code> parameter, <code>name(float)</code>. 217</p> 218<div class="smallexample"> 219<pre class="smallexample">(gdb) b bubble( <kbd>M-?</kbd> 220bubble(int) bubble(double) 221(gdb) b bubble(dou <kbd>M-?</kbd> 222bubble(double) 223</pre></div> 224 225<p>See <a href="Symbols.html#quoting-names">quoting names</a> for a description of other scenarios that 226require quoting. 227</p> 228<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 229overload-resolution off</code> to disable overload resolution; 230see <a href="Debugging-C-Plus-Plus.html#Debugging-C-Plus-Plus"><small>GDB</small> Features for C<tt>++</tt></a>. 231</p> 232<a name="index-completion-of-structure-field-names"></a> 233<a name="index-structure-field-name-completion"></a> 234<a name="index-completion-of-union-field-names"></a> 235<a name="index-union-field-name-completion"></a> 236<p>When completing in an expression which looks up a field in a 237structure, <small>GDB</small> also tries<a name="DOCF2" href="#FOOT2"><sup>2</sup></a> to 238limit completions to the field names available in the type of the 239left-hand-side: 240</p> 241<div class="smallexample"> 242<pre class="smallexample">(gdb) p gdb_stdout.<kbd>M-?</kbd> 243magic to_fputs to_rewind 244to_data to_isatty to_write 245to_delete to_put to_write_async_safe 246to_flush to_read 247</pre></div> 248 249<p>This is because the <code>gdb_stdout</code> is a variable of the type 250<code>struct ui_file</code> that is defined in <small>GDB</small> sources as 251follows: 252</p> 253<div class="smallexample"> 254<pre class="smallexample">struct ui_file 255{ 256 int *magic; 257 ui_file_flush_ftype *to_flush; 258 ui_file_write_ftype *to_write; 259 ui_file_write_async_safe_ftype *to_write_async_safe; 260 ui_file_fputs_ftype *to_fputs; 261 ui_file_read_ftype *to_read; 262 ui_file_delete_ftype *to_delete; 263 ui_file_isatty_ftype *to_isatty; 264 ui_file_rewind_ftype *to_rewind; 265 ui_file_put_ftype *to_put; 266 void *to_data; 267} 268</pre></div> 269 270<div class="footnote"> 271<hr> 272<h4 class="footnotes-heading">Footnotes</h4> 273 274<h3><a name="FOOT2" href="#DOCF2">(2)</a></h3> 275<p>The completer can be 276confused by certain kinds of invalid expressions. Also, it only 277examines the static type of the expression, not the dynamic type.</p> 278</div> 279<hr> 280<div class="header"> 281<p> 282Next: <a href="Command-Options.html#Command-Options" accesskey="n" rel="next">Command Options</a>, Previous: <a href="Command-Settings.html#Command-Settings" accesskey="p" rel="previous">Command Settings</a>, Up: <a href="Commands.html#Commands" accesskey="u" rel="up">Commands</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> 283</div> 284 285 286 287</body> 288</html> 289