Observe the program without interrupting.
trace [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]
[-force-condition] [if CONDITION]Set actions to be taken at a trace.
actions [tracepoint]
> collect
> while-stepping
> end
Set data item to collect.
collect expressions...Set stepping commands.
> while-stepping N
> collect ...
> endSet passcount.
passcount count [tracepoint]Sample: Setup a tracepoint. Trace only work within remote mode, so need a gdbserver.
#include <unistd.h>
int main()
{
int s = 0;
int i = 0;
while (1)
{
s += i;
i += 1;
sleep(3);
}
}
gdbserver --multi :12345
(gdb) target extended-remote :12345
(gdb) set remote exec-file demo
(gdb) file demo
(gdb) start
(gdb) trace demo.c:10
(gdb) actions
> collect i, s
> while-stepping 2
> collect i
> end
> end
(gdb) passcount 20 2
(gdb) info tracepoints
Start trace.
tstartStop trace.
tstopShow status.
tstatusCollect trace.
(gdb) tstart
(gdb) continue
(gdb) tstop
(gdb) tstatus
Trace stopped by a tstop.
Collected 24 trace frames.Select trace frame by index.
tfind start # frame 0
tfind n # frame n
tfind # next frame
tfind - # prev frame
Select trace frame by filter.
tfind tracepoint
tfind line
tfind pc
tfind range
tfind outside
Leave trace frame, back to live debug.
tfind endPrint collected data.
tdumpConvenience variables.
(int) $trace_frame
(int) $tracepoint
(int) $trace_line
(char []) $trace_file
(char []) $trace_funcScan through the trace frames.
(gdb) tfind start
(gdb) while $trace_frame != -1
> frame
> tdump
> tfind
> end
Found trace frame 0, tracepoint 2
#0 0x00000000004006cc in main () at demo.c:10
Data collected at tracepoint 2, trace frame 0:
i = 16
s = 136
Found trace frame 1, tracepoint 2
#0 0x00000000004006d0 in main () at demo.c:10
Data collected at tracepoint 2, trace frame 1:
i = 16
Found trace frame 2, tracepoint 2
#0 0x00000000004006d4 in main () at demo.c:10
Data collected at tracepoint 2, trace frame 2:
i = 16
Found trace frame 3, tracepoint 2
#0 0x00000000004006cc in main () at demo.c:10
Data collected at tracepoint 2, trace frame 3:
i = 17
s = 153Save trace data in client.
tsave filenameSave trace data in server.
tsave -r filenameLoad trace data.
target tfile filenameSample: Save and load trace data.
(gdb) tsave demo.trace(gdb) file demo
(gdb) target tfile demo.trace
(gdb) tfind start
Found trace frame 0, tracepoint 1
#0 0x00000000004006cc in main () at demo.c:10
(gdb) tdump
Data collected at tracepoint 1, trace frame 0:
i = 16
s = 136