]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/nested-subp3.c
Update copyright year range in all GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / nested-subp3.c
1 /* This test program is part of GDB, the GNU debugger.
2
3 Copyright 2015-2019 Free Software Foundation, Inc.
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 <stdlib.h>
19
20 typedef void (*callback_t) (void);
21
22 extern void process (callback_t cb);
23 extern void parent (int first, callback_t cb);
24
25 void
26 ignore (int unused)
27 {
28 (void) unused;
29 }
30
31 void
32 process (callback_t cb)
33 {
34 parent (0, cb);
35 }
36
37 void
38 parent (int first, callback_t cb)
39 {
40 void child (void)
41 {
42 /* When reaching this, there are two block instances for PARENT on the
43 stack: the one that is right in the upper frame is not the one actually
44 used for non-local references, so GDB has to follow the static link in
45 order to get the correct instance, and thus in order to read the proper
46 variables.
47
48 As a simple check, we can verify that under GDB, the following is true:
49 parent_first == first (which should be one: see the IF block below). */
50 const int parent_first = first;
51 ignore (parent_first); /* STOP */
52 ignore (first);
53 }
54
55 if (first)
56 process (&child);
57 else
58 cb ();
59 }
60
61 int
62 main ()
63 {
64 parent (1, NULL);
65 return 0;
66 }