Fix C++ template function matching in cooked index
[binutils-gdb.git] / gdb / testsuite / gdb.base / morestack.c
blob102c528278a6f570eca6c7c1b5006b5779801bef
1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2011-2024 Free Software Foundation, Inc.
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 /* Based on the gcc testcase `gcc/testsuite/gcc.dg/split-1.c'. This test
19 needs to use setrlimit to set the stack size, so it can only run on Unix.
22 #include <stdlib.h>
23 #include <sys/types.h>
24 #include <sys/resource.h>
25 #include <stdio.h>
26 #include <sys/mman.h>
28 /* Use a noinline function to ensure that the buffer is not removed
29 from the stack. */
30 static void use_buffer (char *buf) __attribute__ ((noinline));
31 static void
32 use_buffer (char *buf)
34 buf[0] = '\0';
37 static volatile int marker_var;
39 static void
40 marker_miss (void)
42 marker_var = 0;
45 static void
46 marker_hit (void)
48 marker_var = 0;
51 void *reserved;
52 #define RESERVED_SIZE 0x1000000
54 /* Each recursive call uses 10,000 bytes. We call it 1000 times,
55 using a total of 10,000,000 bytes. If -fsplit-stack is not
56 working, that will overflow our stack limit. */
58 static void
59 down (int i)
61 char buf[10000];
62 static void *last;
64 if (last && last < (void *) buf)
65 marker_hit ();
66 last = buf;
68 if (i == 500)
70 if (munmap (reserved, RESERVED_SIZE) != 0)
71 abort ();
72 reserved = NULL;
75 if (i > 0)
77 use_buffer (buf);
78 down (i - 1);
80 else
81 marker_miss ();
84 int
85 main (void)
87 struct rlimit r;
89 reserved = mmap (NULL, RESERVED_SIZE, PROT_READ | PROT_WRITE,
90 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
91 if (reserved == MAP_FAILED)
92 abort ();
94 /* We set a stack limit because we are usually invoked via make, and
95 make sets the stack limit to be as large as possible. */
96 r.rlim_cur = 8192 * 1024;
97 r.rlim_max = 8192 * 1024;
98 if (setrlimit (RLIMIT_STACK, &r) != 0)
99 abort ();
100 down (1000);
101 return 0;