[Lldb-commits] [lldb] r149443 - in /lldb/trunk: include/lldb/Target/Thread.h source/Target/Thread.cpp source/Target/ThreadList.cpp

Jim Ingham jingham at apple.com
Tue Jan 31 15:09:21 PST 2012


Author: jingham
Date: Tue Jan 31 17:09:20 2012
New Revision: 149443

URL: http://llvm.org/viewvc/llvm-project?rev=149443&view=rev
Log:
Threads now store their "temporary" resume state, so we know whether they were suspended in the most
recent step, and if they weren't allowed to run, don't ask questions about their state unless explicitly
requested to do so.

Modified:
    lldb/trunk/include/lldb/Target/Thread.h
    lldb/trunk/source/Target/Thread.cpp
    lldb/trunk/source/Target/ThreadList.cpp

Modified: lldb/trunk/include/lldb/Target/Thread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Thread.h?rev=149443&r1=149442&r2=149443&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Thread.h (original)
+++ lldb/trunk/include/lldb/Target/Thread.h Tue Jan 31 17:09:20 2012
@@ -807,6 +807,18 @@
     StackFrameList &
     GetStackFrameList ();
     
+    lldb::StateType GetTemporaryResumeState()
+    {
+        return m_temporary_resume_state;
+    }
+    
+    lldb::StateType SetTemporaryResumeState(lldb::StateType resume_state)
+    {
+        lldb::StateType old_temp_resume_state = m_temporary_resume_state;
+        m_temporary_resume_state = resume_state;
+        return old_temp_resume_state;
+    }
+    
     struct ThreadState
     {
         uint32_t           orig_stop_id;
@@ -829,7 +841,9 @@
     lldb::StackFrameListSP m_curr_frames_sp; ///< The stack frames that get lazily populated after a thread stops.
     lldb::StackFrameListSP m_prev_frames_sp; ///< The previous stack frames from the last time this thread stopped.
     int                 m_resume_signal;    ///< The signal that should be used when continuing this thread.
-    lldb::StateType     m_resume_state;     ///< The state that indicates what this thread should do when the process is resumed.
+    lldb::StateType     m_resume_state;     ///< This state is used to force a thread to be suspended from outside the ThreadPlan logic.
+    lldb::StateType     m_temporary_resume_state; ///< This state records what the thread was told to do by the thread plan logic for the current resume.
+                                                  /// It gets set in Thread::WillResume.
     std::auto_ptr<lldb_private::Unwind> m_unwinder_ap;
     bool                m_destroy_called;    // This is used internally to make sure derived Thread classes call DestroyThread.
     uint32_t m_thread_stop_reason_stop_id;   // This is the stop id for which the StopInfo is valid.  Can use this so you know that

Modified: lldb/trunk/source/Target/Thread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Thread.cpp?rev=149443&r1=149442&r2=149443&view=diff
==============================================================================
--- lldb/trunk/source/Target/Thread.cpp (original)
+++ lldb/trunk/source/Target/Thread.cpp Tue Jan 31 17:09:20 2012
@@ -58,6 +58,7 @@
     m_prev_frames_sp (),
     m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER),
     m_resume_state (eStateRunning),
+    m_temporary_resume_state (eStateRunning),
     m_unwinder_ap (),
     m_destroy_called (false),
     m_thread_stop_reason_stop_id (0)
@@ -227,9 +228,20 @@
     m_completed_plan_stack.clear();
     m_discarded_plan_stack.clear();
 
-    StopInfo *stop_info = GetPrivateStopReason().get();
-    if (stop_info)
-        stop_info->WillResume (resume_state);
+    SetTemporaryResumeState(resume_state);
+    
+    // This is a little dubious, but we are trying to limit how often we actually fetch stop info from
+    // the target, 'cause that slows down single stepping.  So assume that if we got to the point where
+    // we're about to resume, and we haven't yet had to fetch the stop reason, then it doesn't need to know
+    // about the fact that we are resuming...
+        const uint32_t process_stop_id = GetProcess().GetStopID();
+    if (m_thread_stop_reason_stop_id == process_stop_id &&
+        (m_actual_stop_info_sp && m_actual_stop_info_sp->IsValid()))
+    {
+        StopInfo *stop_info = GetPrivateStopReason().get();
+        if (stop_info)
+            stop_info->WillResume (resume_state);
+    }
     
     // Tell all the plans that we are about to resume in case they need to clear any state.
     // We distinguish between the plan on the top of the stack and the lower
@@ -260,8 +272,49 @@
     bool should_stop = true;
 
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
+    
+    if (GetResumeState () == eStateSuspended)
+    {
+        if (log)
+            log->Printf ("Thread::%s for tid = 0x%4.4llx, should_stop = 0 (ignore since thread was suspended)", 
+                         __FUNCTION__, 
+                         GetID ());
+//            log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since thread was suspended)", 
+//                         __FUNCTION__, 
+//                         GetID (), 
+//                         GetRegisterContext()->GetPC());
+        return false;
+    }
+    
+    if (GetTemporaryResumeState () == eStateSuspended)
+    {
+        if (log)
+            log->Printf ("Thread::%s for tid = 0x%4.4llx, should_stop = 0 (ignore since thread was suspended)", 
+                         __FUNCTION__, 
+                         GetID ());
+//            log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since thread was suspended)", 
+//                         __FUNCTION__, 
+//                         GetID (), 
+//                         GetRegisterContext()->GetPC());
+        return false;
+    }
+    
+    if (ThreadStoppedForAReason() == false)
+    {
+        if (log)
+            log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since no stop reason)", 
+                         __FUNCTION__, 
+                         GetID (), 
+                         GetRegisterContext()->GetPC());
+        return false;
+    }
+
     if (log)
     {
+        log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx", 
+                     __FUNCTION__, 
+                     GetID (), 
+                     GetRegisterContext()->GetPC());
         log->Printf ("^^^^^^^^ Thread::ShouldStop Begin ^^^^^^^^");
         StreamString s;
         s.IndentMore();
