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