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: Ambiguous Expressions</title> 18 19<meta name="description" content="Debugging with GDB: Ambiguous Expressions"> 20<meta name="keywords" content="Debugging with GDB: Ambiguous Expressions"> 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="Data.html#Data" rel="up" title="Data"> 29<link href="Variables.html#Variables" rel="next" title="Variables"> 30<link href="Expressions.html#Expressions" rel="previous" title="Expressions"> 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="Ambiguous-Expressions"></a> 65<div class="header"> 66<p> 67Next: <a href="Variables.html#Variables" accesskey="n" rel="next">Variables</a>, Previous: <a href="Expressions.html#Expressions" accesskey="p" rel="previous">Expressions</a>, Up: <a href="Data.html#Data" accesskey="u" rel="up">Data</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="Ambiguous-Expressions-1"></a> 71<h3 class="section">10.2 Ambiguous Expressions</h3> 72<a name="index-ambiguous-expressions"></a> 73 74<p>Expressions can sometimes contain some ambiguous elements. For instance, 75some programming languages (notably Ada, C<tt>++</tt> and Objective-C) permit 76a single function name to be defined several times, for application in 77different contexts. This is called <em>overloading</em>. Another example 78involving Ada is generics. A <em>generic package</em> is similar to C<tt>++</tt> 79templates and is typically instantiated several times, resulting in 80the same function name being defined in different contexts. 81</p> 82<p>In some cases and depending on the language, it is possible to adjust 83the expression to remove the ambiguity. For instance in C<tt>++</tt>, you 84can specify the signature of the function you want to break on, as in 85<kbd>break <var>function</var>(<var>types</var>)</kbd>. In Ada, using the fully 86qualified name of your function often makes the expression unambiguous 87as well. 88</p> 89<p>When an ambiguity that needs to be resolved is detected, the debugger 90has the capability to display a menu of numbered choices for each 91possibility, and then waits for the selection with the prompt ‘<samp>></samp>’. 92The first option is always ‘<samp>[0] cancel</samp>’, and typing <kbd>0 <span class="key">RET</span></kbd> 93aborts the current command. If the command in which the expression was 94used allows more than one choice to be selected, the next option in the 95menu is ‘<samp>[1] all</samp>’, and typing <kbd>1 <span class="key">RET</span></kbd> selects all possible 96choices. 97</p> 98<p>For example, the following session excerpt shows an attempt to set a 99breakpoint at the overloaded symbol <code>String::after</code>. 100We choose three particular definitions of that function name: 101</p> 102<div class="smallexample"> 103<pre class="smallexample">(gdb) b String::after 104[0] cancel 105[1] all 106[2] file:String.cc; line number:867 107[3] file:String.cc; line number:860 108[4] file:String.cc; line number:875 109[5] file:String.cc; line number:853 110[6] file:String.cc; line number:846 111[7] file:String.cc; line number:735 112> 2 4 6 113Breakpoint 1 at 0xb26c: file String.cc, line 867. 114Breakpoint 2 at 0xb344: file String.cc, line 875. 115Breakpoint 3 at 0xafcc: file String.cc, line 846. 116Multiple breakpoints were set. 117Use the "delete" command to delete unwanted 118 breakpoints. 119(gdb) 120</pre></div> 121 122<dl compact="compact"> 123<dd><a name="index-set-multiple_002dsymbols"></a> 124</dd> 125<dt><code>set multiple-symbols <var>mode</var></code></dt> 126<dd><a name="index-multiple_002dsymbols-menu"></a> 127 128<p>This option allows you to adjust the debugger behavior when an expression 129is ambiguous. 130</p> 131<p>By default, <var>mode</var> is set to <code>all</code>. If the command with which 132the expression is used allows more than one choice, then <small>GDB</small> 133automatically selects all possible choices. For instance, inserting 134a breakpoint on a function using an ambiguous name results in a breakpoint 135inserted on each possible match. However, if a unique choice must be made, 136then <small>GDB</small> uses the menu to help you disambiguate the expression. 137For instance, printing the address of an overloaded function will result 138in the use of the menu. 139</p> 140<p>When <var>mode</var> is set to <code>ask</code>, the debugger always uses the menu 141when an ambiguity is detected. 142</p> 143<p>Finally, when <var>mode</var> is set to <code>cancel</code>, the debugger reports 144an error due to the ambiguity and the command is aborted. 145</p> 146<a name="index-show-multiple_002dsymbols"></a> 147</dd> 148<dt><code>show multiple-symbols</code></dt> 149<dd><p>Show the current value of the <code>multiple-symbols</code> setting. 150</p></dd> 151</dl> 152 153<hr> 154<div class="header"> 155<p> 156Next: <a href="Variables.html#Variables" accesskey="n" rel="next">Variables</a>, Previous: <a href="Expressions.html#Expressions" accesskey="p" rel="previous">Expressions</a>, Up: <a href="Data.html#Data" accesskey="u" rel="up">Data</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> 157</div> 158 159 160 161</body> 162</html> 163