[gdb/testsuite] Disallow single argument in multi_line
authorTom de Vries <tdevries@suse.de>
Tue, 8 Jun 2021 15:39:05 +0000 (17:39 +0200)
committerTom de Vries <tdevries@suse.de>
Tue, 8 Jun 2021 15:39:05 +0000 (17:39 +0200)
It's a common mistake of mine to do:
...
set l [list "foo" "bar"]
set re [multi_line $l]
...
and to get "foo bar" while I was expecting "foo\r\nbar", which I get after
doing instead:
...
set re [multi_line {*}$l]
...

Detect this type of mistake by erroring out in multi_line when only one
argument is passed.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2021-06-08  Tom de Vries  <tdevries@suse.de>

* lib/gdb.exp (multi_line): Require more than one argument.
* gdb.base/gdbinit-history.exp: Update multi_line call.
* gdb.base/jit-reader.exp: Remove multi_line call.
* gdb.fortran/dynamic-ptype-whatis.exp: Same.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/gdbinit-history.exp
gdb/testsuite/gdb.base/jit-reader.exp
gdb/testsuite/gdb.fortran/dynamic-ptype-whatis.exp
gdb/testsuite/lib/gdb.exp

index e2f1486af348ff2198ba9afc4bd04b9d8e164de3..51abd0e0cffc4ccce3fc98269376aa38c0f66a3f 100644 (file)
@@ -1,3 +1,10 @@
+2021-06-08  Tom de Vries  <tdevries@suse.de>
+
+       * lib/gdb.exp (multi_line): Require more than one argument.
+       * gdb.base/gdbinit-history.exp: Update multi_line call.
+       * gdb.base/jit-reader.exp: Remove multi_line call.
+       * gdb.fortran/dynamic-ptype-whatis.exp: Same.
+
 2021-06-08  Tom de Vries  <tdevries@suse.de>
 
        * gdb.base/info-types.exp.tcl (match_line, gdb_test_lines): Move ...
index 8e3994e60527f5cf02d1f8390059ebac0c05e972..36f4a114a719453459022df165af331285206a36 100644 (file)
@@ -144,7 +144,11 @@ proc check_history { hist } {
        lappend hist_lines "    $idx  $h"
        incr idx
     }
-    set pattern [eval multi_line $hist_lines]
+    if { [llength $hist_lines] == 1 } {
+       set pattern [lindex $hist_lines 0]
+    } else {
+       set pattern [eval multi_line $hist_lines]
+    }
 
     # Check the history.
     gdb_test "show commands" "$pattern.*"
index 25d1100ca60976a74ec03d52eec77f4f46db0888..83e403653d69ac7ef87635f8ff5231ea60998fd1 100644 (file)
@@ -240,9 +240,7 @@ proc jit_reader_test {} {
        # the built-in unwinder cannot backtrace through the mangled
        # stack pointer.
        gdb_test "bt" \
-           [multi_line \
-                "Backtrace stopped: Cannot access memory at address $sp_after_mangling" \
-               ] \
+           "Backtrace stopped: Cannot access memory at address $sp_after_mangling" \
            "bt shows error"
 
        gdb_test "info frame" "Cannot access memory at address.*" \
index d2ffd6d73f7c865be01549114c0b04c54232c7cb..5ea2aa48a050bb00e4c9893fc14e2aa4122f386d 100644 (file)
@@ -73,7 +73,7 @@ gdb_test "whatis var4%t2_array" "type = Type type1, allocatable \\(3\\)"
 gdb_test "whatis var5%t3_array" "type = Type type1 \\(3\\)"
 gdb_test "whatis var6%t4_array" "type = Type type2, allocatable \\(3\\)"
 gdb_test "whatis var7%t5_array" "type = Type type2 \\(4\\)"
-gdb_test "ptype var3%t1_i" [ multi_line "type = integer\\(kind=4\\)" ]
+gdb_test "ptype var3%t1_i" "type = integer\\(kind=4\\)"
 gdb_test "ptype var4%t2_array" [ multi_line "type = Type type1" \
                                     "    integer\\(kind=4\\) :: spacer" \
                                     "    integer\\(kind=4\\) :: t1_i" \
index f7ab2198a25cf6ec4e584788879b42b65c4d927b..8469ec9801c0fccf599003a9344f3a426c24fb28 100644 (file)
@@ -7294,6 +7294,10 @@ proc capture_command_output { command prefix } {
 # being.
 
 proc multi_line { args } {
+    if { [llength $args] == 1 } {
+       set hint "forgot {*} before list argument?"
+       error "multi_line called with one argument ($hint)"
+    }
     return [join $args "\r\n"]
 }
 
This page took 0.036414 seconds and 4 git commands to generate.