1 /* Copyright 1992-2019 Free Software Foundation, Inc.
3 This file is part of GDB.
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 3 of the License, or
8 (at your option) any later version.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* Simple little program that just generates a core dump from inside some
19 nested function calls. */
22 #include <sys/types.h>
34 #define MAPSIZE (8 * 1024)
36 /* Don't make these automatic vars or we will have to walk back up the
37 stack to access them. */
42 int coremaker_data
= 1; /* In Data section */
43 int coremaker_bss
; /* In BSS section */
45 const int coremaker_ro
= 201; /* In Read-Only Data section */
47 /* Note that if the mapping fails for any reason, we set buf2
48 to -1 and the testsuite notices this and reports it as
49 a failure due to a mapping error. This way we don't have
50 to test for specific errors when running the core maker. */
57 /* Allocate and initialize a buffer that will be used to write
58 the file that is later mapped in. */
60 buf1
= (char *) malloc (MAPSIZE
);
61 for (j
= 0; j
< MAPSIZE
; ++j
)
66 /* Write the file to map in */
68 fd
= open ("coremmap.data", O_CREAT
| O_RDWR
, 0666);
71 perror ("coremmap.data open failed");
75 write (fd
, buf1
, MAPSIZE
);
77 /* Now map the file into our address space as buf2 */
79 buf2
= (char *) mmap (0, MAPSIZE
, PROT_READ
| PROT_WRITE
, MAP_PRIVATE
, fd
, 0);
80 if (buf2
== (char *) -1)
82 perror ("mmap failed");
86 /* Verify that the original data and the mapped data are identical.
87 If not, we'd rather fail now than when trying to access the mapped
88 data from the core file. */
90 for (j
= 0; j
< MAPSIZE
; ++j
)
92 if (buf1
[j
] != buf2
[j
])
94 fprintf (stderr
, "mapped data is incorrect");
99 /* Touch buf2 so kernel writes it out into 'core'. */
106 int coremaker_local
[5];
110 /* Force a corefile that includes the data section for AIX. */
114 sigaction (SIGABRT
, (struct sigaction
*)0, &sa
);
115 sa
.sa_flags
|= SA_FULLDUMP
;
116 sigaction (SIGABRT
, &sa
, (struct sigaction
*)0);
120 /* Make sure that coremaker_local doesn't get optimized away. */
121 for (i
= 0; i
< 5; i
++)
122 coremaker_local
[i
] = i
;
124 for (i
= 0; i
< 5; i
++)
125 coremaker_bss
+= coremaker_local
[i
];
126 coremaker_data
= coremaker_ro
+ 1;
137 main (int argc
, char **argv
)
139 if (argc
== 2 && strcmp (argv
[1], "sleep") == 0)