Commit | Line | Data |
---|---|---|
6827a8f8 | 1 | # Test macro scoping. |
88b9d363 | 2 | # Copyright 2002-2022 Free Software Foundation, Inc. |
6827a8f8 JB |
3 | |
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 6 | # the Free Software Foundation; either version 3 of the License, or |
6827a8f8 | 7 | # (at your option) any later version. |
e22f8b7c | 8 | # |
6827a8f8 JB |
9 | # This program is distributed in the hope that it will be useful, |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
e22f8b7c | 13 | # |
6827a8f8 | 14 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
6827a8f8 | 16 | |
6827a8f8 | 17 | |
f8b41b00 TT |
18 | standard_testfile macscp1.c |
19 | set objfile [standard_output_file ${testfile}.o] | |
6827a8f8 | 20 | |
484086b7 | 21 | set options { debug additional_flags=-DFROM_COMMANDLINE=ARG} |
d848e687 | 22 | |
4c93b1db | 23 | get_compiler_info |
a088215a | 24 | if { [test_compiler_info "gcc-*"] } { |
d848e687 | 25 | lappend options additional_flags=-g3 |
a088215a SST |
26 | } elseif { [test_compiler_info "clang-*"] } { |
27 | lappend options additional_flags=-fdebug-macro | |
d848e687 DJ |
28 | } |
29 | ||
87bdc959 TG |
30 | # Generate the intermediate object file. This is required by Darwin to |
31 | # have access to the .debug_macinfo section. | |
32 | if {[gdb_compile "${srcdir}/${subdir}/macscp1.c" "${objfile}" \ | |
33 | object $options] != "" | |
34 | || [gdb_compile "${objfile}" "${binfile}" executable $options] != "" } { | |
84c93cd5 | 35 | untested "failed to compile" |
b60f0898 | 36 | return -1 |
6827a8f8 JB |
37 | } |
38 | ||
f8b41b00 | 39 | clean_restart ${binfile} |
6827a8f8 JB |
40 | |
41 | ||
42 | # Ask GDB to show the current definition of MACRO, and return a list | |
43 | # describing the result. | |
44 | # | |
45 | # The return value has the form {FILE1 FILE2 ... DEF}, which means | |
46 | # that MACRO has the definition `DEF', and was defined in `FILE1', | |
47 | # which was included from `FILE2', included from ... . | |
48 | # | |
49 | # If GDB says that MACRO has no definition, return the string `undefined'. | |
50 | # | |
51 | # If GDB complains that it doesn't have any information about | |
52 | # preprocessor macro definitions, return the string `no-macro-info'. | |
53 | # | |
54 | # If expect times out waiting for GDB, we return the string `timeout'. | |
55 | # | |
56 | # If GDB's output doesn't otherwise match what we're expecting, we | |
57 | # return the empty string. | |
58 | ||
59 | proc info_macro {macro} { | |
60 | global gdb_prompt | |
6827a8f8 JB |
61 | |
62 | set filepat {macscp[0-9]+\.[ch]} | |
63 | set definition {} | |
64 | set location {} | |
65 | ||
484086b7 JK |
66 | # Line number zero is set for macros defined from the compiler command-line. |
67 | # Such macros are not being tested by this function. | |
68 | set nonzero {[1-9][0-9]*} | |
69 | ||
6827a8f8 JB |
70 | send_gdb "info macro ${macro}\n" |
71 | ||
72 | set debug_me 0 | |
73 | ||
74 | if {$debug_me} {exp_internal 1} | |
75 | gdb_expect { | |
484086b7 | 76 | -re "Defined at \[^\r\n\]*(${filepat}):${nonzero}\[\r\n\]" { |
6827a8f8 JB |
77 | # `location' and `definition' should be empty when we see |
78 | # this message. | |
79 | if {[llength $location] == 0 && [llength $definition] == 0} { | |
80 | set location $expect_out(1,string) | |
81 | exp_continue | |
82 | } else { | |
83 | # Exit this expect loop, with a result indicating failure. | |
84 | set definition {} | |
85 | } | |
86 | } | |
87 | -re "The symbol `${macro}' has no definition as a C/C\\+\\+ preprocessor macro\[^\r\n\]*\[\r\n\]" { | |
88 | # `location' and `definition' should be empty when we see | |
89 | # this message. | |
90 | if {[llength $location] == 0 && [llength $definition] == 0} { | |
91 | set definition undefined | |
92 | exp_continue | |
93 | } else { | |
94 | # Exit this expect loop, with a result indicating failure. | |
95 | set definition {} | |
96 | } | |
97 | } | |
484086b7 | 98 | -re "^\[\r\n\]* included at \[^\r\n\]*(${filepat}):${nonzero}\[\r\n\]" { |
6827a8f8 JB |
99 | # `location' should *not* be empty when we see this |
100 | # message. It should have recorded at least the initial | |
101 | # `Defined at ' message (for definitions) or ` at' message | |
102 | # (for undefined symbols). | |
103 | if {[llength $location] != 0} { | |
104 | lappend location $expect_out(1,string) | |
105 | exp_continue | |
106 | } else { | |
107 | # Exit this expect loop, with a result indicating failure. | |
108 | set definition {} | |
109 | } | |
110 | } | |
484086b7 | 111 | -re "^\[\r\n\]*at \[^\r\n\]*(${filepat}):${nonzero}\[\r\n\]" { |
6827a8f8 JB |
112 | # This appears after a `has no definition' message. |
113 | # `location' should be empty when we see it. | |
114 | if {[string compare $definition undefined] == 0 \ | |
115 | && [llength $location] == 0} { | |
116 | set location $expect_out(1,string) | |
117 | exp_continue | |
118 | } else { | |
119 | # Exit this expect loop, with a result indicating failure. | |
120 | set definition {} | |
121 | } | |
122 | } | |
123 | -re "#define ${macro} (\[^\r\n\]*)\[\r\n\]" { | |
124 | # `definition' should be empty when we see this message. | |
125 | if {[string compare $definition ""] == 0} { | |
126 | set definition $expect_out(1,string) | |
127 | exp_continue | |
128 | } else { | |
129 | # Exit this expect loop, with a result indicating failure. | |
130 | set definition {} | |
131 | } | |
132 | } | |
133 | -re "has no preprocessor macro information.*$gdb_prompt $" { | |
134 | set definition no-macro-info | |
135 | } | |
136 | -re "$gdb_prompt $" { | |
137 | # Exit the expect loop; let the existing value of `definition' | |
138 | # indicate failure or success. | |
139 | } | |
140 | timeout { | |
141 | set definition timeout | |
142 | } | |
143 | } | |
144 | if {$debug_me} {exp_internal 0} | |
145 | ||
146 | switch -exact -- $definition { | |
147 | no-macro-info { return no-macro-info } | |
148 | timeout { return timeout } | |
f2292c65 | 149 | undefined { return undefined } |
6827a8f8 JB |
150 | default { |
151 | if {[llength $location] >= 1} { | |
152 | return [concat $location [list $definition]] | |
153 | } else { | |
154 | return {} | |
155 | } | |
156 | } | |
157 | } | |
158 | } | |
159 | ||
160 | ||
161 | # Call info_macro to show the definition of MACRO. Expect a result of | |
162 | # EXPECTED. Use WHERE in pass/fail messages to identify the context. | |
163 | # Return non-zero if we should abort the entire test file, or zero if | |
164 | # we can continue. | |
165 | proc check_macro {macro expected where} { | |
166 | set func_def [info_macro $macro] | |
167 | if {[string compare $func_def $expected] == 0} { | |
168 | pass "info macro $macro $where" | |
169 | } else { | |
170 | switch -exact -- $func_def { | |
171 | no-macro-info { | |
172 | xfail "executable includes no macro debugging information" | |
173 | return 1 | |
174 | } | |
f2292c65 PM |
175 | undefined { |
176 | fail "info macro $macro $where (undefined)" | |
177 | return 1 | |
178 | } | |
6827a8f8 JB |
179 | timeout { |
180 | fail "info macro $macro $where (timeout)" | |
181 | } | |
182 | default { | |
183 | fail "info macro $macro $where" | |
184 | } | |
185 | } | |
186 | } | |
187 | return 0 | |
188 | } | |
44aabfbc | 189 | |
6827a8f8 JB |
190 | |
191 | # List the function FUNC, and then show the definition of MACRO, | |
192 | # expecting the result EXPECTED. | |
193 | proc list_and_check_macro {func macro expected} { | |
44aabfbc | 194 | gdb_test "list $func" ".*${func}.*" "list $func for $macro" |
6827a8f8 JB |
195 | return [check_macro $macro $expected "after `list $func'"] |
196 | } | |
197 | ||
e777225b | 198 | gdb_test "list -q main" ".*main.*" "list main for support check" |
b67c692f | 199 | set macro_support "unknown" |
de97fdd4 | 200 | gdb_test_multiple "info source" "test macro information" { |
b67c692f DJ |
201 | -re "Includes preprocessor macro info\..*$gdb_prompt $" { |
202 | set macro_support 1 | |
203 | verbose "Source has macro information" | |
204 | } | |
205 | -re "Does not include preprocessor macro info\..*$gdb_prompt $" { | |
206 | set macro_support 0 | |
207 | verbose "Source has no macro information" | |
f2292c65 | 208 | } |
b67c692f DJ |
209 | default { |
210 | warning "couldn't check macro support (no valid response)." | |
f2292c65 | 211 | } |
6827a8f8 | 212 | } |
b67c692f | 213 | if {$macro_support == 0} { |
bc6c7af4 | 214 | unsupported "skipping test because debug information does not include macro information." |
b67c692f DJ |
215 | return 0 |
216 | } | |
f2292c65 | 217 | |
b67c692f | 218 | list_and_check_macro main WHERE {macscp1.c {before macscp1_3}} |
6827a8f8 JB |
219 | list_and_check_macro macscp2_2 WHERE {macscp2.h macscp1.c {before macscp2_2}} |
220 | list_and_check_macro macscp3_2 WHERE {macscp3.h macscp1.c {before macscp3_2}} | |
221 | ||
222 | ||
484086b7 JK |
223 | # Assuming the current position inside program by `list' from above. |
224 | gdb_test "info macro FROM_COMMANDLINE" \ | |
225 | "Defined at \[^\r\n\]*:0\r\n-DFROM_COMMANDLINE=ARG" | |
226 | ||
abc9d0dc TT |
227 | gdb_test "info macro __FILE__" "#define __FILE__ \".*macscp3.h\"" \ |
228 | "info macro __FILE__ before running" | |
229 | gdb_test "info macro __LINE__" "#define __LINE__ 26" \ | |
230 | "info macro __LINE__ before running" | |
484086b7 | 231 | |
6827a8f8 JB |
232 | # Although GDB's macro table structures distinguish between multiple |
233 | # #inclusions of the same file, GDB's other structures don't. So the | |
234 | # `list' command here doesn't reliably select one #inclusion or the | |
235 | # other, even though it could. It would be nice to eventually change | |
236 | # GDB's structures to handle this correctly. | |
237 | gdb_test "list macscp4_2_from_macscp2" ".*macscp4_2_, MACSCP4_INCLUSION.*" | |
238 | switch -exact -- [info_macro WHERE] { | |
239 | {macscp4.h macscp2.h macscp1.c {before macscp4_2_..., from macscp2.h}} { | |
240 | pass "info macro WHERE after `list macscp_4_2_from_macscp2'" | |
241 | } | |
242 | {macscp4.h macscp3.h macscp1.c {before macscp4_2_..., from macscp3.h}} { | |
6e5f2c59 | 243 | setup_kfail "gdb/555" *-*-* |
6827a8f8 JB |
244 | fail "info macro WHERE after `list macscp_4_2_from_macscp2' (gdb/555)" |
245 | } | |
246 | timeout { | |
247 | fail "info macro WHERE after `list macscp_4_2_from_macscp2' (timeout)" | |
248 | } | |
249 | default { fail "info macro WHERE after `list macscp_4_2_from_macscp2'" } | |
250 | } | |
251 | ||
252 | gdb_test "list macscp4_2_from_macscp3" ".*macscp4_2_, MACSCP4_INCLUSION.*" | |
253 | switch -exact -- [info_macro WHERE] { | |
254 | {macscp4.h macscp3.h macscp1.c {before macscp4_2_..., from macscp3.h}} { | |
255 | pass "info macro WHERE after `list macscp_4_2_from_macscp3'" | |
256 | } | |
257 | {macscp4.h macscp2.h macscp1.c {before macscp4_2_..., from macscp2.h}} { | |
6e5f2c59 | 258 | setup_kfail "gdb/555" *-*-* |
6827a8f8 JB |
259 | fail "info macro WHERE after `list macscp_4_2_from_macscp3' (gdb/555)" |
260 | } | |
261 | timeout { | |
262 | fail "info macro WHERE after `list macscp_4_2_from_macscp3' (timeout)" | |
263 | } | |
264 | default { fail "info macro WHERE after `list macscp_4_2_from_macscp3'" } | |
265 | } | |
266 | ||
267 | ||
268 | #### Test the selection of the macro scope by the current frame. | |
269 | ||
270 | ### A table of functions, in the order they will be reached, which is | |
271 | ### also the order they appear in the preprocessed output. Each entry | |
272 | ### has the form {FUNCNAME WHERE KFAILWHERE}, where: | |
273 | ### - FUNCNAME is the name of the function, | |
274 | ### - WHERE is the definition we expect to see for the macro `WHERE', as | |
275 | ### returned by `info_macro', and | |
276 | ### - KFAILWHERE is an alternate definition which should be reported | |
277 | ### as a `known failure', due to GDB's inability to distinguish multiple | |
278 | ### #inclusions of the same file. | |
279 | ### KFAILWHERE may be omitted. | |
280 | ||
281 | set funcs { | |
282 | { | |
283 | macscp1_1 | |
284 | {macscp1.c {before macscp1_1}} | |
285 | } | |
286 | { | |
287 | macscp2_1 | |
288 | {macscp2.h macscp1.c {before macscp2_1}} | |
289 | } | |
290 | { | |
291 | macscp4_1_from_macscp2 | |
292 | {macscp4.h macscp2.h macscp1.c {before macscp4_1_..., from macscp2.h}} | |
293 | {macscp4.h macscp3.h macscp1.c {before macscp4_1_..., from macscp3.h}} | |
294 | } | |
295 | { | |
296 | macscp4_2_from_macscp2 | |
297 | {macscp4.h macscp2.h macscp1.c {before macscp4_2_..., from macscp2.h}} | |
298 | {macscp4.h macscp3.h macscp1.c {before macscp4_2_..., from macscp3.h}} | |
299 | } | |
300 | { | |
301 | macscp2_2 | |
302 | {macscp2.h macscp1.c {before macscp2_2}} | |
303 | } | |
304 | { | |
305 | macscp1_2 | |
306 | {macscp1.c {before macscp1_2}} | |
307 | } | |
308 | { | |
309 | macscp3_1 | |
310 | {macscp3.h macscp1.c {before macscp3_1}} | |
311 | } | |
312 | { | |
313 | macscp4_1_from_macscp3 | |
314 | {macscp4.h macscp3.h macscp1.c {before macscp4_1_..., from macscp3.h}} | |
315 | {macscp4.h macscp2.h macscp1.c {before macscp4_1_..., from macscp2.h}} | |
316 | } | |
317 | { | |
318 | macscp4_2_from_macscp3 | |
319 | {macscp4.h macscp3.h macscp1.c {before macscp4_2_..., from macscp3.h}} | |
320 | {macscp4.h macscp2.h macscp1.c {before macscp4_2_..., from macscp2.h}} | |
321 | } | |
322 | { | |
323 | macscp3_2 | |
324 | {macscp3.h macscp1.c {before macscp3_2}} | |
325 | } | |
326 | { | |
327 | macscp1_3 | |
328 | {macscp1.c {before macscp1_3}} | |
329 | } | |
330 | } | |
331 | ||
d848e687 DJ |
332 | proc maybe_kfail { func test_name } { |
333 | # We can't get the right scope info when we're stopped in | |
334 | # the macro4_ functions. | |
335 | if {[string match macscp4_* $func]} { | |
336 | kfail gdb/555 "$test_name" | |
337 | } else { | |
338 | fail "$test_name" | |
339 | } | |
340 | } | |
6827a8f8 JB |
341 | |
342 | # Start the program running. | |
343 | if {! [runto_main]} { | |
344 | fail "macro tests suppressed: couldn't run to main" | |
345 | return 0 | |
346 | } | |
347 | ||
348 | # Set a breakpoint on each of the functions. | |
349 | foreach func_entry $funcs { | |
350 | set func [lindex $func_entry 0] | |
351 | gdb_test "break $func" "Breakpoint.*" | |
352 | } | |
353 | ||
354 | # Run to each of the breakpoints and check the definition (or lack | |
355 | # thereof) of each macro. | |
356 | for {set i 0} {$i < [llength $funcs]} {incr i} { | |
357 | set func_entry [lindex $funcs $i] | |
358 | set func [lindex $func_entry 0] | |
359 | set expected [lindex $func_entry 1] | |
360 | set kfail_expected [lindex $func_entry 2] | |
361 | ||
362 | # Run to the breakpoint for $func. | |
363 | gdb_test "continue" "Breakpoint $decimal, $func .*" "continue to $func" | |
364 | ||
365 | # Check the macro WHERE. | |
366 | set result [info_macro WHERE] | |
367 | if {[string compare $result $expected] == 0} { | |
368 | pass "info macro WHERE stopped in $func" | |
369 | } elseif {[string compare $result $kfail_expected] == 0} { | |
6e5f2c59 | 370 | setup_kfail "gdb/555" *-*-* |
6827a8f8 JB |
371 | fail "info macro WHERE stopped in $func (gdb/555)" |
372 | } elseif {[string compare $result timeout] == 0} { | |
373 | fail "info macro WHERE stopped in $func (timeout)" | |
374 | } else { | |
375 | fail "info macro WHERE stopped in $func" | |
376 | } | |
377 | ||
378 | # Check that the BEFORE_<func> macros for all prior functions are | |
379 | # #defined, and that those for all subsequent functions are not. | |
380 | for {set j 0} {$j < [llength $funcs]} {incr j} { | |
381 | if {$j != $i} { | |
382 | set func_j_entry [lindex $funcs $j] | |
383 | set func_j [lindex $func_j_entry 0] | |
384 | ||
385 | set before_macro "BEFORE_[string toupper $func_j]" | |
386 | set test_name \ | |
387 | "$before_macro defined/undefined when stopped at $func" | |
388 | set result [info_macro $before_macro] | |
389 | ||
6827a8f8 JB |
390 | if {$j < $i} { |
391 | if {[llength $result] >= 2 && \ | |
392 | [string compare [lindex $result end] {}] == 0} { | |
393 | pass $test_name | |
394 | } elseif {[string compare $result timeout] == 0} { | |
395 | fail "$test_name (timeout)" | |
396 | } else { | |
d848e687 | 397 | maybe_kfail $func "$test_name" |
6827a8f8 JB |
398 | } |
399 | } elseif {$j > $i} { | |
400 | switch -- [lindex $result end] { | |
401 | undefined { pass $test_name } | |
402 | timeout { fail "$test_name (timeout)" } | |
403 | default { | |
d848e687 | 404 | maybe_kfail $func "$test_name" |
6827a8f8 JB |
405 | } |
406 | } | |
407 | } | |
408 | ||
409 | set until_macro "UNTIL_[string toupper $func_j]" | |
410 | set test_name \ | |
411 | "$until_macro defined/undefined when stopped at $func" | |
412 | set result [info_macro $until_macro] | |
413 | ||
6827a8f8 JB |
414 | if {$j <= $i} { |
415 | switch -- [lindex $result end] { | |
416 | undefined { pass $test_name } | |
417 | timeout { fail "$test_name (timeout)" } | |
418 | default { | |
d848e687 | 419 | maybe_kfail $func "$test_name" |
6827a8f8 JB |
420 | } |
421 | } | |
422 | } elseif {$j > $i} { | |
423 | if {[llength $result] >= 2 && \ | |
424 | [string compare [lindex $result end] {}] == 0} { | |
425 | pass $test_name | |
426 | } elseif {[string compare $result timeout] == 0} { | |
427 | fail "$test_name (timeout)" | |
428 | } else { | |
d848e687 | 429 | maybe_kfail $func "$test_name" |
6827a8f8 JB |
430 | } |
431 | } | |
432 | } | |
433 | } | |
434 | } | |
d705c43c PA |
435 | |
436 | gdb_test "break [gdb_get_line_number "set breakpoint here"]" \ | |
437 | "Breakpoint.*at.* file .*, line.*" \ | |
438 | "breakpoint macscp_expr" | |
439 | ||
1bb9788d TT |
440 | gdb_test "cond \$bpnum foo == MACRO_TO_EXPAND" \ |
441 | "No symbol \"MACRO_TO_EXPAND\" in current context\." \ | |
442 | "macro MACRO_TO_EXPAND not in scope at breakpoint" | |
443 | ||
444 | # Note that we choose the condition so that this breakpoint never | |
445 | # stops. | |
446 | set l2 [gdb_get_line_number "set second breakpoint here"] | |
447 | gdb_test "break $l2 if foo != MACRO_TO_EXPAND" \ | |
448 | "Breakpoint.*at.*" \ | |
449 | "breakpoint macscp_expr using MACRO_TO_EXPAND" | |
450 | ||
d705c43c PA |
451 | gdb_test "continue" "foo = 0;.*" "continue to macsp_expr" |
452 | ||
7c8adf68 | 453 | gdb_test "print address.addr" \ |
11af934b | 454 | " = 0" |
7c8adf68 | 455 | |
506800a9 TT |
456 | gdb_test "print MACRO_TO_EXPAND" \ |
457 | "No symbol \"MACRO_TO_EXPAND\" in current context\." \ | |
d705c43c PA |
458 | "print expression with macro before define." |
459 | ||
1bb9788d | 460 | gdb_test "next" "foo = 1;.*here.*/" "next to definition 1" |
d705c43c | 461 | |
506800a9 | 462 | gdb_test "print MACRO_TO_EXPAND" \ |
d705c43c PA |
463 | " = 0" \ |
464 | "print expression with macro in scope." | |
465 | ||
27d3a1a2 | 466 | gdb_test_no_output "macro define MACRO_TO_EXPAND 72" \ |
d7d9f01e TT |
467 | "user macro override" |
468 | ||
506800a9 | 469 | gdb_test "print MACRO_TO_EXPAND" \ |
d7d9f01e TT |
470 | " = 72" \ |
471 | "choose user macro" | |
472 | ||
27d3a1a2 | 473 | gdb_test_no_output "macro undef MACRO_TO_EXPAND" \ |
d7d9f01e TT |
474 | "remove user override" |
475 | ||
506800a9 | 476 | gdb_test "print MACRO_TO_EXPAND" \ |
d7d9f01e TT |
477 | " = 0" \ |
478 | "print expression with macro after removing override" | |
479 | ||
abc9d0dc | 480 | gdb_test "next" "foo = 2;.*" "next to definition 2" |
d705c43c | 481 | |
506800a9 TT |
482 | gdb_test "print MACRO_TO_EXPAND" \ |
483 | "No symbol \"MACRO_TO_EXPAND\" in current context\." \ | |
d705c43c | 484 | "print expression with macro after undef." |
d7d9f01e | 485 | |
27d3a1a2 | 486 | gdb_test_no_output "macro define MACRO_TO_EXPAND 5" \ |
d7d9f01e TT |
487 | "basic macro define" |
488 | ||
506800a9 | 489 | gdb_test "print MACRO_TO_EXPAND" \ |
d7d9f01e TT |
490 | " = 5" \ |
491 | "expansion of defined macro" | |
492 | ||
493 | gdb_test "macro list" \ | |
506800a9 | 494 | "macro define MACRO_TO_EXPAND 5" \ |
d7d9f01e TT |
495 | "basic macro list" |
496 | ||
27d3a1a2 | 497 | gdb_test_no_output "macro define MACRO_TO_EXPAND(x) x" \ |
d7d9f01e TT |
498 | "basic redefine, macro with args" |
499 | ||
506800a9 | 500 | gdb_test "print MACRO_TO_EXPAND (7)" \ |
d7d9f01e TT |
501 | " = 7" \ |
502 | "expansion of macro with arguments" | |
503 | ||
27d3a1a2 | 504 | gdb_test_no_output "macro undef MACRO_TO_EXPAND" \ |
d7d9f01e TT |
505 | "basic macro undef" |
506 | ||
506800a9 TT |
507 | gdb_test "print MACRO_TO_EXPAND" \ |
508 | "No symbol \"MACRO_TO_EXPAND\" in current context\." \ | |
d7d9f01e | 509 | "print expression with macro after user undef." |
ccb3ac8a | 510 | |
886a217c TT |
511 | # Regression test; this used to crash. |
512 | gdb_test "macro define" \ | |
513 | "usage: macro define.*" \ | |
514 | "macro define with no arguments" | |
515 | ||
516 | # Regression test; this used to crash. | |
517 | gdb_test "macro undef" \ | |
518 | "usage: macro undef.*" \ | |
519 | "macro undef with no arguments" | |
520 | ||
0d4d0e77 YQ |
521 | # Do completion tests if readline is used. |
522 | ||
523 | if { [readline_is_used] } { | |
524 | ||
525 | # The macro FIFTY_SEVEN is in scope at this point. | |
526 | send_gdb "p FIFTY_\t" | |
527 | gdb_expect { | |
528 | -re "^p FIFTY_SEVEN $" { | |
529 | send_gdb "\n" | |
530 | gdb_expect { | |
531 | -re "^.* = 57.*$gdb_prompt $" { | |
532 | pass "complete 'p FIFTY_SEVEN'" | |
533 | } | |
534 | -re ".*$gdb_prompt $" { fail "complete 'p FIFTY_SEVEN'" } | |
535 | timeout { fail "(timeout) complete 'p FIFTY_SEVEN'" } | |
29361eee YQ |
536 | } |
537 | } | |
0d4d0e77 YQ |
538 | -re ".*$gdb_prompt $" { fail "complete 'p FIFTY_SEVEN'" } |
539 | timeout { fail "(timeout) complete 'p FIFTY_SEVEN' 2" } | |
540 | } | |
9a044a89 | 541 | |
0d4d0e77 YQ |
542 | # The macro TWENTY_THREE is not in scope. |
543 | send_gdb "p TWENTY_\t" | |
544 | gdb_expect { | |
545 | -re "^p TWENTY_\\\x07$" { | |
546 | send_gdb "\n" | |
547 | gdb_expect { | |
548 | -re "No symbol \"TWENTY_\" in current context\\..*$gdb_prompt $" { | |
549 | pass "complete 'p TWENTY_'" | |
550 | } | |
551 | -re ".*$gdb_prompt $" { fail "complete 'p TWENTY_'" } | |
552 | timeout { fail "(timeout) complete 'p TWENTY_'"} | |
29361eee | 553 | } |
29361eee | 554 | } |
0d4d0e77 YQ |
555 | -re ".*$gdb_prompt $" { fail "complete 'p TWENTY_'" } |
556 | timeout { fail "(timeout) complete 'p TWENTY_' 2" } | |
29361eee | 557 | } |
9a044a89 | 558 | |
0d4d0e77 YQ |
559 | # The macro FORTY_EIGHT was undefined and thus is not in scope. |
560 | send_gdb "p FORTY_\t" | |
561 | gdb_expect { | |
562 | -re "^p FORTY_\\\x07$" { | |
563 | send_gdb "\n" | |
564 | gdb_expect { | |
565 | -re "No symbol \"FORTY_\" in current context\\..*$gdb_prompt $" { | |
566 | pass "complete 'p FORTY_'" | |
567 | } | |
568 | -re ".*$gdb_prompt $" { fail "complete 'p FORTY_'" } | |
569 | timeout {fail "(timeout) complete 'p FORTY_'"} | |
29361eee YQ |
570 | } |
571 | } | |
0d4d0e77 YQ |
572 | -re ".*$gdb_prompt $" { fail "complete 'p FORTY_'" } |
573 | timeout { fail "(timeout) complete 'p FORTY_' 2" } | |
574 | } | |
9a044a89 | 575 | |
0d4d0e77 YQ |
576 | gdb_test_no_output "macro define TWENTY_THREE 25" \ |
577 | "defining TWENTY_THREE" | |
578 | ||
579 | # User-defined macros are always in scope. | |
580 | send_gdb "p TWENTY_\t" | |
581 | gdb_expect { | |
582 | -re "^p TWENTY_THREE $" { | |
583 | send_gdb "\n" | |
584 | gdb_expect { | |
585 | -re "^.* = 25.*$gdb_prompt $" { | |
586 | pass "complete 'p TWENTY_THREE'" | |
587 | } | |
588 | -re ".*$gdb_prompt $" { fail "complete 'p TWENTY_THREE'"} | |
589 | timeout { fail "(timeout) complete 'p TWENTY_THREE'" } | |
29361eee | 590 | } |
29361eee | 591 | } |
0d4d0e77 YQ |
592 | -re ".*$gdb_prompt $" { fail "complete 'p TWENTY_THREE'" } |
593 | timeout { fail "(timeout) complete 'p TWENTY_THREE' 2" } | |
29361eee | 594 | } |
29361eee | 595 | } |
9a044a89 | 596 | |
2fae03e8 TT |
597 | # Splicing tests. |
598 | ||
ccb3ac8a | 599 | gdb_test "macro expand SPLICE(x, y)" \ |
2fae03e8 TT |
600 | "expands to: xy" \ |
601 | "basic macro splicing" | |
602 | ||
27d3a1a2 | 603 | gdb_test_no_output "macro define robotinvasion 2010" \ |
2fae03e8 TT |
604 | "define splice helper" |
605 | ||
606 | gdb_test "macro expand SPLICE(robot, invasion)" \ | |
607 | "expands to: *2010" \ | |
608 | "splicing plus expansion" | |
609 | ||
610 | # Varargs tests. | |
611 | ||
27d3a1a2 | 612 | gdb_test_no_output "macro define va_c99(...) varfunc (fixedarg, __VA_ARGS__)" \ |
2fae03e8 TT |
613 | "define first varargs helper" |
614 | ||
27d3a1a2 | 615 | gdb_test_no_output "macro define va2_c99(x, y, ...) varfunc (fixedarg, x, y, __VA_ARGS__)" \ |
2fae03e8 TT |
616 | "define second varargs helper" |
617 | ||
27d3a1a2 | 618 | gdb_test_no_output "macro define va_gnu(args...) varfunc (fixedarg, args)" \ |
2fae03e8 TT |
619 | "define third varargs helper" |
620 | ||
27d3a1a2 | 621 | gdb_test_no_output "macro define va2_gnu(args...) varfunc (fixedarg, ## args)" \ |
2fae03e8 TT |
622 | "define fourth varargs helper" |
623 | ||
a9bbfbd8 TT |
624 | gdb_test_no_output \ |
625 | "macro define va3_cxx2a(x, ...) varfunc (x __VA_OPT__(,) __VA_ARGS__)" \ | |
626 | "define fifth varargs helper" | |
627 | ||
628 | gdb_test_no_output \ | |
629 | "macro define va4_cxx2a(x, ...) varfunc (x __VA_OPT__(, __VA_ARGS__))" \ | |
630 | "define sixth varargs helper" | |
631 | ||
632 | gdb_test_no_output \ | |
633 | "macro define va5_cxx2a(x, ...) varfunc (x __VA_OPT__(,) __VA_OPT__(__VA_ARGS__))" \ | |
634 | "define seventh varargs helper" | |
635 | ||
2fae03e8 | 636 | gdb_test "macro expand va_c99(one, two, three)" \ |
dcb1a1e2 | 637 | "expands to: *varfunc \\(fixedarg, *one, two, three\\)" \ |
2fae03e8 TT |
638 | "c99 varargs expansion" |
639 | ||
640 | gdb_test "macro expand va_c99()" \ | |
dcb1a1e2 | 641 | "expands to: *varfunc \\(fixedarg, *\\)" \ |
2fae03e8 TT |
642 | "c99 varargs expansion without an argument" |
643 | ||
644 | gdb_test "macro expand va2_c99(one, two, three, four)" \ | |
dcb1a1e2 | 645 | "expands to: *varfunc \\(fixedarg, *one, two, three, four\\)" \ |
2fae03e8 TT |
646 | "c99 varargs expansion, multiple formal arguments" |
647 | ||
648 | gdb_test "macro expand va_gnu(one, two, three, four)" \ | |
dcb1a1e2 | 649 | "expands to: *varfunc \\(fixedarg, *one, two, three, four\\)" \ |
2fae03e8 TT |
650 | "gnu varargs expansion" |
651 | ||
652 | gdb_test "macro expand va_gnu()" \ | |
dcb1a1e2 | 653 | "expands to: *varfunc \\(fixedarg, *\\)" \ |
2fae03e8 TT |
654 | "gnu varargs expansion without an argument" |
655 | ||
656 | gdb_test "macro expand va2_gnu()" \ | |
dcb1a1e2 | 657 | "expands to: *varfunc \\(fixedarg\\)" \ |
2fae03e8 TT |
658 | "gnu varargs expansion special splicing without an argument" |
659 | ||
a9bbfbd8 TT |
660 | gdb_test "macro expand va3_cxx2a(23)" \ |
661 | "expands to: *varfunc \\(23 \\)" \ | |
662 | "C++2a __VA_OPT__ handling without variable argument" | |
663 | ||
664 | gdb_test "macro expand va3_cxx2a(23, 24, 25)" \ | |
665 | "expands to: *varfunc \\(23, 24, 25\\)" \ | |
666 | "C++2a __VA_OPT__ handling with variable argument" | |
667 | ||
668 | gdb_test "macro expand va4_cxx2a(23, 24, 25)" \ | |
669 | "expands to: *varfunc \\(23, 24, 25\\)" \ | |
670 | "C++2a __VA_OPT__ conditional __VA_ARGS__ handling with variable argument" | |
671 | ||
672 | gdb_test "macro expand va4_cxx2a(23)" \ | |
673 | "expands to: *varfunc \\(23\\)" \ | |
674 | "C++2a __VA_OPT__ conditional __VA_ARGS__ handling without variable argument" | |
675 | ||
676 | gdb_test "macro expand va5_cxx2a(23, 24, 25)" \ | |
677 | "expands to: *varfunc \\(23,24, 25\\)" \ | |
678 | "C++2a double __VA_OPT__ conditional __VA_ARGS__ handling with variable argument" | |
679 | ||
680 | gdb_test "macro expand va5_cxx2a(23)" \ | |
681 | "expands to: *varfunc \\(23\\)" \ | |
682 | "C++2a double __VA_OPT__ conditional __VA_ARGS__ handling without variable argument" | |
683 | ||
684 | gdb_test_no_output \ | |
685 | "macro define badopt1(x, ...) __VA_OPT__) x" \ | |
686 | "define first invalid varargs helper" | |
687 | gdb_test "macro expand badopt1(5)" \ | |
688 | "__VA_OPT__ must be followed by an open parenthesis" \ | |
689 | "__VA_OPT__ without open paren" | |
690 | ||
691 | gdb_test_no_output \ | |
692 | "macro define badopt2(x, ...) __VA_OPT__(__VA_OPT__(,)) x" \ | |
693 | "define second invalid varargs helper" | |
694 | gdb_test "macro expand badopt2(5)" \ | |
695 | "__VA_OPT__ cannot appear inside __VA_OPT__" \ | |
696 | "__VA_OPT__ inside __VA_OPT__" | |
697 | ||
698 | gdb_test_no_output \ | |
699 | "macro define badopt3(x) __VA_OPT__" \ | |
700 | "define third invalid varargs helper" | |
701 | gdb_test "macro expand badopt3(5)" \ | |
702 | "__VA_OPT__ is only valid in a variadic macro" \ | |
703 | "__VA_OPT__ not in variadic macro" | |
704 | ||
705 | gdb_test_no_output \ | |
706 | "macro define badopt4(x, ...) __VA_OPT__(x" \ | |
707 | "define fourth invalid varargs helper" | |
708 | gdb_test "macro expand badopt4(5)" \ | |
709 | "Unterminated __VA_OPT__" \ | |
710 | "__VA_OPT__ without closing paren" | |
711 | ||
2fae03e8 TT |
712 | # Stringification tests. |
713 | ||
27d3a1a2 | 714 | gdb_test_no_output "macro define str(x) #x" \ |
2fae03e8 TT |
715 | "define stringification macro" |
716 | ||
27d3a1a2 | 717 | gdb_test_no_output "macro define maude 5" \ |
2fae03e8 TT |
718 | "define first stringification helper" |
719 | ||
27d3a1a2 | 720 | gdb_test_no_output "macro define xstr(x) str(x)" \ |
2fae03e8 TT |
721 | "define second stringification helper" |
722 | ||
723 | gdb_test "print str(5)" \ | |
724 | " = \"5\"" \ | |
725 | "simple stringify" | |
726 | ||
727 | gdb_test "print str(hi bob)" \ | |
728 | " = \"hi bob\"" \ | |
729 | "stringify with one space" | |
730 | ||
731 | gdb_test "print str( hi bob )" \ | |
732 | " = \"hi bob\"" \ | |
733 | "stringify with many spaces" | |
734 | ||
735 | gdb_test "print str(hi \"bob\")" \ | |
736 | " = \"hi \\\\\"bob\\\\\"\"" \ | |
737 | "stringify with quotes" | |
738 | ||
739 | gdb_test "print str(hi \\bob\\)" \ | |
740 | " = \"hi \\\\\\\\bob\\\\\\\\\"" \ | |
741 | "stringify with backslashes" | |
742 | ||
743 | gdb_test "print str(maude)" \ | |
744 | " = \"maude\"" \ | |
745 | "stringify without substitution" | |
746 | ||
747 | gdb_test "print xstr(maude)" \ | |
748 | " = \"5\"" \ | |
749 | "stringify with substitution" | |
17c8aaf5 TT |
750 | |
751 | # Regression test for pp-number bug. | |
27d3a1a2 | 752 | gdb_test_no_output "macro define si_addr fields.fault.si_addr" \ |
17c8aaf5 | 753 | "define si_addr macro" |
27d3a1a2 | 754 | |
17c8aaf5 | 755 | gdb_test "macro expand siginfo.si_addr" \ |
11af934b | 756 | "expands to: siginfo.fields.fault.si_addr" |
abc9d0dc TT |
757 | |
758 | gdb_test "print __FILE__" " = \".*macscp1.c\"" | |
759 | gdb_test "print __LINE__" \ | |
760 | " = [gdb_get_line_number {stopping point for line test}]" |