2012-04-02 100 views
5

我有正在運行的進程,但它的可執行文件已被刪除。 如果我嘗試附加GDB我得到了以下錯誤GDB附加到可執行文件被刪除的進程

/home/vivek/binary/releases/20120328101511/bin/app.exe (deleted): No such file or directory. 

我怎麼能把GDB這個過程?

樣品測試情況: 的源代碼:

#include<stdio.h> 
#include<stdlib.h> 
int main(){ 
    for (;;){ 
    printf("Sleeping"); 
    sleep(1); 
    } 
} 

編譯

gcc main.cc -o a.out 
gcc main.cc -o b.out 

運行 ./a.out

現在,從不同的終端刪除的a.out。 and fire gdb attach pgrep a.out file b.out 它不起作用。

以下錯誤GDB顯示:

/tmp/temp/a.out (deleted): No such file or directory. 
A program is being debugged already. Kill it? (y or n) n 
Program not killed. 

回答

7

嘗試使用/proc/<pid>/exe作爲可執行文件。現在它似乎是一個符號鏈接,但是,過去有可能從中提取被刪除的可執行文件。

請參閱Detecting deleted executables

我們可以使用下面的命令來連接GDB

gdb <path-to-binary> <pid> 
+0

?我懷疑它...... – littleadv 2012-04-02 10:01:43

+0

@littleadv:嗯?該問題被標記爲'linux'。 – 2012-04-02 10:03:31

+0

在linux下工作(我剛剛測試過,打算髮布相同的),我沒有在這裏看到任何人提到cygwin。 – Hasturkun 2012-04-02 10:03:34

2

你不能。 GDB需要可執行文件中的符號數據,並且在運行程序時不會被操作系統加載。

+0

我不能指定相同的可執行文件,但在不同的位置? – 2012-04-02 10:13:35

+0

@VivekGoel是的,你可以,假設它的可執行文件... – littleadv 2012-04-02 17:11:22

+0

,但如果我給gdb進程它說可執行刪除。程序已被調試。 – 2012-04-02 18:44:11

相關問題