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