Create-and-Delete-Tracepoints.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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: Create and Delete Tracepoints</title>
  16. <meta name="description" content="Debugging with GDB: Create and Delete Tracepoints">
  17. <meta name="keywords" content="Debugging with GDB: Create and Delete Tracepoints">
  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="Enable-and-Disable-Tracepoints.html#Enable-and-Disable-Tracepoints" rel="next" title="Enable and Disable Tracepoints">
  27. <link href="Set-Tracepoints.html#Set-Tracepoints" rel="previous" title="Set Tracepoints">
  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="Create-and-Delete-Tracepoints"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Enable-and-Disable-Tracepoints.html#Enable-and-Disable-Tracepoints" accesskey="n" rel="next">Enable and Disable Tracepoints</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="Create-and-Delete-Tracepoints-1"></a>
  65. <h4 class="subsection">13.1.1 Create and Delete Tracepoints</h4>
  66. <dl compact="compact">
  67. <dd><a name="index-set-tracepoint"></a>
  68. <a name="index-trace"></a>
  69. </dd>
  70. <dt><code>trace <var>location</var></code></dt>
  71. <dd><p>The <code>trace</code> command is very similar to the <code>break</code> command.
  72. Its argument <var>location</var> can be any valid location.
  73. See <a href="Specify-Location.html#Specify-Location">Specify Location</a>. The <code>trace</code> command defines a tracepoint,
  74. which is a point in the target program where the debugger will briefly stop,
  75. collect some data, and then allow the program to continue. Setting a tracepoint
  76. or changing its actions takes effect immediately if the remote stub
  77. supports the &lsquo;<samp>InstallInTrace</samp>&rsquo; feature (see <a href="General-Query-Packets.html#install-tracepoint-in-tracing">install tracepoint in tracing</a>).
  78. If remote stub doesn&rsquo;t support the &lsquo;<samp>InstallInTrace</samp>&rsquo; feature, all
  79. these changes don&rsquo;t take effect until the next <code>tstart</code>
  80. command, and once a trace experiment is running, further changes will
  81. not have any effect until the next trace experiment starts. In addition,
  82. <small>GDB</small> supports <em>pending tracepoints</em>&mdash;tracepoints whose
  83. address is not yet resolved. (This is similar to pending breakpoints.)
  84. Pending tracepoints are not downloaded to the target and not installed
  85. until they are resolved. The resolution of pending tracepoints requires
  86. <small>GDB</small> support&mdash;when debugging with the remote target, and
  87. <small>GDB</small> disconnects from the remote stub (see <a href="Starting-and-Stopping-Trace-Experiments.html#disconnected-tracing">disconnected tracing</a>), pending tracepoints can not be resolved (and downloaded to
  88. the remote stub) while <small>GDB</small> is disconnected.
  89. </p>
  90. <p>Here are some examples of using the <code>trace</code> command:
  91. </p>
  92. <div class="smallexample">
  93. <pre class="smallexample">(gdb) <b>trace foo.c:121</b> // a source file and line number
  94. (gdb) <b>trace +2</b> // 2 lines forward
  95. (gdb) <b>trace my_function</b> // first source line of function
  96. (gdb) <b>trace *my_function</b> // EXACT start address of function
  97. (gdb) <b>trace *0x2117c4</b> // an address
  98. </pre></div>
  99. <p>You can abbreviate <code>trace</code> as <code>tr</code>.
  100. </p>
  101. </dd>
  102. <dt><code>trace <var>location</var> if <var>cond</var></code></dt>
  103. <dd><p>Set a tracepoint with condition <var>cond</var>; evaluate the expression
  104. <var>cond</var> each time the tracepoint is reached, and collect data only
  105. if the value is nonzero&mdash;that is, if <var>cond</var> evaluates as true.
  106. See <a href="Tracepoint-Conditions.html#Tracepoint-Conditions">Tracepoint Conditions</a>, for more
  107. information on tracepoint conditions.
  108. </p>
  109. </dd>
  110. <dt><code>ftrace <var>location</var> [ if <var>cond</var> ]</code></dt>
  111. <dd><a name="index-set-fast-tracepoint"></a>
  112. <a name="index-fast-tracepoints_002c-setting"></a>
  113. <a name="index-ftrace"></a>
  114. <p>The <code>ftrace</code> command sets a fast tracepoint. For targets that
  115. support them, fast tracepoints will use a more efficient but possibly
  116. less general technique to trigger data collection, such as a jump
  117. instruction instead of a trap, or some sort of hardware support. It
  118. may not be possible to create a fast tracepoint at the desired
  119. location, in which case the command will exit with an explanatory
  120. message.
  121. </p>
  122. <p><small>GDB</small> handles arguments to <code>ftrace</code> exactly as for
  123. <code>trace</code>.
  124. </p>
  125. <p>On 32-bit x86-architecture systems, fast tracepoints normally need to
  126. be placed at an instruction that is 5 bytes or longer, but can be
  127. placed at 4-byte instructions if the low 64K of memory of the target
  128. program is available to install trampolines. Some Unix-type systems,
  129. such as <small>GNU</small>/Linux, exclude low addresses from the program&rsquo;s
  130. address space; but for instance with the Linux kernel it is possible
  131. to let <small>GDB</small> use this area by doing a <code>sysctl</code> command
  132. to set the <code>mmap_min_addr</code> kernel parameter, as in
  133. </p>
  134. <div class="example">
  135. <pre class="example">sudo sysctl -w vm.mmap_min_addr=32768
  136. </pre></div>
  137. <p>which sets the low address to 32K, which leaves plenty of room for
  138. trampolines. The minimum address should be set to a page boundary.
  139. </p>
  140. </dd>
  141. <dt><code>strace <var>location</var> [ if <var>cond</var> ]</code></dt>
  142. <dd><a name="index-set-static-tracepoint"></a>
  143. <a name="index-static-tracepoints_002c-setting"></a>
  144. <a name="index-probe-static-tracepoint-marker"></a>
  145. <a name="index-strace"></a>
  146. <p>The <code>strace</code> command sets a static tracepoint. For targets that
  147. support it, setting a static tracepoint probes a static
  148. instrumentation point, or marker, found at <var>location</var>. It may not
  149. be possible to set a static tracepoint at the desired location, in
  150. which case the command will exit with an explanatory message.
  151. </p>
  152. <p><small>GDB</small> handles arguments to <code>strace</code> exactly as for
  153. <code>trace</code>, with the addition that the user can also specify
  154. <code>-m <var>marker</var></code> as <var>location</var>. This probes the marker
  155. identified by the <var>marker</var> string identifier. This identifier
  156. depends on the static tracepoint backend library your program is
  157. using. You can find all the marker identifiers in the &lsquo;<samp>ID</samp>&rsquo; field
  158. of the <code>info static-tracepoint-markers</code> command output.
  159. See <a href="Listing-Static-Tracepoint-Markers.html#Listing-Static-Tracepoint-Markers">Listing Static Tracepoint
  160. Markers</a>. For example, in the following small program using the UST
  161. tracing engine:
  162. </p>
  163. <div class="smallexample">
  164. <pre class="smallexample">main ()
  165. {
  166. trace_mark(ust, bar33, &quot;str %s&quot;, &quot;FOOBAZ&quot;);
  167. }
  168. </pre></div>
  169. <p>the marker id is composed of joining the first two arguments to the
  170. <code>trace_mark</code> call with a slash, which translates to:
  171. </p>
  172. <div class="smallexample">
  173. <pre class="smallexample">(gdb) info static-tracepoint-markers
  174. Cnt Enb ID Address What
  175. 1 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
  176. Data: &quot;str %s&quot;
  177. [etc...]
  178. </pre></div>
  179. <p>so you may probe the marker above with:
  180. </p>
  181. <div class="smallexample">
  182. <pre class="smallexample">(gdb) strace -m ust/bar33
  183. </pre></div>
  184. <p>Static tracepoints accept an extra collect action &mdash; <code>collect
  185. $_sdata</code>. This collects arbitrary user data passed in the probe point
  186. call to the tracing library. In the UST example above, you&rsquo;ll see
  187. that the third argument to <code>trace_mark</code> is a printf-like format
  188. string. The user data is then the result of running that formatting
  189. string against the following arguments. Note that <code>info
  190. static-tracepoint-markers</code> command output lists that format string in
  191. the &lsquo;<samp>Data:</samp>&rsquo; field.
  192. </p>
  193. <p>You can inspect this data when analyzing the trace buffer, by printing
  194. the $_sdata variable like any other variable available to
  195. <small>GDB</small>. See <a href="Tracepoint-Actions.html#Tracepoint-Actions">Tracepoint Action Lists</a>.
  196. </p>
  197. <a name="index-_0024tpnum"></a>
  198. <a name="index-last-tracepoint-number"></a>
  199. <a name="index-recent-tracepoint-number"></a>
  200. <a name="index-tracepoint-number"></a>
  201. <p>The convenience variable <code>$tpnum</code> records the tracepoint number
  202. of the most recently set tracepoint.
  203. </p>
  204. <a name="index-delete-tracepoint"></a>
  205. <a name="index-tracepoint-deletion"></a>
  206. </dd>
  207. <dt><code>delete tracepoint <span class="roman">[</span><var>num</var><span class="roman">]</span></code></dt>
  208. <dd><p>Permanently delete one or more tracepoints. With no argument, the
  209. default is to delete all tracepoints. Note that the regular
  210. <code>delete</code> command can remove tracepoints also.
  211. </p>
  212. <p>Examples:
  213. </p>
  214. <div class="smallexample">
  215. <pre class="smallexample">(gdb) <b>delete trace 1 2 3</b> // remove three tracepoints
  216. (gdb) <b>delete trace</b> // remove all tracepoints
  217. </pre></div>
  218. <p>You can abbreviate this command as <code>del tr</code>.
  219. </p></dd>
  220. </dl>
  221. <hr>
  222. <div class="header">
  223. <p>
  224. Next: <a href="Enable-and-Disable-Tracepoints.html#Enable-and-Disable-Tracepoints" accesskey="n" rel="next">Enable and Disable Tracepoints</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>
  225. </div>
  226. </body>
  227. </html>