public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pedro Alves <palves@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Fix early return in foreach_with_prefix
Date: Wed, 03 Jul 2019 17:08:00 -0000	[thread overview]
Message-ID: <20190703170848.14224.qmail@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a26c8de0ee938a48bc6f6232cdfac1a5eabaa778

commit a26c8de0ee938a48bc6f6232cdfac1a5eabaa778
Author: Pedro Alves <palves@redhat.com>
Date:   Wed Jul 3 18:05:20 2019 +0100

    Fix early return in foreach_with_prefix
    
    I noticed that an early return in a foreach_with_prefix block does not
    cause the outer scope to return, like:
    
      foreach_with_prefix var {"foo" "bar"} {
         return
      }
      # Control continues here, but it should not.
    
    The problem is that we're missing the usual "return -code" treatment.
    This commit fixes it.
    
    gdb/testsuite/ChangeLog:
    2019-07-03  Pedro Alves  <palves@redhat.com>
    
    	* lib/gdb.exp (foreach_with_prefix): Use "catch" and
    	"return -code".

Diff:
---
 gdb/testsuite/ChangeLog   | 5 +++++
 gdb/testsuite/lib/gdb.exp | 9 ++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 38dcfd3..90b5f8f 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@
 2019-07-03  Pedro Alves  <palves@redhat.com>
 
+	* lib/gdb.exp (foreach_with_prefix): Use "catch" and
+	"return -code".
+
+2019-07-03  Pedro Alves  <palves@redhat.com>
+
 	PR cli/24732
 	* gdb.base/shell.exp: Load completion-support.exp.
 	Adjust expected error output.  Add completion tests.
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index da36ec0..41f0ef5 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -2025,7 +2025,14 @@ proc foreach_with_prefix {var list body} {
     upvar 1 $var myvar
     foreach myvar $list {
 	with_test_prefix "$var=$myvar" {
-	    uplevel 1 $body
+	    set code [catch {uplevel 1 $body} result]
+	}
+
+	if {$code == 1} {
+	    global errorInfo errorCode
+	    return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
+	} else {
+	    return -code $code $result
 	}
     }
 }


                 reply	other threads:[~2019-07-03 17:08 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=20190703170848.14224.qmail@sourceware.org \
    --to=palves@sourceware.org \
    --cc=gdb-cvs@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).