[10/11,gdb/testsuite] Refactor exception handling in tentative_rename

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

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm 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 tentative_rename.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34552
---
 gdb/testsuite/lib/gdb.exp | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
  

Patch

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 99468ac3ef3..e69a598bb10 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -8639,17 +8639,18 @@  proc standard_temp_file {basename} {
 # as is and delete A.  Return 1 if rename happened.
 
 proc tentative_rename { a b } {
-    global errorInfo errorCode
-    set code [catch {file rename -- $a $b} result]
-    if { $code == 1 && [lindex $errorCode 0] == "POSIX" \
-	     && [lindex $errorCode 1] == "EEXIST" } {
-	file delete $a
-	return 0
-    }
-    if {$code == 1} {
-	return -code error -errorinfo $errorInfo -errorcode $errorCode $result
-    } elseif {$code > 1} {
-	return -code $code $result
+    try {
+	file rename -- $a $b
+    } on error {result opts} {
+	set errorcode [dict get $opts -errorcode]
+	if { [lindex $errorcode 0] == "POSIX" \
+		 && [lindex $errorcode 1] == "EEXIST" } {
+	    file delete $a
+	    return 0
+	}
+
+	# Rethrow.
+	return -options $opts $result
     }
     return 1
 }