Completion.html 13 KB

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