@@ -401,6 +454,8 @@
 Thread::ShouldReportStop (Event* event_ptr)
 {
     StateType thread_state = GetResumeState ();
+    StateType temp_thread_state = GetTemporaryResumeState();
+    
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
 
     if (thread_state == eStateSuspended || thread_state == eStateInvalid)
@@ -410,6 +465,20 @@
         return eVoteNoOpinion;
     }
 
+    if (temp_thread_state == eStateSuspended || temp_thread_state == eStateInvalid)
+    {
+        if (log)
+            log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote %i (temporary state was suspended or invalid)\n", GetID(), eVoteNoOpinion);
+        return eVoteNoOpinion;
+    }
+
+    if (!ThreadStoppedForAReason())
+    {
+        if (log)
+            log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote %i (thread didn't stop for a reason.)\n", GetID(), eVoteNoOpinion);
+        return eVoteNoOpinion;
+    }
+
     if (m_completed_plan_stack.size() > 0)
     {
         // Don't use GetCompletedPlan here, since that suppresses private plans.

Modified: lldb/trunk/source/Target/ThreadList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadList.cpp?rev=149443&r1=149442&r2=149443&view=diff
==============================================================================
--- lldb/trunk/source/Target/ThreadList.cpp (original)
+++ lldb/trunk/source/Target/ThreadList.cpp Tue Jan 31 17:09:20 2012
@@ -192,38 +192,10 @@
         log->Printf ("ThreadList::%s: %zu threads", __FUNCTION__, m_threads.size());
     }
 
-    // Run through the threads and ask whether we should stop.  Don't ask
-    // suspended threads, however, it makes more sense for them to preserve their
-    // state across the times the process runs but they don't get a chance to.
     for (pos = m_threads.begin(); pos != end; ++pos)
     {
         ThreadSP thread_sp(*pos);
         
-        if (thread_sp->GetResumeState () == eStateSuspended)
-        {
-            if (log)
-                log->Printf ("ThreadList::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since thread was suspended)", 
-                             __FUNCTION__, 
-                             thread_sp->GetID (), 
-                             thread_sp->GetRegisterContext()->GetPC());
-            continue;
-        }
-        
-        if (thread_sp->ThreadStoppedForAReason() == false)
-        {
-            if (log)
-                log->Printf ("ThreadList::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since no stop reason)", 
-                             __FUNCTION__, 
-                             thread_sp->GetID (), 
-                             thread_sp->GetRegisterContext()->GetPC());
-            continue;
-        }
-
-        if (log)
-            log->Printf ("ThreadList::%s for tid = 0x%4.4llx, pc = 0x%16.16llx", 
-                         __FUNCTION__, 
-                         thread_sp->GetID (), 
-                         thread_sp->GetRegisterContext()->GetPC());
         const bool thread_should_stop = thread_sp->ShouldStop(event_ptr);
         if (thread_should_stop)
             should_stop |= true;
@@ -263,41 +235,31 @@
     for (pos = m_threads.begin(); pos != end; ++pos)
     {
         ThreadSP thread_sp(*pos);
-        if (thread_sp->ThreadStoppedForAReason() && (thread_sp->GetResumeState () != eStateSuspended))
+        const Vote vote = thread_sp->ShouldReportStop (event_ptr);
+        switch (vote)
         {
-            const Vote vote = thread_sp->ShouldReportStop (event_ptr);
-            if (log)
-                log->Printf  ("ThreadList::%s thread 0x%4.4llx: pc = 0x%16.16llx, vote = %s", 
-                              __FUNCTION__,
-                              thread_sp->GetID (), 
-                              thread_sp->GetRegisterContext()->GetPC(),
-                              GetVoteAsCString (vote));
-            switch (vote)
-            {
-            case eVoteNoOpinion:
-                continue;
+        case eVoteNoOpinion:
+            continue;
 
-            case eVoteYes:
-                result = eVoteYes;
-                break;
+        case eVoteYes:
+            result = eVoteYes;
+            break;
 
-            case eVoteNo:
-                if (result == eVoteNoOpinion)
-                {
-                    result = eVoteNo;
-                }
-                else
-                {
-                    if (log)
-                        log->Printf ("ThreadList::%s thread 0x%4.4llx: pc = 0x%16.16llx voted %s, but lost out because result was %s", 
-                                     __FUNCTION__,
-                                     thread_sp->GetID (), 
-                                     thread_sp->GetRegisterContext()->GetPC(),
-                                     GetVoteAsCString (vote),
-                                     GetVoteAsCString (result));
-                }
-                break;
+        case eVoteNo:
+            if (result == eVoteNoOpinion)
+            {
+                result = eVoteNo;
+            }
+            else
+            {
+                if (log)
+                    log->Printf ("ThreadList::%s thread 0x%4.4llx: voted %s, but lost out because result was %s", 
+                                 __FUNCTION__,
+                                 thread_sp->GetID (), 
+                                 GetVoteAsCString (vote),
+                                 GetVoteAsCString (result));
             }
+            break;
         }
     }
     if (log)





More information about the lldb-commits mailing list