]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/signull.c
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / signull.c
CommitLineData
8bfabb04
AC
1/* This testcase is part of GDB, the GNU debugger.
2
6aba47ca 3 Copyright 1996, 1999, 2003, 2004, 2007 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
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>
725603e1 22#include <stdlib.h>
9d9030bc 23#include <string.h>
8bfabb04
AC
24
25enum tests {
9d9030bc 26 code_entry_point, code_descriptor, data_read, data_write
8bfabb04
AC
27};
28
29static volatile enum tests test;
30
31/* Some basic types and zero buffers. */
32
33typedef long data_t;
34typedef long code_t (void);
9d9030bc
AC
35data_t *volatile data;
36code_t *volatile code;
37/* "desc" is intentionally initialized to a data object. This is
38 needed to test function descriptors on arches like ia64. */
39data_t zero[10];
40code_t *volatile desc = (code_t *) (void *) zero;
8bfabb04 41
8f5a3103 42sigjmp_buf env;
8bfabb04
AC
43
44extern void
45keeper (int sig)
46{
725603e1 47 siglongjmp (env, 0);
8bfabb04
AC
48}
49
50extern long
51bowler (void)
52{
53 switch (test)
54 {
9d9030bc
AC
55 case data_read:
56 /* Try to read address zero. */
57 return (*data);
58 case data_write:
59 /* Try to write (the assignment) to address zero. */
60 return (*data) = 1;
8bfabb04 61 case code_entry_point:
9d9030bc
AC
62 /* For typical architectures, call a function at address
63 zero. */
64 return (*code) ();
8bfabb04 65 case code_descriptor:
9d9030bc
AC
66 /* For atypical architectures that use function descriptors,
67 call a function descriptor, the code field of which is zero
68 (which has the effect of jumping to address zero). */
69 return (*desc) ();
8bfabb04
AC
70 }
71}
72
73int
74main ()
75{
76 static volatile int i;
725603e1
UW
77
78 struct sigaction act;
79 memset (&act, 0, sizeof act);
80 act.sa_handler = keeper;
81 sigaction (SIGSEGV, &act, NULL);
82
8bfabb04
AC
83 for (i = 0; i < 10; i++)
84 {
725603e1 85 sigsetjmp (env, 1);
8bfabb04
AC
86 bowler ();
87 }
88}