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