Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [committed][gdb/testsuite] Catch condition evaluation errors in gdb_assert
Date: Wed, 16 Sep 2020 13:28:10 +0200	[thread overview]
Message-ID: <20200916112809.GA13830@delia> (raw)

Hi,

When running test-case gdb.base/watchpoint-stops-at-right-insn.exp, we may run
into a tcl error, which can be reproduced reliably using this trigger patch:
...
+       set hw_watch_pc ""
        gdb_assert {$sw_watch_pc == $hw_watch_pc} \
	  "hw watchpoint stops at right instruction"
...
such that we have:
...
ERROR: tcl error sourcing watchpoint-stops-at-right-insn.exp.
ERROR: missing operand at _@_
in expression "0x4004b7 == _@_"
    (parsing expression "0x4004b7 == ")
    invoked from within
"expr $sw_watch_pc == $hw_watch_pc"
    ("uplevel" body line 1)
    invoked from within
"uplevel 1 expr $condition"
    (procedure "gdb_assert" line 6)
    invoked from within
"gdb_assert {$sw_watch_pc == $hw_watch_pc} \
  "hw watchpoint stops at right instruction""
...

A similar problem was fixed in commit 5f0e2eb79e "GDB/testsuite: Fix a
catastrophic step-over-no-symbols.exp failure", by making the assert condition
more robust:
...
-    gdb_assert {$before_addr != $after_addr} "advanced"
+    gdb_assert {{[string is integer -strict $before_addr] \
+                && [string is integer -strict $after_addr] \
+                && $before_addr != $after_addr}} "advanced"
...

Fix this instead in gdb_assert, by catching errors while evaluating the assert
condition.

Tested on x86_64-linux.

Committed to trunk.

Thanks,
- Tom

[gdb/testsuite] Catch condition evaluation errors in gdb_assert

gdb/testsuite/ChangeLog:

2020-09-16  Tom de Vries  <tdevries@suse.de>

	PR testsuite/26624
	* lib/gdb.exp (gdb_assert): Catch errors in condition evaluation.

---
 gdb/testsuite/lib/gdb.exp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 653f145c1c..59439f8e37 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -1689,8 +1689,8 @@ proc gdb_assert { condition {message ""} } {
 	set message $condition
     }
 
-    set res [uplevel 1 expr $condition]
-    if {!$res} {
+    set code [catch {uplevel 1 expr $condition} res]
+    if {$code != 0 || !$res} {
 	fail $message
     } else {
 	pass $message


                 reply	other threads:[~2020-09-16 11:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200916112809.GA13830@delia \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox