When disabling target async, remove all target event sources from the event loop

The sigall-reverse.exp test occasionally fails with something like this:

 (gdb) PASS: gdb.reverse/sigall-reverse.exp: send signal TERM
 continue
 Continuing.
 The next instruction is syscall exit_group.  It will make the program exit.  Do you want to stop the program?([y] or n) FAIL: gdb.reverse/sigall-reverse.exp: continue to signal exit (timeout)
 FAIL: gdb.reverse/sigall-reverse.exp: reverse to handler of TERM (timeout)
 FAIL: gdb.reverse/sigall-reverse.exp: reverse to gen_TERM (timeout)

This is another event-loop/async related problem exposed by the patch
that made 'query' use gdb_readline_wrapper (588dcc3edb).

The problem is that even though gdb_readline_wrapper disables
target-async while the secondary prompt is in progress, the record
target's async event source is left marked.  So when
gdb_readline_wrapper nests an event loop to process input, it may
happen that that event loop ends up processing a target event while
GDB is not really ready for it.  Here's the relevant part of the
backtrace showing the root issue in action:

...
 #14 0x000000000061cb48 in fetch_inferior_event (client_data=0x0) at src/gdb/infrun.c:4158
 #15 0x0000000000642917 in inferior_event_handler (event_type=INF_REG_EVENT, client_data=0x0) at src/gdb/inf-loop.c:57
 #16 0x000000000077ca5c in record_full_async_inferior_event_handler (data=0x0) at src/gdb/record-full.c:791
 #17 0x0000000000640fdf in invoke_async_event_handler (data=...) at src/gdb/event-loop.c:1067
 #18 0x000000000063fb01 in process_event () at src/gdb/event-loop.c:339
 #19 0x000000000063fb2a in gdb_do_one_event () at src/gdb/event-loop.c:360
 #20 0x000000000074d607 in gdb_readline_wrapper (prompt=0x3588f40 "The next instruction is syscall exit_group.  It will make the program exit.  Do you want to stop the program?([y] or n) ") at src/gdb/top.c:842
 #21 0x0000000000750bd9 in defaulted_query (ctlstr=0x8c6588 "The next instruction is syscall exit_group.  It will make the program exit.  Do you want to stop the program?", defchar=121 'y', args=0x7fff70524410) at src/gdb/utils.c:1279
 #22 0x0000000000750e4c in yquery (ctlstr=0x8c6588 "The next instruction is syscall exit_group.  It will make the program exit.  Do you want to stop the program?") at src/gdb/utils.c:1358
 #23 0x00000000004b020e in record_linux_system_call (syscall=gdb_sys_exit_group, regcache=0x3529450, tdep=0xd6c840 <amd64_linux_record_tdep>) at src/gdb/linux-record.c:1933

With my all-stop-on-top-of-non-stop series, I'm also seeing
gdb.server/ext-attach.exp fail occasionally due to the same issue.

The first part of the fix is for target_async implementations to make
sure to remove/unmark all target-related event sources from the event
loop.

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/
2015-02-03  Pedro Alves  <palves@redhat.com>

	* event-loop.c (clear_async_event_handler): New function.
	* event-loop.h (clear_async_event_handler): New declaration.
	* record-btrace.c (record_btrace_async): New function.
	(init_record_btrace_ops): Install record_btrace_async.
	* record-full.c (record_full_async): New function.
	(record_full_resume): Don't mark the async event source here.
	(init_record_full_ops): Install record_full_async.
	(record_full_core_resume): Don't mark the async event source here.
	(init_record_full_core_ops): Install record_full_async.
	* remote.c (remote_async): Mark and clear the async stop reply
	queue event-loop token as appropriate.
This commit is contained in:
Pedro Alves 2015-02-03 16:07:54 +01:00
parent d9d41e786a
commit b7d2e91626
6 changed files with 72 additions and 13 deletions

View File

@ -1,3 +1,17 @@
2015-02-03 Pedro Alves <palves@redhat.com>
* event-loop.c (clear_async_event_handler): New function.
* event-loop.h (clear_async_event_handler): New declaration.
* record-btrace.c (record_btrace_async): New function.
(init_record_btrace_ops): Install record_btrace_async.
* record-full.c (record_full_async): New function.
(record_full_resume): Don't mark the async event source here.
(init_record_full_ops): Install record_full_async.
(record_full_core_resume): Don't mark the async event source here.
(init_record_full_core_ops): Install record_full_async.
* remote.c (remote_async): Mark and clear the async stop reply
queue event-loop token as appropriate.
2015-02-03 Pedro Alves <palves@redhat.com>
* linux-nat.c (linux_child_follow_fork, linux_nat_wait_1): Use

View File

