Commit | Line | Data |
---|---|---|
a1dea79a FF |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
28e7fd62 | 3 | Copyright 1992-2013 Free Software Foundation, Inc. |
a1dea79a FF |
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 | |
a9762ec7 | 7 | the Free Software Foundation; either version 3 of the License, or |
a1dea79a FF |
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. | |
a9762ec7 | 14 | |
a1dea79a | 15 | You should have received a copy of the GNU General Public License |
c7b778ff | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
a1dea79a | 17 | |
c906108c SS |
18 | #ifdef vxworks |
19 | ||
20 | # include <stdio.h> | |
21 | ||
22 | /* VxWorks does not supply atoi. */ | |
23 | static int | |
24 | atoi (z) | |
25 | char *z; | |
26 | { | |
27 | int i = 0; | |
28 | ||
29 | while (*z >= '0' && *z <= '9') | |
30 | i = i * 10 + (*z++ - '0'); | |
31 | return i; | |
32 | } | |
33 | ||
34 | /* I don't know of any way to pass an array to VxWorks. This function | |
35 | can be called directly from gdb. */ | |
36 | ||
37 | vxmain (arg) | |
38 | char *arg; | |
39 | { | |
40 | char *argv[2]; | |
41 | ||
42 | argv[0] = ""; | |
43 | argv[1] = arg; | |
44 | main (2, argv, (char **) 0); | |
45 | } | |
46 | ||
47 | #else /* ! vxworks */ | |
48 | # include <stdio.h> | |
085dd6e6 | 49 | # include <stdlib.h> |
c906108c SS |
50 | #endif /* ! vxworks */ |
51 | ||
085dd6e6 | 52 | #ifdef PROTOTYPES |
a1dea79a FF |
53 | extern int marker1 (void); |
54 | extern int marker2 (int a); | |
55 | extern void marker3 (char *a, char *b); | |
56 | extern void marker4 (long d); | |
085dd6e6 | 57 | #else |
a1dea79a FF |
58 | extern int marker1 (); |
59 | extern int marker2 (); | |
60 | extern void marker3 (); | |
61 | extern void marker4 (); | |
085dd6e6 | 62 | #endif |
c906108c | 63 | |
f0df251a DJ |
64 | /* We're used by a test that requires malloc, so make sure it is in |
65 | the executable. */ | |
66 | void *need_malloc () | |
67 | { | |
68 | return malloc (1); | |
69 | } | |
70 | ||
c906108c SS |
71 | /* |
72 | * This simple classical example of recursion is useful for | |
73 | * testing stack backtraces and such. | |
74 | */ | |
75 | ||
085dd6e6 JM |
76 | #ifdef PROTOTYPES |
77 | int factorial(int); | |
78 | ||
79 | int | |
80 | main (int argc, char **argv, char **envp) | |
81 | #else | |
c906108c SS |
82 | int |
83 | main (argc, argv, envp) | |
84 | int argc; | |
85 | char *argv[], **envp; | |
085dd6e6 | 86 | #endif |
c906108c | 87 | { |
a50d3602 | 88 | if (argc == 12345) { /* an unlikely value < 2^16, in case uninited */ /* set breakpoint 6 here */ |
c906108c SS |
89 | fprintf (stderr, "usage: factorial <number>\n"); |
90 | return 1; | |
91 | } | |
a50d3602 EZ |
92 | printf ("%d\n", factorial (atoi ("6"))); /* set breakpoint 1 here */ |
93 | /* set breakpoint 12 here */ | |
94 | marker1 (); /* set breakpoint 11 here */ | |
a1dea79a FF |
95 | marker2 (43); /* set breakpoint 20 here */ |
96 | marker3 ("stack", "trace"); /* set breakpoint 21 here */ | |
c906108c | 97 | marker4 (177601976L); |
d394c993 NS |
98 | /* We're used by a test that requires malloc, so make sure it is |
99 | in the executable. */ | |
100 | (void)malloc (1); | |
101 | ||
a50d3602 EZ |
102 | argc = (argc == 12345); /* This is silly, but we can step off of it */ /* set breakpoint 2 here */ |
103 | return argc; /* set breakpoint 10 here */ | |
e1c2defa | 104 | } /* set breakpoint 10a here */ |
c906108c | 105 | |
085dd6e6 JM |
106 | #ifdef PROTOTYPES |
107 | int factorial (int value) | |
108 | #else | |
c906108c SS |
109 | int factorial (value) |
110 | int value; | |
085dd6e6 | 111 | #endif |
c906108c | 112 | { |
a50d3602 | 113 | if (value > 1) { /* set breakpoint 7 here */ |
c906108c SS |
114 | value *= factorial (value - 1); |
115 | } | |
a1dea79a | 116 | return (value); /* set breakpoint 19 here */ |
c906108c SS |
117 | } |
118 | ||
f286b2c3 JL |
119 | #ifdef PROTOTYPES |
120 | int multi_line_if_conditional (int a, int b, int c) | |
121 | #else | |
122 | int multi_line_if_conditional (a, b, c) | |
123 | int a, b, c; | |
124 | #endif | |
125 | { | |
a50d3602 | 126 | if (a /* set breakpoint 3 here */ |
f286b2c3 JL |
127 | && b |
128 | && c) | |
129 | return 0; | |
130 | else | |
131 | return 1; | |
132 | } | |
133 | ||
134 | #ifdef PROTOTYPES | |
135 | int multi_line_while_conditional (int a, int b, int c) | |
136 | #else | |
137 | int multi_line_while_conditional (a, b, c) | |
138 | int a, b, c; | |
139 | #endif | |
140 | { | |
a50d3602 | 141 | while (a /* set breakpoint 4 here */ |
f286b2c3 JL |
142 | && b |
143 | && c) | |
144 | { | |
145 | a--, b--, c--; | |
146 | } | |
147 | return 0; | |
148 | } |