From patchwork Wed Jul 3 17:09:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 33521 Received: (qmail 28192 invoked by alias); 3 Jul 2019 17:09:05 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 27955 invoked by uid 89); 3 Jul 2019 17:09:05 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 03 Jul 2019 17:09:04 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EEE83308330D for ; Wed, 3 Jul 2019 17:09:02 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E91C832AE for ; Wed, 3 Jul 2019 17:09:02 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [pushed] Fix early return in foreach_with_prefix Date: Wed, 3 Jul 2019 18:09:00 +0100 Message-Id: <20190703170900.10951-1-palves@redhat.com> 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 * lib/gdb.exp (foreach_with_prefix): Use "catch" and "return -code". --- 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 38dcfd38df0..90b5f8ff8b5 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-07-03 Pedro Alves + + * lib/gdb.exp (foreach_with_prefix): Use "catch" and + "return -code". + 2019-07-03 Pedro Alves PR cli/24732 diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index da36ec0d4aa..41f0ef58393 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 } } }