No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

249 líneas
12KB

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