Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb: add process_target_ops_ref
@ 2026-04-20 18:38 Simon Marchi
  2026-04-21  9:26 ` Andrew Burgess
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2026-04-20 18:38 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

This is just a more specifically typed version of target_ops_ref, which
avoids needing some as_process_stratum_target calls.

Change-Id: I9d0d7954bebd3a8b947961752e4816fbced06eb5
---
 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 4a907ea8ce86..f3f15c9ae1d0 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 df2fe5cfd990..5d937f3ae858 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 9fb29be01b69..81726849d1e7 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, target_ops_ref_policy> target_ops_ref;
+using target_ops_ref = gdb::ref_ptr<target_ops, target_ops_ref_policy>;
+using process_target_ops_ref
+  = gdb::ref_ptr<process_stratum_target, target_ops_ref_policy>;
 
 /* Native target backends call this once at initialization time to
    inform the core about which is the target that can respond to "run"

base-commit: 9b9cbb09d85e40adb9a22f3c97de74b6c9c5e205
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: add process_target_ops_ref
  2026-04-20 18:38 [PATCH] gdb: add process_target_ops_ref Simon Marchi
@ 2026-04-21  9:26 ` Andrew Burgess
  2026-04-21 14:27   ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2026-04-21  9:26 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches; +Cc: Simon Marchi

Simon Marchi <simon.marchi@efficios.com> writes:

> This is just a more specifically typed version of target_ops_ref, which
> avoids needing some as_process_stratum_target calls.

LGTM.

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew

>
> Change-Id: I9d0d7954bebd3a8b947961752e4816fbced06eb5
> ---
>  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 4a907ea8ce86..f3f15c9ae1d0 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 df2fe5cfd990..5d937f3ae858 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 9fb29be01b69..81726849d1e7 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, target_ops_ref_policy> target_ops_ref;
> +using target_ops_ref = gdb::ref_ptr<target_ops, target_ops_ref_policy>;
> +using process_target_ops_ref
> +  = gdb::ref_ptr<process_stratum_target, target_ops_ref_policy>;
>  
>  /* Native target backends call this once at initialization time to
>     inform the core about which is the target that can respond to "run"
>
> base-commit: 9b9cbb09d85e40adb9a22f3c97de74b6c9c5e205
> -- 
> 2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: add process_target_ops_ref
  2026-04-21  9:26 ` Andrew Burgess
@ 2026-04-21 14:27   ` Simon Marchi
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2026-04-21 14:27 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 4/21/26 5:26 AM, Andrew Burgess wrote:
> Simon Marchi <simon.marchi@efficios.com> writes:
> 
>> This is just a more specifically typed version of target_ops_ref, which
>> avoids needing some as_process_stratum_target calls.
> 
> LGTM.
> 
> Approved-By: Andrew Burgess <aburgess@redhat.com>
> 
> Thanks,
> Andrew

Thanks, pushed.

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-21 14:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-20 18:38 [PATCH] gdb: add process_target_ops_ref Simon Marchi
2026-04-21  9:26 ` Andrew Burgess
2026-04-21 14:27   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox