]>
Commit | Line | Data |
---|---|---|
28d41a99 MS |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
ecd75fc8 | 3 | Copyright 2008-2014 Free Software Foundation, Inc. |
28d41a99 MS |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | ||
428b16bd PA |
18 | #include <stdio.h> |
19 | #include <stdlib.h> | |
28d41a99 MS |
20 | |
21 | #ifdef PROTOTYPES | |
22 | extern int marker1 (void); | |
23 | extern int marker2 (int a); | |
24 | extern void marker3 (char *a, char *b); | |
25 | extern void marker4 (long d); | |
26 | #else | |
27 | extern int marker1 (); | |
28 | extern int marker2 (); | |
29 | extern void marker3 (); | |
30 | extern void marker4 (); | |
31 | #endif | |
32 | ||
33 | /* | |
34 | * This simple classical example of recursion is useful for | |
35 | * testing stack backtraces and such. | |
36 | */ | |
37 | ||
38 | #ifdef PROTOTYPES | |
39 | int factorial(int); | |
40 | ||
41 | int | |
42 | main (int argc, char **argv, char **envp) | |
43 | #else | |
44 | int | |
45 | main (argc, argv, envp) | |
46 | int argc; | |
47 | char *argv[], **envp; | |
48 | #endif | |
49 | { | |
28d41a99 MS |
50 | if (argc == 12345) { /* an unlikely value < 2^16, in case uninited */ /* set breakpoint 6 here */ |
51 | fprintf (stderr, "usage: factorial <number>\n"); | |
52 | return 1; | |
53 | } | |
54 | printf ("%d\n", factorial (atoi ("6"))); /* set breakpoint 1 here */ | |
55 | /* set breakpoint 12 here */ | |
56 | marker1 (); /* set breakpoint 11 here */ | |
57 | marker2 (43); /* set breakpoint 20 here */ | |
58 | marker3 ("stack", "trace"); /* set breakpoint 21 here */ | |
59 | marker4 (177601976L); | |
60 | /* We're used by a test that requires malloc, so make sure it is | |
61 | in the executable. */ | |
62 | (void)malloc (1); | |
63 | ||
64 | argc = (argc == 12345); /* This is silly, but we can step off of it */ /* set breakpoint 2 here */ | |
65 | return argc; /* set breakpoint 10 here */ | |
66 | } /* set breakpoint 10a here */ | |
67 | ||
68 | #ifdef PROTOTYPES | |
69 | int factorial (int value) | |
70 | #else | |
71 | int factorial (value) | |
72 | int value; | |
73 | #endif | |
74 | { | |
75 | if (value > 1) { /* set breakpoint 7 here */ | |
76 | value *= factorial (value - 1); | |
77 | } | |
78 | return (value); /* set breakpoint 19 here */ | |
79 | } | |
80 | ||
81 | #ifdef PROTOTYPES | |
82 | int multi_line_if_conditional (int a, int b, int c) | |
83 | #else | |
84 | int multi_line_if_conditional (a, b, c) | |
85 | int a, b, c; | |
86 | #endif | |
87 | { | |
88 | if (a /* set breakpoint 3 here */ | |
89 | && b | |
90 | && c) | |
91 | return 0; | |
92 | else | |
93 | return 1; | |
94 | } | |
95 | ||
96 | #ifdef PROTOTYPES | |
97 | int multi_line_while_conditional (int a, int b, int c) | |
98 | #else | |
99 | int multi_line_while_conditional (a, b, c) | |
100 | int a, b, c; | |
101 | #endif | |
102 | { | |
103 | while (a /* set breakpoint 4 here */ | |
104 | && b | |
105 | && c) | |
106 | { | |
107 | a--, b--, c--; | |
108 | } | |
109 | return 0; | |
110 | } |