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 2 of the License, or (at
9 your option) any later version.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 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, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Simple little program that just generates a core dump from inside some
22 nested function calls. */
25 #include <sys/types.h>
36 #define MAPSIZE (8 * 1024)
38 /* Don't make these automatic vars or we will have to walk back up the
39 stack to access them. */
44 int coremaker_data
= 1; /* In Data section */
45 int coremaker_bss
; /* In BSS section */
47 const int coremaker_ro
= 201; /* In Read-Only Data section */
49 /* Note that if the mapping fails for any reason, we set buf2
50 to -1 and the testsuite notices this and reports it as
51 a failure due to a mapping error. This way we don't have
52 to test for specific errors when running the core maker. */
59 /* Allocate and initialize a buffer that will be used to write
60 the file that is later mapped in. */
62 buf1
= (char *) malloc (MAPSIZE
);
63 for (j
= 0; j
< MAPSIZE
; ++j
)
68 /* Write the file to map in */
70 fd
= open ("coremmap.data", O_CREAT
| O_RDWR
, 0666);
73 perror ("coremmap.data open failed");
77 write (fd
, buf1
, MAPSIZE
);
79 /* Now map the file into our address space as buf2 */
81 buf2
= (char *) mmap (0, MAPSIZE
, PROT_READ
| PROT_WRITE
, MAP_PRIVATE
, fd
, 0);
82 if (buf2
== (char *) -1)
84 perror ("mmap failed");
88 /* Verify that the original data and the mapped data are identical.
89 If not, we'd rather fail now than when trying to access the mapped
90 data from the core file. */
92 for (j
= 0; j
< MAPSIZE
; ++j
)
94 if (buf1
[j
] != buf2
[j
])
96 fprintf (stderr
, "mapped data is incorrect");
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;
This page took 0.033539 seconds and 5 git commands to generate.