[PATCH 11/11] [gdb/testsuite] Refactor exception handling in with_stub_devices

Tom de Vries <[email protected]>
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
Use with_override and try/finally to simplify with_stub_devices.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34552
---
 gdb/testsuite/gdb.rocm/hcc-amdgpu-targets.exp | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/gdb/testsuite/gdb.rocm/hcc-amdgpu-targets.exp b/gdb/testsuite/gdb.rocm/hcc-amdgpu-targets.exp
index 8f04cca7981..7f90a112138 100644
--- a/gdb/testsuite/gdb.rocm/hcc-amdgpu-targets.exp
+++ b/gdb/testsuite/gdb.rocm/hcc-amdgpu-targets.exp
@@ -24,13 +24,16 @@ load_lib rocm.exp
 # Run BODY with find_amdgpu_devices stubbed to return DEVICES, then
 # restore the original proc.
 proc with_stub_devices {devices body} {
-    rename find_amdgpu_devices __saved_find_amdgpu_devices
     # tclint-disable-next-line command-args
-    proc find_amdgpu_devices {} [list return $devices]
-    set code [catch {uplevel 1 $body} result]
-    rename find_amdgpu_devices {}
-    rename __saved_find_amdgpu_devices find_amdgpu_devices
-    return -code $code $result
+    proc with_stub_devices_find_amdgpu_devices {} [list return $devices]
+    try {
+	# tclint-disable-next-line command-args
+	with_override \
+	    find_amdgpu_devices with_stub_devices_find_amdgpu_devices \
+	    $body
+    } finally {
+	rename with_stub_devices_find_amdgpu_devices {}
+    }
 }
 
 # Tests using find_amdgpu_devices (no HCC_AMDGPU_TARGET env var).
-- 
2.51.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.