[Lldb-commits] [lldb] r124180 - in /lldb/trunk: source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp tools/debugserver/source/MacOSX/MachThread.cpp tools/debugserver/source/MacOSX/MachThread.h

Greg Clayton gclayton at apple.com
Mon Jan 24 22:55:14 PST 2011


Author: gclayton
Date: Tue Jan 25 00:55:13 2011
New Revision: 124180

URL: http://llvm.org/viewvc/llvm-project?rev=124180&view=rev
Log:
Reverting recent thread resume changes as it was causing testing issues.
We will need to try again soon, but this change was causing instability.


Modified:
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp
    lldb/trunk/tools/debugserver/source/MacOSX/MachThread.h

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=124180&r1=124179&r2=124180&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Tue Jan 25 00:55:13 2011
@@ -1307,7 +1307,7 @@
     {
         StringExtractorGDBRemote response;
         bool send_async = true;
-        if (m_gdb_comm.SendPacketAndWaitForResponse("k", 1, response, 3, send_async))
+        if (m_gdb_comm.SendPacketAndWaitForResponse("k", 1, response, 2, send_async))
         {
             char packet_cmd = response.GetChar(0);
 
@@ -1319,7 +1319,8 @@
         }
         else
         {
-            error.SetErrorString("kill packet failed");
+            SetExitStatus(SIGABRT, NULL);
+            //error.SetErrorString("kill packet failed");
         }
     }
     StopAsyncThread ();
@@ -1936,8 +1937,8 @@
                 ::snprintf (arg_cstr, sizeof(arg_cstr), "--log-flags=%s", env_debugserver_log_flags);
                 debugserver_args.AppendArgument(arg_cstr);
             }
-            debugserver_args.AppendArgument("--log-file=/tmp/debugserver.txt");
-            debugserver_args.AppendArgument("--log-flags=0x800e0e");
+//            debugserver_args.AppendArgument("--log-file=/tmp/debugserver.txt");
+//            debugserver_args.AppendArgument("--log-flags=0x800e0e");
 
             // Now append the program arguments
             if (launch_process)

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp?rev=124180&r1=124179&r2=124180&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp Tue Jan 25 00:55:13 2011
@@ -30,15 +30,14 @@
     m_state (eStateUnloaded),
     m_state_mutex (PTHREAD_MUTEX_RECURSIVE),
     m_breakID (INVALID_NUB_BREAK_ID),
-    m_suspend_count (0),
+    m_suspendCount (0),
     m_arch_ap (DNBArchProtocol::Create (this)),
-    m_reg_sets (m_arch_ap->GetRegisterSetInfo (&n_num_reg_sets)),
-    m_basic_info_valid (false)
+    m_reg_sets (m_arch_ap->GetRegisterSetInfo (&n_num_reg_sets))
 {
     // Get the thread state so we know if a thread is in a state where we can't
     // muck with it and also so we get the suspend count correct in case it was
     // already suspended
-    GetBasicInfo(true);
+    GetBasicInfo();
     DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::MachThread ( process = %p, tid = 0x%4.4x, seq_id = %u )", &m_process, m_tid, m_seq_id);
 }
 
@@ -49,7 +48,7 @@
 
 
 
-int32_t
+uint32_t
 MachThread::Suspend()
 {
     DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::%s ( )", __FUNCTION__);
@@ -57,47 +56,14 @@
     {
         DNBError err(::thread_suspend (m_tid), DNBError::MachKernel);
         if (err.Success())
-            m_suspend_count++;
+            m_suspendCount++;
         if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
             err.LogThreaded("::thread_suspend (%4.4x)", m_tid);
     }
-    return m_suspend_count;
-}
-
-int32_t
-MachThread::ForceResume ()
-{
-    // We need to resume this all the way to 0.  
-    DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::%s ( )", __FUNCTION__);
-    // Okay, now m_basic_info has the full suspend count.  So I'll just
-    // keep decrementing the suspend count till that is zero, and at the same time
-    // decrement m_suspend_count.  If that goes below zero, then the next time we
-    // call RestoreSuspendCount, we'll have to suspend it back to 0.
-    uint32_t num_suspends = m_basic_info.suspend_count + m_suspend_count;
-    DNBError err;
-    while (num_suspends > 0)
-    {
-        if (m_suspend_count < 0)
-         DNBLogThreadedIf(LOG_THREAD, "MachThread::%s ( ) (tid = %4.4x) setting suspend count negative = %d", __FUNCTION__,
-                     m_tid, m_suspend_count);
-        err = ::thread_resume (m_tid);
-        if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
-            err.LogThreaded("ForceResume ::thread_resume (%4.4x)", m_tid);
-        if (err.Success())
-        {
-            --m_suspend_count;
-            --num_suspends;
-        }
-        else
-        {
-            break;
-        }
-    }
-    return m_suspend_count;
-
+    return SuspendCount();
 }
 
