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