您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

234 行
10KB

  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>Debugging C Plus Plus (Debugging with GDB)</title>
  17. <meta name="description" content="Debugging C Plus Plus (Debugging with GDB)">
  18. <meta name="keywords" content="Debugging C Plus Plus (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="C.html#C" rel="up" title="C">
  26. <link href="Decimal-Floating-Point.html#Decimal-Floating-Point" rel="next" title="Decimal Floating Point">
  27. <link href="Debugging-C.html#Debugging-C" rel="prev" title="Debugging C">
  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="Debugging-C-Plus-Plus"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Decimal-Floating-Point.html#Decimal-Floating-Point" accesskey="n" rel="next">Decimal Floating Point</a>, Previous: <a href="Debugging-C.html#Debugging-C" accesskey="p" rel="prev">Debugging C</a>, Up: <a href="C.html#C" accesskey="u" rel="up">C</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="GDB-Features-for-C_002b_002b"></a>
  64. <h4 class="subsubsection">15.4.1.7 <small>GDB</small> Features for C<tt>++</tt></h4>
  65. <a name="index-commands-for-C_002b_002b"></a>
  66. <p>Some <small>GDB</small> commands are particularly useful with C<tt>++</tt>, and some are
  67. designed specifically for use with C<tt>++</tt>. Here is a summary:
  68. </p>
  69. <dl compact="compact">
  70. <dd><a name="index-break-in-overloaded-functions"></a>
  71. </dd>
  72. <dt><code><span class="roman">breakpoint menus</span></code></dt>
  73. <dd><p>When you want a breakpoint in a function whose name is overloaded,
  74. <small>GDB</small> has the capability to display a menu of possible breakpoint
  75. locations to help you specify which function definition you want.
  76. See <a href="Ambiguous-Expressions.html#Ambiguous-Expressions">Ambiguous Expressions</a>.
  77. </p>
  78. <a name="index-overloading-in-C_002b_002b"></a>
  79. </dd>
  80. <dt><code>rbreak <var>regex</var></code></dt>
  81. <dd><p>Setting breakpoints using regular expressions is helpful for setting
  82. breakpoints on overloaded functions that are not members of any special
  83. classes.
  84. See <a href="Set-Breaks.html#Set-Breaks">Setting Breakpoints</a>.
  85. </p>
  86. <a name="index-C_002b_002b-exception-handling"></a>
  87. </dd>
  88. <dt><code>catch throw</code></dt>
  89. <dt><code>catch rethrow</code></dt>
  90. <dt><code>catch catch</code></dt>
  91. <dd><p>Debug C<tt>++</tt> exception handling using these commands. See <a href="Set-Catchpoints.html#Set-Catchpoints">Setting Catchpoints</a>.
  92. </p>
  93. <a name="index-inheritance"></a>
  94. </dd>
  95. <dt><code>ptype <var>typename</var></code></dt>
  96. <dd><p>Print inheritance relationships as well as other information for type
  97. <var>typename</var>.
  98. See <a href="Symbols.html#Symbols">Examining the Symbol Table</a>.
  99. </p>
  100. </dd>
  101. <dt><code>info vtbl <var>expression</var>.</code></dt>
  102. <dd><p>The <code>info vtbl</code> command can be used to display the virtual
  103. method tables of the object computed by <var>expression</var>. This shows
  104. one entry per virtual table; there may be multiple virtual tables when
  105. multiple inheritance is in use.
  106. </p>
  107. <a name="index-C_002b_002b-demangling"></a>
  108. </dd>
  109. <dt><code>demangle <var>name</var></code></dt>
  110. <dd><p>Demangle <var>name</var>.
  111. See <a href="Symbols.html#Symbols">Symbols</a>, for a more complete description of the <code>demangle</code> command.
  112. </p>
  113. <a name="index-C_002b_002b-symbol-display"></a>
  114. </dd>
  115. <dt><code>set print demangle</code></dt>
  116. <dt><code>show print demangle</code></dt>
  117. <dt><code>set print asm-demangle</code></dt>
  118. <dt><code>show print asm-demangle</code></dt>
  119. <dd><p>Control whether C<tt>++</tt> symbols display in their source form, both when
  120. displaying code as C<tt>++</tt> source and when displaying disassemblies.
  121. See <a href="Print-Settings.html#Print-Settings">Print Settings</a>.
  122. </p>
  123. </dd>
  124. <dt><code>set print object</code></dt>
  125. <dt><code>show print object</code></dt>
  126. <dd><p>Choose whether to print derived (actual) or declared types of objects.
  127. See <a href="Print-Settings.html#Print-Settings">Print Settings</a>.
  128. </p>
  129. </dd>
  130. <dt><code>set print vtbl</code></dt>
  131. <dt><code>show print vtbl</code></dt>
  132. <dd><p>Control the format for printing virtual function tables.
  133. See <a href="Print-Settings.html#Print-Settings">Print Settings</a>.
  134. (The <code>vtbl</code> commands do not work on programs compiled with the HP
  135. ANSI C<tt>++</tt> compiler (<code>aCC</code>).)
  136. </p>
  137. <a name="index-set-overload_002dresolution"></a>
  138. <a name="index-overloaded-functions_002c-overload-resolution"></a>
  139. </dd>
  140. <dt><code>set overload-resolution on</code></dt>
  141. <dd><p>Enable overload resolution for C<tt>++</tt> expression evaluation. The default
  142. is on. For overloaded functions, <small>GDB</small> evaluates the arguments
  143. and searches for a function whose signature matches the argument types,
  144. using the standard C<tt>++</tt> conversion rules (see <a href="C-Plus-Plus-Expressions.html#C-Plus-Plus-Expressions">C<tt>++</tt> Expressions</a>, for details).
  145. If it cannot find a match, it emits a message.
  146. </p>
  147. </dd>
  148. <dt><code>set overload-resolution off</code></dt>
  149. <dd><p>Disable overload resolution for C<tt>++</tt> expression evaluation. For
  150. overloaded functions that are not class member functions, <small>GDB</small>
  151. chooses the first function of the specified name that it finds in the
  152. symbol table, whether or not its arguments are of the correct type. For
  153. overloaded functions that are class member functions, <small>GDB</small>
  154. searches for a function whose signature <em>exactly</em> matches the
  155. argument types.
  156. </p>
  157. <a name="index-show-overload_002dresolution"></a>
  158. </dd>
  159. <dt><code>show overload-resolution</code></dt>
  160. <dd><p>Show the current setting of overload resolution.
  161. </p>
  162. </dd>
  163. <dt><code><span class="roman">Overloaded symbol names</span></code></dt>
  164. <dd><p>You can specify a particular definition of an overloaded symbol, using
  165. the same notation that is used to declare such symbols in C<tt>++</tt>: type
  166. <code><var>symbol</var>(<var>types</var>)</code> rather than just <var>symbol</var>. You can
  167. also use the <small>GDB</small> command-line word completion facilities to list the
  168. available choices, or to finish the type list for you.
  169. See <a href="Completion.html#Completion">Command Completion</a>, for details on how to do this.
  170. </p>
  171. </dd>
  172. <dt><code><span class="roman">Breakpoints in functions with ABI tags</span></code></dt>
  173. <dd>
  174. <p>The GNU C<tt>++</tt> compiler introduced the notion of ABI &ldquo;tags&rdquo;, which
  175. correspond to changes in the ABI of a type, function, or variable that
  176. would not otherwise be reflected in a mangled name. See
  177. <a href="https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/">https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/</a>
  178. for more detail.
  179. </p>
  180. <p>The ABI tags are visible in C<tt>++</tt> demangled names. For example, a
  181. function that returns a std::string:
  182. </p>
  183. <div class="smallexample">
  184. <pre class="smallexample">std::string function(int);
  185. </pre></div>
  186. <p>when compiled for the C++11 ABI is marked with the <code>cxx11</code> ABI
  187. tag, and <small>GDB</small> displays the symbol like this:
  188. </p>
  189. <div class="smallexample">
  190. <pre class="smallexample">function[abi:cxx11](int)
  191. </pre></div>
  192. <p>You can set a breakpoint on such functions simply as if they had no
  193. tag. For example:
  194. </p>
  195. <div class="smallexample">
  196. <pre class="smallexample">(gdb) b function(int)
  197. Breakpoint 2 at 0x40060d: file main.cc, line 10.
  198. (gdb) info breakpoints
  199. Num Type Disp Enb Address What
  200. 1 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
  201. at main.cc:10
  202. </pre></div>
  203. <p>On the rare occasion you need to disambiguate between different ABI
  204. tags, you can do so by simply including the ABI tag in the function
  205. name, like:
  206. </p>
  207. <div class="smallexample">
  208. <pre class="smallexample">(gdb) b ambiguous[abi:other_tag](int)
  209. </pre></div>
  210. </dd>
  211. </dl>
  212. <hr>
  213. <div class="header">
  214. <p>
  215. Next: <a href="Decimal-Floating-Point.html#Decimal-Floating-Point" accesskey="n" rel="next">Decimal Floating Point</a>, Previous: <a href="Debugging-C.html#Debugging-C" accesskey="p" rel="prev">Debugging C</a>, Up: <a href="C.html#C" accesskey="u" rel="up">C</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>
  216. </div>
  217. </body>
  218. </html>