1# Test macro scoping. 2# Copyright 2002-2020 Free Software Foundation, Inc. 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 6# the Free Software Foundation; either version 3 of the License, or 7# (at your option) any later version. 8# 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. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 18standard_testfile macscp1.c 19set objfile [standard_output_file ${testfile}.o] 20 21set options { debug additional_flags=-DFROM_COMMANDLINE=ARG} 22 23get_compiler_info 24if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } { 25 lappend options additional_flags=-g3 26} 27 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] != "" } { 33 untested "failed to compile" 34 return -1 35} 36 37clean_restart ${binfile} 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 59 60 set filepat {macscp[0-9]+\.[ch]} 61 set definition {} 62 set location {} 63 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 68 send_gdb "info macro ${macro}\n" 69 70 set debug_me 0 71 72 if {$debug_me} {exp_internal 1} 73 gdb_expect { 74 -re "Defined at \[^\r\n\]*(${filepat}):${nonzero}\[\r\n\]" { 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 } 96 -re "^\[\r\n\]* included at \[^\r\n\]*(${filepat}):${nonzero}\[\r\n\]" { 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 } 109 -re "^\[\r\n\]*at \[^\r\n\]*(${filepat}):${nonzero}\[\r\n\]" { 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 } 147 undefined { return undefined } 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 } 173 undefined { 174 fail "info macro $macro $where (undefined)" 175 return 1 176 } 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} 187 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} { 192 gdb_test "list $func" ".*${func}.*" "list $func for $macro" 193 return [check_macro $macro $expected "after `list $func'"] 194} 195 196gdb_test "list main" ".*main.*" "list main for support check" 197set macro_support "unknown" 198gdb_test_multiple "info source" "test macro information" { 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" 206 } 207 default { 208 warning "couldn't check macro support (no valid response)." 209 } 210} 211if {$macro_support == 0} { 212 unsupported "skipping test because debug information does not include macro information." 213 return 0 214} 215 216list_and_check_macro main WHERE {macscp1.c {before macscp1_3}} 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 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 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" 229 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}} { 241 setup_kfail "gdb/555" *-*-* 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}} { 256 setup_kfail "gdb/555" *-*-* 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 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} 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} { 368 setup_kfail "gdb/555" *-*-* 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 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 { 395 maybe_kfail $func "$test_name" 396 } 397 } elseif {$j > $i} { 398 switch -- [lindex $result end] { 399 undefined { pass $test_name } 400 timeout { fail "$test_name (timeout)" } 401 default { 402 maybe_kfail $func "$test_name" 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 412 if {$j <= $i} { 413 switch -- [lindex $result end] { 414 undefined { pass $test_name } 415 timeout { fail "$test_name (timeout)" } 416 default { 417 maybe_kfail $func "$test_name" 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 { 427 maybe_kfail $func "$test_name" 428 } 429 } 430 } 431 } 432} 433 434gdb_test "break [gdb_get_line_number "set breakpoint here"]" \ 435 "Breakpoint.*at.* file .*, line.*" \ 436 "breakpoint macscp_expr" 437 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 449gdb_test "continue" "foo = 0;.*" "continue to macsp_expr" 450 451gdb_test "print address.addr" \ 452 " = 0" 453 454gdb_test "print MACRO_TO_EXPAND" \ 455 "No symbol \"MACRO_TO_EXPAND\" in current context\." \ 456 "print expression with macro before define." 457 458gdb_test "next" "foo = 1;.*here.*/" "next to definition 1" 459 460gdb_test "print MACRO_TO_EXPAND" \ 461 " = 0" \ 462 "print expression with macro in scope." 463 464gdb_test_no_output "macro define MACRO_TO_EXPAND 72" \ 465 "user macro override" 466 467gdb_test "print MACRO_TO_EXPAND" \ 468 " = 72" \ 469 "choose user macro" 470 471gdb_test_no_output "macro undef MACRO_TO_EXPAND" \ 472 "remove user override" 473 474gdb_test "print MACRO_TO_EXPAND" \ 475 " = 0" \ 476 "print expression with macro after removing override" 477 478gdb_test "next" "foo = 2;.*" "next to definition 2" 479 480gdb_test "print MACRO_TO_EXPAND" \ 481 "No symbol \"MACRO_TO_EXPAND\" in current context\." \ 482 "print expression with macro after undef." 483 484gdb_test_no_output "macro define MACRO_TO_EXPAND 5" \ 485 "basic macro define" 486 487gdb_test "print MACRO_TO_EXPAND" \ 488 " = 5" \ 489 "expansion of defined macro" 490 491gdb_test "macro list" \ 492 "macro define MACRO_TO_EXPAND 5" \ 493 "basic macro list" 494 495gdb_test_no_output "macro define MACRO_TO_EXPAND(x) x" \ 496 "basic redefine, macro with args" 497 498gdb_test "print MACRO_TO_EXPAND (7)" \ 499 " = 7" \ 500 "expansion of macro with arguments" 501 502gdb_test_no_output "macro undef MACRO_TO_EXPAND" \ 503 "basic macro undef" 504 505gdb_test "print MACRO_TO_EXPAND" \ 506 "No symbol \"MACRO_TO_EXPAND\" in current context\." \ 507 "print expression with macro after user undef." 508 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 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'" } 534 } 535 } 536 -re ".*$gdb_prompt $" { fail "complete 'p FIFTY_SEVEN'" } 537 timeout { fail "(timeout) complete 'p FIFTY_SEVEN' 2" } 538 } 539 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_'"} 551 } 552 } 553 -re ".*$gdb_prompt $" { fail "complete 'p TWENTY_'" } 554 timeout { fail "(timeout) complete 'p TWENTY_' 2" } 555 } 556 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_'"} 568 } 569 } 570 -re ".*$gdb_prompt $" { fail "complete 'p FORTY_'" } 571 timeout { fail "(timeout) complete 'p FORTY_' 2" } 572 } 573 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'" } 588 } 589 } 590 -re ".*$gdb_prompt $" { fail "complete 'p TWENTY_THREE'" } 591 timeout { fail "(timeout) complete 'p TWENTY_THREE' 2" } 592 } 593} 594 595# Splicing tests. 596 597gdb_test "macro expand SPLICE(x, y)" \ 598 "expands to: xy" \ 599 "basic macro splicing" 600 601gdb_test_no_output "macro define robotinvasion 2010" \ 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 610gdb_test_no_output "macro define va_c99(...) varfunc (fixedarg, __VA_ARGS__)" \ 611 "define first varargs helper" 612 613gdb_test_no_output "macro define va2_c99(x, y, ...) varfunc (fixedarg, x, y, __VA_ARGS__)" \ 614 "define second varargs helper" 615 616gdb_test_no_output "macro define va_gnu(args...) varfunc (fixedarg, args)" \ 617 "define third varargs helper" 618 619gdb_test_no_output "macro define va2_gnu(args...) varfunc (fixedarg, ## args)" \ 620 "define fourth varargs helper" 621 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 634gdb_test "macro expand va_c99(one, two, three)" \ 635 "expands to: *varfunc \\(fixedarg, *one, two, three\\)" \ 636 "c99 varargs expansion" 637 638gdb_test "macro expand va_c99()" \ 639 "expands to: *varfunc \\(fixedarg, *\\)" \ 640 "c99 varargs expansion without an argument" 641 642gdb_test "macro expand va2_c99(one, two, three, four)" \ 643 "expands to: *varfunc \\(fixedarg, *one, two, three, four\\)" \ 644 "c99 varargs expansion, multiple formal arguments" 645 646gdb_test "macro expand va_gnu(one, two, three, four)" \ 647 "expands to: *varfunc \\(fixedarg, *one, two, three, four\\)" \ 648 "gnu varargs expansion" 649 650gdb_test "macro expand va_gnu()" \ 651 "expands to: *varfunc \\(fixedarg, *\\)" \ 652 "gnu varargs expansion without an argument" 653 654gdb_test "macro expand va2_gnu()" \ 655 "expands to: *varfunc \\(fixedarg\\)" \ 656 "gnu varargs expansion special splicing without an argument" 657 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 710# Stringification tests. 711 712gdb_test_no_output "macro define str(x) #x" \ 713 "define stringification macro" 714 715gdb_test_no_output "macro define maude 5" \ 716 "define first stringification helper" 717 718gdb_test_no_output "macro define xstr(x) str(x)" \ 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" 748 749# Regression test for pp-number bug. 750gdb_test_no_output "macro define si_addr fields.fault.si_addr" \ 751 "define si_addr macro" 752 753gdb_test "macro expand siginfo.si_addr" \ 754 "expands to: siginfo.fields.fault.si_addr" 755 756gdb_test "print __FILE__" " = \".*macscp1.c\"" 757gdb_test "print __LINE__" \ 758 " = [gdb_get_line_number {stopping point for line test}]" 759