Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

288 linhas
13KB

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