125 lines
5.9 KiB
HTML
125 lines
5.9 KiB
HTML
<html lang="en">
|
|
<head>
|
|
<title>Ambiguous Expressions - Debugging with GDB</title>
|
|
<meta http-equiv="Content-Type" content="text/html">
|
|
<meta name="description" content="Debugging with GDB">
|
|
<meta name="generator" content="makeinfo 4.13">
|
|
<link title="Top" rel="start" href="index.html#Top">
|
|
<link rel="up" href="Data.html#Data" title="Data">
|
|
<link rel="prev" href="Expressions.html#Expressions" title="Expressions">
|
|
<link rel="next" href="Variables.html#Variables" title="Variables">
|
|
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
|
|
<!--
|
|
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.''
|
|
-->
|
|
<meta http-equiv="Content-Style-Type" content="text/css">
|
|
<style type="text/css"><!--
|
|
pre.display { font-family:inherit }
|
|
pre.format { font-family:inherit }
|
|
pre.smalldisplay { font-family:inherit; font-size:smaller }
|
|
pre.smallformat { font-family:inherit; font-size:smaller }
|
|
pre.smallexample { font-size:smaller }
|
|
pre.smalllisp { font-size:smaller }
|
|
span.sc { font-variant:small-caps }
|
|
span.roman { font-family:serif; font-weight:normal; }
|
|
span.sansserif { font-family:sans-serif; font-weight:normal; }
|
|
--></style>
|
|
</head>
|
|
<body>
|
|
<div class="node">
|
|
<a name="Ambiguous-Expressions"></a>
|
|
<p>
|
|
Next: <a rel="next" accesskey="n" href="Variables.html#Variables">Variables</a>,
|
|
Previous: <a rel="previous" accesskey="p" href="Expressions.html#Expressions">Expressions</a>,
|
|
Up: <a rel="up" accesskey="u" href="Data.html#Data">Data</a>
|
|
<hr>
|
|
</div>
|
|
|
|
<h3 class="section">10.2 Ambiguous Expressions</h3>
|
|
|
|
<p><a name="index-ambiguous-expressions-632"></a>
|
|
Expressions can sometimes contain some ambiguous elements. For instance,
|
|
some programming languages (notably Ada, C<tt>++</tt> and Objective-C) permit
|
|
a single function name to be defined several times, for application in
|
|
different contexts. This is called <dfn>overloading</dfn>. Another example
|
|
involving Ada is generics. A <dfn>generic package</dfn> is similar to C<tt>++</tt>
|
|
templates and is typically instantiated several times, resulting in
|
|
the same function name being defined in different contexts.
|
|
|
|
<p>In some cases and depending on the language, it is possible to adjust
|
|
the expression to remove the ambiguity. For instance in C<tt>++</tt>, you
|
|
can specify the signature of the function you want to break on, as in
|
|
<kbd>break </kbd><var>function</var><kbd>(</kbd><var>types</var><kbd>)</kbd>. In Ada, using the fully
|
|
qualified name of your function often makes the expression unambiguous
|
|
as well.
|
|
|
|
<p>When an ambiguity that needs to be resolved is detected, the debugger
|
|
has the capability to display a menu of numbered choices for each
|
|
possibility, and then waits for the selection with the prompt ‘<samp><span class="samp">></span></samp>’.
|
|
The first option is always ‘<samp><span class="samp">[0] cancel</span></samp>’, and typing <kbd>0 <RET></kbd>
|
|
aborts the current command. If the command in which the expression was
|
|
used allows more than one choice to be selected, the next option in the
|
|
menu is ‘<samp><span class="samp">[1] all</span></samp>’, and typing <kbd>1 <RET></kbd> selects all possible
|
|
choices.
|
|
|
|
<p>For example, the following session excerpt shows an attempt to set a
|
|
breakpoint at the overloaded symbol <code>String::after</code>.
|
|
We choose three particular definitions of that function name:
|
|
|
|
<!-- FIXME! This is likely to change to show arg type lists, at least -->
|
|
<pre class="smallexample"> (gdb) b String::after
|
|
[0] cancel
|
|
[1] all
|
|
[2] file:String.cc; line number:867
|
|
[3] file:String.cc; line number:860
|
|
[4] file:String.cc; line number:875
|
|
[5] file:String.cc; line number:853
|
|
[6] file:String.cc; line number:846
|
|
[7] file:String.cc; line number:735
|
|
> 2 4 6
|
|
Breakpoint 1 at 0xb26c: file String.cc, line 867.
|
|
Breakpoint 2 at 0xb344: file String.cc, line 875.
|
|
Breakpoint 3 at 0xafcc: file String.cc, line 846.
|
|
Multiple breakpoints were set.
|
|
Use the "delete" command to delete unwanted
|
|
breakpoints.
|
|
(gdb)
|
|
</pre>
|
|
|
|
<a name="index-set-multiple_002dsymbols-633"></a>
|
|
<dl><dt><code>set multiple-symbols </code><var>mode</var><dd><a name="index-multiple_002dsymbols-menu-634"></a>
|
|
This option allows you to adjust the debugger behavior when an expression
|
|
is ambiguous.
|
|
|
|
<p>By default, <var>mode</var> is set to <code>all</code>. If the command with which
|
|
the expression is used allows more than one choice, then <span class="sc">gdb</span>
|
|
automatically selects all possible choices. For instance, inserting
|
|
a breakpoint on a function using an ambiguous name results in a breakpoint
|
|
inserted on each possible match. However, if a unique choice must be made,
|
|
then <span class="sc">gdb</span> uses the menu to help you disambiguate the expression.
|
|
For instance, printing the address of an overloaded function will result
|
|
in the use of the menu.
|
|
|
|
<p>When <var>mode</var> is set to <code>ask</code>, the debugger always uses the menu
|
|
when an ambiguity is detected.
|
|
|
|
<p>Finally, when <var>mode</var> is set to <code>cancel</code>, the debugger reports
|
|
an error due to the ambiguity and the command is aborted.
|
|
|
|
<p><a name="index-show-multiple_002dsymbols-635"></a><br><dt><code>show multiple-symbols</code><dd>Show the current value of the <code>multiple-symbols</code> setting.
|
|
</dl>
|
|
|
|
</body></html>
|
|
|