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