dd77bbdec08b4f0964e75053d592e1622924e313
[binutils-gdb.git] / gdb / testsuite / gdb.base / signull.c
1 /* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 1996, 1999, 2003 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 02111-1307, USA. */
19
20 #include <signal.h>
21 #include <setjmp.h>
22 #include <stdlib.h>
23
24 enum tests {
25 code_entry_point, code_descriptor, data_pointer
26 };
27
28 static volatile enum tests test;
29
30 /* Some basic types and zero buffers. */
31
32 typedef long data_t;
33 typedef long code_t (void);
34 static volatile data_t *data[10];
35 static volatile code_t *code[10];
36
37 sigjmp_buf env;
38
39 extern void
40 keeper (int sig)
41 {
42 siglongjmp (env, 0);
43 }
44
45 extern long
46 bowler (void)
47 {
48 switch (test)
49 {
50 case data_pointer:
51 return *data[0];
52 case code_entry_point:
53 return code[0] ();
54 case code_descriptor:
55 return ((code_t *) &code) ();
56 }
57 }
58
59 int
60 main ()
61 {
62 static volatile int i;
63
64 struct sigaction act;
65 memset (&act, 0, sizeof act);
66 act.sa_handler = keeper;
67 sigaction (SIGSEGV, &act, NULL);
68
69 for (i = 0; i < 10; i++)
70 {
71 sigsetjmp (env, 1);
72 bowler ();
73 }
74 }