Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

250 Zeilen
11KB

  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-2020 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 6.5, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  16. <title>Calling (Debugging with GDB)</title>
  17. <meta name="description" content="Calling (Debugging with GDB)">
  18. <meta name="keywords" content="Calling (Debugging with GDB)">
  19. <meta name="resource-type" content="document">
  20. <meta name="distribution" content="global">
  21. <meta name="Generator" content="makeinfo">
  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="Altering.html#Altering" rel="up" title="Altering">
  26. <link href="Patching.html#Patching" rel="next" title="Patching">
  27. <link href="Returning.html#Returning" rel="prev" title="Returning">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.indentedblock {margin-right: 0em}
  32. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  33. blockquote.smallquotation {font-size: smaller}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.lisp {margin-left: 3.2em}
  37. div.smalldisplay {margin-left: 3.2em}
  38. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  50. span.roman {font-family: initial; font-weight: normal}
  51. span.sansserif {font-family: sans-serif; font-weight: normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en">
  57. <a name="Calling"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Patching.html#Patching" accesskey="n" rel="next">Patching</a>, Previous: <a href="Returning.html#Returning" accesskey="p" rel="prev">Returning</a>, Up: <a href="Altering.html#Altering" accesskey="u" rel="up">Altering</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>
  61. </div>
  62. <hr>
  63. <a name="Calling-Program-Functions"></a>
  64. <h3 class="section">17.5 Calling Program Functions</h3>
  65. <dl compact="compact">
  66. <dd><a name="index-calling-functions"></a>
  67. <a name="index-inferior-functions_002c-calling"></a>
  68. </dd>
  69. <dt><code>print <var>expr</var></code></dt>
  70. <dd><p>Evaluate the expression <var>expr</var> and display the resulting value.
  71. The expression may include calls to functions in the program being
  72. debugged.
  73. </p>
  74. <a name="index-call"></a>
  75. </dd>
  76. <dt><code>call <var>expr</var></code></dt>
  77. <dd><p>Evaluate the expression <var>expr</var> without displaying <code>void</code>
  78. returned values.
  79. </p>
  80. <p>You can use this variant of the <code>print</code> command if you want to
  81. execute a function from your program that does not return anything
  82. (a.k.a. <em>a void function</em>), but without cluttering the output
  83. with <code>void</code> returned values that <small>GDB</small> will otherwise
  84. print. If the result is not void, it is printed and saved in the
  85. value history.
  86. </p></dd>
  87. </dl>
  88. <p>It is possible for the function you call via the <code>print</code> or
  89. <code>call</code> command to generate a signal (e.g., if there&rsquo;s a bug in
  90. the function, or if you passed it incorrect arguments). What happens
  91. in that case is controlled by the <code>set unwindonsignal</code> command.
  92. </p>
  93. <p>Similarly, with a C<tt>++</tt> program it is possible for the function you
  94. call via the <code>print</code> or <code>call</code> command to generate an
  95. exception that is not handled due to the constraints of the dummy
  96. frame. In this case, any exception that is raised in the frame, but has
  97. an out-of-frame exception handler will not be found. GDB builds a
  98. dummy-frame for the inferior function call, and the unwinder cannot
  99. seek for exception handlers outside of this dummy-frame. What happens
  100. in that case is controlled by the
  101. <code>set unwind-on-terminating-exception</code> command.
  102. </p>
  103. <dl compact="compact">
  104. <dt><code>set unwindonsignal</code></dt>
  105. <dd><a name="index-set-unwindonsignal"></a>
  106. <a name="index-unwind-stack-in-called-functions"></a>
  107. <a name="index-call-dummy-stack-unwinding"></a>
  108. <p>Set unwinding of the stack if a signal is received while in a function
  109. that <small>GDB</small> called in the program being debugged. If set to on,
  110. <small>GDB</small> unwinds the stack it created for the call and restores
  111. the context to what it was before the call. If set to off (the
  112. default), <small>GDB</small> stops in the frame where the signal was
  113. received.
  114. </p>
  115. </dd>
  116. <dt><code>show unwindonsignal</code></dt>
  117. <dd><a name="index-show-unwindonsignal"></a>
  118. <p>Show the current setting of stack unwinding in the functions called by
  119. <small>GDB</small>.
  120. </p>
  121. </dd>
  122. <dt><code>set unwind-on-terminating-exception</code></dt>
  123. <dd><a name="index-set-unwind_002don_002dterminating_002dexception"></a>
  124. <a name="index-unwind-stack-in-called-functions-with-unhandled-exceptions"></a>
  125. <a name="index-call-dummy-stack-unwinding-on-unhandled-exception_002e"></a>
  126. <p>Set unwinding of the stack if a C<tt>++</tt> exception is raised, but left
  127. unhandled while in a function that <small>GDB</small> called in the program being
  128. debugged. If set to on (the default), <small>GDB</small> unwinds the stack
  129. it created for the call and restores the context to what it was before
  130. the call. If set to off, <small>GDB</small> the exception is delivered to
  131. the default C<tt>++</tt> exception handler and the inferior terminated.
  132. </p>
  133. </dd>
  134. <dt><code>show unwind-on-terminating-exception</code></dt>
  135. <dd><a name="index-show-unwind_002don_002dterminating_002dexception"></a>
  136. <p>Show the current setting of stack unwinding in the functions called by
  137. <small>GDB</small>.
  138. </p>
  139. </dd>
  140. <dt><code>set may-call-functions</code></dt>
  141. <dd><a name="index-set-may_002dcall_002dfunctions"></a>
  142. <a name="index-disabling-calling-functions-in-the-program"></a>
  143. <a name="index-calling-functions-in-the-program_002c-disabling"></a>
  144. <p>Set permission to call functions in the program.
  145. This controls whether <small>GDB</small> will attempt to call functions in
  146. the program, such as with expressions in the <code>print</code> command. It
  147. defaults to <code>on</code>.
  148. </p>
  149. <p>To call a function in the program, <small>GDB</small> has to temporarily
  150. modify the state of the inferior. This has potentially undesired side
  151. effects. Also, having <small>GDB</small> call nested functions is likely to
  152. be erroneous and may even crash the program being debugged. You can
  153. avoid such hazards by forbidding <small>GDB</small> from calling functions
  154. in the program being debugged. If calling functions in the program
  155. is forbidden, GDB will throw an error when a command (such as printing
  156. an expression) starts a function call in the program.
  157. </p>
  158. </dd>
  159. <dt><code>show may-call-functions</code></dt>
  160. <dd><a name="index-show-may_002dcall_002dfunctions"></a>
  161. <p>Show permission to call functions in the program.
  162. </p>
  163. </dd>
  164. </dl>
  165. <a name="Calling-functions-with-no-debug-info"></a>
  166. <h4 class="subsection">17.5.1 Calling functions with no debug info</h4>
  167. <a name="index-no-debug-info-functions"></a>
  168. <p>Sometimes, a function you wish to call is missing debug information.
  169. In such case, <small>GDB</small> does not know the type of the function,
  170. including the types of the function&rsquo;s parameters. To avoid calling
  171. the inferior function incorrectly, which could result in the called
  172. function functioning erroneously and even crash, <small>GDB</small> refuses
  173. to call the function unless you tell it the type of the function.
  174. </p>
  175. <p>For prototyped (i.e. ANSI/ISO style) functions, there are two ways
  176. to do that. The simplest is to cast the call to the function&rsquo;s
  177. declared return type. For example:
  178. </p>
  179. <div class="smallexample">
  180. <pre class="smallexample">(gdb) p getenv (&quot;PATH&quot;)
  181. 'getenv' has unknown return type; cast the call to its declared return type
  182. (gdb) p (char *) getenv (&quot;PATH&quot;)
  183. $1 = 0x7fffffffe7ba &quot;/usr/local/bin:/&quot;...
  184. </pre></div>
  185. <p>Casting the return type of a no-debug function is equivalent to
  186. casting the function to a pointer to a prototyped function that has a
  187. prototype that matches the types of the passed-in arguments, and
  188. calling that. I.e., the call above is equivalent to:
  189. </p>
  190. <div class="smallexample">
  191. <pre class="smallexample">(gdb) p ((char * (*) (const char *)) getenv) (&quot;PATH&quot;)
  192. </pre></div>
  193. <p>and given this prototyped C or C++ function with float parameters:
  194. </p>
  195. <div class="smallexample">
  196. <pre class="smallexample">float multiply (float v1, float v2) { return v1 * v2; }
  197. </pre></div>
  198. <p>these calls are equivalent:
  199. </p>
  200. <div class="smallexample">
  201. <pre class="smallexample">(gdb) p (float) multiply (2.0f, 3.0f)
  202. (gdb) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
  203. </pre></div>
  204. <p>If the function you wish to call is declared as unprototyped (i.e.
  205. old K&amp;R style), you must use the cast-to-function-pointer syntax, so
  206. that <small>GDB</small> knows that it needs to apply default argument
  207. promotions (promote float arguments to double). See <a href="ABI.html#ABI">float
  208. promotion</a>. For example, given this unprototyped C function with
  209. float parameters, and no debug info:
  210. </p>
  211. <div class="smallexample">
  212. <pre class="smallexample">float
  213. multiply_noproto (v1, v2)
  214. float v1, v2;
  215. {
  216. return v1 * v2;
  217. }
  218. </pre></div>
  219. <p>you call it like this:
  220. </p>
  221. <div class="smallexample">
  222. <pre class="smallexample"> (gdb) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
  223. </pre></div>
  224. <hr>
  225. <div class="header">
  226. <p>
  227. Next: <a href="Patching.html#Patching" accesskey="n" rel="next">Patching</a>, Previous: <a href="Returning.html#Returning" accesskey="p" rel="prev">Returning</a>, Up: <a href="Altering.html#Altering" accesskey="u" rel="up">Altering</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>
  228. </div>
  229. </body>
  230. </html>