Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use tracing in GDB

In the documentation for gdb:

The tracepoint facility is currently available only for remote targets. See section Specifying a Debugging Target. In addition, your remote target must know how to collect trace data. This functionality is implemented in the remote stub; however, none of the stubs distributed with GDB support tracepoints as of this writing.

Emphasis mine. Where can I get such a stub (for C/C++ code compiled with GCC on Debian x86 or x64)? Or how do I go about making one? The documentation on writing stubs only mentions implementing functions to communicate with the serial ports. Thanks!

like image 259
Gaius Avatar asked Aug 24 '11 10:08

Gaius


People also ask

What is gdb trace?

Using gdb's trace and collect commands, you can specify locations in the program, called tracepoints, and arbitrary expressions to evaluate when those tracepoints are reached. Later, using the tfind command, you can examine the values those expressions had when the program hit the tracepoints.

How do I trace a function call in gdb?

For each function breakpoint, I instruct GDB to print a short backtrace and then continue execution. I can then stop the program run at any time using CTRL-C and observe where the program is, what functions are being called, and what arguments they are being called with.

How do I add a breakpoint in gdb?

Setting breakpoints A breakpoint is like a stop sign in your code -- whenever gdb gets to a breakpoint it halts execution of your program and allows you to examine it. To set breakpoints, type "break [filename]:[linenumber]". For example, if you wanted to set a breakpoint at line 55 of main.


1 Answers

I don't know much about remotes but some targets in gdb now do support tracepoints there is possibly a way to get at this using a 'normal' gdb info or show command, I could not find it. in the output below tracepoints are supported due to the 'supported=1', this may not be limited to the gdb stub, but also the kernel the stub is running on.

$ gdbserver/gdbserver :12345 ~/tests/test &
$ gdb -quiet
(gdb) file ~/tests/test
Reading symbols from /home/ratmice/tests/test...done.
(gdb) target remote :12345
Remote debugging using :12345
Remote debugging from host 127.0.0.1
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
0x00000035dd600b20 in _start () from /lib64/ld-linux-x86-64.so.2
Created trace state variable $trace_timestamp for target's variable 1.
Missing separate debuginfos, use: debuginfo-install glibc-2.13-2.x86_64
(gdb) interpreter-exec mi2 -trace-status
^done,supported="1",running="0",frames="0",frames-created="0",buffer-size="5242880",buffer-free="5242880",disconnected="0",circular="0"
like image 181
matt Avatar answered Oct 22 '22 19:10

matt