]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/signull.c
Update Copyright year range in all files maintained by GDB.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / signull.c
CommitLineData
8bfabb04
AC
1/* This testcase is part of GDB, the GNU debugger.
2
ecd75fc8 3 Copyright 1996-2014 Free Software Foundation, Inc.
8bfabb04
AC
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
a9762ec7 7 the Free Software Foundation; either version 3 of the License, or
8bfabb04
AC
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.
a9762ec7 14
8bfabb04 15 You should have received a copy of the GNU General Public License
a9762ec7 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8bfabb04
AC
17
18#include <signal.h>
19#include <setjmp.h>
725603e1 20#include <stdlib.h>
9d9030bc 21#include <string.h>
8bfabb04
AC
22
23enum tests {
9d9030bc 24 code_entry_point, code_descriptor, data_read, data_write
8bfabb04
AC
25};
26
27static volatile enum tests test;
28
29/* Some basic types and zero buffers. */
30
31typedef long data_t;
32typedef long code_t (void);
9d9030bc
AC
33data_t *volatile data;
34code_t *volatile code;
35/* "desc" is intentionally initialized to a data object. This is
36 needed to test function descriptors on arches like ia64. */
37data_t zero[10];
38code_t *volatile desc = (code_t *) (void *) zero;
8bfabb04 39
8f5a3103 40sigjmp_buf env;
8bfabb04
AC
41
42extern void
43keeper (int sig)
44{
725603e1 45 siglongjmp (env, 0);
8bfabb04
AC
46}
47
48extern long
49bowler (void)
50{
51 switch (test)
52 {
9d9030bc
AC
53 case data_read:
54 /* Try to read address zero. */
55 return (*data);
56 case data_write:
57 /* Try to write (the assignment) to address zero. */
58 return (*data) = 1;
8bfabb04 59 case code_entry_point:
9d9030bc
AC
60 /* For typical architectures, call a function at address
61 zero. */
62 return (*code) ();
8bfabb04 63 case code_descriptor:
9d9030bc
AC
64 /* For atypical architectures that use function descriptors,
65 call a function descriptor, the code field of which is zero
66 (which has the effect of jumping to address zero). */
67 return (*desc) ();
8bfabb04
AC
68 }
69}
70
71int
72main ()
73{
74 static volatile int i;
725603e1
UW
75
76 struct sigaction act;
77 memset (&act, 0, sizeof act);
78 act.sa_handler = keeper;
79 sigaction (SIGSEGV, &act, NULL);
aacd552b 80 sigaction (SIGBUS, &act, NULL);
725603e1 81
8bfabb04
AC
82 for (i = 0; i < 10; i++)
83 {
725603e1 84 sigsetjmp (env, 1);
8bfabb04
AC
85 bowler ();
86 }
87}