]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/break.c
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / break.c
CommitLineData
a1dea79a
FF
1/* This testcase is part of GDB, the GNU debugger.
2
6aba47ca
DJ
3 Copyright 1992, 1993, 1994, 1995, 1999, 2002, 2003, 2007
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
8 the Free Software Foundation; either version 2 of the License, or
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.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 Please email any bugs, comments, and/or additions to this file to:
21 bug-gdb@prep.ai.mit.edu */
22
c906108c
SS
23#ifdef vxworks
24
25# include <stdio.h>
26
27/* VxWorks does not supply atoi. */
28static int
29atoi (z)
30 char *z;
31{
32 int i = 0;
33
34 while (*z >= '0' && *z <= '9')
35 i = i * 10 + (*z++ - '0');
36 return i;
37}
38
39/* I don't know of any way to pass an array to VxWorks. This function
40 can be called directly from gdb. */
41
42vxmain (arg)
43char *arg;
44{
45 char *argv[2];
46
47 argv[0] = "";
48 argv[1] = arg;
49 main (2, argv, (char **) 0);
50}
51
52#else /* ! vxworks */
53# include <stdio.h>
085dd6e6 54# include <stdlib.h>
c906108c
SS
55#endif /* ! vxworks */
56
085dd6e6 57#ifdef PROTOTYPES
a1dea79a
FF
58extern int marker1 (void);
59extern int marker2 (int a);
60extern void marker3 (char *a, char *b);
61extern void marker4 (long d);
085dd6e6 62#else
a1dea79a
FF
63extern int marker1 ();
64extern int marker2 ();
65extern void marker3 ();
66extern void marker4 ();
085dd6e6 67#endif
c906108c
SS
68
69/*
70 * This simple classical example of recursion is useful for
71 * testing stack backtraces and such.
72 */
73
085dd6e6
JM
74#ifdef PROTOTYPES
75int factorial(int);
76
77int
78main (int argc, char **argv, char **envp)
79#else
c906108c
SS
80int
81main (argc, argv, envp)
82int argc;
83char *argv[], **envp;
085dd6e6 84#endif
c906108c
SS
85{
86#ifdef usestubs
a50d3602 87 set_debug_traps(); /* set breakpoint 5 here */
c906108c
SS
88 breakpoint();
89#endif
a50d3602 90 if (argc == 12345) { /* an unlikely value < 2^16, in case uninited */ /* set breakpoint 6 here */
c906108c
SS
91 fprintf (stderr, "usage: factorial <number>\n");
92 return 1;
93 }
a50d3602
EZ
94 printf ("%d\n", factorial (atoi ("6"))); /* set breakpoint 1 here */
95 /* set breakpoint 12 here */
96 marker1 (); /* set breakpoint 11 here */
a1dea79a
FF
97 marker2 (43); /* set breakpoint 20 here */
98 marker3 ("stack", "trace"); /* set breakpoint 21 here */
c906108c 99 marker4 (177601976L);
d394c993
NS
100 /* We're used by a test that requires malloc, so make sure it is
101 in the executable. */
102 (void)malloc (1);
103
a50d3602
EZ
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 */
e1c2defa 106} /* set breakpoint 10a here */
c906108c 107
085dd6e6
JM
108#ifdef PROTOTYPES
109int factorial (int value)
110#else
c906108c
SS
111int factorial (value)
112int value;
085dd6e6 113#endif
c906108c 114{
a50d3602 115 if (value > 1) { /* set breakpoint 7 here */
c906108c
SS
116 value *= factorial (value - 1);
117 }
a1dea79a 118 return (value); /* set breakpoint 19 here */
c906108c
SS
119}
120
f286b2c3
JL
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{
a50d3602 128 if (a /* set breakpoint 3 here */
f286b2c3
JL
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{
a50d3602 143 while (a /* set breakpoint 4 here */
f286b2c3
JL
144 && b
145 && c)
146 {
147 a--, b--, c--;
148 }
149 return 0;
150}