[lldb-dev] Race condition or wrong API usage?

Filipe Cabecinhas filcab at gmail.com
Tue May 8 04:02:26 PDT 2012


Hi all! 

I'm having some weird problems with asynchronous API usage. I will address it in this email as if it was a bug, but it may be wrong API usage from my part.

The main problem is the run lock being write locked when the process is stopped (and I got a state changed event).
What happens is:

Create a target (a simple 'hello world'-like program) and set a breakpoint
Set Async mode.

Set up an SBListener that will listen (on the SBDebugger) for lldb.SBProcess.eBroadcastBitStateChanged, from event class lldb.SBProcess.GetBroadcasterClassName().
Call SBTarget::LaunchSimple(None, None, os.getcwd())
Wait for an event
The process is now in a stopped state (checked using GetStateFromEvent() == eStateStopped)
Try to get the stopped thread. There isn't any (the only thread has eStopReasonInvalid).

Why does this happen?

SBTarget::Launch() will start the process (the run_lock gets created write-locked, the Process' public state will be eStateRunning) and wait for it to stop (when it stops, the Event's DoOnRemoval will change the public state (to eStateStopped) of the Process and call WriteUnlock()).
After the process stopped on entry, we want to continue until we hit our breakpoint. SBTarget::Launch calls Process::Resume, which will call WriteTryLock (succeeding) and call into Process::PrivateResume()

The lock will not be unlocked again.
The Process' private state will toggle between the stopped and running states several times, before stopping at the breakpoint. When it stops at the breakpoint, it will set the Process' public state to eStateStopped. But the public state was already eStateStopped, so we won't call WriteUnlock on Process.cpp:1310.

Any clues on where to look for? I've started debugging it but maybe Greg will know best where to look and how to fix this.

Attached is a test that show the problem (main.cpp is from python_api/process).

Thanks, 

  Filipe

-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: application/octet-stream
Size: 1044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20120508/906142cb/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile
Type: application/octet-stream
Size: 77 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20120508/906142cb/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestProcessRWLock.py
Type: application/octet-stream
Size: 4019 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20120508/906142cb/attachment-0002.obj>


More information about the lldb-dev mailing list