diff options
author | Tom Tromey <tom@tromey.com> | 2018-06-14 15:41:12 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-09-17 00:42:17 -0600 |
commit | 117f580a97f721465d62d0630594dafdcd89e4e8 (patch) | |
tree | b9e38004fa77250030c883f113f40215a20c30d8 /gdb | |
parent | dd848631cb96f7d25270faeee4c9736577230a29 (diff) | |
download | gdb-117f580a97f721465d62d0630594dafdcd89e4e8.zip gdb-117f580a97f721465d62d0630594dafdcd89e4e8.tar.gz gdb-117f580a97f721465d62d0630594dafdcd89e4e8.tar.bz2 |
Remove cleanup from infrun.c
This removes a cleanup from infrun.c by taking advantage of the
previous patch to introduce a use of unique_xmalloc_ptr.
gdb/ChangeLog
2018-09-17 Tom Tromey <tom@tromey.com>
* infrun.c (struct infcall_suspend_state) <registers>: Now a
unique_ptr.
<siginfo_data>: Now a unique_xmalloc_ptr.
(save_infcall_suspend_state, restore_infcall_suspend_state)
(discard_infcall_suspend_state)
(get_infcall_suspend_state_regcache): Update.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 9 | ||||
-rw-r--r-- | gdb/infrun.c | 29 |
2 files changed, 20 insertions, 18 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index af8db7a..d5441c8 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,14 @@ 2018-09-17 Tom Tromey <tom@tromey.com> + * infrun.c (struct infcall_suspend_state) <registers>: Now a + unique_ptr. + <siginfo_data>: Now a unique_xmalloc_ptr. + (save_infcall_suspend_state, restore_infcall_suspend_state) + (discard_infcall_suspend_state) + (get_infcall_suspend_state_regcache): Update. + +2018-09-17 Tom Tromey <tom@tromey.com> + * gdbthread.h (struct thread_suspend_state): Add initializers. (class thread_info) <suspend>: Remove initializer. * infrun.c (struct infcall_suspend_state): Add initializers. diff --git a/gdb/infrun.c b/gdb/infrun.c index 6039ae3..d350ad1 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -8810,7 +8810,7 @@ struct infcall_suspend_state struct thread_suspend_state thread_suspend; /* Other fields: */ - readonly_detached_regcache *registers = nullptr; + std::unique_ptr<readonly_detached_regcache> registers; /* Format of SIGINFO_DATA or NULL if it is not present. */ struct gdbarch *siginfo_gdbarch = nullptr; @@ -8818,7 +8818,7 @@ struct infcall_suspend_state /* 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 = nullptr; + gdb::unique_xmalloc_ptr<gdb_byte> siginfo_data; }; struct infcall_suspend_state * @@ -8828,25 +8828,20 @@ save_infcall_suspend_state (void) struct thread_info *tp = inferior_thread (); struct regcache *regcache = get_current_regcache (); struct gdbarch *gdbarch = regcache->arch (); - gdb_byte *siginfo_data = NULL; + gdb::unique_xmalloc_ptr<gdb_byte> siginfo_data; if (gdbarch_get_siginfo_type_p (gdbarch)) { struct type *type = gdbarch_get_siginfo_type (gdbarch); size_t len = TYPE_LENGTH (type); - struct cleanup *back_to; - siginfo_data = (gdb_byte *) xmalloc (len); - back_to = make_cleanup (xfree, siginfo_data); + siginfo_data.reset ((gdb_byte *) xmalloc (len)); if (target_read (current_top_target (), TARGET_OBJECT_SIGNAL_INFO, NULL, - siginfo_data, 0, len) == len) - discard_cleanups (back_to); - else + siginfo_data.get (), 0, len) != len) { /* Errors ignored. */ - do_cleanups (back_to); - siginfo_data = NULL; + siginfo_data.reset (nullptr); } } @@ -8855,7 +8850,7 @@ save_infcall_suspend_state (void) if (siginfo_data) { inf_state->siginfo_gdbarch = gdbarch; - inf_state->siginfo_data = siginfo_data; + inf_state->siginfo_data = std::move (siginfo_data); } inf_state->thread_suspend = tp->suspend; @@ -8864,7 +8859,7 @@ save_infcall_suspend_state (void) GDB_SIGNAL_0 anyway. */ tp->suspend.stop_signal = GDB_SIGNAL_0; - inf_state->registers = new readonly_detached_regcache (*regcache); + inf_state->registers.reset (new readonly_detached_regcache (*regcache)); return inf_state; } @@ -8886,14 +8881,14 @@ restore_infcall_suspend_state (struct infcall_suspend_state *inf_state) /* Errors ignored. */ target_write (current_top_target (), TARGET_OBJECT_SIGNAL_INFO, NULL, - inf_state->siginfo_data, 0, TYPE_LENGTH (type)); + inf_state->siginfo_data.get (), 0, TYPE_LENGTH (type)); } /* The inferior can be gone if the user types "print exit(0)" (and perhaps other times). */ if (target_has_execution) /* NB: The register write goes through to the target. */ - regcache->restore (inf_state->registers); + regcache->restore (inf_state->registers.get ()); discard_infcall_suspend_state (inf_state); } @@ -8914,15 +8909,13 @@ make_cleanup_restore_infcall_suspend_state void discard_infcall_suspend_state (struct infcall_suspend_state *inf_state) { - delete inf_state->registers; - xfree (inf_state->siginfo_data); delete inf_state; } readonly_detached_regcache * get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state) { - return inf_state->registers; + return inf_state->registers.get (); } /* infcall_control_state contains state regarding gdb's control of the |