Ambiguous-Expressions.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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-2019 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 5.2, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>Debugging with GDB: Ambiguous Expressions</title>
  16. <meta name="description" content="Debugging with GDB: Ambiguous Expressions">
  17. <meta name="keywords" content="Debugging with GDB: Ambiguous Expressions">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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="Data.html#Data" rel="up" title="Data">
  26. <link href="Variables.html#Variables" rel="next" title="Variables">
  27. <link href="Expressions.html#Expressions" rel="prev" title="Expressions">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="Ambiguous-Expressions"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Variables.html#Variables" accesskey="n" rel="next">Variables</a>, Previous: <a href="Expressions.html#Expressions" accesskey="p" rel="prev">Expressions</a>, Up: <a href="Data.html#Data" accesskey="u" rel="up">Data</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>
  62. </div>
  63. <hr>
  64. <a name="Ambiguous-Expressions-1"></a>
  65. <h3 class="section">10.2 Ambiguous Expressions</h3>
  66. <a name="index-ambiguous-expressions"></a>
  67. <p>Expressions can sometimes contain some ambiguous elements. For instance,
  68. some programming languages (notably Ada, C<tt>++</tt> and Objective-C) permit
  69. a single function name to be defined several times, for application in
  70. different contexts. This is called <em>overloading</em>. Another example
  71. involving Ada is generics. A <em>generic package</em> is similar to C<tt>++</tt>
  72. templates and is typically instantiated several times, resulting in
  73. the same function name being defined in different contexts.
  74. </p>
  75. <p>In some cases and depending on the language, it is possible to adjust
  76. the expression to remove the ambiguity. For instance in C<tt>++</tt>, you
  77. can specify the signature of the function you want to break on, as in
  78. <kbd>break <var>function</var>(<var>types</var>)</kbd>. In Ada, using the fully
  79. qualified name of your function often makes the expression unambiguous
  80. as well.
  81. </p>
  82. <p>When an ambiguity that needs to be resolved is detected, the debugger
  83. has the capability to display a menu of numbered choices for each
  84. possibility, and then waits for the selection with the prompt &lsquo;<samp>&gt;</samp>&rsquo;.
  85. The first option is always &lsquo;<samp>[0] cancel</samp>&rsquo;, and typing <kbd>0 <span class="key">RET</span></kbd>
  86. aborts the current command. If the command in which the expression was
  87. used allows more than one choice to be selected, the next option in the
  88. menu is &lsquo;<samp>[1] all</samp>&rsquo;, and typing <kbd>1 <span class="key">RET</span></kbd> selects all possible
  89. choices.
  90. </p>
  91. <p>For example, the following session excerpt shows an attempt to set a
  92. breakpoint at the overloaded symbol <code>String::after</code>.
  93. We choose three particular definitions of that function name:
  94. </p>
  95. <div class="smallexample">
  96. <pre class="smallexample">(gdb) b String::after
  97. [0] cancel
  98. [1] all
  99. [2] file:String.cc; line number:867
  100. [3] file:String.cc; line number:860
  101. [4] file:String.cc; line number:875
  102. [5] file:String.cc; line number:853
  103. [6] file:String.cc; line number:846
  104. [7] file:String.cc; line number:735
  105. &gt; 2 4 6
  106. Breakpoint 1 at 0xb26c: file String.cc, line 867.
  107. Breakpoint 2 at 0xb344: file String.cc, line 875.
  108. Breakpoint 3 at 0xafcc: file String.cc, line 846.
  109. Multiple breakpoints were set.
  110. Use the &quot;delete&quot; command to delete unwanted
  111. breakpoints.
  112. (gdb)
  113. </pre></div>
  114. <dl compact="compact">
  115. <dd><a name="index-set-multiple_002dsymbols"></a>
  116. </dd>
  117. <dt><code>set multiple-symbols <var>mode</var></code></dt>
  118. <dd><a name="index-multiple_002dsymbols-menu"></a>
  119. <p>This option allows you to adjust the debugger behavior when an expression
  120. is ambiguous.
  121. </p>
  122. <p>By default, <var>mode</var> is set to <code>all</code>. If the command with which
  123. the expression is used allows more than one choice, then <small>GDB</small>
  124. automatically selects all possible choices. For instance, inserting
  125. a breakpoint on a function using an ambiguous name results in a breakpoint
  126. inserted on each possible match. However, if a unique choice must be made,
  127. then <small>GDB</small> uses the menu to help you disambiguate the expression.
  128. For instance, printing the address of an overloaded function will result
  129. in the use of the menu.
  130. </p>
  131. <p>When <var>mode</var> is set to <code>ask</code>, the debugger always uses the menu
  132. when an ambiguity is detected.
  133. </p>
  134. <p>Finally, when <var>mode</var> is set to <code>cancel</code>, the debugger reports
  135. an error due to the ambiguity and the command is aborted.
  136. </p>
  137. <a name="index-show-multiple_002dsymbols"></a>
  138. </dd>
  139. <dt><code>show multiple-symbols</code></dt>
  140. <dd><p>Show the current value of the <code>multiple-symbols</code> setting.
  141. </p></dd>
  142. </dl>
  143. <hr>
  144. <div class="header">
  145. <p>
  146. Next: <a href="Variables.html#Variables" accesskey="n" rel="next">Variables</a>, Previous: <a href="Expressions.html#Expressions" accesskey="p" rel="prev">Expressions</a>, Up: <a href="Data.html#Data" accesskey="u" rel="up">Data</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>
  147. </div>
  148. </body>
  149. </html>