2014-06-25 13 views
3

我正在研究項目Ubuntu Linux,當我使用GDB調試應用程序並中斷CTRL + Z時,我得到SIGTSTPGDB正如預期的中斷。爲什麼每次使用'cont'命令時,在gdb中運行時,一個CTRL-Z會一直髮送SIGTSTP信號?

但是當我後,使用cont,我仍然有SIGTSTP,我再說一遍cont了很多時間,但接縫它只是行爲相同,只是一再給我SIGTSTP

以下兩個呼叫棧或者重複:

The call stack is as following alterativly: 
Program received signal SIGTSTP, Stopped (user). 
[Switching to Thread 0x7fffef73d700 (LWP 32591)] 
0x00007ffff636dffd in read() from /lib/x86_64-linux-gnu/libc.so.6 
(gdb) bt 
#0 0x00007ffff636dffd in read() from /lib/x86_64-linux-gnu/libc.so.6 
#1 0x00007ffff6301ff8 in _IO_file_underflow() from /lib/x86_64-linux-gnu/libc.so.6 
#2 0x00007ffff630303e in _IO_default_uflow() from /lib/x86_64-linux-gnu/libc.so.6 
#3 0x00007ffff62f718a in _IO_getline_info() from /lib/x86_64-linux-gnu/libc.so.6 
#4 0x00007ffff62f606b in fgets() from /lib/x86_64-linux-gnu/libc.so.6 
... .... .... .... 
#11 0x00007ffff664ee9a in start_thread() from /lib/x86_64-linux-gnu/libpthread.so.0 
#12 0x00007ffff637b3fd in clone() from /lib/x86_64-linux-gnu/libc.so.6 
#13 0x0000000000000000 in ??() 
(gdb) c 
Continuing. 
Program received signal SIGTSTP, Stopped (user). 
[Switching to Thread 0x7fffeef3c700 (LWP 32592)] 
0x00007ffff6374763 in select() from /lib/x86_64-linux-gnu/libc.so.6 
(gdb) bt 
#0 0x00007ffff6374763 in select() from /lib/x86_64-linux-gnu/libc.so.6 
... ... ... ... 
#6 0x00007ffff664ee9a in start_thread() from /lib/x86_64-linux-gnu/libpthread.so.0 
#7 0x00007ffff637b3fd in clone() from /lib/x86_64-linux-gnu/libc.so.6 
#8 0x0000000000000000 in ??() 

所以任何原因是什麼?謝謝。

回答

0

我通常使用Ctrl + C(SIGINT)來插入正在運行的進程並設置斷點。

我認爲這將是有益的 http://web.mit.edu/gnu/doc/html/gdb_toc.html#SEC40

+0

但接縫Ctrl + C不能在我的linux終端上工作。它什麼都不做。任何可能的原因? – ZijingWu

+0

你可以檢查終端的鍵盤綁定嗎?我想這個選項已經被別人使用。這是不確定的。由於複製的默認映射也是Ctrl + Shift + C。 – user3079864

4

gdb通常(這是可配置)安排將停止該程序,並重新獲得終端的控制時,信號將要通過程序來接收。

gdb通常(可配置)在恢復執行時發送信號給程序。

使用info signals命令可以看到這些設置。

(gdb) info signals 
Signal  Stop Print Pass to program Description 
SIGINT  Yes Yes  No    Interrupt 
... 
SIGTSTP  Yes Yes  Yes    Stopped (user) 
... 

在這種情況下,

  • 鍵入Ctrl-C鍵將停止該程序,continue將恢復它不發送任何信號給它。
  • 打字Ctrl-Z將停止該程序,並且continue將伴隨一個SIGTSTP信號恢復它,因此它會立即再次停止。如果您再次輸入continue,則應恢復。

有兩種方法可以在不向其發送SIGTSTP信號的情況下恢復程序。

第一種是使用handle SIGTSTP nopass命令,該命令會將「傳遞到程序」標誌更改爲「否」。

第二種是使用signal命令而不是continue。從內置的幫助:

(gdb) help signal 
Continue program with the specified signal. 
Usage: signal SIGNAL 
The SIGNAL argument is processed the same as the handle command. 

An argument of "0" means continue the program without sending it a signal. 
This is useful in cases where the program stopped because of a signal, 
and you want to resume the program while discarding the signal. 

所以,signal 0將恢復無SIGTSTP信號的節目被傳遞給它。

+0

對於我以前不知道的「信號信號」的+1信號。但是這仍然沒有解決我的問題。 – ZijingWu

+0

所以如果你輸入'signal 0',你立即看到程序再次被SIGTSTP停止了? –

相關問題