Commit | Line | Data |
---|---|---|
075559bc AC |
1 | #include <signal.h> |
2 | #include <unistd.h> | |
3 | #include <stdlib.h> | |
4 | ||
5 | void foo (void); | |
6 | void bar (void); | |
7 | ||
8 | void subroutine (int); | |
9 | void handler (int); | |
10 | void have_a_very_merry_interrupt (void); | |
11 | ||
12 | main () | |
13 | { | |
075559bc AC |
14 | foo (); /* Put a breakpoint on foo() and call it to see a dummy frame */ |
15 | ||
16 | ||
17 | have_a_very_merry_interrupt (); | |
075559bc AC |
18 | } |
19 | ||
20 | void | |
21 | foo (void) | |
22 | { | |
075559bc AC |
23 | } |
24 | ||
25 | void | |
26 | bar (void) | |
27 | { | |
28 | char *nuller = 0; | |
29 | ||
075559bc AC |
30 | *nuller = 'a'; /* try to cause a segfault */ |
31 | } | |
32 | ||
33 | void | |
34 | handler (int sig) | |
35 | { | |
36 | subroutine (sig); | |
37 | } | |
38 | ||
c56716b0 JM |
39 | /* The first statement in subroutine () is a place for a breakpoint. |
40 | Without it, the breakpoint is put on the while comparison and will | |
41 | be hit at each iteration. */ | |
42 | ||
075559bc AC |
43 | void |
44 | subroutine (int in) | |
45 | { | |
5d0331e5 JM |
46 | int count = in; |
47 | while (count < 100) | |
48 | count++; | |
075559bc AC |
49 | } |
50 | ||
51 | void | |
52 | have_a_very_merry_interrupt (void) | |
53 | { | |
075559bc AC |
54 | signal (SIGALRM, handler); |
55 | alarm (1); | |
56 | sleep (2); /* We'll receive that signal while sleeping */ | |
57 | } | |
58 |