]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/sepdebug.c
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / sepdebug.c
CommitLineData
6aba47ca
DJ
1/* Copyright 1994, 1995, 1999, 2002, 2003, 2004, 2007
2Free Software 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
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
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.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 Please email any bugs, comments, and/or additions to this file to:
19 bug-gdb@prep.ai.mit.edu */
20
21#ifdef vxworks
22
23# include <stdio.h>
24
25/* VxWorks does not supply atoi. */
26static int
27atoi (z)
28 char *z;
29{
30 int i = 0;
31
32 while (*z >= '0' && *z <= '9')
33 i = i * 10 + (*z++ - '0');
34 return i;
35}
36
37/* I don't know of any way to pass an array to VxWorks. This function
38 can be called directly from gdb. */
39
40vxmain (arg)
41char *arg;
42{
43 char *argv[2];
44
45 argv[0] = "";
46 argv[1] = arg;
47 main (2, argv, (char **) 0);
48}
49
50#else /* ! vxworks */
51# include <stdio.h>
52# include <stdlib.h>
53#endif /* ! vxworks */
54
55/*
56 * The following functions do nothing useful. They are included simply
57 * as places to try setting breakpoints at. They are explicitly
58 * "one-line functions" to verify that this case works (some versions
59 * of gcc have or have had problems with this).
60 */
61
62#ifdef PROTOTYPES
63int marker1 (void) { return (0); }
64int marker2 (int a) { return (1); } /* set breakpoint 8 here */
65void marker3 (char *a, char *b) {}
66void marker4 (long d) {} /* set breakpoint 14 here */
67#else
68int marker1 () { return (0); }
69int marker2 (a) int a; { return (1); } /* set breakpoint 9 here */
70void marker3 (a, b) char *a, *b; {}
71void marker4 (d) long d; {} /* set breakpoint 13 here */
72#endif
73
74/*
75 * This simple classical example of recursion is useful for
76 * testing stack backtraces and such.
77 */
78
79#ifdef PROTOTYPES
80int factorial(int);
81
82int
83main (int argc, char **argv, char **envp)
84#else
85int
86main (argc, argv, envp)
87int argc;
88char *argv[], **envp;
89#endif
90{
91#ifdef usestubs
92 set_debug_traps(); /* set breakpoint 5 here */
93 breakpoint();
94#endif
95 if (argc == 12345) { /* an unlikely value < 2^16, in case uninited */ /* set breakpoint 6 here */
96 fprintf (stderr, "usage: factorial <number>\n");
97 return 1;
98 }
99 printf ("%d\n", factorial (atoi ("6"))); /* set breakpoint 1 here */
100 /* set breakpoint 12 here */
101 marker1 (); /* set breakpoint 11 here */
102 marker2 (43);
103 marker3 ("stack", "trace");
104 marker4 (177601976L);
105 argc = (argc == 12345); /* This is silly, but we can step off of it */ /* set breakpoint 2 here */
106 return argc; /* set breakpoint 10 here */
107}
108
109#ifdef PROTOTYPES
110int factorial (int value)
111#else
112int factorial (value)
113int value;
114#endif
115{
116 if (value > 1) { /* set breakpoint 7 here */
117 value *= factorial (value - 1);
118 }
119 return (value);
120}
121
122#ifdef PROTOTYPES
123int multi_line_if_conditional (int a, int b, int c)
124#else
125int multi_line_if_conditional (a, b, c)
126 int a, b, c;
127#endif
128{
129 if (a /* set breakpoint 3 here */
130 && b
131 && c)
132 return 0;
133 else
134 return 1;
135}
136
137#ifdef PROTOTYPES
138int multi_line_while_conditional (int a, int b, int c)
139#else
140int multi_line_while_conditional (a, b, c)
141 int a, b, c;
142#endif
143{
144 while (a /* set breakpoint 4 here */
145 && b
146 && c)
147 {
148 a--, b--, c--;
149 }
150 return 0;
151}