13.1.6 Tracepoint Action Lists
- This command will prompt for a list of actions to be taken when the
tracepoint is hit. If the tracepoint number num is not
specified, this command sets the actions for the one that was most
recently defined (so that you can define a tracepoint and then say
actionswithout bothering about its number). You specify the actions themselves on the following lines, one action at a time, and terminate the actions list with a line containing just
end. So far, the only defined actions are
actionsis actually equivalent to
commands(see Breakpoint Command Lists), except that only the defined actions are allowed; any other gdb command is rejected.
(gdb) collect data // collect some data (gdb) while-stepping 5 // single-step 5 times, collect data (gdb) end // signals the end of actions.
In the following example, the action list begins with
collectcommands indicating the things to be collected when the tracepoint is hit. Then, in order to single-step and collect additional data following the tracepoint, a
while-steppingcommand is used, followed by the list of things to be collected after each step in a sequence of single steps. The
while-steppingcommand is terminated by its own separate
endcommand. Lastly, the action list is terminated by an
(gdb) trace foo (gdb) actions Enter actions for tracepoint 1, one per line: > collect bar,baz > collect $regs > while-stepping 12 > collect $pc, arr[i] > end end
- Collect values of the given expressions when the tracepoint is hit.
This command accepts a comma-separated list of any valid expressions.
In addition to global, static, or local variables, the following
special arguments are supported:
- Collect all registers.
- Collect all function arguments.
- Collect all local variables.
- Collect static tracepoint marker specific data. Only available for
static tracepoints. See Tracepoint Action Lists. On the UST static tracepoints library backend, an
instrumentation point resembles a
printffunction call. The tracing library is able to collect user specified data formatted to a character string using the format provided by the programmer that instrumented the program. Other backends have similar mechanisms. Here's an example of a UST marker call:
const char master_name = "$your_name"; trace_mark(channel1, marker1, "hello %s", master_name)
In this case, collecting
$_sdatacollects the string hello $yourname. When analyzing the trace buffer, you can inspect $_sdata like any other variable available to gdb.
You can give several consecutive
collectcommands, each one with a single argument, or one
collectcommand with several arguments separated by commas; the effect is the same.
info scope(see info scope) is particularly useful for figuring out what data to collect.
- Evaluate the given expressions when the tracepoint is hit. This
command accepts a comma-separated list of expressions. The results
are discarded, so this is mainly useful for assigning values to trace
state variables (see Trace State Variables) without adding those
values to the trace buffer, as would be the case if the
collectaction were used.
- Perform n single-step instruction traces after the tracepoint,
collecting new data after each step. The
while-steppingcommand is followed by the list of what to collect while stepping (followed by its own
> while-stepping 12 > collect $regs, myglobal > end >
$pcis not automatically collected by
while-stepping; you need to explicitly collect that register if you need it. You may abbreviate
- This variable is a list of expressions to collect at each tracepoint
hit. It is effectively an additional
collectaction prepended to every tracepoint action list. The expressions are parsed individually for each tracepoint, so for instance a variable named
xyzmay be interpreted as a global for one tracepoint, and a local for another, as appropriate to the tracepoint's location.
- Show the list of expressions that are collected by default at each tracepoint hit.