1 /* Copyright 1992-2020 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 /* This test has two large memory areas buf_rw and buf_ro.
20 buf_rw is written to by the program while buf_ro is initialized at
21 compile / load time. Thus, when a core file is created, buf_rw's
22 memory should reside in the core file, but buf_ro probably won't be.
23 Instead, the contents of buf_ro are available from the executable.
25 Now, for the wrinkle: We create a one page read-only mapping over
26 both of these areas. This will create a one page "hole" of all
29 Will GDB be able to correctly read memory from each of the four
30 (or six, if you count the regions on the other side of each hole)
34 #include <sys/types.h>
43 /* These are globals so that we can find them easily when debugging
46 unsigned long long addr
;
51 char buf_rw
[24 * 1024];
53 /* 24 KiB worth of data. For this test case, we can't allocate a
54 buffer and then fill it; we want GDB to have to read this data
55 from the executable; it should NOT find it in the core file. */
58 0xc5, 0xc5, 0xc5, 0xc5, \
59 0xc5, 0xc5, 0xc5, 0xc5, \
60 0xc5, 0xc5, 0xc5, 0xc5, \
61 0xc5, 0xc5, 0xc5, 0xc5
64 C5_16, C5_16, C5_16, C5_16, \
65 C5_16, C5_16, C5_16, C5_16, \
66 C5_16, C5_16, C5_16, C5_16, \
67 C5_16, C5_16, C5_16, C5_16
70 C5_256, C5_256, C5_256, C5_256
73 C5_1k, C5_1k, C5_1k, C5_1k, \
74 C5_1k, C5_1k, C5_1k, C5_1k, \
75 C5_1k, C5_1k, C5_1k, C5_1k, \
76 C5_1k, C5_1k, C5_1k, C5_1k, \
77 C5_1k, C5_1k, C5_1k, C5_1k, \
78 C5_1k, C5_1k, C5_1k, C5_1k
80 const char buf_ro
[] = { C5_24k
};
83 main (int argc
, char **argv
)
88 pagesize
= sysconf (_SC_PAGESIZE
);
93 /* Verify that pagesize is a power of 2. */
95 for (i
= 0; i
< 4 * sizeof (pagesize
); i
++)
96 if (pagesize
& (1 << i
))
101 fprintf (stderr
, "pagesize is not a power of 2.\n");
105 /* Compute an address that should be within buf_ro. Complain if not. */
106 addr
= ((unsigned long long) buf_ro
+ pagesize
) & ~(pagesize
- 1);
108 if (addr
<= (unsigned long long) buf_ro
109 || addr
>= (unsigned long long) buf_ro
+ sizeof (buf_ro
))
111 fprintf (stderr
, "Unable to compute a suitable address within buf_ro.\n");
115 mbuf_ro
= mmap ((void *) addr
, pagesize
, PROT_READ
,
116 MAP_ANONYMOUS
| MAP_PRIVATE
| MAP_FIXED
, -1, 0);
118 if (mbuf_ro
== MAP_FAILED
)
120 fprintf (stderr
, "mmap #1 failed: %s.\n", strerror (errno
));
124 /* Write (and fill) the R/W region. */
125 for (i
= 0; i
< sizeof (buf_rw
); i
++)
128 /* Compute an mmap address within buf_rw. Complain if it's somewhere
130 addr
= ((unsigned long long) buf_rw
+ pagesize
) & ~(pagesize
- 1);
132 if (addr
<= (unsigned long long) buf_rw
133 || addr
>= (unsigned long long) buf_rw
+ sizeof (buf_rw
))
135 fprintf (stderr
, "Unable to compute a suitable address within buf_rw.\n");
139 mbuf_rw
= mmap ((void *) addr
, pagesize
, PROT_READ
,
140 MAP_ANONYMOUS
| MAP_PRIVATE
| MAP_FIXED
, -1, 0);
142 if (mbuf_rw
== MAP_FAILED
)
144 fprintf (stderr
, "mmap #2 failed: %s.\n", strerror (errno
));
148 /* With correct ulimit, etc. this should cause a core dump. */
This page took 0.039683 seconds and 4 git commands to generate.