-int32_t
+uint32_t
 MachThread::Resume()
 {
     DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::%s ( )", __FUNCTION__);
@@ -105,59 +71,49 @@
     {
         RestoreSuspendCount();
     }
-    return m_suspend_count;
+    return SuspendCount();
 }
 
 bool
 MachThread::RestoreSuspendCount()
 {
-    DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::%s ( ) (tid = %4.4x) our suspend count = %d", __FUNCTION__,
-                     m_tid, m_suspend_count);
+    DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::%s ( )", __FUNCTION__);
     DNBError err;
     if (ThreadIDIsValid(m_tid) == false)
         return false;
-    if (m_suspend_count > 0)
+    if (m_suspendCount > 0)
     {
-        while (m_suspend_count > 0)
+        while (m_suspendCount > 0)
         {
             err = ::thread_resume (m_tid);
             if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
-                err.LogThreaded("RestoreSuspendCount ::thread_resume (%4.4x)", m_tid);
-            if (err.Success())
-                --m_suspend_count;
-            else
-            {
-                if (GetBasicInfo(true))
-                    m_suspend_count = m_basic_info.suspend_count;
-                else
-                    m_suspend_count = 0;
-                return false; // ??? 
-            }
-        }
-    }
-    else if (m_suspend_count < 0)
-    {
-         DNBLogThreadedIf(LOG_THREAD, "MachThread::%s ( ) (tid = %4.4x) negative suspend count = %d", __FUNCTION__,
-                     m_tid, m_suspend_count);
-        while (m_suspend_count < 0)
-        {
-            err = ::thread_suspend (m_tid);
-            if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
-                err.LogThreaded("RestoreSuspendCount ::thread_suspend (%4.4x)", m_tid);
-                
+                err.LogThreaded("::thread_resume (%4.4x)", m_tid);
             if (err.Success())
-                ++m_suspend_count;
+                --m_suspendCount;
             else
             {
-                if (GetBasicInfo(true))
-                    m_suspend_count = m_basic_info.suspend_count;
+                if (GetBasicInfo())
+                    m_suspendCount = m_basicInfo.suspend_count;
                 else
-                    m_suspend_count = 0;
+                    m_suspendCount = 0;
                 return false; // ??? 
             }
-
         }
     }
+    // We don't currently really support resuming a thread that was externally
+    // suspended. If/when we do, we will need to make the code below work and
+    // m_suspendCount will need to become signed instead of unsigned.
+//    else if (m_suspendCount < 0)
+//    {
+//        while (m_suspendCount < 0)
+//        {
+//            err = ::thread_suspend (m_tid);
+//            if (err.Success())
+//                ++m_suspendCount;
+//            if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
+//                err.LogThreaded("::thread_suspend (%4.4x)", m_tid);
+//        }
+//    }
     return true;
 }
 
@@ -237,9 +193,10 @@
 bool
 MachThread::IsUserReady()
 {
-    GetBasicInfo (false);
+    if (m_basicInfo.run_state == 0)
+        GetBasicInfo ();
     
-    switch (m_basic_info.run_state)
+    switch (m_basicInfo.run_state)
     {
     default: 
     case TH_STATE_UNINTERRUPTIBLE:  
@@ -255,16 +212,10 @@
 }
 
 struct thread_basic_info *
-MachThread::GetBasicInfo (bool force)
+MachThread::GetBasicInfo ()
 {
-    if (!force && m_basic_info_valid)
-        return &m_basic_info;
-        
-    if (MachThread::GetBasicInfo(m_tid, &m_basic_info))
-    {
-        m_basic_info_valid = true;
-        return &m_basic_info;
-    }
+    if (MachThread::GetBasicInfo(m_tid, &m_basicInfo))
+        return &m_basicInfo;
     return NULL;
 }
 
@@ -336,7 +287,7 @@
 {
     const char * thread_run_state = NULL;
 
-    switch (m_basic_info.run_state)
+    switch (m_basicInfo.run_state)
     {
     case TH_STATE_RUNNING:          thread_run_state = "running"; break;    // 1 thread is running normally
     case TH_STATE_STOPPED:          thread_run_state = "stopped"; break;    // 2 thread is stopped
@@ -353,15 +304,15 @@
         GetPC(INVALID_NUB_ADDRESS),
         GetSP(INVALID_NUB_ADDRESS),
         m_breakID,
-        m_basic_info.user_time.seconds,      m_basic_info.user_time.microseconds,
-        m_basic_info.system_time.seconds,    m_basic_info.system_time.microseconds,
-        m_basic_info.cpu_usage,
-        m_basic_info.policy,
-        m_basic_info.run_state,
+        m_basicInfo.user_time.seconds,      m_basicInfo.user_time.microseconds,
+        m_basicInfo.system_time.seconds,    m_basicInfo.system_time.microseconds,
+        m_basicInfo.cpu_usage,
+        m_basicInfo.policy,
+        m_basicInfo.run_state,
         thread_run_state,
-        m_basic_info.flags,
-        m_basic_info.suspend_count, m_suspend_count,
-        m_basic_info.sleep_time);
+        m_basicInfo.flags,
+        m_basicInfo.suspend_count, m_suspendCount,
+        m_basicInfo.sleep_time);
     //DumpRegisterState(0);
 }
 
