]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/testsuite] Rewrite gdb_test_lines
authorTom de Vries <tdevries@suse.de>
Wed, 23 Jun 2021 21:46:04 +0000 (23:46 +0200)
committerTom de Vries <tdevries@suse.de>
Wed, 23 Jun 2021 21:46:04 +0000 (23:46 +0200)
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  <tdevries@suse.de>

* 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.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/info-macros.exp
gdb/testsuite/gdb.base/info-types.exp.tcl
gdb/testsuite/gdb.cp/cplusfuncs.exp
gdb/testsuite/lib/gdb.exp

index 19f780f83528471a01e0041633f5a86409783a47..a790e6856ae13aa61c7ed9b9544cb581883d1f57 100644 (file)
@@ -1,3 +1,12 @@
+2021-06-23  Tom de Vries  <tdevries@suse.de>
+
+       * 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  <schwab@suse.de>
 
        PR symtab/27999
index 3d096a3db51c0e44d534111288c10aa813ab624c..44b0b45988d06af876647c5e2cd261ddbad83310 100644 (file)
@@ -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"]
index c820adc4ac1721fbdc27c1583ceb2fd0a8f32ec4..20b54dad299cda7bf5d671963be4700bfe6c8d81 100644 (file)
@@ -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
index 19be8abc2acc651d263f5d8c21fe0b01ebde2d17..737401553057ade1eaa6bcda28c93eb3b2f0f6c0 100644 (file)
@@ -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}.*"]
 }
index 4bb2da31c1f3139403faf807337fca7a03b36a80..02b65617ea4037502c64d692b05ac0b772656560 100644 (file)
@@ -1432,86 +1432,41 @@ proc gdb_test_sequence { args } {
 }
 
 \f
-# 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
+#   <line1>^M
+#   <line2>^M
+#   (gdb)
+# the portion matched using RE is:
+#  '<line1>^M
+#   <line2>^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