From a879e037b22dea8cb12133823f45c954a16d5542 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 20 Apr 2026 14:38:41 -0400 Subject: [PATCH] gdb: add process_target_ops_ref This is just a more specifically typed version of target_ops_ref, which avoids needing some as_process_stratum_target calls. Change-Id: I9d0d7954bebd3a8b947961752e4816fbced06eb5 Approved-By: Andrew Burgess --- gdb/infcmd.c | 5 +++-- gdb/target.c | 8 +++----- gdb/target.h | 4 +++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 4a907ea8ce8..f3f15c9ae1d 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -3042,7 +3042,8 @@ detach_command (const char *args, int from_tty) detaching the parent. Otherwise detaching could close the target. */ inferior *inf = current_inferior (); - auto target_ref = target_ops_ref::new_reference (inf->process_target ()); + auto target_ref + = process_target_ops_ref::new_reference (inf->process_target ()); /* Save this before detaching, since detaching may unpush the process_stratum target. */ @@ -3068,7 +3069,7 @@ detach_command (const char *args, int from_tty) deprecated_detach_hook (); if (!was_non_stop_p) - restart_after_all_stop_detach (as_process_stratum_target (target_ref.get ())); + restart_after_all_stop_detach (target_ref.get ()); disable_commit_resumed.reset_and_commit (); } diff --git a/gdb/target.c b/gdb/target.c index df2fe5cfd99..5d937f3ae85 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -2562,14 +2562,12 @@ target_detach (inferior *inf, int from_tty) /* Hold a strong reference because detaching may unpush the target. */ - auto proc_target_ref = target_ops_ref::new_reference (inf->process_target ()); + auto proc_target_ref + = process_target_ops_ref::new_reference (inf->process_target ()); current_inferior ()->top_target ()->detach (inf, from_tty); - process_stratum_target *proc_target - = as_process_stratum_target (proc_target_ref.get ()); - - registers_changed_ptid (proc_target, save_pid_ptid); + registers_changed_ptid (proc_target_ref.get (), save_pid_ptid); /* We have to ensure we have no frame cache left. Normally, registers_changed_ptid (save_pid_ptid) calls reinit_frame_cache when diff --git a/gdb/target.h b/gdb/target.h index 9fb29be01b6..81726849d1e 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -1442,7 +1442,9 @@ struct target_ops_ref_policy }; /* A gdb::ref_ptr pointer to a target_ops. */ -typedef gdb::ref_ptr target_ops_ref; +using target_ops_ref = gdb::ref_ptr; +using process_target_ops_ref + = gdb::ref_ptr; /* Native target backends call this once at initialization time to inform the core about which is the target that can respond to "run"