<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <!-- 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." --> <!-- Created by GNU Texinfo 6.4, http://www.gnu.org/software/texinfo/ --> <head> <title>Debugging C Plus Plus (Debugging with GDB)</title> <meta name="description" content="Debugging C Plus Plus (Debugging with GDB)"> <meta name="keywords" content="Debugging C Plus Plus (Debugging with GDB)"> <meta name="resource-type" content="document"> <meta name="distribution" content="global"> <meta name="Generator" content="makeinfo"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="index.html#Top" rel="start" title="Top"> <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> <link href="C.html#C" rel="up" title="C"> <link href="Decimal-Floating-Point.html#Decimal-Floating-Point" rel="next" title="Decimal Floating Point"> <link href="Debugging-C.html#Debugging-C" rel="prev" title="Debugging C"> <style type="text/css"> <!-- a.summary-letter {text-decoration: none} blockquote.indentedblock {margin-right: 0em} blockquote.smallindentedblock {margin-right: 0em; font-size: smaller} blockquote.smallquotation {font-size: smaller} div.display {margin-left: 3.2em} div.example {margin-left: 3.2em} div.lisp {margin-left: 3.2em} div.smalldisplay {margin-left: 3.2em} div.smallexample {margin-left: 3.2em} div.smalllisp {margin-left: 3.2em} kbd {font-style: oblique} pre.display {font-family: inherit} pre.format {font-family: inherit} pre.menu-comment {font-family: serif} pre.menu-preformatted {font-family: serif} pre.smalldisplay {font-family: inherit; font-size: smaller} pre.smallexample {font-size: smaller} pre.smallformat {font-family: inherit; font-size: smaller} pre.smalllisp {font-size: smaller} span.nolinebreak {white-space: nowrap} span.roman {font-family: initial; font-weight: normal} span.sansserif {font-family: sans-serif; font-weight: normal} ul.no-bullet {list-style: none} --> </style> </head> <body lang="en"> <a name="Debugging-C-Plus-Plus"></a> <div class="header"> <p> 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> [<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> </div> <hr> <a name="GDB-Features-for-C_002b_002b"></a> <h4 class="subsubsection">15.4.1.7 <small>GDB</small> Features for C<tt>++</tt></h4> <a name="index-commands-for-C_002b_002b"></a> <p>Some <small>GDB</small> commands are particularly useful with C<tt>++</tt>, and some are designed specifically for use with C<tt>++</tt>. Here is a summary: </p> <dl compact="compact"> <dd><a name="index-break-in-overloaded-functions"></a> </dd> <dt><code><span class="roman">breakpoint menus</span></code></dt> <dd><p>When you want a breakpoint in a function whose name is overloaded, <small>GDB</small> has the capability to display a menu of possible breakpoint locations to help you specify which function definition you want. See <a href="Ambiguous-Expressions.html#Ambiguous-Expressions">Ambiguous Expressions</a>. </p> <a name="index-overloading-in-C_002b_002b"></a> </dd> <dt><code>rbreak <var>regex</var></code></dt> <dd><p>Setting breakpoints using regular expressions is helpful for setting breakpoints on overloaded functions that are not members of any special classes. See <a href="Set-Breaks.html#Set-Breaks">Setting Breakpoints</a>. </p> <a name="index-C_002b_002b-exception-handling"></a> </dd> <dt><code>catch throw</code></dt> <dt><code>catch rethrow</code></dt> <dt><code>catch catch</code></dt> <dd><p>Debug C<tt>++</tt> exception handling using these commands. See <a href="Set-Catchpoints.html#Set-Catchpoints">Setting Catchpoints</a>. </p> <a name="index-inheritance"></a> </dd> <dt><code>ptype <var>typename</var></code></dt> <dd><p>Print inheritance relationships as well as other information for type <var>typename</var>. See <a href="Symbols.html#Symbols">Examining the Symbol Table</a>. </p> </dd> <dt><code>info vtbl <var>expression</var>.</code></dt> <dd><p>The <code>info vtbl</code> command can be used to display the virtual method tables of the object computed by <var>expression</var>. This shows one entry per virtual table; there may be multiple virtual tables when multiple inheritance is in use. </p> <a name="index-C_002b_002b-demangling"></a> </dd> <dt><code>demangle <var>name</var></code></dt> <dd><p>Demangle <var>name</var>. See <a href="Symbols.html#Symbols">Symbols</a>, for a more complete description of the <code>demangle</code> command. </p> <a name="index-C_002b_002b-symbol-display"></a> </dd> <dt><code>set print demangle</code></dt> <dt><code>show print demangle</code></dt> <dt><code>set print asm-demangle</code></dt> <dt><code>show print asm-demangle</code></dt> <dd><p>Control whether C<tt>++</tt> symbols display in their source form, both when displaying code as C<tt>++</tt> source and when displaying disassemblies. See <a href="Print-Settings.html#Print-Settings">Print Settings</a>. </p> </dd> <dt><code>set print object</code></dt> <dt><code>show print object</code></dt> <dd><p>Choose whether to print derived (actual) or declared types of objects. See <a href="Print-Settings.html#Print-Settings">Print Settings</a>. </p> </dd> <dt><code>set print vtbl</code></dt> <dt><code>show print vtbl</code></dt> <dd><p>Control the format for printing virtual function tables. See <a href="Print-Settings.html#Print-Settings">Print Settings</a>. (The <code>vtbl</code> commands do not work on programs compiled with the HP ANSI C<tt>++</tt> compiler (<code>aCC</code>).) </p> <a name="index-set-overload_002dresolution"></a> <a name="index-overloaded-functions_002c-overload-resolution"></a> </dd> <dt><code>set overload-resolution on</code></dt> <dd><p>Enable overload resolution for C<tt>++</tt> expression evaluation. The default is on. For overloaded functions, <small>GDB</small> evaluates the arguments and searches for a function whose signature matches the argument types, 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). If it cannot find a match, it emits a message. </p> </dd> <dt><code>set overload-resolution off</code></dt> <dd><p>Disable overload resolution for C<tt>++</tt> expression evaluation. For overloaded functions that are not class member functions, <small>GDB</small> chooses the first function of the specified name that it finds in the symbol table, whether or not its arguments are of the correct type. For overloaded functions that are class member functions, <small>GDB</small> searches for a function whose signature <em>exactly</em> matches the argument types. </p> <a name="index-show-overload_002dresolution"></a> </dd> <dt><code>show overload-resolution</code></dt> <dd><p>Show the current setting of overload resolution. </p> </dd> <dt><code><span class="roman">Overloaded symbol names</span></code></dt> <dd><p>You can specify a particular definition of an overloaded symbol, using the same notation that is used to declare such symbols in C<tt>++</tt>: type <code><var>symbol</var>(<var>types</var>)</code> rather than just <var>symbol</var>. You can also use the <small>GDB</small> command-line word completion facilities to list the available choices, or to finish the type list for you. See <a href="Completion.html#Completion">Command Completion</a>, for details on how to do this. </p> </dd> <dt><code><span class="roman">Breakpoints in functions with ABI tags</span></code></dt> <dd> <p>The GNU C<tt>++</tt> compiler introduced the notion of ABI “tags”, which correspond to changes in the ABI of a type, function, or variable that would not otherwise be reflected in a mangled name. See <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> for more detail. </p> <p>The ABI tags are visible in C<tt>++</tt> demangled names. For example, a function that returns a std::string: </p> <div class="smallexample"> <pre class="smallexample">std::string function(int); </pre></div> <p>when compiled for the C++11 ABI is marked with the <code>cxx11</code> ABI tag, and <small>GDB</small> displays the symbol like this: </p> <div class="smallexample"> <pre class="smallexample">function[abi:cxx11](int) </pre></div> <p>You can set a breakpoint on such functions simply as if they had no tag. For example: </p> <div class="smallexample"> <pre class="smallexample">(gdb) b function(int) Breakpoint 2 at 0x40060d: file main.cc, line 10. (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y 0x0040060d in function[abi:cxx11](int) at main.cc:10 </pre></div> <p>On the rare occasion you need to disambiguate between different ABI tags, you can do so by simply including the ABI tag in the function name, like: </p> <div class="smallexample"> <pre class="smallexample">(gdb) b ambiguous[abi:other_tag](int) </pre></div> </dd> </dl> <hr> <div class="header"> <p> 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> [<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> </div> </body> </html>