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

Message ID 20260824135855.1195963-12-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-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed

Commit Message

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

Comments

Keith Seitz Sept. 1, 2026, 4:10 p.m. UTC | #1
Hi,

On 8/24/26 6:58 AM, Tom de Vries wrote:
> 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 {}
> +    }

IIUC, this try block using with_override is effectively evaluating
"$body" in this context (with_stub_devices). Previously the
uplevel would cause this to run in the caller.

Is this missing a call to transparent_uplevel?

Keith
  

Patch

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).