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