xref: /openbsd-src/gnu/usr.bin/binutils/gdb/testsuite/gdb.base/coremaker2.c (revision 11efff7f3ac2b3cfeff0c0cddc14294d9b3aca4f)
1*11efff7fSkettenis /* Copyright 1992, 1993, 1994, 1995, 1996, 1999
2*11efff7fSkettenis    Free Software Foundation, Inc.
3*11efff7fSkettenis 
4*11efff7fSkettenis    This file is part of GDB.
5*11efff7fSkettenis 
6*11efff7fSkettenis    This program is free software; you can redistribute it and/or modify
7*11efff7fSkettenis    it under the terms of the GNU General Public License as published by
8*11efff7fSkettenis    the Free Software Foundation; either version 2 of the License, or (at
9*11efff7fSkettenis    your option) any later version.
10*11efff7fSkettenis 
11*11efff7fSkettenis    This program is distributed in the hope that it will be useful, but
12*11efff7fSkettenis    WITHOUT ANY WARRANTY; without even the implied warranty of
13*11efff7fSkettenis    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*11efff7fSkettenis    General Public License for more details.
15*11efff7fSkettenis 
16*11efff7fSkettenis    You should have received a copy of the GNU General Public License
17*11efff7fSkettenis    along with this program; if not, write to the Free Software
18*11efff7fSkettenis    Foundation, Inc., 59 Temple Place - Suite 330,
19*11efff7fSkettenis    Boston, MA 02111-1307, USA.  */
20*11efff7fSkettenis 
21b725ae77Skettenis /* Simple little program that just generates a core dump from inside some
22b725ae77Skettenis    nested function calls.  Keep this as self contained as possible, I.E.
23b725ae77Skettenis    use no environment resources other than possibly abort(). */
24b725ae77Skettenis 
25b725ae77Skettenis #ifndef __STDC__
26b725ae77Skettenis #define	const	/**/
27b725ae77Skettenis #endif
28b725ae77Skettenis 
29b725ae77Skettenis #ifndef HAVE_ABORT
30b725ae77Skettenis #define HAVE_ABORT 1
31b725ae77Skettenis #endif
32b725ae77Skettenis 
33b725ae77Skettenis #if HAVE_ABORT
34b725ae77Skettenis #define ABORT abort()
35b725ae77Skettenis #else
36b725ae77Skettenis #define ABORT {char *invalid = 0; *invalid = 0xFF;}
37b725ae77Skettenis #endif
38b725ae77Skettenis 
39b725ae77Skettenis /* Don't make these automatic vars or we will have to walk back up the
40b725ae77Skettenis    stack to access them. */
41b725ae77Skettenis 
42b725ae77Skettenis char *buf1;
43b725ae77Skettenis char *buf2;
44b725ae77Skettenis 
45b725ae77Skettenis int coremaker_data = 1;	/* In Data section */
46b725ae77Skettenis int coremaker_bss;	/* In BSS section */
47b725ae77Skettenis 
48b725ae77Skettenis const int coremaker_ro = 201;	/* In Read-Only Data section */
49b725ae77Skettenis 
50b725ae77Skettenis void
func2(int x)51b725ae77Skettenis func2 (int x)
52b725ae77Skettenis {
53b725ae77Skettenis   int coremaker_local[5];
54b725ae77Skettenis   int i;
55b725ae77Skettenis   static int y;
56b725ae77Skettenis 
57b725ae77Skettenis   /* Make sure that coremaker_local doesn't get optimized away. */
58b725ae77Skettenis   for (i = 0; i < 5; i++)
59b725ae77Skettenis     coremaker_local[i] = i;
60b725ae77Skettenis   coremaker_bss = 0;
61b725ae77Skettenis   for (i = 0; i < 5; i++)
62b725ae77Skettenis     coremaker_bss += coremaker_local[i];
63b725ae77Skettenis   coremaker_data = coremaker_ro + 1;
64b725ae77Skettenis   y = 10 * x;
65b725ae77Skettenis   ABORT;
66b725ae77Skettenis }
67b725ae77Skettenis 
68b725ae77Skettenis void
func1(int x)69b725ae77Skettenis func1 (int x)
70b725ae77Skettenis {
71b725ae77Skettenis   func2 (x * 2);
72b725ae77Skettenis }
73b725ae77Skettenis 
main()74b725ae77Skettenis int main ()
75b725ae77Skettenis {
76b725ae77Skettenis   func1 (10);
77b725ae77Skettenis   return 0;
78b725ae77Skettenis }
79