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