2003-11-23 Michael Chastain <mec@shout.net>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / break.c
CommitLineData
c906108c
SS
1#ifdef vxworks
2
3# include <stdio.h>
4
5/* VxWorks does not supply atoi. */
6static int
7atoi (z)
8 char *z;
9{
10 int i = 0;
11
12 while (*z >= '0' && *z <= '9')
13 i = i * 10 + (*z++ - '0');
14 return i;
15}
16
17/* I don't know of any way to pass an array to VxWorks. This function
18 can be called directly from gdb. */
19
20vxmain (arg)
21char *arg;
22{
23 char *argv[2];
24
25 argv[0] = "";
26 argv[1] = arg;
27 main (2, argv, (char **) 0);
28}
29
30#else /* ! vxworks */
31# include <stdio.h>
085dd6e6 32# include <stdlib.h>
c906108c
SS
33#endif /* ! vxworks */
34
35/*
36 * The following functions do nothing useful. They are included simply
37 * as places to try setting breakpoints at. They are explicitly
38 * "one-line functions" to verify that this case works (some versions
39 * of gcc have or have had problems with this).
40 */
41
085dd6e6
JM
42#ifdef PROTOTYPES
43int marker1 (void) { return (0); }
a50d3602 44int marker2 (int a) { return (1); } /* set breakpoint 8 here */
085dd6e6 45void marker3 (char *a, char *b) {}
a50d3602 46void marker4 (long d) {} /* set breakpoint 14 here */
085dd6e6 47#else
c906108c 48int marker1 () { return (0); }
a50d3602 49int marker2 (a) int a; { return (1); } /* set breakpoint 9 here */
c906108c 50void marker3 (a, b) char *a, *b; {}
a50d3602 51void marker4 (d) long d; {} /* set breakpoint 13 here */
085dd6e6 52#endif
c906108c
SS
53
54/*
55 * This simple classical example of recursion is useful for
56 * testing stack backtraces and such.
57 */
58
085dd6e6
JM
59#ifdef PROTOTYPES
60int factorial(int);
61
62int
63main (int argc, char **argv, char **envp)
64#else
c906108c
SS
65int
66main (argc, argv, envp)
67int argc;
68char *argv[], **envp;
085dd6e6 69#endif
c906108c
SS
70{
71#ifdef usestubs
a50d3602 72 set_debug_traps(); /* set breakpoint 5 here */
c906108c
SS
73 breakpoint();
74#endif
a50d3602 75 if (argc == 12345) { /* an unlikely value < 2^16, in case uninited */ /* set breakpoint 6 here */
c906108c
SS
76 fprintf (stderr, "usage: factorial <number>\n");
77 return 1;
78 }
a50d3602
EZ
79 printf ("%d\n", factorial (atoi ("6"))); /* set breakpoint 1 here */
80 /* set breakpoint 12 here */
81 marker1 (); /* set breakpoint 11 here */
c906108c
SS
82 marker2 (43);
83 marker3 ("stack", "trace");
84 marker4 (177601976L);
a50d3602
EZ
85 argc = (argc == 12345); /* This is silly, but we can step off of it */ /* set breakpoint 2 here */
86 return argc; /* set breakpoint 10 here */
c906108c
SS
87}
88
085dd6e6
JM
89#ifdef PROTOTYPES
90int factorial (int value)
91#else
c906108c
SS
92int factorial (value)
93int value;
085dd6e6 94#endif
c906108c 95{
a50d3602 96 if (value > 1) { /* set breakpoint 7 here */
c906108c
SS
97 value *= factorial (value - 1);
98 }
99 return (value);
100}
101
f286b2c3
JL
102#ifdef PROTOTYPES
103int multi_line_if_conditional (int a, int b, int c)
104#else
105int multi_line_if_conditional (a, b, c)
106 int a, b, c;
107#endif
108{
a50d3602 109 if (a /* set breakpoint 3 here */
f286b2c3
JL
110 && b
111 && c)
112 return 0;
113 else
114 return 1;
115}
116
117#ifdef PROTOTYPES
118int multi_line_while_conditional (int a, int b, int c)
119#else
120int multi_line_while_conditional (a, b, c)
121 int a, b, c;
122#endif
123{
a50d3602 124 while (a /* set breakpoint 4 here */
f286b2c3
JL
125 && b
126 && c)
127 {
128 a--, b--, c--;
129 }
130 return 0;
131}
This page took 0.412914 seconds and 4 git commands to generate.