gdb/testsuite: show evaluation errors in gdb_assert
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 23 Nov 2020 22:26:00 +0000 (17:26 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 23 Nov 2020 22:26:00 +0000 (17:26 -0500)
Let's say you put this gdb_assert in a test:

    gdb_assert "some invalid tcl code"

You just get:

    FAIL: gdb.base/template.exp: some invalid tcl code

That's not very easy to debug, since you don't know what's invalid in
your code.

Change gdb_assert to print the error message when catch's return code is
1 (TCL_ERROR).  The "warning" is shown both on stdout and in the log
file.  Mark the test as unresolved, because the evaluation error means
we couldn't reach a valid pass/fail conclusion.

gdb/testsuite/ChangeLog:

* lib/gdb.exp (gdb_assert): Show error message on error.

Change-Id: Ie6477859554e909ed8d07fb2769c6f2f55e7cce6

gdb/testsuite/ChangeLog
gdb/testsuite/lib/gdb.exp

index da7823fddf29905225a0d34a9755b39713102937..d6358dd88563068d84c360ccbb289d63125a8761 100644 (file)
@@ -1,3 +1,7 @@
+2020-11-23  Simon Marchi  <simon.marchi@efficios.com>
+
+       * lib/gdb.exp (gdb_assert): Show error message on error.
+
 2020-11-23  Tom de Vries  <tdevries@suse.de>
 
        * gdb.ada/enum_idx_packed.exp: Limit setup_kfail to gnat 9 and 10.
index c42933b3f41ec540762393bfb0d30c5c4d160366..f2954fd5192be628778e6c8a0480388770881419 100644 (file)
@@ -1728,7 +1728,14 @@ proc gdb_assert { condition {message ""} } {
     }
 
     set code [catch {uplevel 1 expr $condition} res]
-    if {$code != 0 || !$res} {
+    if {$code == 1} {
+       # If code is 1 (TCL_ERROR), it means evaluation failed and res contains
+       # an error message.  Print the error message, and set res to 0 since we
+       # want to return a boolean.
+       warning "While evaluating expression in gdb_assert: $res"
+       unresolved $message
+       set res 0
+    } elseif { !$res } {
        fail $message
     } else {
        pass $message
This page took 0.037548 seconds and 4 git commands to generate.