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 | ||
a59add0c | 12 | int |
075559bc AC |
13 | main () |
14 | { | |
075559bc AC |
15 | foo (); /* Put a breakpoint on foo() and call it to see a dummy frame */ |
16 | ||
17 | ||
18 | have_a_very_merry_interrupt (); | |
a59add0c | 19 | return 0; |
075559bc AC |
20 | } |
21 | ||
22 | void | |
23 | foo (void) | |
24 | { | |
075559bc AC |
25 | } |
26 | ||
27 | void | |
28 | bar (void) | |
29 | { | |
d93f7b5c YQ |
30 | *(char *)0 = 0; /* try to cause a segfault */ |
31 | ||
32 | /* On MMU-less system, previous memory access to address zero doesn't | |
33 | trigger a SIGSEGV. Trigger a SIGILL. Each arch should define its | |
34 | own illegal instruction here. */ | |
35 | #if defined(__arm__) | |
36 | asm(".word 0xf8f00000"); | |
37 | #elif defined(__TMS320C6X__) | |
38 | asm(".word 0x56454313"); | |
39 | #else | |
40 | #endif | |
075559bc | 41 | |
075559bc AC |
42 | } |
43 | ||
44 | void | |
45 | handler (int sig) | |
46 | { | |
47 | subroutine (sig); | |
48 | } | |
49 | ||
c56716b0 JM |
50 | /* The first statement in subroutine () is a place for a breakpoint. |
51 | Without it, the breakpoint is put on the while comparison and will | |
52 | be hit at each iteration. */ | |
53 | ||
075559bc AC |
54 | void |
55 | subroutine (int in) | |
56 | { | |
5d0331e5 JM |
57 | int count = in; |
58 | while (count < 100) | |
59 | count++; | |
075559bc AC |
60 | } |
61 | ||
62 | void | |
63 | have_a_very_merry_interrupt (void) | |
64 | { | |
075559bc AC |
65 | signal (SIGALRM, handler); |
66 | alarm (1); | |
67 | sleep (2); /* We'll receive that signal while sleeping */ | |
68 | } | |
69 |