From: Tom de Vries Date: Wed, 23 Jun 2021 21:46:04 +0000 (+0200) Subject: [gdb/testsuite] Rewrite gdb_test_lines X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2dd865d7c13559fe389e0c3e9ba4a92c5e312e9b;p=binutils-gdb.git [gdb/testsuite] Rewrite gdb_test_lines On Ubuntu 20.04, when the debug info package for libc is not installed, I get: FAIL: gdb.base/info-types-c++.exp: info types FAIL: gdb.base/info-types-c.exp: info types The reason is that the output of info types is exactly: (gdb) info types All defined types: File /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.base/info-types.c: 52: typedef enum {...} anon_enum_t; 45: typedef struct {...} anon_struct_t; 68: typedef union {...} anon_union_t; 28: typedef struct baz_t baz; 31: typedef struct baz_t * baz_ptr; 21: struct baz_t; double 33: enum enum_t; float int 38: typedef enum enum_t my_enum_t; 17: typedef float my_float_t; 16: typedef int my_int_t; 54: typedef enum {...} nested_anon_enum_t; 47: typedef struct {...} nested_anon_struct_t; 70: typedef union {...} nested_anon_union_t; 30: typedef struct baz_t nested_baz; 29: typedef struct baz_t nested_baz_t; 39: typedef enum enum_t nested_enum_t; 19: typedef float nested_float_t; 18: typedef int nested_int_t; 62: typedef union union_t nested_union_t; 56: union union_t; unsigned int (gdb) The lines we expect in the test contain an empty line at the end: ... "62:\[\t \]+typedef union union_t nested_union_t;" \ "56:\[\t \]+union union_t;" \ "--optional" "\[\t \]+unsigned int" \ ""] This is written with the supposition that other files will be listed, so an empty line will be included to separate the symbols from this file from the next one. This empty line is not included when info-types.c is the only file listed. Fix this by rewriting gdb_test_lines to accept a single, plain tcl multiline regexp, such that we can write: ... "62:\[\t \]+typedef union union_t nested_union_t;" \ "56:\[\t \]+union union_t;(" \ "\[\t \]+unsigned int)?" \ "($|\r\n.*)"] ... Tested affected test-cases: - gdb.base/info-types-c.exp - gdb.base/info-types-c++.exp - gdb.base/info-macros.exp - gdb.cp/cplusfuncs.exp on x86_64-linux (openSUSE Leap 15.2), both with check and check-read1. Also tested the first two with gcc-4.8. Also tested on ubuntu 18.04. gdb/testsuite/ChangeLog: 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. --- 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. - -proc gdb_test_lines { command message patterns } { +# 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 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