Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

378 lines
15KB

  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>Convenience Funs (Debugging with GDB)</title>
  17. <meta name="description" content="Convenience Funs (Debugging with GDB)">
  18. <meta name="keywords" content="Convenience Funs (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="Data.html#Data" rel="up" title="Data">
  26. <link href="Registers.html#Registers" rel="next" title="Registers">
  27. <link href="Convenience-Vars.html#Convenience-Vars" rel="prev" title="Convenience Vars">
  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="Convenience-Funs"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Registers.html#Registers" accesskey="n" rel="next">Registers</a>, Previous: <a href="Convenience-Vars.html#Convenience-Vars" accesskey="p" rel="prev">Convenience Vars</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>
  61. </div>
  62. <hr>
  63. <a name="Convenience-Functions"></a>
  64. <h3 class="section">10.12 Convenience Functions</h3>
  65. <a name="index-convenience-functions"></a>
  66. <p><small>GDB</small> also supplies some <em>convenience functions</em>. These
  67. have a syntax similar to convenience variables. A convenience
  68. function can be used in an expression just like an ordinary function;
  69. however, a convenience function is implemented internally to
  70. <small>GDB</small>.
  71. </p>
  72. <p>These functions do not require <small>GDB</small> to be configured with
  73. <code>Python</code> support, which means that they are always available.
  74. </p>
  75. <dl compact="compact">
  76. <dt><code>$_isvoid (<var>expr</var>)</code></dt>
  77. <dd><a name="index-_0024_005fisvoid_002c-convenience-function"></a>
  78. <p>Return one if the expression <var>expr</var> is <code>void</code>. Otherwise it
  79. returns zero.
  80. </p>
  81. <p>A <code>void</code> expression is an expression where the type of the result
  82. is <code>void</code>. For example, you can examine a convenience variable
  83. (see <a href="Convenience-Vars.html#Convenience-Vars">Convenience Variables</a>) to check whether
  84. it is <code>void</code>:
  85. </p>
  86. <div class="smallexample">
  87. <pre class="smallexample">(gdb) print $_exitcode
  88. $1 = void
  89. (gdb) print $_isvoid ($_exitcode)
  90. $2 = 1
  91. (gdb) run
  92. Starting program: ./a.out
  93. [Inferior 1 (process 29572) exited normally]
  94. (gdb) print $_exitcode
  95. $3 = 0
  96. (gdb) print $_isvoid ($_exitcode)
  97. $4 = 0
  98. </pre></div>
  99. <p>In the example above, we used <code>$_isvoid</code> to check whether
  100. <code>$_exitcode</code> is <code>void</code> before and after the execution of the
  101. program being debugged. Before the execution there is no exit code to
  102. be examined, therefore <code>$_exitcode</code> is <code>void</code>. After the
  103. execution the program being debugged returned zero, therefore
  104. <code>$_exitcode</code> is zero, which means that it is not <code>void</code>
  105. anymore.
  106. </p>
  107. <p>The <code>void</code> expression can also be a call of a function from the
  108. program being debugged. For example, given the following function:
  109. </p>
  110. <div class="smallexample">
  111. <pre class="smallexample">void
  112. foo (void)
  113. {
  114. }
  115. </pre></div>
  116. <p>The result of calling it inside <small>GDB</small> is <code>void</code>:
  117. </p>
  118. <div class="smallexample">
  119. <pre class="smallexample">(gdb) print foo ()
  120. $1 = void
  121. (gdb) print $_isvoid (foo ())
  122. $2 = 1
  123. (gdb) set $v = foo ()
  124. (gdb) print $v
  125. $3 = void
  126. (gdb) print $_isvoid ($v)
  127. $4 = 1
  128. </pre></div>
  129. </dd>
  130. <dt><code>$_gdb_setting_str (<var>setting</var>)</code></dt>
  131. <dd><a name="index-_0024_005fgdb_005fsetting_005fstr_002c-convenience-function"></a>
  132. <p>Return the value of the <small>GDB</small> <var>setting</var> as a string.
  133. <var>setting</var> is any setting that can be used in a <code>set</code> or
  134. <code>show</code> command (see <a href="Controlling-GDB.html#Controlling-GDB">Controlling GDB</a>).
  135. </p>
  136. <div class="smallexample">
  137. <pre class="smallexample">(gdb) show print frame-arguments
  138. Printing of non-scalar frame arguments is &quot;scalars&quot;.
  139. (gdb) p $_gdb_setting_str(&quot;print frame-arguments&quot;)
  140. $1 = &quot;scalars&quot;
  141. (gdb) p $_gdb_setting_str(&quot;height&quot;)
  142. $2 = &quot;30&quot;
  143. (gdb)
  144. </pre></div>
  145. </dd>
  146. <dt><code>$_gdb_setting (<var>setting</var>)</code></dt>
  147. <dd><a name="index-_0024_005fgdb_005fsetting_002c-convenience-function"></a>
  148. <p>Return the value of the <small>GDB</small> <var>setting</var>.
  149. The type of the returned value depends on the setting.
  150. </p>
  151. <p>The value type for boolean and auto boolean settings is <code>int</code>.
  152. The boolean values <code>off</code> and <code>on</code> are converted to
  153. the integer values <code>0</code> and <code>1</code>. The value <code>auto</code> is
  154. converted to the value <code>-1</code>.
  155. </p>
  156. <p>The value type for integer settings is either <code>unsigned int</code>
  157. or <code>int</code>, depending on the setting.
  158. </p>
  159. <p>Some integer settings accept an <code>unlimited</code> value.
  160. Depending on the setting, the <code>set</code> command also accepts
  161. the value <code>0</code> or the value <code>-1</code> as a synonym for
  162. <code>unlimited</code>.
  163. For example, <code>set height unlimited</code> is equivalent to
  164. <code>set height 0</code>.
  165. </p>
  166. <p>Some other settings that accept the <code>unlimited</code> value
  167. use the value <code>0</code> to literally mean zero.
  168. For example, <code>set history size 0</code> indicates to not
  169. record any <small>GDB</small> commands in the command history.
  170. For such settings, <code>-1</code> is the synonym
  171. for <code>unlimited</code>.
  172. </p>
  173. <p>See the documentation of the corresponding <code>set</code> command for
  174. the numerical value equivalent to <code>unlimited</code>.
  175. </p>
  176. <p>The <code>$_gdb_setting</code> function converts the unlimited value
  177. to a <code>0</code> or a <code>-1</code> value according to what the
  178. <code>set</code> command uses.
  179. </p>
  180. <div class="smallexample">
  181. <pre class="smallexample">(gdb) p $_gdb_setting_str(&quot;height&quot;)
  182. $1 = &quot;30&quot;
  183. (gdb) p $_gdb_setting(&quot;height&quot;)
  184. $2 = 30
  185. (gdb) set height unlimited
  186. (gdb) p $_gdb_setting_str(&quot;height&quot;)
  187. $3 = &quot;unlimited&quot;
  188. (gdb) p $_gdb_setting(&quot;height&quot;)
  189. $4 = 0
  190. </pre><pre class="smallexample">(gdb) p $_gdb_setting_str(&quot;history size&quot;)
  191. $5 = &quot;unlimited&quot;
  192. (gdb) p $_gdb_setting(&quot;history size&quot;)
  193. $6 = -1
  194. (gdb) p $_gdb_setting_str(&quot;disassemble-next-line&quot;)
  195. $7 = &quot;auto&quot;
  196. (gdb) p $_gdb_setting(&quot;disassemble-next-line&quot;)
  197. $8 = -1
  198. (gdb)
  199. </pre></div>
  200. <p>Other setting types (enum, filename, optional filename, string, string noescape)
  201. are returned as string values.
  202. </p>
  203. </dd>
  204. <dt><code>$_gdb_maint_setting_str (<var>setting</var>)</code></dt>
  205. <dd><a name="index-_0024_005fgdb_005fmaint_005fsetting_005fstr_002c-convenience-function"></a>
  206. <p>Like the <code>$_gdb_setting_str</code> function, but works with
  207. <code>maintenance set</code> variables.
  208. </p>
  209. </dd>
  210. <dt><code>$_gdb_maint_setting (<var>setting</var>)</code></dt>
  211. <dd><a name="index-_0024_005fgdb_005fmaint_005fsetting_002c-convenience-function"></a>
  212. <p>Like the <code>$_gdb_setting</code> function, but works with
  213. <code>maintenance set</code> variables.
  214. </p>
  215. </dd>
  216. </dl>
  217. <p>The following functions require <small>GDB</small> to be configured with
  218. <code>Python</code> support.
  219. </p>
  220. <dl compact="compact">
  221. <dt><code>$_memeq(<var>buf1</var>, <var>buf2</var>, <var>length</var>)</code></dt>
  222. <dd><a name="index-_0024_005fmemeq_002c-convenience-function"></a>
  223. <p>Returns one if the <var>length</var> bytes at the addresses given by
  224. <var>buf1</var> and <var>buf2</var> are equal.
  225. Otherwise it returns zero.
  226. </p>
  227. </dd>
  228. <dt><code>$_regex(<var>str</var>, <var>regex</var>)</code></dt>
  229. <dd><a name="index-_0024_005fregex_002c-convenience-function"></a>
  230. <p>Returns one if the string <var>str</var> matches the regular expression
  231. <var>regex</var>. Otherwise it returns zero.
  232. The syntax of the regular expression is that specified by <code>Python</code>&rsquo;s
  233. regular expression support.
  234. </p>
  235. </dd>
  236. <dt><code>$_streq(<var>str1</var>, <var>str2</var>)</code></dt>
  237. <dd><a name="index-_0024_005fstreq_002c-convenience-function"></a>
  238. <p>Returns one if the strings <var>str1</var> and <var>str2</var> are equal.
  239. Otherwise it returns zero.
  240. </p>
  241. </dd>
  242. <dt><code>$_strlen(<var>str</var>)</code></dt>
  243. <dd><a name="index-_0024_005fstrlen_002c-convenience-function"></a>
  244. <p>Returns the length of string <var>str</var>.
  245. </p>
  246. </dd>
  247. <dt><code>$_caller_is(<var>name</var><span class="roman">[</span>, <var>number_of_frames</var><span class="roman">]</span>)</code></dt>
  248. <dd><a name="index-_0024_005fcaller_005fis_002c-convenience-function"></a>
  249. <p>Returns one if the calling function&rsquo;s name is equal to <var>name</var>.
  250. Otherwise it returns zero.
  251. </p>
  252. <p>If the optional argument <var>number_of_frames</var> is provided,
  253. it is the number of frames up in the stack to look.
  254. The default is 1.
  255. </p>
  256. <p>Example:
  257. </p>
  258. <div class="smallexample">
  259. <pre class="smallexample">(gdb) backtrace
  260. #0 bottom_func ()
  261. at testsuite/gdb.python/py-caller-is.c:21
  262. #1 0x00000000004005a0 in middle_func ()
  263. at testsuite/gdb.python/py-caller-is.c:27
  264. #2 0x00000000004005ab in top_func ()
  265. at testsuite/gdb.python/py-caller-is.c:33
  266. #3 0x00000000004005b6 in main ()
  267. at testsuite/gdb.python/py-caller-is.c:39
  268. (gdb) print $_caller_is (&quot;middle_func&quot;)
  269. $1 = 1
  270. (gdb) print $_caller_is (&quot;top_func&quot;, 2)
  271. $1 = 1
  272. </pre></div>
  273. </dd>
  274. <dt><code>$_caller_matches(<var>regexp</var><span class="roman">[</span>, <var>number_of_frames</var><span class="roman">]</span>)</code></dt>
  275. <dd><a name="index-_0024_005fcaller_005fmatches_002c-convenience-function"></a>
  276. <p>Returns one if the calling function&rsquo;s name matches the regular expression
  277. <var>regexp</var>. Otherwise it returns zero.
  278. </p>
  279. <p>If the optional argument <var>number_of_frames</var> is provided,
  280. it is the number of frames up in the stack to look.
  281. The default is 1.
  282. </p>
  283. </dd>
  284. <dt><code>$_any_caller_is(<var>name</var><span class="roman">[</span>, <var>number_of_frames</var><span class="roman">]</span>)</code></dt>
  285. <dd><a name="index-_0024_005fany_005fcaller_005fis_002c-convenience-function"></a>
  286. <p>Returns one if any calling function&rsquo;s name is equal to <var>name</var>.
  287. Otherwise it returns zero.
  288. </p>
  289. <p>If the optional argument <var>number_of_frames</var> is provided,
  290. it is the number of frames up in the stack to look.
  291. The default is 1.
  292. </p>
  293. <p>This function differs from <code>$_caller_is</code> in that this function
  294. checks all stack frames from the immediate caller to the frame specified
  295. by <var>number_of_frames</var>, whereas <code>$_caller_is</code> only checks the
  296. frame specified by <var>number_of_frames</var>.
  297. </p>
  298. </dd>
  299. <dt><code>$_any_caller_matches(<var>regexp</var><span class="roman">[</span>, <var>number_of_frames</var><span class="roman">]</span>)</code></dt>
  300. <dd><a name="index-_0024_005fany_005fcaller_005fmatches_002c-convenience-function"></a>
  301. <p>Returns one if any calling function&rsquo;s name matches the regular expression
  302. <var>regexp</var>. Otherwise it returns zero.
  303. </p>
  304. <p>If the optional argument <var>number_of_frames</var> is provided,
  305. it is the number of frames up in the stack to look.
  306. The default is 1.
  307. </p>
  308. <p>This function differs from <code>$_caller_matches</code> in that this function
  309. checks all stack frames from the immediate caller to the frame specified
  310. by <var>number_of_frames</var>, whereas <code>$_caller_matches</code> only checks the
  311. frame specified by <var>number_of_frames</var>.
  312. </p>
  313. </dd>
  314. <dt><code>$_as_string(<var>value</var>)</code></dt>
  315. <dd><a name="index-_0024_005fas_005fstring_002c-convenience-function"></a>
  316. <p>Return the string representation of <var>value</var>.
  317. </p>
  318. <p>This function is useful to obtain the textual label (enumerator) of an
  319. enumeration value. For example, assuming the variable <var>node</var> is of
  320. an enumerated type:
  321. </p>
  322. <div class="smallexample">
  323. <pre class="smallexample">(gdb) printf &quot;Visiting node of type %s\n&quot;, $_as_string(node)
  324. Visiting node of type NODE_INTEGER
  325. </pre></div>
  326. </dd>
  327. <dt><code>$_cimag(<var>value</var>)</code></dt>
  328. <dt><code>$_creal(<var>value</var>)</code></dt>
  329. <dd><a name="index-_0024_005fcimag_002c-convenience-function"></a>
  330. <a name="index-_0024_005fcreal_002c-convenience-function"></a>
  331. <p>Return the imaginary (<code>$_cimag</code>) or real (<code>$_creal</code>) part of
  332. the complex number <var>value</var>.
  333. </p>
  334. <p>The type of the imaginary or real part depends on the type of the
  335. complex number, e.g., using <code>$_cimag</code> on a <code>float complex</code>
  336. will return an imaginary part of type <code>float</code>.
  337. </p>
  338. </dd>
  339. </dl>
  340. <p><small>GDB</small> provides the ability to list and get help on
  341. convenience functions.
  342. </p>
  343. <dl compact="compact">
  344. <dt><code>help function</code></dt>
  345. <dd><a name="index-help-function"></a>
  346. <a name="index-show-all-convenience-functions"></a>
  347. <p>Print a list of all convenience functions.
  348. </p></dd>
  349. </dl>
  350. <hr>
  351. <div class="header">
  352. <p>
  353. Next: <a href="Registers.html#Registers" accesskey="n" rel="next">Registers</a>, Previous: <a href="Convenience-Vars.html#Convenience-Vars" accesskey="p" rel="prev">Convenience Vars</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>
  354. </div>
  355. </body>
  356. </html>