[09/11,gdb/testsuite] Refactor exception handling in lock_file_acquire/release

Message ID 20260824135855.1195963-10-tdevries@suse.de
State New
Headers
Series Refactor exception handling |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Tom de Vries Aug. 24, 2026, 1:58 p.m. UTC
  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(-)
  

Patch

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.