Why not use the signal under gdb to capture the signal?

Category: Linux/Unix Community -> Applications Author: tinver123 Date: 2009-10-05 11:06:32
 
tinver123
2009-10-05 11:06:32
For example the following procedure to run directly in gdb quit
while the normal start running when the signal handler is able to go to handle_signal in

# include <stdio.h>
# include <signal.h>

void InitSignal (void);
void handle_signal (int s);

/ * After initialization and each treatment is called * /
void InitSignal (void)
{
signal (SIGPIPE, handle_signal);
}

/ * signal handler * /
void handle_signal (int s)
{
printf ("SIGPIPE occured. \ n");
InitSignal ();
}

void
fun ()
{
raise (SIGPIPE);
printf ("run% s \ n", __ func__);
}

int
main ()
{
InitSignal ( );
sleep (1);
fun ();
printf ("run% s \ n", __ func__);
}
chx1525225
2009-10-05 11:15:50
me how can:
(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% s \ n ", __ func__);
(gdb) s
run fun
25}
(gdb) ; s
main () at address.c: 33
33 ; printf ("run% s \ n", __ 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.
yefeng881002
2009-10-05 11:19:41
Oh
is not caught in a signal whenever gdb will stop?

I also shows these, I think the program directly out of the!
Program received signal SIGPIPE, Broken pipe.
0xffffe410 in __ kernel_vsyscall ()
chenxiang1729
2009-10-05 11:36:55
is your sleep pause right