From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [pushed 1/3] [gdb/testsuite] Use transparent_uplevel in foreach_with_prefix
Date: Thu, 24 Sep 2026 16:06:02 +0200 [thread overview]
Message-ID: <20260924140605.1009056-1-tdevries@suse.de> (raw)
After the 2 previous commits:
- foreach_with_prefix is simplified (foreach handles break and continue), and
- PR34553 is fixed in foreach_with_prefix (added -level increment).
It now looks like this:
...
proc foreach_with_prefix {var list body} {
upvar 1 $var myvar
catch {
foreach myvar $list {
with_test_prefix "$var=$myvar" {
uplevel 1 $body
}
}
} result opts
return -options [dict incr opts -level] $result
...
However, IWBN to use transparent_uplevel, which ideally should replace the
catch, the uplevel and the -level increment.
I finally came up with this solution:
...
transparent_uplevel [subst_vars {
foreach $var {$list} {
with_test_prefix "$var=[set $var]" {
$body
}
}
}]
...
which also gets rid of the myvar.
The only gotcha is that the implementation is wrapped in [subst_vars {}],
which provides a way to get values of variables defined in:
- the foreach_with_prefix using $var, and
- the caller using [set var].
---
gdb/testsuite/lib/gdb.exp | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index cad1ac65913..589e25a12e1 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3356,15 +3356,13 @@ proc with_test_prefix { prefix body } {
# including the iterator's name and current value in the prefix.
proc foreach_with_prefix {var list body} {
- upvar 1 $var myvar
- catch {
- foreach myvar $list {
- with_test_prefix "$var=$myvar" {
- uplevel 1 $body
+ transparent_uplevel [subst_vars {
+ foreach $var {$list} {
+ with_test_prefix "$var=[set $var]" {
+ $body
}
}
- } result opts
- return -options [dict incr opts -level] $result
+ }]
}
# Like TCL's native proc, but defines a procedure that wraps its body
base-commit: 0b17fe8b941e1b95535caa61664e96b19c607777
--
2.51.0
next reply other threads:[~2026-09-24 14:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 14:06 Tom de Vries [this message]
2026-09-24 14:06 ` [pushed 2/3] [gdb/testsuite] Add gdb.testsuite/foreach_with_prefix-2.exp Tom de Vries
2026-09-24 14:06 ` [pushed 3/3] [gdb/testsuite] Simplify foreach_mi_ui_mode 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=20260924140605.1009056-1-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