Automatic date update in version.in
[binutils-gdb.git] / gdb / testsuite / gdb.reverse / step-reverse.c
blob307c0c39cbabc11f62fa393610f61db261a88037
1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2008-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 #include <stdlib.h>
19 #include <string.h>
21 /* Test various kinds of stepping.
23 int myglob = 0;
25 int callee() { /* ENTER CALLEE */
26 return myglob++; /* ARRIVED IN CALLEE */
27 } /* RETURN FROM CALLEE */
29 /* We need to make this function take more than a single instruction
30 to run, otherwise it could hide PR gdb/16678, as reverse execution can
31 step over a single-instruction function. */
32 int
33 recursive_callee (int val)
35 if (val == 0)
36 return 0;
37 val /= 2;
38 if (val > 1)
39 val++;
40 return recursive_callee (val); /* RECURSIVE CALL */
41 } /* EXIT RECURSIVE FUNCTION */
43 /* A structure which, we hope, will need to be passed using memcpy. */
44 struct rhomboidal {
45 int rather_large[100];
48 void
49 large_struct_by_value (struct rhomboidal r)
51 myglob += r.rather_large[42]; /* step-test.exp: arrive here 1 */
54 int main () {
55 int w,x,y,z;
56 int a[10], b[10];
58 /* Test "next" and "step" */
59 w = 0; /* BREAK AT MAIN */
60 x = 1; /* NEXT TEST 1 */
61 y = 2; /* STEP TEST 1 */
62 z = 3; /* REVERSE NEXT TEST 1 */
63 w = w + 2; /* NEXT TEST 2 */
64 x = x + 3; /* REVERSE STEP TEST 1 */
65 y = y + 4;
66 z = z + 5; /* STEP TEST 2 */
68 /* Test that next goes over recursive calls too */
69 recursive_callee (32); /* NEXT OVER THIS RECURSION */
71 /* Test that "next" goes over a call */
72 callee(); /* NEXT OVER THIS CALL */
74 /* Test that "step" doesn't */
75 callee(); /* STEP INTO THIS CALL */
77 /* Test "stepi" */
78 a[5] = a[3] - a[4]; /* FINISH TEST */
79 callee(); /* STEPI TEST */
81 /* Test "nexti" */
82 callee(); /* NEXTI TEST */
84 y = w + z;
87 struct rhomboidal r;
88 memset (r.rather_large, 0, sizeof (r.rather_large));
89 r.rather_large[42] = 10;
90 large_struct_by_value (r); /* step-test.exp: large struct by value */
93 exit (0); /* end of main */