From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 2/5] Remove cleanup from infrun.c
Date: Wed, 11 Jul 2018 14:16:00 -0000 [thread overview]
Message-ID: <20180711141552.10136-3-tom@tromey.com> (raw)
In-Reply-To: <20180711141552.10136-1-tom@tromey.com>
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-07-11 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.
---
gdb/ChangeLog | 9 +++++++++
gdb/infrun.c | 29 +++++++++++------------------
2 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8c0d7b5f6a9..d46ccf53999 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2018-07-11 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-07-11 Tom Tromey <tom@tromey.com>
* infrun.c (struct infcall_suspend_state): Add initializers.
diff --git a/gdb/infrun.c b/gdb/infrun.c
index da71f3132a0..1157b266b1a 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -8813,7 +8813,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;
@@ -8821,7 +8821,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 *
@@ -8831,25 +8831,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);
}
}
@@ -8858,7 +8853,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;
@@ -8867,7 +8862,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;
}
@@ -8889,14 +8884,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);
}
@@ -8917,15 +8912,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
--
2.17.1
next prev parent reply other threads:[~2018-07-11 14:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-11 14:16 [RFA 0/5] remove some infrun-related cleanups Tom Tromey
2018-07-11 14:15 ` [RFA 4/5] Remove two infrun cleanups Tom Tromey
2018-07-11 14:15 ` [RFA 1/5] Use new and delete for struct infcall_suspend_state Tom Tromey
2018-07-11 15:33 ` Simon Marchi
2018-07-11 14:16 ` Tom Tromey [this message]
2018-07-11 14:16 ` [RFA 5/5] Remove release_stop_context_cleanup Tom Tromey
2018-07-11 14:16 ` [RFA 3/5] Use new and delete for struct infcall_control_state Tom Tromey
2018-07-11 15:36 ` Simon Marchi
2018-07-11 15:42 ` Simon Marchi
2018-07-11 14:54 ` [RFA 0/5] remove some infrun-related cleanups Pedro Alves
2018-07-11 15:16 ` Simon Marchi
2018-07-11 19:29 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180711141552.10136-3-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox