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