blob: 75ae38b4241c01a5eddc3c24527defa1c4faeb2f [file] [log] [blame]
<html lang="en">
<head>
<title>Create and Delete Tracepoints - Debugging with GDB</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Debugging with GDB">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Set-Tracepoints.html#Set-Tracepoints" title="Set Tracepoints">
<link rel="next" href="Enable-and-Disable-Tracepoints.html#Enable-and-Disable-Tracepoints" title="Enable and Disable Tracepoints">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Copyright (C) 1988-2019 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Free Software'' and ``Free Software Needs
Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
and with the Back-Cover Texts as in (a) below.
(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
this GNU Manual. Buying copies from GNU Press supports the FSF in
developing GNU and promoting software freedom.''
-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="Create-and-Delete-Tracepoints"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Enable-and-Disable-Tracepoints.html#Enable-and-Disable-Tracepoints">Enable and Disable Tracepoints</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Set-Tracepoints.html#Set-Tracepoints">Set Tracepoints</a>
<hr>
</div>
<h4 class="subsection">13.1.1 Create and Delete Tracepoints</h4>
<a name="index-set-tracepoint-863"></a>
<a name="index-trace-864"></a>
<dl><dt><code>trace </code><var>location</var><dd>The <code>trace</code> command is very similar to the <code>break</code> command.
Its argument <var>location</var> can be any valid location.
See <a href="Specify-Location.html#Specify-Location">Specify Location</a>. The <code>trace</code> command defines a tracepoint,
which is a point in the target program where the debugger will briefly stop,
collect some data, and then allow the program to continue. Setting a tracepoint
or changing its actions takes effect immediately if the remote stub
supports the &lsquo;<samp><span class="samp">InstallInTrace</span></samp>&rsquo; feature (see <a href="install-tracepoint-in-tracing.html#install-tracepoint-in-tracing">install tracepoint in tracing</a>).
If remote stub doesn't support the &lsquo;<samp><span class="samp">InstallInTrace</span></samp>&rsquo; feature, all
these changes don't take effect until the next <code>tstart</code>
command, and once a trace experiment is running, further changes will
not have any effect until the next trace experiment starts. In addition,
<span class="sc">gdb</span> supports <dfn>pending tracepoints</dfn>&mdash;tracepoints whose
address is not yet resolved. (This is similar to pending breakpoints.)
Pending tracepoints are not downloaded to the target and not installed
until they are resolved. The resolution of pending tracepoints requires
<span class="sc">gdb</span> support&mdash;when debugging with the remote target, and
<span class="sc">gdb</span> disconnects from the remote stub (see <a href="disconnected-tracing.html#disconnected-tracing">disconnected tracing</a>), pending tracepoints can not be resolved (and downloaded to
the remote stub) while <span class="sc">gdb</span> is disconnected.
<p>Here are some examples of using the <code>trace</code> command:
<pre class="smallexample"> (gdb) <b>trace foo.c:121</b> // a source file and line number
(gdb) <b>trace +2</b> // 2 lines forward
(gdb) <b>trace my_function</b> // first source line of function
(gdb) <b>trace *my_function</b> // EXACT start address of function
(gdb) <b>trace *0x2117c4</b> // an address
</pre>
<p class="noindent">You can abbreviate <code>trace</code> as <code>tr</code>.
<br><dt><code>trace </code><var>location</var><code> if </code><var>cond</var><dd>Set a tracepoint with condition <var>cond</var>; evaluate the expression
<var>cond</var> each time the tracepoint is reached, and collect data only
if the value is nonzero&mdash;that is, if <var>cond</var> evaluates as true.
See <a href="Tracepoint-Conditions.html#Tracepoint-Conditions">Tracepoint Conditions</a>, for more
information on tracepoint conditions.
<br><dt><code>ftrace </code><var>location</var><code> [ if </code><var>cond</var><code> ]</code><dd><a name="index-set-fast-tracepoint-865"></a><a name="index-fast-tracepoints_002c-setting-866"></a><a name="index-ftrace-867"></a>The <code>ftrace</code> command sets a fast tracepoint. For targets that
support them, fast tracepoints will use a more efficient but possibly
less general technique to trigger data collection, such as a jump
instruction instead of a trap, or some sort of hardware support. It
may not be possible to create a fast tracepoint at the desired
location, in which case the command will exit with an explanatory
message.
<p><span class="sc">gdb</span> handles arguments to <code>ftrace</code> exactly as for
<code>trace</code>.
<p>On 32-bit x86-architecture systems, fast tracepoints normally need to
be placed at an instruction that is 5 bytes or longer, but can be
placed at 4-byte instructions if the low 64K of memory of the target
program is available to install trampolines. Some Unix-type systems,
such as <span class="sc">gnu</span>/Linux, exclude low addresses from the program's
address space; but for instance with the Linux kernel it is possible
to let <span class="sc">gdb</span> use this area by doing a <samp><span class="command">sysctl</span></samp> command
to set the <code>mmap_min_addr</code> kernel parameter, as in
<pre class="example"> sudo sysctl -w vm.mmap_min_addr=32768
</pre>
<p class="noindent">which sets the low address to 32K, which leaves plenty of room for
trampolines. The minimum address should be set to a page boundary.
<br><dt><code>strace </code><var>location</var><code> [ if </code><var>cond</var><code> ]</code><dd><a name="index-set-static-tracepoint-868"></a><a name="index-static-tracepoints_002c-setting-869"></a><a name="index-probe-static-tracepoint-marker-870"></a><a name="index-strace-871"></a>The <code>strace</code> command sets a static tracepoint. For targets that
support it, setting a static tracepoint probes a static
instrumentation point, or marker, found at <var>location</var>. It may not
be possible to set a static tracepoint at the desired location, in
which case the command will exit with an explanatory message.
<p><span class="sc">gdb</span> handles arguments to <code>strace</code> exactly as for
<code>trace</code>, with the addition that the user can also specify
<code>-m </code><var>marker</var> as <var>location</var>. This probes the marker
identified by the <var>marker</var> string identifier. This identifier
depends on the static tracepoint backend library your program is
using. You can find all the marker identifiers in the &lsquo;<samp><span class="samp">ID</span></samp>&rsquo; field
of the <code>info static-tracepoint-markers</code> command output.
See <a href="Listing-Static-Tracepoint-Markers.html#Listing-Static-Tracepoint-Markers">Listing Static Tracepoint Markers</a>. For example, in the following small program using the UST
tracing engine:
<pre class="smallexample"> main ()
{
trace_mark(ust, bar33, "str %s", "FOOBAZ");
}
</pre>
<p class="noindent">the marker id is composed of joining the first two arguments to the
<code>trace_mark</code> call with a slash, which translates to:
<pre class="smallexample"> (gdb) info static-tracepoint-markers
Cnt Enb ID Address What
1 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
Data: "str %s"
[etc...]
</pre>
<p class="noindent">so you may probe the marker above with:
<pre class="smallexample"> (gdb) strace -m ust/bar33
</pre>
<p>Static tracepoints accept an extra collect action &mdash; <code>collect
$_sdata</code>. This collects arbitrary user data passed in the probe point
call to the tracing library. In the UST example above, you'll see
that the third argument to <code>trace_mark</code> is a printf-like format
string. The user data is then the result of running that formating
string against the following arguments. Note that <code>info
static-tracepoint-markers</code> command output lists that format string in
the &lsquo;<samp><span class="samp">Data:</span></samp>&rsquo; field.
<p>You can inspect this data when analyzing the trace buffer, by printing
the $_sdata variable like any other variable available to
<span class="sc">gdb</span>. See <a href="Tracepoint-Actions.html#Tracepoint-Actions">Tracepoint Action Lists</a>.
<p><a name="index-g_t_0024tpnum-872"></a><a name="index-last-tracepoint-number-873"></a><a name="index-recent-tracepoint-number-874"></a><a name="index-tracepoint-number-875"></a>The convenience variable <code>$tpnum</code> records the tracepoint number
of the most recently set tracepoint.
<p><a name="index-delete-tracepoint-876"></a><a name="index-tracepoint-deletion-877"></a><br><dt><code>delete tracepoint </code><span class="roman">[</span><var>num</var><span class="roman">]</span><dd>Permanently delete one or more tracepoints. With no argument, the
default is to delete all tracepoints. Note that the regular
<code>delete</code> command can remove tracepoints also.
<p>Examples:
<pre class="smallexample"> (gdb) <b>delete trace 1 2 3</b> // remove three tracepoints
(gdb) <b>delete trace</b> // remove all tracepoints
</pre>
<p class="noindent">You can abbreviate this command as <code>del tr</code>.
</dl>
</body></html>