[RFA,1/5] Use new and delete for struct infcall_suspend_state

Message ID 20180711141552.10136-2-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey July 11, 2018, 2:15 p.m. UTC
  This changes infrun.c to use new and delete for infcall_suspend_state.
This enables the coming cleanups.

gdb/ChangeLog
2018-07-11  Tom Tromey  <tom@tromey.com>

	* infrun.c (struct infcall_suspend_state): Add initializers.
	(save_infcall_suspend_state): Use new.
	(discard_infcall_suspend_state): Use delete.
---
 gdb/ChangeLog |  6 ++++++
 gdb/infrun.c  | 12 ++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)
  

Comments

Simon Marchi July 11, 2018, 3:32 p.m. UTC | #1
On 2018-07-11 10:15, Tom Tromey wrote:
> diff --git a/gdb/infrun.c b/gdb/infrun.c
> index dd7e69e718e..da71f3132a0 100644
> --- a/gdb/infrun.c
> +++ b/gdb/infrun.c
> @@ -8810,18 +8810,18 @@ siginfo_make_value (struct gdbarch *gdbarch,
> struct internalvar *var,
> 
>  struct infcall_suspend_state
>  {
> -  struct thread_suspend_state thread_suspend;
> +  struct thread_suspend_state thread_suspend {};

Small nit: You could push the {} initialization to the 
thread_suspend_state class.  That is, initialize thread_suspend_state's 
fields directly.  You can then remove these {}, as well as on 
thread_info::suspend.

Simon
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7c74c87d8c5..8c0d7b5f6a9 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@ 
+2018-07-11  Tom Tromey  <tom@tromey.com>
+
+	* infrun.c (struct infcall_suspend_state): Add initializers.
+	(save_infcall_suspend_state): Use new.
+	(discard_infcall_suspend_state): Use delete.
+
 2018-07-11  Alan Hayward  <alan.hayward@arm.com>
 
 	* target-descriptions.c (tdesc_register_bitsize): Rename.
diff --git a/gdb/infrun.c b/gdb/infrun.c
index dd7e69e718e..da71f3132a0 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -8810,18 +8810,18 @@  siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var,
 
 struct infcall_suspend_state
 {
-  struct thread_suspend_state thread_suspend;
+  struct thread_suspend_state thread_suspend {};
 
   /* Other fields:  */
-  readonly_detached_regcache *registers;
+  readonly_detached_regcache *registers = nullptr;
 
   /* Format of SIGINFO_DATA or NULL if it is not present.  */
-  struct gdbarch *siginfo_gdbarch;
+  struct gdbarch *siginfo_gdbarch = nullptr;
 
   /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
      TYPE_LENGTH (gdbarch_get_siginfo_type ()).  For different gdbarch the
      content would be invalid.  */
-  gdb_byte *siginfo_data;
+  gdb_byte *siginfo_data = nullptr;
 };
 
 struct infcall_suspend_state *
@@ -8853,7 +8853,7 @@  save_infcall_suspend_state (void)
 	}
     }
 
-  inf_state = XCNEW (struct infcall_suspend_state);
+  inf_state = new struct infcall_suspend_state;
 
   if (siginfo_data)
     {
@@ -8919,7 +8919,7 @@  discard_infcall_suspend_state (struct infcall_suspend_state *inf_state)
 {
   delete inf_state->registers;
   xfree (inf_state->siginfo_data);
-  xfree (inf_state);
+  delete inf_state;
 }
 
 readonly_detached_regcache *