]>
Commit | Line | Data |
---|---|---|
baab3753 AB |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
1d506c26 | 3 | Copyright 2023-2024 Free Software Foundation, Inc. |
baab3753 AB |
4 | |
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. | |
9 | ||
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. | |
14 | ||
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/>. */ | |
17 | ||
18 | #include <stddef.h> | |
19 | #include <string.h> | |
20 | ||
21 | /* A memory area used as the malloc memory buffer. */ | |
22 | ||
23 | static char arena[256]; | |
24 | ||
25 | /* Override malloc(). When GDB tries to push strings into the inferior we | |
26 | will always return the same pointer (to arena). This does mean we can't | |
27 | have multiple strings in use at the same time, but that's fine for this | |
28 | simple test. On each malloc call the contents of arena are reset, which | |
29 | should make it more obvious if GDB tried to print memory that it | |
30 | shouldn't. */ | |
31 | ||
32 | void * | |
33 | malloc (size_t size) | |
34 | { | |
35 | /* Reset the contents of arena, and ensure there's a null-character at | |
36 | the end just in case GDB tries to print memory that it shouldn't. */ | |
37 | memset (arena, 'X', sizeof (arena)); | |
38 | arena [sizeof (arena) - 1] = '\0'; | |
39 | if (size > sizeof (arena)) | |
40 | return NULL; | |
41 | return arena; | |
42 | } | |
43 | ||
44 | /* This function is called from GDB. */ | |
45 | ||
46 | void | |
47 | take_string (const char *str) | |
48 | { | |
49 | /* Nothing. */ | |
50 | } | |
51 | ||
52 | int | |
53 | main (void) | |
54 | { | |
55 | return 0; | |
56 | } |