+2013-10-04 Yao Qi <yao@codesourcery.com>
+
+ * remote-notif.h (REMOTE_NOTIF_ID): New enum.
+ (struct notif_client) <pending_event>: Moved
+ to struct remote_notif_state.
+ <id>: New field.
+ (struct remote_notif_state) <pending_event>: New field.
+ (notif_event_xfree): Declare.
+ * remote-notif.c (handle_notification): Adjust.
+ (notif_event_xfree): New function.
+ (do_notif_event_xfree): Call notif_event_xfree.
+ (remote_notif_state_xfree): Call notif_event_xfree to free
+ each element in field pending_event.
+ * remote.c (discard_pending_stop_replies): Remove declaration.
+ (discard_pending_stop_replies_in_queue): Declare.
+ (remote_close): Call discard_pending_stop_replies_in_queue
+ instead of discard_pending_stop_replies.
+ (remote_start_remote): Adjust.
+ (stop_reply_xfree): Call notif_event_xfree.
+ (notif_client_stop): Adjust initialization.
+ (remote_notif_remove_all): Rename it to ...
+ (remove_stop_reply_for_inferior): ... this. Update comments.
+ Don't check INF is NULL.
+ (discard_pending_stop_replies): Return early if notif_state is
+ NULL. Adjust. Don't check INF is NULL.
+ (remote_notif_get_pending_events): Adjust.
+ (discard_pending_stop_replies_in_queue): New function.
+ (remote_wait_ns): Likewise.
+
2013-10-04 Yao Qi <yao@codesourcery.com>
* remote-notif.c (DECLARE_QUEUE_P): Remove.
¬if_client_stop,
};
+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
if (nc == NULL)
return;
- if (nc->pending_event)
+ if (state->pending_event[nc->id] != NULL)
{
/* We've already parsed the in-flight reply, but the stub for some
reason thought we didn't, possibly due to timeout on its side.
/* Be careful to only set it after parsing, since an error
may be thrown then. */
- nc->pending_event = event;
+ state->pending_event[nc->id] = event;
/* Notify the event loop there's a stop reply to acknowledge
and that there may be more events to fetch. */
}
}
-/* Cleanup wrapper. */
+/* Invoke destructor of EVENT and xfree it. */
-static void
-do_notif_event_xfree (void *arg)
+void
+notif_event_xfree (struct notif_event *event)
{
- struct notif_event *event = arg;
-
- if (event && event->dtr)
+ if (event != NULL && event->dtr != NULL)
event->dtr (event);
xfree (event);
}
+/* Cleanup wrapper. */
+
+static void
+do_notif_event_xfree (void *arg)
+{
+ notif_event_xfree (arg);
+}
+
/* Return an allocated remote_notif_state. */
struct remote_notif_state *
void
remote_notif_state_xfree (struct remote_notif_state *state)
{
+ int i;
+
QUEUE_free (notif_client_p, state->notif_queue);
/* Unregister async_event_handler for notification. */
if (state->get_pending_events_token != NULL)
delete_async_event_handler (&state->get_pending_events_token);
+ for (i = 0; i < REMOTE_NOTIF_LAST; i++)
+ notif_event_xfree (state->pending_event[i]);
+
xfree (state);
}
void (*dtr) (struct notif_event *self);
};
+/* ID of the notif_client. */
+
+enum REMOTE_NOTIF_ID
+{
+ REMOTE_NOTIF_STOP = 0,
+ REMOTE_NOTIF_LAST,
+};
+
/* A client to a sort of async remote notification. */
typedef struct notif_client
/* Allocate an event. */
struct notif_event *(*alloc_event) (void);
- /* One pending event. This is where we keep it until it is
- acknowledged. When there is a notification packet, parse it,
- and create an object of 'struct notif_event' to assign to
- it. This field is unchanged until GDB starts to ack this
- notification (which is done by
- remote.c:remote_notif_pending_replies). */
- struct notif_event *pending_event;
+ /* Id of this notif_client. */
+ const enum REMOTE_NOTIF_ID id;
} *notif_client_p;
DECLARE_QUEUE_P (notif_client_p);
the remote side into our event queue. */
struct async_event_handler *get_pending_events_token;
+
+/* One pending event for each notification client. This is where we
+ keep it until it is acknowledged. When there is a notification
+ packet, parse it, and create an object of 'struct notif_event' to
+ assign to it. This field is unchanged until GDB starts to ack
+ this notification (which is done by
+ remote.c:remote_notif_pending_replies). */
+
+ struct notif_event *pending_event[REMOTE_NOTIF_LAST];
};
void remote_notif_ack (struct notif_client *nc, char *buf);
struct notif_event *remote_notif_parse (struct notif_client *nc,
char *buf);
+void notif_event_xfree (struct notif_event *event);
+
void handle_notification (struct remote_notif_state *notif_state,
char *buf);
static void stop_reply_xfree (struct stop_reply *);
static void remote_parse_stop_reply (char *, struct stop_reply *);
static void push_stop_reply (struct stop_reply *);
-static void discard_pending_stop_replies (struct inferior *);
+static void discard_pending_stop_replies_in_queue (void);
static int peek_stop_reply (ptid_t ptid);
static void remote_async_inferior_event_handler (gdb_client_data);
inferior_ptid = null_ptid;
discard_all_inferiors ();
- /* Stop replies may from inferiors which are still unknown to GDB.
- We are closing the remote target, so we should discard
- everything, including the stop replies from GDB-unknown
- inferiors. */
- discard_pending_stop_replies (NULL);
+ /* We are closing the remote target, so we should discard
+ everything of this target. */
+ discard_pending_stop_replies_in_queue ();
if (remote_async_inferior_event_token)
delete_async_event_handler (&remote_async_inferior_event_token);
/* remote_notif_get_pending_replies acks this one, and gets
the rest out. */
- notif_client_stop.pending_event
+ rs->notif_state->pending_event[notif_client_stop.id]
= remote_notif_parse (notif, rs->buf);
remote_notif_get_pending_events (notif);
static void
stop_reply_xfree (struct stop_reply *r)
{
- if (r != NULL)
- {
- VEC_free (cached_reg_t, r->regcache);
- xfree (r);
- }
+ notif_event_xfree ((struct notif_event *) r);
}
static void
remote_notif_stop_ack,
remote_notif_stop_can_get_pending_events,
remote_notif_stop_alloc_reply,
- NULL,
+ REMOTE_NOTIF_STOP,
};
/* A parameter to pass data in and out. */
struct stop_reply *output;
};
-/* Remove all queue elements meet the condition it checks. */
+/* Remove stop replies in the queue if its pid is equal to the given
+ inferior's pid. */
static int
-remote_notif_remove_all (QUEUE (stop_reply_p) *q,
- QUEUE_ITER (stop_reply_p) *iter,
- stop_reply_p event,
- void *data)
+remove_stop_reply_for_inferior (QUEUE (stop_reply_p) *q,
+ QUEUE_ITER (stop_reply_p) *iter,
+ stop_reply_p event,
+ void *data)
{
struct queue_iter_param *param = data;
struct inferior *inf = param->input;
- if (inf == NULL || ptid_get_pid (event->ptid) == inf->pid)
+ if (ptid_get_pid (event->ptid) == inf->pid)
{
stop_reply_xfree (event);
QUEUE_remove_elem (stop_reply_p, q, iter);
return 1;
}
-/* Discard all pending stop replies of inferior INF. If INF is NULL,
- discard everything. */
+/* Discard all pending stop replies of inferior INF. */
static void
discard_pending_stop_replies (struct inferior *inf)
{
int i;
struct queue_iter_param param;
- struct stop_reply *reply
- = (struct stop_reply *) notif_client_stop.pending_event;
+ struct stop_reply *reply;
+ struct remote_state *rs = get_remote_state ();
+ struct remote_notif_state *rns = rs->notif_state;
+
+ /* This function can be notified when an inferior exists. When the
+ target is not remote, the notification state is NULL. */
+ if (rs->remote_desc == NULL)
+ return;
+
+ reply = (struct stop_reply *) rns->pending_event[notif_client_stop.id];
/* Discard the in-flight notification. */
- if (reply != NULL
- && (inf == NULL
- || ptid_get_pid (reply->ptid) == inf->pid))
+ if (reply != NULL && ptid_get_pid (reply->ptid) == inf->pid)
{
stop_reply_xfree (reply);
- notif_client_stop.pending_event = NULL;
+ rns->pending_event[notif_client_stop.id] = NULL;
}
param.input = inf;
/* Discard the stop replies we have already pulled with
vStopped. */
QUEUE_iterate (stop_reply_p, stop_reply_queue,
- remote_notif_remove_all, ¶m);
+ remove_stop_reply_for_inferior, ¶m);
+}
+
+/* Discard the stop replies in stop_reply_queue. */
+
+static void
+discard_pending_stop_replies_in_queue (void)
+{
+ struct queue_iter_param param;
+
+ param.input = NULL;
+ param.output = NULL;
+ /* Discard the stop replies we have already pulled with
+ vStopped. */
+ QUEUE_iterate (stop_reply_p, stop_reply_queue,
+ remove_stop_reply_for_inferior, ¶m);
}
/* A parameter to pass data in and out. */
{
struct remote_state *rs = get_remote_state ();
- if (nc->pending_event)
+ if (rs->notif_state->pending_event[nc->id] != NULL)
{
if (notif_debug)
fprintf_unfiltered (gdb_stdlog,
nc->name);
/* acknowledge */
- nc->ack (nc, rs->buf, nc->pending_event);
- nc->pending_event = NULL;
+ nc->ack (nc, rs->buf, rs->notif_state->pending_event[nc->id]);
+ rs->notif_state->pending_event[nc->id] = NULL;
while (1)
{
/* Acknowledge a pending stop reply that may have arrived in the
mean time. */
- if (notif_client_stop.pending_event != NULL)
+ if (rs->notif_state->pending_event[notif_client_stop.id] != NULL)
remote_notif_get_pending_events (¬if_client_stop);
/* If indeed we noticed a stop reply, we're done. */