1 /* Copyright 1992-2022 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>
44 /* These are globals so that we can find them easily when debugging
52 char buf_rw
[256 * 1024];
55 0xc5, 0xc5, 0xc5, 0xc5, \
56 0xc5, 0xc5, 0xc5, 0xc5, \
57 0xc5, 0xc5, 0xc5, 0xc5, \
58 0xc5, 0xc5, 0xc5, 0xc5
61 C5_16, C5_16, C5_16, C5_16, \
62 C5_16, C5_16, C5_16, C5_16, \
63 C5_16, C5_16, C5_16, C5_16, \
64 C5_16, C5_16, C5_16, C5_16
67 C5_256, C5_256, C5_256, C5_256
70 C5_1k, C5_1k, C5_1k, C5_1k, \
71 C5_1k, C5_1k, C5_1k, C5_1k
74 C5_8k, C5_8k, C5_8k, C5_8k, \
75 C5_8k, C5_8k, C5_8k, C5_8k
78 C5_64k, C5_64k, C5_64k, C5_64k
80 /* 256 KiB worth of data. For this test case, we can't allocate a
81 buffer and then fill it; we want GDB to have to read this data
82 from the executable; it should NOT find it in the core file. */
84 const char buf_ro
[] = { C5_256k
};
87 main (int argc
, char **argv
)
92 pagesize
= sysconf (_SC_PAGESIZE
);
97 /* Verify that pagesize is a power of 2. */
99 for (i
= 0; i
< 4 * sizeof (pagesize
); i
++)
100 if (pagesize
& (1 << i
))
105 fprintf (stderr
, "pagesize is not a power of 2.\n");
109 /* Compute an address that should be within buf_ro. Complain if not. */
110 addr
= ((uintptr_t) buf_ro
+ pagesize
) & ~(pagesize
- 1);
112 if (addr
<= (uintptr_t) buf_ro
113 || addr
>= (uintptr_t) buf_ro
+ sizeof (buf_ro
))
115 fprintf (stderr
, "Unable to compute a suitable address within buf_ro.\n");
119 mbuf_ro
= mmap ((void *) addr
, pagesize
, PROT_READ
,
120 MAP_ANONYMOUS
| MAP_PRIVATE
| MAP_FIXED
, -1, 0);
122 if (mbuf_ro
== MAP_FAILED
)
124 fprintf (stderr
, "mmap #1 failed: %s.\n", strerror (errno
));
128 /* Write (and fill) the R/W region. */
129 for (i
= 0; i
< sizeof (buf_rw
); i
++)
132 /* Compute an mmap address within buf_rw. Complain if it's somewhere
134 addr
= ((uintptr_t) buf_rw
+ pagesize
) & ~(pagesize
- 1);
136 if (addr
<= (uintptr_t) buf_rw
137 || addr
>= (uintptr_t) buf_rw
+ sizeof (buf_rw
))
139 fprintf (stderr
, "Unable to compute a suitable address within buf_rw.\n");
143 mbuf_rw
= mmap ((void *) addr
, pagesize
, PROT_READ
,
144 MAP_ANONYMOUS
| MAP_PRIVATE
| MAP_FIXED
, -1, 0);
146 if (mbuf_rw
== MAP_FAILED
)
148 fprintf (stderr
, "mmap #2 failed: %s.\n", strerror (errno
));
152 /* With correct ulimit, etc. this should cause a core dump. */
This page took 0.03482 seconds and 4 git commands to generate.