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 2 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, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 /* Test GDB's ability to restore saved registers from stack frames
21 when using the `return' command.
22 Jim Blandy <jimb@cygnus.com> --- December 1998 */
26 /* This is the Emacs Lisp expression I used to generate the functions
27 in this file. If people modify the functions manually, instead of
28 changing this expression and re-running it, then evaluating this
29 expression could wipe out their work, so you probably shouldn't
30 re-run it. But I leave it here for reference.
32 (defun callee (n) (format "callee%d" n))
33 (defun caller (n) (format "caller%d" n))
34 (defun local (n) (format "l%d" n))
36 (if (zerop n) (insert "0")
40 (if (< j n) (insert "+"))
42 (defun local-chain (n previous first-end)
45 (insert " register int " (local j)
46 " = increment (" previous ");")
49 (insert " /" "* " first-end " prologue *" "/")
50 (setq first-end nil)))
52 (setq previous (local j))
58 (goto-char (point-max))
59 (search-backward "generated code starts here")
61 (let ((start (point)))
62 (search-forward "generated code ends here")
64 (delete-region start (point)))
66 ;; Generate callee functions.
69 (insert (format "/%s Returns n * %d + %d %s/\n"
70 "*" i (/ (+ i (* i i)) 2) "*"))
72 (insert (callee i) " (int n)\n")
74 (local-chain i "n" (callee i))
81 ;; Generate caller functions.
85 (insert (caller i) " (void)\n")
87 (let ((last (local-chain i "0x7eeb" (caller i))))
88 (insert " register int n;\n")
91 (insert " n = " (callee j) " ("
92 (if (> j 0) "n + " "")
101 ;; Generate driver function.
103 (insert "driver (void)\n")
107 (insert " printf (\"" (caller i) " () => %d\\n\", "
108 (caller i) " ());\n")
120 /* generated code starts here */
121 /* Returns n * 0 + 0 */
128 /* Returns n * 1 + 1 */
132 register int l1
= increment (n
); /* callee1 prologue */
136 /* Returns n * 2 + 3 */
140 register int l1
= increment (n
); /* callee2 prologue */
141 register int l2
= increment (l1
);
145 /* Returns n * 3 + 6 */
149 register int l1
= increment (n
); /* callee3 prologue */
150 register int l2
= increment (l1
);
151 register int l3
= increment (l2
);
155 /* Returns n * 4 + 10 */
159 register int l1
= increment (n
); /* callee4 prologue */
160 register int l2
= increment (l1
);
161 register int l3
= increment (l2
);
162 register int l4
= increment (l3
);
166 /* Returns n * 5 + 15 */
170 register int l1
= increment (n
); /* callee5 prologue */
171 register int l2
= increment (l1
);
172 register int l3
= increment (l2
);
173 register int l4
= increment (l3
);
174 register int l5
= increment (l4
);
175 return l1
+l2
+l3
+l4
+l5
;
181 register int l1
= increment (0x7eeb); /* caller1 prologue */
184 n
= callee1 (n
+ l1
);
185 n
= callee2 (n
+ l1
);
186 n
= callee3 (n
+ l1
);
187 n
= callee4 (n
+ l1
);
188 n
= callee5 (n
+ l1
);
195 register int l1
= increment (0x7eeb); /* caller2 prologue */
196 register int l2
= increment (l1
);
199 n
= callee1 (n
+ l2
);
200 n
= callee2 (n
+ l2
);
201 n
= callee3 (n
+ l2
);
202 n
= callee4 (n
+ l2
);
203 n
= callee5 (n
+ l2
);
210 register int l1
= increment (0x7eeb); /* caller3 prologue */
211 register int l2
= increment (l1
);
212 register int l3
= increment (l2
);
215 n
= callee1 (n
+ l3
);
216 n
= callee2 (n
+ l3
);
217 n
= callee3 (n
+ l3
);
218 n
= callee4 (n
+ l3
);
219 n
= callee5 (n
+ l3
);
226 register int l1
= increment (0x7eeb); /* caller4 prologue */
227 register int l2
= increment (l1
);
228 register int l3
= increment (l2
);
229 register int l4
= increment (l3
);
232 n
= callee1 (n
+ l4
);
233 n
= callee2 (n
+ l4
);
234 n
= callee3 (n
+ l4
);
235 n
= callee4 (n
+ l4
);
236 n
= callee5 (n
+ l4
);
237 return n
+l1
+l2
+l3
+l4
;
243 register int l1
= increment (0x7eeb); /* caller5 prologue */
244 register int l2
= increment (l1
);
245 register int l3
= increment (l2
);
246 register int l4
= increment (l3
);
247 register int l5
= increment (l4
);
250 n
= callee1 (n
+ l5
);
251 n
= callee2 (n
+ l5
);
252 n
= callee3 (n
+ l5
);
253 n
= callee4 (n
+ l5
);
254 n
= callee5 (n
+ l5
);
255 return n
+l1
+l2
+l3
+l4
+l5
;
261 printf ("caller1 () => %d\n", caller1 ());
262 printf ("caller2 () => %d\n", caller2 ());
263 printf ("caller3 () => %d\n", caller3 ());
264 printf ("caller4 () => %d\n", caller4 ());
265 printf ("caller5 () => %d\n", caller5 ());
268 /* generated code ends here */