Tracepoint-Actions.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 5.1, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>Debugging with GDB: Tracepoint Actions</title>
  16. <meta name="description" content="Debugging with GDB: Tracepoint Actions">
  17. <meta name="keywords" content="Debugging with GDB: Tracepoint Actions">
  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="Set-Tracepoints.html#Set-Tracepoints" rel="up" title="Set Tracepoints">
  26. <link href="Listing-Tracepoints.html#Listing-Tracepoints" rel="next" title="Listing Tracepoints">
  27. <link href="Trace-State-Variables.html#Trace-State-Variables" rel="previous" title="Trace State Variables">
  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="Tracepoint-Actions"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Listing-Tracepoints.html#Listing-Tracepoints" accesskey="n" rel="next">Listing Tracepoints</a>, Previous: <a href="Trace-State-Variables.html#Trace-State-Variables" accesskey="p" rel="previous">Trace State Variables</a>, Up: <a href="Set-Tracepoints.html#Set-Tracepoints" accesskey="u" rel="up">Set Tracepoints</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="Tracepoint-Action-Lists"></a>
  65. <h4 class="subsection">13.1.6 Tracepoint Action Lists</h4>
  66. <dl compact="compact">
  67. <dd><a name="index-actions"></a>
  68. <a name="index-tracepoint-actions"></a>
  69. </dd>
  70. <dt><code>actions <span class="roman">[</span><var>num</var><span class="roman">]</span></code></dt>
  71. <dd><p>This command will prompt for a list of actions to be taken when the
  72. tracepoint is hit. If the tracepoint number <var>num</var> is not
  73. specified, this command sets the actions for the one that was most
  74. recently defined (so that you can define a tracepoint and then say
  75. <code>actions</code> without bothering about its number). You specify the
  76. actions themselves on the following lines, one action at a time, and
  77. terminate the actions list with a line containing just <code>end</code>. So
  78. far, the only defined actions are <code>collect</code>, <code>teval</code>, and
  79. <code>while-stepping</code>.
  80. </p>
  81. <p><code>actions</code> is actually equivalent to <code>commands</code> (see <a href="Break-Commands.html#Break-Commands">Breakpoint Command Lists</a>), except that only the defined
  82. actions are allowed; any other <small>GDB</small> command is rejected.
  83. </p>
  84. <a name="index-remove-actions-from-a-tracepoint"></a>
  85. <p>To remove all actions from a tracepoint, type &lsquo;<samp>actions <var>num</var></samp>&rsquo;
  86. and follow it immediately with &lsquo;<samp>end</samp>&rsquo;.
  87. </p>
  88. <div class="smallexample">
  89. <pre class="smallexample">(gdb) <b>collect <var>data</var></b> // collect some data
  90. (gdb) <b>while-stepping 5</b> // single-step 5 times, collect data
  91. (gdb) <b>end</b> // signals the end of actions.
  92. </pre></div>
  93. <p>In the following example, the action list begins with <code>collect</code>
  94. commands indicating the things to be collected when the tracepoint is
  95. hit. Then, in order to single-step and collect additional data
  96. following the tracepoint, a <code>while-stepping</code> command is used,
  97. followed by the list of things to be collected after each step in a
  98. sequence of single steps. The <code>while-stepping</code> command is
  99. terminated by its own separate <code>end</code> command. Lastly, the action
  100. list is terminated by an <code>end</code> command.
  101. </p>
  102. <div class="smallexample">
  103. <pre class="smallexample">(gdb) <b>trace foo</b>
  104. (gdb) <b>actions</b>
  105. Enter actions for tracepoint 1, one per line:
  106. &gt; collect bar,baz
  107. &gt; collect $regs
  108. &gt; while-stepping 12
  109. &gt; collect $pc, arr[i]
  110. &gt; end
  111. end
  112. </pre></div>
  113. <a name="index-collect-_0028tracepoints_0029"></a>
  114. </dd>
  115. <dt><code>collect<span class="roman">[</span>/<var>mods</var><span class="roman">]</span> <var>expr1</var>, <var>expr2</var>, &hellip;</code></dt>
  116. <dd><p>Collect values of the given expressions when the tracepoint is hit.
  117. This command accepts a comma-separated list of any valid expressions.
  118. In addition to global, static, or local variables, the following
  119. special arguments are supported:
  120. </p>
  121. <dl compact="compact">
  122. <dt><code>$regs</code></dt>
  123. <dd><p>Collect all registers.
  124. </p>
  125. </dd>
  126. <dt><code>$args</code></dt>
  127. <dd><p>Collect all function arguments.
  128. </p>
  129. </dd>
  130. <dt><code>$locals</code></dt>
  131. <dd><p>Collect all local variables.
  132. </p>
  133. </dd>
  134. <dt><code>$_ret</code></dt>
  135. <dd><p>Collect the return address. This is helpful if you want to see more
  136. of a backtrace.
  137. </p>
  138. <p><em>Note:</em> The return address location can not always be reliably
  139. determined up front, and the wrong address / registers may end up
  140. collected instead. On some architectures the reliability is higher
  141. for tracepoints at function entry, while on others it&rsquo;s the opposite.
  142. When this happens, backtracing will stop because the return address is
  143. found unavailable (unless another collect rule happened to match it).
  144. </p>
  145. </dd>
  146. <dt><code>$_probe_argc</code></dt>
  147. <dd><p>Collects the number of arguments from the static probe at which the
  148. tracepoint is located.
  149. See <a href="Static-Probe-Points.html#Static-Probe-Points">Static Probe Points</a>.
  150. </p>
  151. </dd>
  152. <dt><code>$_probe_arg<var>n</var></code></dt>
  153. <dd><p><var>n</var> is an integer between 0 and 11. Collects the <var>n</var>th argument
  154. from the static probe at which the tracepoint is located.
  155. See <a href="Static-Probe-Points.html#Static-Probe-Points">Static Probe Points</a>.
  156. </p>
  157. </dd>
  158. <dt><code>$_sdata</code></dt>
  159. <dd><a name="index-_0024_005fsdata_002c-collect"></a>
  160. <p>Collect static tracepoint marker specific data. Only available for
  161. static tracepoints. See <a href="#Tracepoint-Actions">Tracepoint Action
  162. Lists</a>. On the UST static tracepoints library backend, an
  163. instrumentation point resembles a <code>printf</code> function call. The
  164. tracing library is able to collect user specified data formatted to a
  165. character string using the format provided by the programmer that
  166. instrumented the program. Other backends have similar mechanisms.
  167. Here&rsquo;s an example of a UST marker call:
  168. </p>
  169. <div class="smallexample">
  170. <pre class="smallexample"> const char master_name[] = &quot;$your_name&quot;;
  171. trace_mark(channel1, marker1, &quot;hello %s&quot;, master_name)
  172. </pre></div>
  173. <p>In this case, collecting <code>$_sdata</code> collects the string
  174. &lsquo;<samp>hello $yourname</samp>&rsquo;. When analyzing the trace buffer, you can
  175. inspect &lsquo;<samp>$_sdata</samp>&rsquo; like any other variable available to
  176. <small>GDB</small>.
  177. </p></dd>
  178. </dl>
  179. <p>You can give several consecutive <code>collect</code> commands, each one
  180. with a single argument, or one <code>collect</code> command with several
  181. arguments separated by commas; the effect is the same.
  182. </p>
  183. <p>The optional <var>mods</var> changes the usual handling of the arguments.
  184. <code>s</code> requests that pointers to chars be handled as strings, in
  185. particular collecting the contents of the memory being pointed at, up
  186. to the first zero. The upper bound is by default the value of the
  187. <code>print elements</code> variable; if <code>s</code> is followed by a decimal
  188. number, that is the upper bound instead. So for instance
  189. &lsquo;<samp>collect/s25 mystr</samp>&rsquo; collects as many as 25 characters at
  190. &lsquo;<samp>mystr</samp>&rsquo;.
  191. </p>
  192. <p>The command <code>info scope</code> (see <a href="Symbols.html#Symbols">info scope</a>) is
  193. particularly useful for figuring out what data to collect.
  194. </p>
  195. <a name="index-teval-_0028tracepoints_0029"></a>
  196. </dd>
  197. <dt><code>teval <var>expr1</var>, <var>expr2</var>, &hellip;</code></dt>
  198. <dd><p>Evaluate the given expressions when the tracepoint is hit. This
  199. command accepts a comma-separated list of expressions. The results
  200. are discarded, so this is mainly useful for assigning values to trace
  201. state variables (see <a href="Trace-State-Variables.html#Trace-State-Variables">Trace State Variables</a>) without adding those
  202. values to the trace buffer, as would be the case if the <code>collect</code>
  203. action were used.
  204. </p>
  205. <a name="index-while_002dstepping-_0028tracepoints_0029"></a>
  206. </dd>
  207. <dt><code>while-stepping <var>n</var></code></dt>
  208. <dd><p>Perform <var>n</var> single-step instruction traces after the tracepoint,
  209. collecting new data after each step. The <code>while-stepping</code>
  210. command is followed by the list of what to collect while stepping
  211. (followed by its own <code>end</code> command):
  212. </p>
  213. <div class="smallexample">
  214. <pre class="smallexample">&gt; while-stepping 12
  215. &gt; collect $regs, myglobal
  216. &gt; end
  217. &gt;
  218. </pre></div>
  219. <p>Note that <code>$pc</code> is not automatically collected by
  220. <code>while-stepping</code>; you need to explicitly collect that register if
  221. you need it. You may abbreviate <code>while-stepping</code> as <code>ws</code> or
  222. <code>stepping</code>.
  223. </p>
  224. </dd>
  225. <dt><code>set default-collect <var>expr1</var>, <var>expr2</var>, &hellip;</code></dt>
  226. <dd><a name="index-set-default_002dcollect"></a>
  227. <a name="index-default-collection-action"></a>
  228. <p>This variable is a list of expressions to collect at each tracepoint
  229. hit. It is effectively an additional <code>collect</code> action prepended
  230. to every tracepoint action list. The expressions are parsed
  231. individually for each tracepoint, so for instance a variable named
  232. <code>xyz</code> may be interpreted as a global for one tracepoint, and a
  233. local for another, as appropriate to the tracepoint&rsquo;s location.
  234. </p>
  235. </dd>
  236. <dt><code>show default-collect</code></dt>
  237. <dd><a name="index-show-default_002dcollect"></a>
  238. <p>Show the list of expressions that are collected by default at each
  239. tracepoint hit.
  240. </p>
  241. </dd>
  242. </dl>
  243. <hr>
  244. <div class="header">
  245. <p>
  246. Next: <a href="Listing-Tracepoints.html#Listing-Tracepoints" accesskey="n" rel="next">Listing Tracepoints</a>, Previous: <a href="Trace-State-Variables.html#Trace-State-Variables" accesskey="p" rel="previous">Trace State Variables</a>, Up: <a href="Set-Tracepoints.html#Set-Tracepoints" accesskey="u" rel="up">Set Tracepoints</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>
  247. </div>
  248. </body>
  249. </html>