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