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