diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 19f780f8352..a790e6856ae 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2021-06-23 Tom de Vries + + * lib/gdb.exp (gdb_test_lines): Rewrite to accept single + multiline tcl regexp. + * gdb.base/info-types.exp.tcl: Update. Make empty line at end of + regexp optional. + * gdb.base/info-macros.exp: Update. + * gdb.cp/cplusfuncs.exp: Update. + 2021-06-22 Andreas Schwab PR symtab/27999 diff --git a/gdb/testsuite/gdb.base/info-macros.exp b/gdb/testsuite/gdb.base/info-macros.exp index 3d096a3db51..44b0b45988d 100644 --- a/gdb/testsuite/gdb.base/info-macros.exp +++ b/gdb/testsuite/gdb.base/info-macros.exp @@ -273,6 +273,9 @@ gdb_test_multiple_with_read1_timeout_factor 10 "$test" $testname { set test "info macros info-macros.c:42" -set r1 "#define DEF_MACROS" +set r1 "#define DEF_MACROS " set r2 "#define ONE" -gdb_test_lines "$test" "" [list $r1 "--any" $r2] +gdb_test_lines "$test" "" [multi_line \ + "" \ + "$r1" \ + "(.*\r\n)?$r2"] diff --git a/gdb/testsuite/gdb.base/info-types.exp.tcl b/gdb/testsuite/gdb.base/info-types.exp.tcl index c820adc4ac1..20b54dad299 100644 --- a/gdb/testsuite/gdb.base/info-types.exp.tcl +++ b/gdb/testsuite/gdb.base/info-types.exp.tcl @@ -43,8 +43,8 @@ proc run_test { lang } { if { $lang == "c++" } { set output_lines \ [list \ - "All defined types:" \ - "--any" \ + "^All defined types:" \ + ".*" \ $file_re \ "98:\[\t \]+CL;" \ "42:\[\t \]+anon_struct_t;" \ @@ -74,14 +74,14 @@ proc run_test { lang } { "39:\[\t \]+typedef enum_t nested_enum_t;" \ "19:\[\t \]+typedef float nested_float_t;" \ "18:\[\t \]+typedef int nested_int_t;" \ - "62:\[\t \]+typedef union_t nested_union_t;" \ - "--optional" "\[\t \]+unsigned int" \ - ""] + "62:\[\t \]+typedef union_t nested_union_t;(" \ + "\[\t \]+unsigned int)?" \ + "($|\r\n.*)"] } else { set output_lines \ [list \ - "All defined types:" \ - "--any" \ + "^All defined types:" \ + ".*" \ $file_re \ "52:\[\t \]+typedef enum {\\.\\.\\.} anon_enum_t;" \ "45:\[\t \]+typedef struct {\\.\\.\\.} anon_struct_t;" \ @@ -105,12 +105,12 @@ proc run_test { lang } { "19:\[\t \]+typedef float nested_float_t;" \ "18:\[\t \]+typedef int nested_int_t;" \ "62:\[\t \]+typedef union union_t nested_union_t;" \ - "56:\[\t \]+union union_t;" \ - "--optional" "\[\t \]+unsigned int" \ - ""] + "56:\[\t \]+union union_t;(" \ + "\[\t \]+unsigned int)?" \ + "($|\r\n.*)"] } - gdb_test_lines "info types" "" $output_lines + gdb_test_lines "info types" "" [multi_line {*}$output_lines] } run_test $lang diff --git a/gdb/testsuite/gdb.cp/cplusfuncs.exp b/gdb/testsuite/gdb.cp/cplusfuncs.exp index 19be8abc2ac..73740155305 100644 --- a/gdb/testsuite/gdb.cp/cplusfuncs.exp +++ b/gdb/testsuite/gdb.cp/cplusfuncs.exp @@ -294,7 +294,7 @@ proc info_func_regexp { name demangled } { set file_re "File .*[string_to_regexp $srcfile]:" gdb_test_lines "info function $name" "info function for \"$name\"" \ - [list \ + [multi_line \ "$file_re" \ "$decimal:\t(class|)${demangled}.*"] } diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 4bb2da31c1f..02b65617ea4 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -1432,86 +1432,41 @@ proc gdb_test_sequence { args } { } -# Match LINE against regexp OUTPUT_LINES[IDX]. Helper function for -# gdb_test_lines. -proc match_line { line output_lines idx_name } { - upvar $idx_name idx - - while { 1 } { - if { $idx == [llength $output_lines] } { - # Ran out of regexps, bail out. - return -1 - } - - set re [lindex $output_lines $idx] - set opt 0 - set any 0 - if { $re == "--optional" } { - # Optional, get actual regexp. - set opt 1 - incr idx - set re [lindex $output_lines $idx] - } elseif { $re == "--any" } { - set any 1 - incr idx - set re [lindex $output_lines $idx] - } - - if { [regexp $re $line] } { - # Match. - incr idx - if { $idx == [llength $output_lines] } { - # Last match, we're done. - return 1 - } - # Match found, keep looking for next match. - return 0 - } else { - # No match. - if { $idx == 0 } { - # First match not found, just keep looking for first match. - return 0 - } elseif { $opt } { - # Try next regexp on same line. - incr idx - continue - } elseif { $any } { - # Try again with next line. - incr idx -1 - return 0 - } else { - # Mismatch, bail out. - return -1 - } - } - break - } - - # Keep going. - return 0 -} - -# Match output of COMMAND line-by-line, using PATTERNS. +# Match output of COMMAND using RE. Read output line-by-line. # Report pass/fail with MESSAGE. +# For a command foo with output: +# (gdb) foo^M +# ^M +# ^M +# (gdb) +# the portion matched using RE is: +# '^M +# ^M +# ' -proc gdb_test_lines { command message patterns } { +proc gdb_test_lines { command message re } { set found 0 set idx 0 if { $message == ""} { set message $command } + set lines "" gdb_test_multiple $command $message { -re "\r\n(\[^\r\n\]*)(?=\r\n)" { - if { $found == 0 } { - set line $expect_out(1,string) - set found [match_line $line $patterns idx] + set line $expect_out(1,string) + if { $lines eq "" } { + append lines "$line" + } else { + append lines "\r\n$line" } exp_continue } -re -wrap "" { - gdb_assert { $found == 1 } $gdb_test_name + append lines "\r\n" } } + + gdb_assert { [regexp $re $lines] } $message } # Test that a command gives an error. For pass or fail, return