aboutsummaryrefslogtreecommitdiff
path: root/gdb/remote-notif.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2019-01-23 22:16:53 -0700
committerTom Tromey <tom@tromey.com>2019-03-06 16:04:31 -0700
commit32603266e5688718faad35b7502aa0b72a42764a (patch)
treef686b0e4adf854552bacf4aa2079bd9ae6ac0a4b /gdb/remote-notif.c
parent9799571ecb648ea2e911498cfdc7fafe3237c94a (diff)
downloadgdb-32603266e5688718faad35b7502aa0b72a42764a.zip
gdb-32603266e5688718faad35b7502aa0b72a42764a.tar.gz
gdb-32603266e5688718faad35b7502aa0b72a42764a.tar.bz2
C++ify remote notification code
This C++ifies the remote notification code -- replacing function pointers with virtual methods and using unique_ptr. This allows for the removal of some cleanups. 2019-03-06 Tom Tromey <tom@tromey.com> * remote.c (struct stop_reply_deleter): Remove. (stop_reply_up): Update. (struct stop_reply): Derive from notif_event. Don't typedef. <regcache>: Now a std::vector. (stop_reply_xfree): Remove. (stop_reply::~stop_reply): Rename from stop_reply_dtr. (remote_notif_stop_alloc_reply): Return a unique_ptr. Use new. (remote_target::discard_pending_stop_replies): Use delete. (remote_target::remote_parse_stop_reply): Update. (remote_target::process_stop_reply): Update. * remote-notif.h (struct notif_event): Add virtual destructor. Remove "dtr" member. (struct notif_client) <alloc_event>: Return a unique_ptr. (notif_event_xfree): Don't declare. (notif_event_up): New typedef. * remote-notif.c (remote_notif_ack, remote_notif_parse): Update. (notif_event_xfree, do_notif_event_xfree): Remove. (remote_notif_state_xfree): Update.
Diffstat (limited to 'gdb/remote-notif.c')
-rw-r--r--gdb/remote-notif.c42
1 files changed, 7 insertions, 35 deletions
diff --git a/gdb/remote-notif.c b/gdb/remote-notif.c
index ae9a94d..eece947 100644
--- a/gdb/remote-notif.c
+++ b/gdb/remote-notif.c
@@ -52,8 +52,6 @@ static struct notif_client *notifs[] =
gdb_static_assert (ARRAY_SIZE (notifs) == REMOTE_NOTIF_LAST);
-static void do_notif_event_xfree (void *arg);
-
/* Parse the BUF for the expected notification NC, and send packet to
acknowledge. */
@@ -61,18 +59,14 @@ void
remote_notif_ack (remote_target *remote,
struct notif_client *nc, const char *buf)
{
- struct notif_event *event = nc->alloc_event ();
- struct cleanup *old_chain
- = make_cleanup (do_notif_event_xfree, event);
+ notif_event_up event = nc->alloc_event ();
if (notif_debug)
fprintf_unfiltered (gdb_stdlog, "notif: ack '%s'\n",
nc->ack_command);
- nc->parse (remote, nc, buf, event);
- nc->ack (remote, nc, buf, event);
-
- discard_cleanups (old_chain);
+ nc->parse (remote, nc, buf, event.get ());
+ nc->ack (remote, nc, buf, event.release ());
}
/* Parse the BUF for the expected notification NC. */
@@ -81,17 +75,14 @@ struct notif_event *
remote_notif_parse (remote_target *remote,
struct notif_client *nc, const char *buf)
{
- struct notif_event *event = nc->alloc_event ();
- struct cleanup *old_chain
- = make_cleanup (do_notif_event_xfree, event);
+ notif_event_up event = nc->alloc_event ();
if (notif_debug)
fprintf_unfiltered (gdb_stdlog, "notif: parse '%s'\n", nc->name);
- nc->parse (remote, nc, buf, event);
+ nc->parse (remote, nc, buf, event.get ());
- discard_cleanups (old_chain);
- return event;
+ return event.release ();
}
DEFINE_QUEUE_P (notif_client_p);
@@ -216,25 +207,6 @@ handle_notification (struct remote_notif_state *state, const char *buf)
}
}
-/* Invoke destructor of EVENT and xfree it. */
-
-void
-notif_event_xfree (struct notif_event *event)
-{
- if (event != NULL && event->dtr != NULL)
- event->dtr (event);
-
- xfree (event);
-}
-
-/* Cleanup wrapper. */
-
-static void
-do_notif_event_xfree (void *arg)
-{
- notif_event_xfree ((struct notif_event *) arg);
-}
-
/* Return an allocated remote_notif_state. */
struct remote_notif_state *
@@ -269,7 +241,7 @@ remote_notif_state_xfree (struct remote_notif_state *state)
delete_async_event_handler (&state->get_pending_events_token);
for (i = 0; i < REMOTE_NOTIF_LAST; i++)
- notif_event_xfree (state->pending_event[i]);
+ delete state->pending_event[i];
xfree (state);
}