Fix null pointer dereference in process_debug_info()
[binutils-gdb.git] / gdb / testsuite / gdb.opt / inline-break.c
blob9e31bd9901e8ccb5949e141353caa84024767eec
1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright (C) 2012-2024 Free Software Foundation, Inc.
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.
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.
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/>. */
18 /* The file ../gdb.dwarf2/inline-break.S was generated manually from
19 this file, and should be regenerated if this file is modified. */
21 #ifdef __GNUC__
22 # define ATTR __attribute__((gnu_inline)) __attribute__((always_inline))
23 #else
24 # define ATTR
25 #endif
27 /* A static inlined function that is called once. */
29 static inline ATTR int
30 func1 (int x)
32 return x * 23; /* break here */
35 /* A non-static inlined function that is called once. */
37 inline ATTR int
38 func2 (int x)
40 return x * 17;
43 /* A static inlined function that calls another static inlined
44 function. */
46 static inline ATTR int
47 func3b (int x)
49 return x < 14 ? 1 : 2;
52 static inline ATTR int
53 func3a (int x)
55 return func3b (x * 23);
58 /* A non-static inlined function that calls a static inlined
59 function. */
61 static inline ATTR int
62 func4b (int x)
64 return x < 13 ? 1 : 2;
67 inline ATTR int
68 func4a (int x)
70 return func4b (x * 17);
73 /* A static inlined function that calls a non-static inlined
74 function. */
76 inline ATTR int
77 func5b (int x)
79 return x < 12 ? 1 : 2;
82 static inline ATTR int
83 func5a (int x)
85 return func5b (x * 23);
88 /* A non-static inlined function that calls another non-static inlined
89 function. */
91 inline ATTR int
92 func6b (int x)
94 return x < 14 ? 3 : 2;
97 inline ATTR int
98 func6a (int x)
100 return func6b (x * 17);
103 /* A static inlined function that is called more than once. */
105 static inline ATTR int
106 func7b (int x)
108 return x < 23 ? 1 : 4;
111 static inline ATTR int
112 func7a (int x)
114 return func7b (x * 29);
117 /* A non-static inlined function that is called more than once. */
119 inline ATTR int
120 func8b (int x)
122 return x < 7 ? 11 : 9;
125 static inline ATTR int
126 func8a (int x)
128 return func8b (x * 31);
131 static inline ATTR int
132 inline_func1 (int x)
134 int y = 1; /* inline_func1 */
136 return y + x;
139 static int
140 not_inline_func1 (int x)
142 int y = 2; /* not_inline_func1 */
144 return y + inline_func1 (x);
147 inline ATTR int
148 inline_func2 (int x)
150 int y = 3; /* inline_func2 */
152 return y + not_inline_func1 (x);
156 not_inline_func2 (int x)
158 int y = 4; /* not_inline_func2 */
160 return y + inline_func2 (x);
163 static inline ATTR int
164 inline_func3 (int x)
166 int y = 5; /* inline_func3 */
168 return y + not_inline_func2 (x);
171 static int
172 not_inline_func3 (int x)
174 int y = 6; /* not_inline_func3 */
176 return y + inline_func3 (x);
179 /* The following three functions serve to exercise GDB's inline frame
180 skipping logic when setting a user breakpoint on an inline function
181 by name. */
183 /* A static inlined function that is called by another static inlined
184 function. */
186 static inline ATTR int
187 func_inline_callee (int x)
189 return x * 23;
192 /* A static inlined function that calls another static inlined
193 function. The body of the function is as simple as possible so
194 that both functions are inlined to the same PC address. */
196 static inline ATTR int
197 func_inline_caller (int x)
199 return func_inline_callee (x);
202 /* An extern not-inline function that calls a static inlined
203 function. */
206 func_extern_caller (int x)
208 return func_inline_caller (x);
211 /* Entry point. */
214 main (int argc, char *argv[])
216 /* Declaring x as volatile here prevents GCC from combining calls.
217 If GCC is allowed to combine calls then some of them end up with
218 no instructions at all, so there is no specific address for GDB
219 to set a breakpoint at. */
220 volatile int x = argc;
222 x = func1 (x);
224 x = func2 (x);
226 x = func3a (x);
228 x = func4a (x);
230 x = func5a (x);
232 x = func6a (x);
234 x = func7a (x) + func7b (x);
236 x = func8a (x) + func8b (x);
238 x = not_inline_func3 (-21);
240 func_extern_caller (1);
242 return x;