2010-09-11 33 views
6

每次程序到達特定行時,我想記錄一個局部變量的值,即t。因此,我想:gdb:tstart錯誤的含義「當你的目標是'exec'時,你不能這樣做」

 
(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' 

但錯誤信息:「你不能這樣做,當你的目標是'高管「」和「你不能這樣做,當你的目標是'孩子」」也沒有什麼幫助對我來說。這些錯誤意味着什麼?

+0

你爲什麼要使用'trace'上的本地程序?如果您的目標是更快地創建斷點+命令,似乎目前還沒有其他選擇,但未來可能會提供代碼注入功能:http://stackoverflow.com/a/31712150/895245 – 2015-07-31 14:40:55

回答

14

The tracepoint facility is currently available only for remote targets.

你應該能夠執行您使用gdbserver的願望跟蹤實驗。例如:

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

在另一個窗口:

$ 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 

跟蹤實驗,現在收集的數據...

+0

解釋爲什麼它只適用於'remote'也很酷。我猜這不是硬件支持,只是爲了減少許多斷點的帶寬瓶頸,將控制權交還給GDB。 – 2015-07-31 14:38:31

0

盡我所能找到的是

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

負載文件名 根據什麼遠程調試設備配置到GDB, 負載命令可用。 如果存在,它的意思是使 文件名(可執行文件)可用於 在遠程系統上的調試 - 通過 下載或動態鏈接,用於 示例。 load還會在gdb中記錄 文件名符號表,如 add-symbol-file命令。

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

錯誤消息「你不能這樣做, 當你的目標是......」

The file is loaded at whatever address is specified in the 

可執行文件。對於某些目標文件 格式,您可以在鏈接程序時指定加載 地址;對於 等格式,如a.out,對象 指定一個固定的文件格式地址。

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

程序進入閃存。

load does not repeat if you press <RET> again after using it. 
+2

我們都知道如何使用谷歌。您可能想避免提供實際上沒有回答任何問題的答案:-) – 2010-09-11 16:01:11

相關問題