diff options
author | Pedro Alves <palves@redhat.com> | 2015-10-22 16:40:45 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2015-10-22 16:40:45 +0100 |
commit | c72f45d16c16954478dcd87531df146f68acd87c (patch) | |
tree | 946900777a8d88d146e28216d7ab14817cbabf7f /gdb/procfs.h | |
parent | 2213f746d3ab63715c24c3197ae207486464091b (diff) | |
download | gdb-c72f45d16c16954478dcd87531df146f68acd87c.zip gdb-c72f45d16c16954478dcd87531df146f68acd87c.tar.gz gdb-c72f45d16c16954478dcd87531df146f68acd87c.tar.bz2 |
gdb/Windows: use windows_wait/windows_resume directly in initial startup
Explation below based on what Joel wrote at:
https://sourceware.org/ml/gdb-patches/2015-10/msg00274.html
The merge async/sync code paths patch broke attaching on Windows.
This is what we observe, after attaching to any process. At first, it
seems like everything worked fine, since the process stops, and we get
the prompt back:
(gdb) att 3156
Attaching to program `C:\[...]\foo.exe', process 3156
[New Thread 3156.0xcd8]
[New Thread 3156.0xfe4]
0x7770000d in ntdll!DbgBreakPoint () from C:\Windows\SysWOW64\ntdll.dll
(gdb)
However, enter any commands at all, and GDB appears to be hanging.
For instance:
(gdb) set lang ada
[nothing happens]
Despite appearances, GDB is not reading from the prompt. It is
blocked waiting for an event from the inferior. And since our
inferior is stopped, there aren't going to be any events to read.
In chronological order, what happens is that windows_attach calls
do_initial_windows_stuff, which performs the inferior creation,
and repeatedly waits until we get the first SIGTRAP:
while (1)
{
stop_after_trap = 1;
wait_for_inferior ();
tp = inferior_thread ();
if (tp->suspend.stop_signal != GDB_SIGNAL_TRAP)
resume (tp->suspend.stop_signal);
else
break;
}
The call to wait_for_inferior triggers a call to do_target_wait to get
the event, followed by handle_inferior_event to process it. However,
because the first couple of events are "spurious" events, GDB resumes
the execution, and prepares the inferior to wait again:
case TARGET_WAITKIND_SPURIOUS:
[...]
resume (GDB_SIGNAL_0);
prepare_to_wait (ecs);
And prepare_to_wait just does...
ecs->wait_some_more = 1;
if (!target_is_async_p ())
mark_infrun_async_event_handler ();
... which as a result sets the infrun_async_event_handler "ready"
flag to 1.
We get a couple of spurious events before we get the initial SIGTRAP,
at which point we exit the "while (1)" loop above, after which we
reach the end of the attach_command, followed by the normal
end-of-command processing (normal_stop, bp handling, printing the GDB
prompt), back finally to the root of the event loop.
Notice that, at this point, nothing has unset the "ready" flag for the
infrun_async_event_handler. So, when another cycle of
gdb_do_one_event from the event loop, we eventually call
check_async_event_handlers, which finds that the infrun async event
handler is "ready", and therefore calls it's associated "proc"
callback, which does...
inferior_event_handler (INF_REG_EVENT, NULL);
... triggering a blocking call to target_wait, thus hanging forever.
The fix is to use windows_wait and windows_resume directly, similarly
to gdbserver. This will also allow getting rid of 'stop_after_trap'.
gdb/ChangeLog:
2015-10-22 Pedro Alves <palves@redhat.com>
* windows-nat.c (do_initial_windows_stuff): Rewrite loop using
windows_wait and windows_resume directly instead of
wait_for_inferior and resume.
Diffstat (limited to 'gdb/procfs.h')
0 files changed, 0 insertions, 0 deletions