Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tracepoint not working in gdb and it shows "Trace can only be run on remote targets"

Tags:

gdb

I want to use tracepoints to debug a prog on a local machine where i have full access. I am able to set the tracepoint and its passcount and using info tr gives me

(gdb) info tr

Num Enb Address PassC StepC What

1 y 0x080b7529 2 0 in search_tcp at tcp_pkt.c:412

Actions for tracepoint 1: collect flow end

Then i run the prog, it runs as usual and in the end when i give tfind or tdump to collect the required data it shows:

(gdb) tfind 1

Trace can only be run on remote targets.

(gdb) tdump

Trace can only be run on remote targets.

Even i tried using "tstart" but it shows again "Trace can only be run on remote targets."

Any idea on what is the meaning of this message ? Is tracepoing usage not supported currently ? OR is it for debugging some remote machine over LAN or some other network ? Any help would be greatly appreciated.

thanks vikas

like image 904
mezda Avatar asked Dec 21 '22 02:12

mezda


1 Answers

Any idea on what is the meaning of this message ?

The meaning is exactly what the message says: the tracepoint facility is implemented only in gdbserver, and not in GDB itself, so you can't use tstart when debugging natively (when GDB controls the inferior (being debugged) process directly).

Instead, you need to set up a remote debugging session (which can still be done on a single machine):

gdbserver :10000 ./a.out  # start gdbserver listening on port 10000

In another window:

gdb -ex 'target remote :10000' ./a.out

Now you'll have GDB with a remote target (which is the gdbserver running on the same host), and tstart etc. will work.

Update:

But now i see the following msg:
(gdb) tstart
Target does not support this command.
(gdb) r
The "remote" target does not support "run".

Before you can use tstart, you need to set trace and actions, as documented here.

And you can't run because the inferior process is already running. Use continue instead.

Update 2:

(gdb) trace testprog.c:273
Tracepoint 1 at 0x4578f7: file testprog.c, line 273.
(gdb) passcount 2 1
Setting tracepoint 1's passcount to 2
(gdb) actions 1
Enter actions for tracepoint 1, one per line.
End with a line saying just "end".
> collect id1
> end
(gdb) tstart
Target does not support this command

It sounds like your gdbserver is old, and does in fact not support tracing.

What do

gdb --version
gdbserver --version

produce?

Update 3:

Apparently your gdbserver is too old.

Even though GDB itself supported tracepoints since version 4.17, gdbserver only started supporting the tracepoints with version 7.2

Update 4:

where to give this option "-f filename" that my program takes as input

Simple. You can read the documentation for gdbserver, but I believe you are looking for this invocation:

gdbserver :10000 ./a.out -f filename
like image 128
Employed Russian Avatar answered Apr 14 '23 12:04

Employed Russian