This is an archive of the discontinued LLVM Phabricator instance.

[lldb] [gdb-remote] Ensure that all threads stop in non-stop mode
Needs ReviewPublic

Authored by mgorny on Jul 12 2022, 3:22 AM.



Issue a vCont;t request after getting an asynchronous stop
notification in non-stop mode in order to ensure that all threads are
stopped. This is needed for servers implementing thread-level non-stop
mode (e.g. gdbserver). Unlike the current version of LLGS, these
servers do not stop all threads whenever one of them stops.

Depending on whether any threads were running at the time, the vCont;t
packet may or may not yield an asynchronous stop notification. Rather
than attempting to wait on that, use a combination of ?
and qfThreadInfo packets to determine whether all threads are stopped.

Issue a ? request first in order to obtain stop reasons for all
the stopped threads. As a bonus, this request clears the asynchronous
notification queue for any notification vCont;t may have produced.
Afterwards, obtain the complete thread list using qfThreadInfo.
If all debugged threads had stop reasons, it means that they all stopped
already and we can proceed. Otherwise, try again.

This logic should also be handle to handle the corner case of a new
thread being started after the vCont;t request.

We limit the stop attempts to 25 to avoid hanging when communicating
with a broken server.

Sponsored by: The FreeBSD Foundation

Diff Detail