@ -1050,6 +1050,14 @@ mark_async_event_handler (async_event_handler *async_handler_ptr)
async_handler_ptr->ready = 1;
}
/* See event-loop.h. */
void
clear_async_event_handler (async_event_handler *async_handler_ptr)
{
async_handler_ptr->ready = 0;
}
struct async_event_handler_data
{
async_event_handler_func* proc;

View File

@ -131,3 +131,7 @@ extern void
/* Call the handler from HANDLER the next time through the event
loop. */
extern void mark_async_event_handler (struct async_event_handler *handler);
/* Mark the handler (ASYNC_HANDLER_PTR) as NOT ready. */
extern void clear_async_event_handler (struct async_event_handler *handler);

View File

@ -266,6 +266,22 @@ record_btrace_close (struct target_ops *self)
btrace_teardown (tp);
}
/* The to_async method of target record-btrace. */
static void
record_btrace_async (struct target_ops *ops,
void (*callback) (enum inferior_event_type event_type,
void *context),
void *context)
{
if (callback != NULL)
mark_async_event_handler (record_btrace_async_inferior_event_handler);
else
clear_async_event_handler (record_btrace_async_inferior_event_handler);
ops->beneath->to_async (ops->beneath, callback, context);
}
/* The to_info_record method of target record-btrace. */
static void
@ -1940,6 +1956,7 @@ init_record_btrace_ops (void)
ops->to_doc = "Collect control-flow trace and provide the execution history.";
ops->to_open = record_btrace_open;
ops->to_close = record_btrace_close;
ops->to_async = record_btrace_async;
ops->to_detach = record_detach;
ops->to_disconnect = record_disconnect;
ops->to_mourn_inferior = record_mourn_inferior;

View File

@ -910,6 +910,22 @@ record_full_close (struct target_ops *self)
delete_async_event_handler (&record_full_async_inferior_event_token);
}
/* "to_async" target method. */
static void
record_full_async (struct target_ops *ops,
void (*callback) (enum inferior_event_type event_type,
void *context),
void *context)
{
if (callback != NULL)
mark_async_event_handler (record_full_async_inferior_event_token);
else
clear_async_event_handler (record_full_async_inferior_event_token);
ops->beneath->to_async (ops->beneath, callback, context);
}
static int record_full_resume_step = 0;
/* True if we've been resumed, and so each record_full_wait call should
@ -989,12 +1005,7 @@ record_full_resume (struct target_ops *ops, ptid_t ptid, int step,
/* We are about to start executing the inferior (or simulate it),
let's register it with the event loop. */
if (target_can_async_p ())
{
target_async (inferior_event_handler, 0);
/* Notify the event loop there's an event to wait for. We do
most of the work in record_full_wait. */
mark_async_event_handler (record_full_async_inferior_event_token);
}
target_async (inferior_event_handler, 0);
}
static int record_full_get_sig = 0;
@ -1902,6 +1913,7 @@ init_record_full_ops (void)
"Log program while executing and replay execution from log.";
record_full_ops.to_open = record_full_open;
record_full_ops.to_close = record_full_close;
record_full_ops.to_async = record_full_async;
record_full_ops.to_resume = record_full_resume;
record_full_ops.to_wait = record_full_wait;
record_full_ops.to_disconnect = record_disconnect;
@ -1943,12 +1955,7 @@ record_full_core_resume (struct target_ops *ops, ptid_t ptid, int step,
/* We are about to start executing the inferior (or simulate it),
let's register it with the event loop. */
if (target_can_async_p ())
{
target_async (inferior_event_handler, 0);
/* Notify the event loop there's an event to wait for. */
mark_async_event_handler (record_full_async_inferior_event_token);
}
target_async (inferior_event_handler, 0);
}
/* "to_kill" method for prec over corefile. */
@ -2141,6 +2148,7 @@ init_record_full_core_ops (void)
"Log program while executing and replay execution from log.";
record_full_core_ops.to_open = record_full_open;
record_full_core_ops.to_close = record_full_close;
record_full_core_ops.to_async = record_full_async;
record_full_core_ops.to_resume = record_full_core_resume;
record_full_core_ops.to_wait = record_full_wait;
record_full_core_ops.to_kill = record_full_core_kill;

View File

@ -11691,9 +11691,17 @@ remote_async (struct target_ops *ops,
serial_async (rs->remote_desc, remote_async_serial_handler, rs);
rs->async_client_callback = callback;
rs->async_client_context = context;
/* If there are pending events in the stop reply queue tell the
event loop to process them. */
if (!QUEUE_is_empty (stop_reply_p, stop_reply_queue))
mark_async_event_handler (remote_async_inferior_event_token);
}
else
serial_async (rs->remote_desc, NULL, NULL);
{
serial_async (rs->remote_desc, NULL, NULL);
clear_async_event_handler (remote_async_inferior_event_token);
}
}
static void