]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.reverse/finish-reverse-next.c
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.reverse / finish-reverse-next.c
1 /* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 2012-2024 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 /* The reverse finish command should return from a function and stop on
19 the first instruction of the source line where the function call is made.
20 Specifically, the behavior should match doing a reverse next from the
21 first instruction in the function. GDB should only require one reverse
22 step or next statement to reach the previous source code line.
23
24 This test verifies the fix for gdb bugzilla:
25
26 https://sourceware.org/bugzilla/show_bug.cgi?id=29927
27
28 PowerPC supports two entry points to a function. The normal entry point
29 is called the local entry point (LEP). The alternate entry point is called
30 the global entry point (GEP). The GEP is only used if the table of
31 contents (TOC) value stored in register r2 needs to be setup prior to
32 execution starting at the LEP. A function call via a function pointer
33 will entry via the GEP. A normal function call will enter via the LEP.
34
35 This test has been expanded to include tests to verify the reverse-finish
36 command works properly if the function is called via the GEP. The original
37 test only verified the reverse-finish command for a normal call that used
38 the LEP. */
39
40 int
41 function2 (int a, int b)
42 {
43 int ret = 0;
44 ret = ret + a + b;
45 return ret;
46 }
47
48 int
49 function1 (int a, int b) // FUNCTION1
50 {
51 int ret = 0;
52 int (*funp) (int, int) = &function2;
53 /* The assembly code for this function when compiled for PowerPC is as
54 follows:
55
56 0000000010000758 <function1>:
57 10000758: 02 10 40 3c lis r2,4098 <- GEP
58 1000075c: 00 7f 42 38 addi r2,r2,32512
59 10000760: a6 02 08 7c mflr r0 <- LEP
60 10000764: 10 00 01 f8 std r0,16(r1)
61 ....
62
63 When the function is called on PowerPC with function1 (a, b) the call
64 enters at the Local Entry Point (LEP). When the function is called via
65 a function pointer, the Global Entry Point (GEP) for function1 is used.
66 The GEP sets up register 2 before reaching the LEP.
67 */
68 ret = funp (a + 1, b + 2);
69 return ret;
70 }
71
72 int
73 main(int argc, char* argv[])
74 {
75 int a, b;
76 int (*funp) (int, int) = &function1;
77
78 /* Call function via Local Entry Point (LEP). */
79
80 a = 1;
81 b = 5;
82
83 function1 (a, b); // CALL VIA LEP
84
85 /* Call function via Global Entry Point (GEP). */
86 a = 10;
87 b = 50;
88
89 funp (a, b); // CALL VIA GEP
90 return 0;
91 }