aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2021-02-04 13:13:30 -0500
committerSimon Marchi <simon.marchi@polymtl.ca>2021-02-04 13:13:30 -0500
commit6b36ddeb1edbdc3039075e4e220a108579b82121 (patch)
tree2da067b706982abb51c73583e2003546065bd02a /gdb
parentee87f50b8d2a0599675657a9fd2774c08261b29c (diff)
downloadgdb-6b36ddeb1edbdc3039075e4e220a108579b82121.zip
gdb-6b36ddeb1edbdc3039075e4e220a108579b82121.tar.gz
gdb-6b36ddeb1edbdc3039075e4e220a108579b82121.tar.bz2
gdb: make async event handlers clear themselves
The `ready` flag of async event handlers is cleared by the async event handler system right before invoking the associated callback, in check_async_event_handlers. This is not ideal with how the infrun subsystem consumes events: all targets' async event handler callbacks essentially just invoke `inferior_event_handler`, which eventually calls `fetch_inferior_event` and `do_target_wait`. `do_target_wait` picks an inferior at random, and thus a target at random (it could be the target whose `ready` flag was cleared, or not), and pulls one event from it. So it's possible that: - the async event handler for a target A is called - we end up consuming an event for target B - all threads of target B are stopped, target_async(0) is called on it, so its async event handler is cleared (e.g. record_btrace_target::async) As a result, target A still has events to report while its async event handler is left unmarked, so these events are not consumed. To counter this, at the end of their async event handler callbacks, targets check if they still have something to report and re-mark their async event handler (e.g. remote_async_inferior_event_handler). The linux_nat target does not suffer from this because it doesn't use an async event handler at the moment. It only uses a pipe registered with the event loop. It is written to in the SIGCHLD handler (and in other spots that want to get target wait method called) and read from in the target's wait method. So if linux_nat happened to be target A in the example above, the pipe would just stay readable, and the event loop would wake up again, until linux_nat's wait method is finally called and consumes the contents of the pipe. I think it would be nicer if targets using async_event_handler worked in a similar way, where the flag would stay set until the target's wait method is actually called. As a first step towards that, this patch moves the responsibility of clearing the ready flags of async event handlers to the invoked callback. All async event handler callbacks are modified to clear their ready flag before doing anything else. So in practice, nothing changes with this patch. It's only the responsibility of clearing the flag that is shifted toward the callee. gdb/ChangeLog: * async-event.h (async_event_handler_func): Add documentation. * async-event.c (check_async_event_handlers): Don't clear async_event_handler ready flag. * infrun.c (infrun_async_inferior_event_handler): Clear ready flag. * record-btrace.c (record_btrace_handle_async_inferior_event): Likewise. * record-full.c (record_full_async_inferior_event_handler): Likewise. * remote-notif.c (remote_async_get_pending_events_handler): Likewise. * remote.c (remote_async_inferior_event_handler): Likewise. Change-Id: I179ef8e99580eae642d332846fd13664dbddc0c1
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog15
-rw-r--r--gdb/async-event.c1
-rw-r--r--gdb/async-event.h9
-rw-r--r--gdb/infrun.c1
-rw-r--r--gdb/record-btrace.c1
-rw-r--r--gdb/record-full.c1
-rw-r--r--gdb/remote-notif.c4
-rw-r--r--gdb/remote.c5
8 files changed, 33 insertions, 4 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4ac326b..137f3be 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,18 @@
+2021-02-04 Simon Marchi <simon.marchi@efficios.com>
+
+ * async-event.h (async_event_handler_func): Add documentation.
+ * async-event.c (check_async_event_handlers): Don't clear
+ async_event_handler ready flag.
+ * infrun.c (infrun_async_inferior_event_handler): Clear ready
+ flag.
+ * record-btrace.c (record_btrace_handle_async_inferior_event):
+ Likewise.
+ * record-full.c (record_full_async_inferior_event_handler):
+ Likewise.
+ * remote-notif.c (remote_async_get_pending_events_handler):
+ Likewise.
+ * remote.c (remote_async_inferior_event_handler): Likewise.
+
2021-02-03 Simon Marchi <simon.marchi@polymtl.ca>
* infrun.c (handle_inferior_event): Move stop_soon variable to
diff --git a/gdb/async-event.c b/gdb/async-event.c
index 18dac77..c4ab731 100644
--- a/gdb/async-event.c
+++ b/gdb/async-event.c
@@ -322,7 +322,6 @@ check_async_event_handlers ()
{
if (async_handler_ptr->ready)
{
- async_handler_ptr->ready = 0;
event_loop_debug_printf ("invoking async event handler `%s`",
async_handler_ptr->name);
(*async_handler_ptr->proc) (async_handler_ptr->client_data);
diff --git a/gdb/async-event.h b/gdb/async-event.h
index 0f4c892..9d96235 100644
--- a/gdb/async-event.h
+++ b/gdb/async-event.h
@@ -24,6 +24,15 @@
struct async_signal_handler;
struct async_event_handler;
typedef void (sig_handler_func) (gdb_client_data);
+
+/* Type of async event handler callbacks.
+
+ DATA is the client data originally passed to create_async_event_handler.
+
+ The callback is called when the async event handler is marked. The callback
+ is responsible for clearing the async event handler if it no longer needs
+ to be called. */
+
typedef void (async_event_handler_func) (gdb_client_data);
extern struct async_signal_handler *
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 6ec269a..a271220 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -9212,6 +9212,7 @@ static const struct internalvar_funcs siginfo_funcs =
static void
infrun_async_inferior_event_handler (gdb_client_data data)
{
+ clear_async_event_handler (infrun_async_inferior_event_token);
inferior_event_handler (INF_REG_EVENT);
}
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 81686ee..ea339b8 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -325,6 +325,7 @@ record_btrace_auto_disable (void)
static void
record_btrace_handle_async_inferior_event (gdb_client_data data)
{
+ clear_async_event_handler (record_btrace_async_inferior_event_handler);
inferior_event_handler (INF_REG_EVENT);
}
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 22eaaa4..247573c 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -903,6 +903,7 @@ static struct async_event_handler *record_full_async_inferior_event_token;
static void
record_full_async_inferior_event_handler (gdb_client_data data)
{
+ clear_async_event_handler (record_full_async_inferior_event_token);
inferior_event_handler (INF_REG_EVENT);
}
diff --git a/gdb/remote-notif.c b/gdb/remote-notif.c
index 035d5f4..5a3e139 100644
--- a/gdb/remote-notif.c
+++ b/gdb/remote-notif.c
@@ -108,8 +108,10 @@ remote_notif_process (struct remote_notif_state *state,
static void
remote_async_get_pending_events_handler (gdb_client_data data)
{
+ remote_notif_state *notif_state = (remote_notif_state *) data;
+ clear_async_event_handler (notif_state->get_pending_events_token);
gdb_assert (target_is_non_stop_p ());
- remote_notif_process ((struct remote_notif_state *) data, NULL);
+ remote_notif_process (notif_state, NULL);
}
/* Remote notification handler. Parse BUF, queue notification and
diff --git a/gdb/remote.c b/gdb/remote.c
index c544fe7..47538fc 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -14259,10 +14259,11 @@ remote_async_serial_handler (struct serial *scb, void *context)
static void
remote_async_inferior_event_handler (gdb_client_data data)
{
- inferior_event_handler (INF_REG_EVENT);
-
remote_target *remote = (remote_target *) data;
remote_state *rs = remote->get_remote_state ();
+ clear_async_event_handler (rs->remote_async_inferior_event_token);
+
+ inferior_event_handler (INF_REG_EVENT);
/* inferior_event_handler may have consumed an event pending on the
infrun side without calling target_wait on the REMOTE target, or