@@ -370,11 +321,7 @@
 {
     if (thread_action->addr != INVALID_NUB_ADDRESS)
         SetPC (thread_action->addr);
-    // DidStop restores the state to it's natural state, and sets
-    // m_suspend_count to 0 in the process, and then here is the only
-    // place that we should be suspending or resuming (and thus changing
-    // that state.
-    assert (m_suspend_count == 0);
+
     SetState (thread_action->state);
     switch (thread_action->state)
     {
@@ -384,10 +331,8 @@
         break;
 
     case eStateRunning:
-        Resume();
-        break;
     case eStateStepping:
-        ForceResume();
+        Resume();
         break;
     }
     m_arch_ap->ThreadWillResume();
@@ -493,7 +438,7 @@
     RestoreSuspendCount();
 
     // Update the basic information for a thread
-    GetBasicInfo (true);
+    MachThread::GetBasicInfo(m_tid, &m_basicInfo);
 
 #if ENABLE_AUTO_STEPPING_OVER_BP
     // See if we were at a breakpoint when we last resumed that we disabled,
@@ -503,7 +448,7 @@
     if (NUB_BREAK_ID_IS_VALID(breakID))
     {
         m_process->EnableBreakpoint(breakID);
-        if (m_basic_info.suspend_count > 0)
+        if (m_basicInfo.suspend_count > 0)
         {
             SetState(eStateSuspended);
         }
@@ -526,7 +471,7 @@
     }
     else
     {
-        if (m_basic_info.suspend_count > 0)
+        if (m_basicInfo.suspend_count > 0)
         {
             SetState(eStateSuspended);
         }
@@ -536,7 +481,7 @@
         }
     }
 #else
-    if (m_basic_info.suspend_count > 0)
+    if (m_basicInfo.suspend_count > 0)
         SetState(eStateSuspended);
     else
         SetState(eStateStopped);

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachThread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachThread.h?rev=124180&r1=124179&r2=124180&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachThread.h (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachThread.h Tue Jan 25 00:55:13 2011
@@ -49,6 +49,11 @@
 
     uint32_t        SequenceID() const { return m_seq_id; }
     static bool     ThreadIDIsValid(thread_t thread);
+    uint32_t        Resume();
+    uint32_t        Suspend();
+    uint32_t        SuspendCount() const { return m_suspendCount; }
+    bool            RestoreSuspendCount();
+
     bool            GetRegisterState(int flavor, bool force);
     bool            SetRegisterState(int flavor);
     uint64_t        GetPC(uint64_t failValue = INVALID_NUB_ADDRESS);    // Get program counter
@@ -87,6 +92,8 @@
                     }
 
     bool            IsUserReady();
+    struct thread_basic_info *
+                    GetBasicInfo ();
     const char *    GetBasicInfoAsString () const;
     const char *    GetName ();
     
@@ -97,13 +104,6 @@
     }
 
 protected:
-    int32_t         Resume();
-    int32_t         ForceResume();
-    int32_t         Suspend();
-//    uint32_t        SuspendCount() const { return m_suspendCount; }
-    bool            RestoreSuspendCount();
-    struct thread_basic_info *
-                    GetBasicInfo (bool force);
     static bool     GetBasicInfo(thread_t threadID, struct thread_basic_info *basic_info);
 
     bool
@@ -118,9 +118,8 @@
     nub_state_t                     m_state;        // The state of our process
     PThreadMutex                    m_state_mutex;  // Multithreaded protection for m_state
     nub_break_t                     m_breakID;      // Breakpoint that this thread is (stopped)/was(running) at (NULL for none)
-    struct thread_basic_info        m_basic_info;    // Basic information for a thread used to see if a thread is valid
-    bool                            m_basic_info_valid;
-    uint32_t                        m_suspend_count; // The current suspend count
+    struct thread_basic_info        m_basicInfo;    // Basic information for a thread used to see if a thread is valid
+    uint32_t                        m_suspendCount; // The current suspend count
     MachException::Data             m_stop_exception; // The best exception that describes why this thread is stopped
     std::auto_ptr<DNBArchProtocol>  m_arch_ap;      // Arch specific information for register state and more
     const DNBRegisterSetInfo *const m_reg_sets;      // Register set information for this thread
@@ -129,7 +128,6 @@
     thread_identifier_info_data_t   m_ident_info;
     struct proc_threadinfo          m_proc_threadinfo;
     std::string                     m_dispatch_queue_name;
-
 #endif
 
 };





More information about the lldb-commits mailing list