[lldb-dev] Thread state
Kaylor, Andrew
andrew.kaylor at intel.com
Mon Apr 29 15:55:29 PDT 2013
In preparation for getting multithreaded debugging working in LLDB on Linux I'm trying to get the thread state in lldb::Thread objects to be kept up-to-date in some reasonable fashion. I recently added a preliminary test that checks the thread state of a single-threaded program and to my surprise that test fails even on Darwin platforms. The test initially fails because threads aren't marked as stopped when a breakpoint is hit in the thread.
I realize Process objects have both a private and a public state and that the latter doesn't always correspond to the actual state of the inferior process, and if I'm not mistaken there are some transitory times when the private state also doesn't match the inferior's actual state. I've also seen that Thread objects maintain a 'state' (which I take to be analogous to the Process' private state) and a 'resume_state' (which I believe is the state the thread should go into after a resume operation). I'm stating all of this here so that if there's an error in my understanding of the design it might be easier to spot.
I've been specifically trying to get the Thread state to be correctly updated when the inferior stops. I've found two ways of doing this:
1. Have Thread::WillStop call Thread::SetState(eStateStopped).
2. Have the ProcessPOSIX::SendMessage call Thread::SetState for the thread associated with the event.
Option 1 is pretty straightforward, but it feels like it might be happening too late in the overall flow.
Option 2 only solves the problem for POSIX platforms, but it feels more consistent with the current design. For the record, ProcessPOSIX::SendMessage is called by the Linux/FreeBSD ProcessMonitor callback function after they've figured out what a signal/trap from the inferior means. This potential solution is represented in the attached patch.
The reason I care about the thread state is that I'm going to need to manually stop background threads when something like a breakpoint happens and bad things will happen if I try to stop a thread that's already stopped. The ProcessPOSIX::SendMessage method seems like a good candidate for where to stop the other threads, and so that's why I'm leaning toward Option 2.
However, I'm not certain I completely understand the existing design in all of the related areas, so I thought I ought to step back and ask for feedback at this point.
Comments? Suggestions?
Thank,
Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20130429/c76d8364/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: thread-state.patch
Type: application/octet-stream
Size: 2783 bytes
Desc: thread-state.patch
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20130429/c76d8364/attachment.obj>
More information about the lldb-dev
mailing list