[lldb-dev] Thread state

jingham at apple.com jingham at apple.com
Thu May 2 12:07:32 PDT 2013


This seems like the sort of thing that if it can be done generically it should.  WillStop does seem too late.  Process::SetPrivateState is the call that triggers notifying the rest of the lldb world that the process has stopped, so you definitely want to do it before that.  

In your suggested patch you are almost always doing it right before you call SetPrivateState, which suggests to me that probably it should be done there.  If there is Process Plugin specific knowledge to figure out the thread state, you may need some virtual method in the plugin to do that, which you call from SetPrivateState.

But I am not sure what you mean by "multi-threaded debugging"?  Are you talking about having the process (or at least some of its threads) stay running while some of the threads stay stopped?  If you are going to start thinking along those lines than a static call on thread to set it's state isn't going to work.  After all, you are going to get some notification from the target that a target has stopped.  So you set that thread's state to stopped, and then send the event to the generic execution control.  While you're processing that, another thread stops, so you change its state and send another event. But the processing of the first event is only mid-way through, so now it is dealing with a thread state that changed out from under it.  No good.

If you really want to do "keep-alive" debugging, then which thread(s) participated in the stop needs to be recorded in the process event, and handled from there.

Jim




On May 2, 2013, at 11:21 AM, "Kaylor, Andrew" <andrew.kaylor at intel.com> wrote:

> Ping.
>  
> From: lldb-dev-bounces at cs.uiuc.edu [mailto:lldb-dev-bounces at cs.uiuc.edu] On Behalf Of Kaylor, Andrew
> Sent: Monday, April 29, 2013 3:55 PM
> To: lldb-dev at cs.uiuc.edu; Jim Ingham; Greg Clayton
> Subject: [lldb-dev] Thread state
>  
> 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
>  
> <thread-state.patch>





More information about the lldb-dev mailing list