当前位置: 技术问答>linux和unix
为什么在gdb下无法用signal捕捉到信号?
来源: 互联网 发布时间:2016-04-01
本文导语: 比如下列程序,在gdb中运行会直接退出 而正常启动运行的时候则能转到信号处理函数handle_signal中 #include #include void InitSignal(void); void handle_signal(int s) ; /*初始化时及每次处理完时调用*/ void InitSignal(void) { signa...
比如下列程序,在gdb中运行会直接退出
而正常启动运行的时候则能转到信号处理函数handle_signal中
#include
#include
void InitSignal(void);
void handle_signal(int s) ;
/*初始化时及每次处理完时调用*/
void InitSignal(void)
{
signal (SIGPIPE, handle_signal);
}
/*信号处理函数*/
void handle_signal(int s)
{
printf ("SIGPIPE occured.n");
InitSignal();
}
void
fun ()
{
raise (SIGPIPE);
printf ("run %sn", __func__);
}
int
main ()
{
InitSignal ();
sleep (1);
fun ();
printf ("run %sn", __func__);
}
而正常启动运行的时候则能转到信号处理函数handle_signal中
#include
#include
void InitSignal(void);
void handle_signal(int s) ;
/*初始化时及每次处理完时调用*/
void InitSignal(void)
{
signal (SIGPIPE, handle_signal);
}
/*信号处理函数*/
void handle_signal(int s)
{
printf ("SIGPIPE occured.n");
InitSignal();
}
void
fun ()
{
raise (SIGPIPE);
printf ("run %sn", __func__);
}
int
main ()
{
InitSignal ();
sleep (1);
fun ();
printf ("run %sn", __func__);
}
|
我的怎么可以:
(gdb) b main
Breakpoint 1 at 0x80484a9: file address.c, line 30.
(gdb) s
The program is not being run.
(gdb) r
Starting program: /home/test/a.out
Breakpoint 1, main () at address.c:30
30 InitSignal ();
(gdb) s
InitSignal () at address.c:10
10 signal (SIGPIPE, handle_signal);
(gdb) s
11 }
(gdb) s
main () at address.c:31
31 sleep (1);
(gdb) s
32 fun ();
(gdb) s
fun () at address.c:23
23 raise (SIGPIPE);
(gdb) s
Program received signal SIGPIPE, Broken pipe.
0xffffe410 in __kernel_vsyscall ()
(gdb) s
Single stepping until exit from function __kernel_vsyscall,
which has no line number information.
handle_signal (s=13) at address.c:15
15 {
(gdb) s
16 printf ("SIGPIPE occured.n");
(gdb) s
SIGPIPE occured.
17 InitSignal();
(gdb) s
InitSignal () at address.c:10
10 signal (SIGPIPE, handle_signal);
(gdb) s
11 }
(gdb) s
handle_signal (s=13) at address.c:18
18 }
(gdb) s
0xffffe410 in __kernel_vsyscall ()
(gdb) s
Single stepping until exit from function __kernel_vsyscall,
which has no line number information.
0xb7e2e9a1 in raise () from /lib/tls/i686/cmov/libc.so.6
(gdb) s
Single stepping until exit from function raise,
which has no line number information.
fun () at address.c:24
24 printf ("run %sn", __func__);
(gdb) s
run fun
25 }
(gdb) s
main () at address.c:33
33 printf ("run %sn", __func__);
(gdb) s
run main
34 }
(gdb) s
0xb7e1aea2 in __libc_start_main () from /lib/tls/i686/cmov/libc.so.6
(gdb) s
Single stepping until exit from function __libc_start_main,
which has no line number information.
Program exited with code 011.
(gdb) b main
Breakpoint 1 at 0x80484a9: file address.c, line 30.
(gdb) s
The program is not being run.
(gdb) r
Starting program: /home/test/a.out
Breakpoint 1, main () at address.c:30
30 InitSignal ();
(gdb) s
InitSignal () at address.c:10
10 signal (SIGPIPE, handle_signal);
(gdb) s
11 }
(gdb) s
main () at address.c:31
31 sleep (1);
(gdb) s
32 fun ();
(gdb) s
fun () at address.c:23
23 raise (SIGPIPE);
(gdb) s
Program received signal SIGPIPE, Broken pipe.
0xffffe410 in __kernel_vsyscall ()
(gdb) s
Single stepping until exit from function __kernel_vsyscall,
which has no line number information.
handle_signal (s=13) at address.c:15
15 {
(gdb) s
16 printf ("SIGPIPE occured.n");
(gdb) s
SIGPIPE occured.
17 InitSignal();
(gdb) s
InitSignal () at address.c:10
10 signal (SIGPIPE, handle_signal);
(gdb) s
11 }
(gdb) s
handle_signal (s=13) at address.c:18
18 }
(gdb) s
0xffffe410 in __kernel_vsyscall ()
(gdb) s
Single stepping until exit from function __kernel_vsyscall,
which has no line number information.
0xb7e2e9a1 in raise () from /lib/tls/i686/cmov/libc.so.6
(gdb) s
Single stepping until exit from function raise,
which has no line number information.
fun () at address.c:24
24 printf ("run %sn", __func__);
(gdb) s
run fun
25 }
(gdb) s
main () at address.c:33
33 printf ("run %sn", __func__);
(gdb) s
run main
34 }
(gdb) s
0xb7e1aea2 in __libc_start_main () from /lib/tls/i686/cmov/libc.so.6
(gdb) s
Single stepping until exit from function __libc_start_main,
which has no line number information.
Program exited with code 011.