1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 1998, 1999, 2001, 2003, 2004, 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/>.
19 /* Test GDB's ability to restore saved registers from stack frames
20 when using the `return' command.
21 Jim Blandy <jimb@cygnus.com> --- December 1998 */
25 /* This is the Emacs Lisp expression I used to generate the functions
26 in this file. If people modify the functions manually, instead of
27 changing this expression and re-running it, then evaluating this
28 expression could wipe out their work, so you probably shouldn't
29 re-run it. But I leave it here for reference.
31 (defun callee (n) (format "callee%d" n))
32 (defun caller (n) (format "caller%d" n))
33 (defun local (n) (format "l%d" n))
35 (if (zerop n) (insert "0")
39 (if (< j n) (insert "+"))
41 (defun local-chain (n previous first-end)
44 (insert " register int " (local j)
45 " = increment (" previous ");")
48 (insert " /" "* " first-end " prologue *" "/")
49 (setq first-end nil)))
51 (setq previous (local j))
57 (goto-char (point-max))
58 (search-backward "generated code starts here")
60 (let ((start (point)))
61 (search-forward "generated code ends here")
63 (delete-region start (point)))
65 ;; Generate callee functions.
68 (insert (format "/%s Returns n * %d + %d %s/\n"
69 "*" i (/ (+ i (* i i)) 2) "*"))
71 (insert (callee i) " (int n)\n")
73 (local-chain i "n" (callee i))
80 ;; Generate caller functions.
84 (insert (caller i) " (void)\n")
86 (let ((last (local-chain i "0x7eeb" (caller i))))
87 (insert " register int n;\n")
90 (insert " n = " (callee j) " ("
91 (if (> j 0) "n + " "")
100 ;; Generate driver function.
102 (insert "driver (void)\n")
106 (insert " printf (\"" (caller i) " () => %d\\n\", "
107 (caller i) " ());\n")
119 /* generated code starts here */
120 /* Returns n * 0 + 0 */
127 /* Returns n * 1 + 1 */
131 register int l1
= increment (n
); /* callee1 prologue */
135 /* Returns n * 2 + 3 */
139 register int l1
= increment (n
); /* callee2 prologue */
140 register int l2
= increment (l1
);
144 /* Returns n * 3 + 6 */
148 register int l1
= increment (n
); /* callee3 prologue */
149 register int l2
= increment (l1
);
150 register int l3
= increment (l2
);
154 /* Returns n * 4 + 10 */
158 register int l1
= increment (n
); /* callee4 prologue */
159 register int l2
= increment (l1
);
160 register int l3
= increment (l2
);
161 register int l4
= increment (l3
);
165 /* Returns n * 5 + 15 */
169 register int l1
= increment (n
); /* callee5 prologue */
170 register int l2
= increment (l1
);
171 register int l3
= increment (l2
);
172 register int l4
= increment (l3
);
173 register int l5
= increment (l4
);
174 return l1
+l2
+l3
+l4
+l5
;
180 register int l1
= increment (0x7eeb); /* caller1 prologue */
183 n
= callee1 (n
+ l1
);
184 n
= callee2 (n
+ l1
);
185 n
= callee3 (n
+ l1
);
186 n
= callee4 (n
+ l1
);
187 n
= callee5 (n
+ l1
);
194 register int l1
= increment (0x7eeb); /* caller2 prologue */
195 register int l2
= increment (l1
);
198 n
= callee1 (n
+ l2
);
199 n
= callee2 (n
+ l2
);
200 n
= callee3 (n
+ l2
);
201 n
= callee4 (n
+ l2
);
202 n
= callee5 (n
+ l2
);
209 register int l1
= increment (0x7eeb); /* caller3 prologue */
210 register int l2
= increment (l1
);
211 register int l3
= increment (l2
);
214 n
= callee1 (n
+ l3
);
215 n
= callee2 (n
+ l3
);
216 n
= callee3 (n
+ l3
);
217 n
= callee4 (n
+ l3
);
218 n
= callee5 (n
+ l3
);
225 register int l1
= increment (0x7eeb); /* caller4 prologue */
226 register int l2
= increment (l1
);
227 register int l3
= increment (l2
);
228 register int l4
= increment (l3
);
231 n
= callee1 (n
+ l4
);
232 n
= callee2 (n
+ l4
);
233 n
= callee3 (n
+ l4
);
234 n
= callee4 (n
+ l4
);
235 n
= callee5 (n
+ l4
);
236 return n
+l1
+l2
+l3
+l4
;
242 register int l1
= increment (0x7eeb); /* caller5 prologue */
243 register int l2
= increment (l1
);
244 register int l3
= increment (l2
);
245 register int l4
= increment (l3
);
246 register int l5
= increment (l4
);
249 n
= callee1 (n
+ l5
);
250 n
= callee2 (n
+ l5
);
251 n
= callee3 (n
+ l5
);
252 n
= callee4 (n
+ l5
);
253 n
= callee5 (n
+ l5
);
254 return n
+l1
+l2
+l3
+l4
+l5
;
260 printf ("caller1 () => %d\n", caller1 ());
261 printf ("caller2 () => %d\n", caller2 ());
262 printf ("caller3 () => %d\n", caller3 ());
263 printf ("caller4 () => %d\n", caller4 ());
264 printf ("caller5 () => %d\n", caller5 ());
267 /* generated code ends here */