--------------------------------------------------------------------------------
在console下按Ctrl-C后确实发送了SIGINT信号,但是gdb里的缺省设置将会导致由GDB截获的该信息,调试的应用程序无法接受到该信号。
有两种方法可以使调试的应用程序接受到信号:
(1)改变gdb信号处理的设置
比如,以下设置会告诉gdb在接收到SIGINT时不要停止、打印出来、传递给调试目标程序
=====================================
(gdb) handle SIGINT nostop print pass
SIGINT is used by the debugger.
Are you sure you want to change it? (y or n) y
Signal Stop Print Pass to program Description
SIGINT No Yes Yes Interrupt
(gdb)
=====================================
(2)使用gdb命令直接向调试的应用程序发送信号
首先在你希望发送信号的语句处设置断点,然后运行程序,当停止到断点所在位置后,用gdb的signal命令发送信号给调试目标程序
====================================
(gdb) signal SIGINT
Continuing with signal SIGINT.
Breakpoint 1, handler (signal=2) at main.cpp:15
15 printf("Signal handler...\n";
====================================
;-( 但是这两种方法目前MC都还不支持,所以需要等新版本的MC才可以方便的支持你这种调试情况,呵呵。临时先手工调试一下吧。
新版本将会增加
(1)调试器的信号处理设置
(2)支持发送信号命令
调试用例:
============
/*
* This program is uninterruptable with
* Ctrl+C, uses signal handler
*/
#include <stdio.h>;
#include <signal.h>;
#include <unistd.h>;
/* The signal handler function */
void handler( int signal ) {
printf("Signal handler...\n";
psignal( signal, "Signal: ";
} /*handler*/
main() {
/* Registering the handler, catching
SIGINT signals */
signal( SIGINT, handler );
/* Do nothing */
while( 1 ) {
printf("Running...\n";
sleep(10);
} /*while*/
} /*main*/