[Bug 45454] New: Race condition in debugserver stdout processing during application exit.

Bug ID 45454
Summary Race condition in debugserver stdout processing during application exit.
Product lldb
Version 10.0
Hardware PC
OS All
Status NEW
Severity normal
Priority P
Component All Bugs
Assignee lldb-dev@lists.llvm.org
Reporter uldis.kalninsh@gmail.com
CC jdevlieghere@apple.com, llvm-bugs@lists.llvm.org

There is a race condition in debugserver where application state processing
thread sends event_proc_state_changed before all the STDOUT is posted to
internal buffers.

Explanation:

Debugserver processes STDOUT in separate thread that runs select on the socket
attached to debugged process STDOUT/STDERR. This thread reads the socket
contents and posts them to internal STDOUT buffer and emits eBroadcastBitSTDOUT
event. When application finishes, the sockets receive EOF and the thread exits.

When debugged application exits, the process state thread flushes any output
available in internal STDOUT buffer and emits "event_proc_state_changed" event,
which is picked up by main event processing loop and sent to lldb as the last
message.

If State processing thread gets to the STDOUT buffer before STDOUT processing
thread can update the buffer, the last output from application is lost.

The state processing thread probably needs to join the STDOUT thread before
checking if any last STDOUT is left in there. Seems that in some way, this is
already done for profiling data thread.