1 /* Copyright 1992, 1993, 1994, 1995, 1996, 1999, 2007
2 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 /* Simple little program that just generates a core dump from inside some
20 nested function calls. */
23 #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");
104 int coremaker_local
[5];
108 /* Force a corefile that includes the data section for AIX. */
112 sigaction (SIGABRT
, (struct sigaction
*)0, &sa
);
113 sa
.sa_flags
|= SA_FULLDUMP
;
114 sigaction (SIGABRT
, &sa
, (struct sigaction
*)0);
118 /* Make sure that coremaker_local doesn't get optimized away. */
119 for (i
= 0; i
< 5; i
++)
120 coremaker_local
[i
] = i
;
122 for (i
= 0; i
< 5; i
++)
123 coremaker_bss
+= coremaker_local
[i
];
124 coremaker_data
= coremaker_ro
+ 1;
This page took 0.033426 seconds and 5 git commands to generate.