From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 04/11] [gdb/testsuite] Refactor exception handling in foreach_with_prefix
Date: Mon, 24 Aug 2026 15:58:48 +0200 [thread overview]
Message-ID: <20260824135855.1195963-5-tdevries@suse.de> (raw)
In-Reply-To: <20260824135855.1195963-1-tdevries@suse.de>
Refactor foreach_with_prefix using return -options.
Likewise in foreach_mi_ui_mode.
Both procs also have the return -level 2 problem (PR34553), so fix this using
"[dict incr opts -level]".
Also add a PR34553 regression test for foreach_with_prefix.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34553
---
.../gdb.testsuite/foreach_with_prefix.exp | 27 +++++++++++++++++++
gdb/testsuite/lib/gdb.exp | 12 +++------
gdb/testsuite/lib/mi-support.exp | 12 +++------
3 files changed, 33 insertions(+), 18 deletions(-)
diff --git a/gdb/testsuite/gdb.testsuite/foreach_with_prefix.exp b/gdb/testsuite/gdb.testsuite/foreach_with_prefix.exp
index 04762d9baef..20a0f1022be 100644
--- a/gdb/testsuite/gdb.testsuite/foreach_with_prefix.exp
+++ b/gdb/testsuite/gdb.testsuite/foreach_with_prefix.exp
@@ -71,6 +71,33 @@ with_test_prefix "return" {
check_sequence $seq "0 0"
}
+# Test TCL_RETURN (2), level 2.
+foreach foreach_variant {foreach foreach_with_prefix} {
+ with_test_prefix "$foreach_variant: return level 2" {
+ proc test_return_level_2_inner {} {
+ set seq ""
+ $::foreach_variant var1 {0 1} {
+ $::foreach_variant var2 {0 1} {
+ lappend seq $var1 $var2
+ return -level 2 $seq
+ }
+ }
+ return $seq
+ }
+ proc test_return_level_2_outer {} {
+ test_return_level_2_inner
+ return "outer"
+ }
+
+ try {
+ set seq "initial"
+ set seq [test_return_level_2_outer]
+ } finally {
+ check_sequence $seq "0 0"
+ }
+ }
+}
+
# Test TCL_BREAK (3).
with_test_prefix "break" {
set seq ""
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index c8254ac9dd3..88a42aff4ac 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3305,20 +3305,14 @@ proc with_test_prefix { prefix body } {
proc foreach_with_prefix {var list body} {
upvar 1 $var myvar
- set code [catch {
+ catch {
foreach myvar $list {
with_test_prefix "$var=$myvar" {
uplevel 1 $body
}
}
- } result]
-
- if {$code == 1} {
- global errorInfo errorCode
- return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
- } else {
- return -code $code $result
- }
+ } result opts
+ return -options [dict incr opts -level] $result
}
# Like TCL's native proc, but defines a procedure that wraps its body
diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index 2e87769b538..240bc844350 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -2931,20 +2931,14 @@ proc foreach_mi_ui_mode { var_name body } {
set modes {"main" "separate"}
}
- set code [catch {
+ catch {
foreach var $modes {
with_test_prefix "$var_name=$var" {
uplevel 1 $body
}
}
- } result]
-
- if {$code == 1} {
- global errorInfo errorCode
- return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
- } else {
- return -code $code $result
- }
+ } result opts
+ return -options [dict incr opts -level] $result
}
# Check if GDB has information about the stderr symbol.
--
2.51.0
next prev parent reply other threads:[~2026-08-24 14:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 13:58 [PATCH 00/11] [gdb/testsuite] Refactor exception handling Tom de Vries
2026-08-24 13:58 ` [PATCH 01/11] [gdb/testsuite] Normalize indentation in with_test_prefix Tom de Vries
2026-08-24 13:58 ` [PATCH 02/11] [gdb/testsuite] Fix return -level 2 bug " Tom de Vries
2026-08-24 13:58 ` [PATCH 03/11] [gdb/testsuite] Simplify foreach_with_prefix Tom de Vries
2026-08-24 13:58 ` Tom de Vries [this message]
2026-08-24 13:58 ` [PATCH 05/11] [gdb/testsuite] Add transparent_uplevel Tom de Vries
2026-08-24 13:58 ` [PATCH 06/11] [gdb/testsuite] Refactor exception handling Tom de Vries
2026-08-24 13:58 ` [PATCH 07/11] [gdb/testsuite] Refactor exception handling in gdb_expect Tom de Vries
2026-08-24 13:58 ` [PATCH 08/11] [gdb/testsuite] Refactor exception handling in gdb_test_multiple Tom de Vries
2026-08-25 7:29 ` Tom de Vries
2026-08-24 13:58 ` [PATCH 09/11] [gdb/testsuite] Refactor exception handling in lock_file_acquire/release Tom de Vries
2026-08-24 13:58 ` [PATCH 10/11] [gdb/testsuite] Refactor exception handling in tentative_rename Tom de Vries
2026-08-24 13:58 ` [PATCH 11/11] [gdb/testsuite] Refactor exception handling in with_stub_devices Tom de Vries
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=20260824135855.1195963-5-tdevries@suse.de \
--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