1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 1998-2019 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 /* Test GDB's ability to restore saved registers from stack frames
19 when using the `return' command.
20 Jim Blandy <jimb@cygnus.com> --- December 1998 */
24 /* This is the Emacs Lisp expression I used to generate the functions
25 in this file. If people modify the functions manually, instead of
26 changing this expression and re-running it, then evaluating this
27 expression could wipe out their work, so you probably shouldn't
28 re-run it. But I leave it here for reference.
30 (defun callee (n) (format "callee%d" n))
31 (defun caller (n) (format "caller%d" n))
32 (defun local (n) (format "l%d" n))
34 (if (zerop n) (insert "0")
38 (if (< j n) (insert "+"))
40 (defun local-chain (n previous first-end)
43 (insert " register int " (local j)
44 " = increment (" previous ");")
47 (insert " /" "* " first-end " prologue *" "/")
48 (setq first-end nil)))
50 (setq previous (local j))
56 (goto-char (point-max))
57 (search-backward "generated code starts here")
59 (let ((start (point)))
60 (search-forward "generated code ends here")
62 (delete-region start (point)))
64 ;; Generate callee functions.
67 (insert (format "/%s Returns n * %d + %d %s/\n"
68 "*" i (/ (+ i (* i i)) 2) "*"))
70 (insert (callee i) " (int n)\n")
72 (local-chain i "n" (callee i))
79 ;; Generate caller functions.
83 (insert (caller i) " (void)\n")
85 (let ((last (local-chain i "0x7eeb" (caller i))))
86 (insert " register int n;\n")
89 (insert " n = " (callee j) " ("
90 (if (> j 0) "n + " "")
99 ;; Generate driver function.
101 (insert "driver (void)\n")
105 (insert " printf (\"" (caller i) " () => %d\\n\", "
106 (caller i) " ());\n")
118 /* generated code starts here */
119 /* Returns n * 0 + 0 */
126 /* Returns n * 1 + 1 */
130 register int l1
= increment (n
); /* callee1 prologue */
134 /* Returns n * 2 + 3 */
138 register int l1
= increment (n
); /* callee2 prologue */
139 register int l2
= increment (l1
);
143 /* Returns n * 3 + 6 */
147 register int l1
= increment (n
); /* callee3 prologue */
148 register int l2
= increment (l1
);
149 register int l3
= increment (l2
);
153 /* Returns n * 4 + 10 */
157 register int l1
= increment (n
); /* callee4 prologue */
158 register int l2
= increment (l1
);
159 register int l3
= increment (l2
);
160 register int l4
= increment (l3
);
164 /* Returns n * 5 + 15 */
168 register int l1
= increment (n
); /* callee5 prologue */
169 register int l2
= increment (l1
);
170 register int l3
= increment (l2
);
171 register int l4
= increment (l3
);
172 register int l5
= increment (l4
);
173 return l1
+l2
+l3
+l4
+l5
;
179 register int l1
= increment (0x7eeb); /* caller1 prologue */
182 n
= callee1 (n
+ l1
);
183 n
= callee2 (n
+ l1
);
184 n
= callee3 (n
+ l1
);
185 n
= callee4 (n
+ l1
);
186 n
= callee5 (n
+ l1
);
193 register int l1
= increment (0x7eeb); /* caller2 prologue */
194 register int l2
= increment (l1
);
197 n
= callee1 (n
+ l2
);
198 n
= callee2 (n
+ l2
);
199 n
= callee3 (n
+ l2
);
200 n
= callee4 (n
+ l2
);
201 n
= callee5 (n
+ l2
);
208 register int l1
= increment (0x7eeb); /* caller3 prologue */
209 register int l2
= increment (l1
);
210 register int l3
= increment (l2
);
213 n
= callee1 (n
+ l3
);
214 n
= callee2 (n
+ l3
);
215 n
= callee3 (n
+ l3
);
216 n
= callee4 (n
+ l3
);
217 n
= callee5 (n
+ l3
);
224 register int l1
= increment (0x7eeb); /* caller4 prologue */
225 register int l2
= increment (l1
);
226 register int l3
= increment (l2
);
227 register int l4
= increment (l3
);
230 n
= callee1 (n
+ l4
);
231 n
= callee2 (n
+ l4
);
232 n
= callee3 (n
+ l4
);
233 n
= callee4 (n
+ l4
);
234 n
= callee5 (n
+ l4
);
235 return n
+l1
+l2
+l3
+l4
;
241 register int l1
= increment (0x7eeb); /* caller5 prologue */
242 register int l2
= increment (l1
);
243 register int l3
= increment (l2
);
244 register int l4
= increment (l3
);
245 register int l5
= increment (l4
);
248 n
= callee1 (n
+ l5
);
249 n
= callee2 (n
+ l5
);
250 n
= callee3 (n
+ l5
);
251 n
= callee4 (n
+ l5
);
252 n
= callee5 (n
+ l5
);
253 return n
+l1
+l2
+l3
+l4
+l5
;
259 printf ("caller1 () => %d\n", caller1 ());
260 printf ("caller2 () => %d\n", caller2 ());
261 printf ("caller3 () => %d\n", caller3 ());
262 printf ("caller4 () => %d\n", caller4 ());
263 printf ("caller5 () => %d\n", caller5 ());
266 /* generated code ends here */