Commit | Line | Data |
---|---|---|
e2882c85 | 1 | /* Copyright 1992-2018 Free Software Foundation, Inc. |
0a8490ad MC |
2 | |
3 | This file is part of GDB. | |
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 JB |
7 | the Free Software Foundation; either version 3 of the License, or |
8 | (at your option) any later version. | |
0a8490ad | 9 | |
a9762ec7 JB |
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. | |
0a8490ad MC |
14 | |
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/>. */ |
0a8490ad | 17 | |
d65308ae RM |
18 | /* Simple little program that just generates a core dump from inside some |
19 | nested function calls. Keep this as self contained as possible, I.E. | |
20 | use no environment resources other than possibly abort(). */ | |
21 | ||
22 | #ifndef __STDC__ | |
23 | #define const /**/ | |
24 | #endif | |
25 | ||
26 | #ifndef HAVE_ABORT | |
27 | #define HAVE_ABORT 1 | |
28 | #endif | |
29 | ||
30 | #if HAVE_ABORT | |
c9133d23 | 31 | #include <stdlib.h> |
d65308ae RM |
32 | #define ABORT abort() |
33 | #else | |
34 | #define ABORT {char *invalid = 0; *invalid = 0xFF;} | |
35 | #endif | |
36 | ||
2e98ca53 JK |
37 | #ifdef USE_RLIMIT |
38 | # include <sys/resource.h> | |
39 | # ifndef RLIM_INFINITY | |
40 | # define RLIM_INFINITY -1 | |
41 | # endif | |
42 | #endif /* USE_RLIMIT */ | |
43 | ||
d65308ae RM |
44 | /* Don't make these automatic vars or we will have to walk back up the |
45 | stack to access them. */ | |
46 | ||
47 | char *buf1; | |
48 | char *buf2; | |
49 | ||
50 | int coremaker_data = 1; /* In Data section */ | |
51 | int coremaker_bss; /* In BSS section */ | |
52 | ||
53 | const int coremaker_ro = 201; /* In Read-Only Data section */ | |
54 | ||
55 | void | |
56 | func2 (int x) | |
57 | { | |
58 | int coremaker_local[5]; | |
59 | int i; | |
60 | static int y; | |
61 | ||
2e98ca53 JK |
62 | #ifdef USE_RLIMIT |
63 | { | |
64 | struct rlimit rlim = { RLIM_INFINITY, RLIM_INFINITY }; | |
65 | ||
66 | setrlimit (RLIMIT_CORE, &rlim); | |
67 | } | |
68 | #endif | |
69 | ||
d65308ae RM |
70 | /* Make sure that coremaker_local doesn't get optimized away. */ |
71 | for (i = 0; i < 5; i++) | |
72 | coremaker_local[i] = i; | |
73 | coremaker_bss = 0; | |
74 | for (i = 0; i < 5; i++) | |
75 | coremaker_bss += coremaker_local[i]; | |
76 | coremaker_data = coremaker_ro + 1; | |
77 | y = 10 * x; | |
78 | ABORT; | |
79 | } | |
80 | ||
81 | void | |
82 | func1 (int x) | |
83 | { | |
84 | func2 (x * 2); | |
85 | } | |
86 | ||
87 | int main () | |
88 | { | |
89 | func1 (10); | |
90 | return 0; | |
91 | } |