I have managed to obtain traces using GDB tracepoints in a remote debugging session as explained in this and this other question. I am able to see the frames correctly, as well as the arguments, locals and so on. Then I export the traces to a trace file (tsave
command) for further offline analysis as follows:
gdb -q trace_test
Reading symbols from trace_test...
(gdb) target remote :1234
(gdb) trace 3
Tracepoint 1 at 0x555555555157: file /home/juangburgos/Documents/REPOS/trace_test/main.cpp, line 3.
(gdb) trace 8
Tracepoint 2 at 0x555555555184: file /home/juangburgos/Documents/REPOS/trace_test/main.cpp, line 8.
(gdb) b 9
Breakpoint 3 at 0x55555555519a: file /home/juangburgos/Documents/REPOS/trace_test/main.cpp, line 9.
(gdb) actions 1
Enter actions for tracepoint 1, one per line.
End with a line saying just "end".
>collect $regs,$args,$locals,$_ret,$trace_timestamp
>end
(gdb) tstart
(gdb) c
Continuing.
Breakpoint 3, main () at /home/juangburgos/Documents/REPOS/trace_test/main.cpp:9
9 return 0;
(gdb) tstop
(gdb) tfind start
Found trace frame 0, tracepoint 1
#0 foo (a=33, b=4) at /home/juangburgos/Documents/REPOS/trace_test/main.cpp:3
3 return a + b + b;
(gdb) tsave /home/juangburgos/Documents/REPOS/build-trace_test-Desktop-Debug/trace02.tfile
Trace data saved to file '/home/juangburgos/Documents/REPOS/build-trace_test-Desktop-Debug/trace02.tfile'.
(gdb) q
The problem now is when I load the trace file in another offline GDB session, then the frames, args, locals are not displayed, only showing ??
:
gdb -q trace_test
Reading symbols from trace_test...
(gdb) target tfile /home/juangburgos/Documents/REPOS/build-trace_test-Desktop-Debug/trace02.tfile
Tracepoint 1 at 0x1157: file /home/juangburgos/Documents/REPOS/trace_test/main.cpp, line 3.
Created tracepoint 1 for target's tracepoint 1 at 0x555555555157.
Tracepoint 2 at 0x1184: file /home/juangburgos/Documents/REPOS/trace_test/main.cpp, line 8.
Created tracepoint 2 for target's tracepoint 2 at 0x555555555184.
(gdb) tfind start
Found trace frame 0, tracepoint 1
#0 0x0000555555555157 in ?? ()
Anybody knows what could be causing it? I know it is supposed to work, since that is the defining use case for trace files.
Pay attention to this part of the message that GDB is outputting:
Tracepoint 1 at 0x1157: file ... Created tracepoint 1 for target's tracepoint 1 at 0x555555555157.
It appears GDB is not able to translate the memory offsets from the trace file (0x555555555157
) into the memory offset of the loaded image (0x1157
).
Try to load the symbols with an offset that matches the difference that is observed.
I.e. 0x555555555157 - 0x1157 = 0x555555554000
, then execute:
add-symbol-file ./trace_test -o 0x555555554000
And try tfind start
again.