views:

83

answers:

2

I would like to record the value of a local variable, t, each time that the program reaches a certain line. Accordingly, I tried:

(gdb) trace stoer_wagner_min_cut.hpp :197
Tracepoint 1 at 0x4123a0: file ./boost/graph/stoer_wagner_min_cut.hpp, line 197.
(gdb) actions
Enter actions for tracepoint 1, one per line.
End with a line saying just "end".
> collect t
> end
(gdb) tstart
You can't do that when your target is `exec'
(gdb) break main
Breakpoint 2 at 0x401448: file time_stoer_wagner.cpp, line 50.
(gdb) run
Starting program: C:\Users\Daniel\Documents\projects\stoer_wagner_min_cut/time_stoer_wagner.exe
[New Thread 3908.0x39c]

Breakpoint 2, main () at time_stoer_wagner.cpp:50
50        std::ifstream ifs("prgen_500_50_2.txt");
(gdb) tstart
You can't do that when your target is `child'

but the error messages "You can't do that when your target is `exec'" and "You can't do that when your target is `child'" are not helpful to me. What do these errors mean?

A: 

Best I could find is

http://sources.redhat.com/gdb/current/onlinedocs/gdb.html

load filename Depending on what remote debugging facilities are configured into gdb, the load command may be available. Where it exists, it is meant to make filename (an executable) available for debugging on the remote system—by downloading, or dynamic linking, for example. load also records the filename symbol table in gdb, like the add-symbol-file command.

If your gdb does not have a load command, attempting to execute it gets

the error message “You can't do that when your target is ...”

The file is loaded at whatever address is specified in the

executable. For some object file formats, you can specify the load address when you link the program; for other formats, like a.out, the object file format specifies a fixed address.

Depending on the remote side capabilities, gdb may be able to load

programs into flash memory.

load does not repeat if you press <RET> again after using it.
Roman A. Taycher
We all know how to use Google. You may want to refrain from providing answers which don't actually answer anything :-)
Employed Russian
+2  A: 

The tracepoint facility is currently available only for remote targets.

You should be able to perform the tracing experiment you desire by using gdbserver. Example:

$ gdbserver :0 ./a.out 
Process ./a.out created; pid = 21838
Listening on port 51596

In another window:

$ gdb -q ./a.out 
Reading symbols from /tmp/a.out...done.
(gdb) target remote :51596

0x00007fa76ec3fa60 in _start () from /lib64/ld-linux-x86-64.so.2
(gdb) list foo
1   int foo(int x)
2   {
3     return x;
4   }
5   
6   int main()
7   {
8     for(int i = 0; i < 10; ++i)
9       foo(i);
10    return 0;
11  }
(gdb) trace 3
Tracepoint 1 at 0x40053f: file t.c, line 3.
(gdb) actions
> collect x
> end
(gdb) c

Tracing experiment now collects the data ...

Employed Russian