[06/12] gdb: add gdbarch_up

Message ID 20221206135729.3937767-7-simon.marchi@efficios.com
State Committed
Commit d246d904adf3e338c731c123219a8246281002e2
Headers
Series Initial support for ROCm platform (AMDGPU) debugging |

Commit Message

Simon Marchi Dec. 6, 2022, 1:57 p.m. UTC
  Add a gdbarch_up unique pointer type, that calls gdbarch_free on
deletion.  This is used in the ROCm support patch at the end of this
series.

Change-Id: I4b808892d35d69a590ce83180f41afd91705b2c8
---
 gdb/gdbarch.h | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Comments

Andrew Burgess Dec. 6, 2022, 5:07 p.m. UTC | #1
Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

> Add a gdbarch_up unique pointer type, that calls gdbarch_free on
> deletion.  This is used in the ROCm support patch at the end of this
> series.

LGTM.

Thanks,
Andrew

>
> Change-Id: I4b808892d35d69a590ce83180f41afd91705b2c8
> ---
>  gdb/gdbarch.h | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
> index 196c7981450..d3af5ee00d1 100644
> --- a/gdb/gdbarch.h
> +++ b/gdb/gdbarch.h
> @@ -306,6 +306,14 @@ extern struct gdbarch *gdbarch_alloc (const struct gdbarch_info *info,
>  
>  extern void gdbarch_free (struct gdbarch *);
>  
> +struct gdbarch_deleter
> +{
> +  void operator() (gdbarch *arch) const
> +  { gdbarch_free (arch); }
> +};
> +
> +using gdbarch_up = std::unique_ptr<gdbarch, gdbarch_deleter>;
> +
>  /* Get the obstack owned by ARCH.  */
>  
>  extern obstack *gdbarch_obstack (gdbarch *arch);
> -- 
> 2.38.1
  

Patch

diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 196c7981450..d3af5ee00d1 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -306,6 +306,14 @@  extern struct gdbarch *gdbarch_alloc (const struct gdbarch_info *info,
 
 extern void gdbarch_free (struct gdbarch *);
 
+struct gdbarch_deleter
+{
+  void operator() (gdbarch *arch) const
+  { gdbarch_free (arch); }
+};
+
+using gdbarch_up = std::unique_ptr<gdbarch, gdbarch_deleter>;
+
 /* Get the obstack owned by ARCH.  */
 
 extern obstack *gdbarch_obstack (gdbarch *arch);