From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 09/11] [gdb/testsuite] Refactor exception handling in lock_file_acquire/release
Date: Mon, 24 Aug 2026 15:58:53 +0200 [thread overview]
Message-ID: <20260824135855.1195963-10-tdevries@suse.de> (raw)
In-Reply-To: <20260824135855.1195963-1-tdevries@suse.de>
Use try/on-error to simplify lock_file_acquire/release.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34552
---
gdb/testsuite/lib/gdb-utils.exp | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.exp
index 1f04a626cbc..35329f3c46e 100644
--- a/gdb/testsuite/lib/gdb-utils.exp
+++ b/gdb/testsuite/lib/gdb-utils.exp
@@ -184,7 +184,9 @@ proc version_compare { l1 op l2 } {
proc lock_file_acquire {lockfile} {
verbose -log "acquiring lock file: $::subdir/${::gdb_test_file_name}.exp"
while {true} {
- if {![catch {open $lockfile {WRONLY CREAT EXCL}} rc]} {
+ try {
+ open $lockfile {WRONLY CREAT EXCL}
+ } on ok {rc} {
set msg "locked by $::subdir/${::gdb_test_file_name}.exp"
verbose -log "lock file: $msg"
# For debugging, put info in the lockfile about who owns
@@ -192,6 +194,8 @@ proc lock_file_acquire {lockfile} {
puts $rc $msg
flush $rc
return [list $rc $lockfile]
+ } on error {} {
+ # Ignore and try again.
}
after 10
}
@@ -202,18 +206,20 @@ proc lock_file_acquire {lockfile} {
proc lock_file_release {info} {
verbose -log "releasing lock file: $::subdir/${::gdb_test_file_name}.exp"
- if {![catch {fconfigure [lindex $info 0]}]} {
- if {![catch {
- close [lindex $info 0]
- file delete -force [lindex $info 1]
- } rc]} {
- return ""
- } else {
- return -code error "Error releasing lockfile: '$rc'"
- }
- } else {
+ try {
+ fconfigure [lindex $info 0]
+ } on error {} {
error "invalid lock"
}
+
+ try {
+ close [lindex $info 0]
+ file delete -force [lindex $info 1]
+ } on error {rc} {
+ error "Error releasing lockfile: '$rc'"
+ }
+
+ return ""
}
# Return directory where we keep lock files.
--
2.51.0
next prev parent reply other threads:[~2026-08-24 14:02 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 ` [PATCH 04/11] [gdb/testsuite] Refactor exception handling in foreach_with_prefix Tom de Vries
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 ` Tom de Vries [this message]
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-10-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