[Lldb-commits] [lldb] r144875 - in /lldb/trunk: include/lldb/Core/State.h source/API/SBDebugger.cpp source/Commands/CommandObjectProcess.cpp source/Commands/CommandObjectTarget.cpp source/Core/State.cpp source/Host/macosx/Host.mm source/Target/Process.cpp

Greg Clayton gclayton at apple.com
Wed Nov 16 17:23:07 PST 2011


Author: gclayton
Date: Wed Nov 16 19:23:07 2011
New Revision: 144875

URL: http://llvm.org/viewvc/llvm-project?rev=144875&view=rev
Log:
Fixed an issue with the pthread_setspecific() where we weren't NULL-ing out
the thread specific data and were destroying the thread specfic data more
than once.

Also added the ability to ask a lldb::StateType if it is stopped with an
additional paramter of "must_exist" which means that the state must be a
stopped state for a process that still exists. This means that eStateExited
and eStateUnloaded will no longer return true if "must_exist" is set to true.


Modified:
    lldb/trunk/include/lldb/Core/State.h
    lldb/trunk/source/API/SBDebugger.cpp
    lldb/trunk/source/Commands/CommandObjectProcess.cpp
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Core/State.cpp
    lldb/trunk/source/Host/macosx/Host.mm
    lldb/trunk/source/Target/Process.cpp

Modified: lldb/trunk/include/lldb/Core/State.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/State.h?rev=144875&r1=144874&r2=144875&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/State.h (original)
+++ lldb/trunk/include/lldb/Core/State.h Wed Nov 16 19:23:07 2011
@@ -32,12 +32,44 @@
 const char *
 StateAsCString (lldb::StateType state);
 
+//------------------------------------------------------------------
+/// Check if a state represents a state where the process or thread
+/// is running.
+///
+/// @param[in] state
+///     The StateType enumeration value
+///
+/// @return
+///     \b true if the state represents a process or thread state
+///     where the process or thread is running, \b false otherwise.
+//------------------------------------------------------------------
 bool
 StateIsRunningState (lldb::StateType state);
 
+//------------------------------------------------------------------
+/// Check if a state represents a state where the process or thread
+/// is stopped. Stopped can mean stopped when the process is still
+/// around, or stopped when the process has exited or doesn't exist 
+/// yet. The \a must_exist argument tells us which of these cases is
+/// desired.
+///
+/// @param[in] state
+///     The StateType enumeration value
+///
+/// @param[in] must_exist
+///     A boolean that indicates the thread must also be alive
+///     so states like unloaded or exited won't return true.
+///
+/// @return
+///     \b true if the state represents a process or thread state
+///     where the process or thread is stopped. If \a must_exist is 
+///     \b true, then the process can't be exited or unloaded,
+///     otherwise exited and unloaded or other states where the
+///     process no longer exists are considered to be stopped. 
+//------------------------------------------------------------------
 bool
-StateIsStoppedState (lldb::StateType state);
-    
+StateIsStoppedState (lldb::StateType state, bool must_exist);
+
 const char *
 GetPermissionsAsCString (uint32_t permissions);
     

Modified: lldb/trunk/source/API/SBDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=144875&r1=144874&r2=144875&view=diff
==============================================================================
--- lldb/trunk/source/API/SBDebugger.cpp (original)
+++ lldb/trunk/source/API/SBDebugger.cpp Wed Nov 16 19:23:07 2011
@@ -452,7 +452,7 @@
 {
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
-    const bool result = lldb_private::StateIsStoppedState (state);
+    const bool result = lldb_private::StateIsStoppedState (state, false);
     if (log)
         log->Printf ("SBDebugger::StateIsStoppedState (state=%s) => %i", 
                      StateAsCString (state), result);

Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=144875&r1=144874&r2=144875&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Wed Nov 16 19:23:07 2011
@@ -284,7 +284,8 @@
                         if (synchronous_execution)
                         {
                             state = process->WaitForProcessToStop (NULL);
-                            if (!StateIsStoppedState(state))
+                            const bool must_be_alive = true;
+                            if (!StateIsStoppedState(state, must_be_alive))
                             {
                                 result.AppendErrorWithFormat ("process isn't stopped: %s", StateAsCString(state));
                             }                    

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=144875&r1=144874&r2=144875&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Wed Nov 16 19:23:07 2011
@@ -82,7 +82,7 @@
         lldb::pid_t pid = process_sp->GetID();
         StateType state = process_sp->GetState();
         if (show_stopped_process_status)
-            show_process_status = StateIsStoppedState(state);
+            show_process_status = StateIsStoppedState(state, true);
         const char *state_cstr = StateAsCString (state);
         if (pid != LLDB_INVALID_PROCESS_ID)
             strm.Printf ("%spid=%i", properties++ > 0 ? ", " : " ( ", pid);

Modified: lldb/trunk/source/Core/State.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/State.cpp?rev=144875&r1=144874&r2=144875&view=diff
==============================================================================
--- lldb/trunk/source/Core/State.cpp (original)
+++ lldb/trunk/source/Core/State.cpp Wed Nov 16 19:23:07 2011
@@ -90,7 +90,7 @@
 }
 
 bool
-lldb_private::StateIsStoppedState (StateType state)
+lldb_private::StateIsStoppedState (StateType state, bool must_exist)
 {
     switch (state)
     {
@@ -105,9 +105,11 @@
         break;
 
     case eStateUnloaded:
+    case eStateExited:
+        return !must_exist;
+
     case eStateStopped:
     case eStateCrashed:
-    case eStateExited:
     case eStateSuspended:
         return true;
     }

Modified: lldb/trunk/source/Host/macosx/Host.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Host.mm?rev=144875&r1=144874&r2=144875&view=diff
==============================================================================
--- lldb/trunk/source/Host/macosx/Host.mm (original)
+++ lldb/trunk/source/Host/macosx/Host.mm Wed Nov 16 19:23:07 2011
@@ -68,6 +68,9 @@
 using namespace lldb;
 using namespace lldb_private;
 
+static pthread_once_t g_thread_create_once = PTHREAD_ONCE_INIT;
+static pthread_key_t g_thread_create_key = 0;
+
 class MacOSXDarwinThread
 {
 public:
@@ -98,12 +101,17 @@
     ~MacOSXDarwinThread()
     {
         if (m_pool)
+        {
             [m_pool release];
+            m_pool = nil;
+        }
     }
 
     static void PThreadDestructor (void *v)
     {
-        delete (MacOSXDarwinThread*)v;
+        if (v)
+            delete static_cast<MacOSXDarwinThread*>(v);
+        ::pthread_setspecific (g_thread_create_key, NULL);
     }
 
 protected:
@@ -112,9 +120,6 @@
     DISALLOW_COPY_AND_ASSIGN (MacOSXDarwinThread);
 };
 
-static pthread_once_t g_thread_create_once = PTHREAD_ONCE_INIT;
-static pthread_key_t g_thread_create_key = 0;
-
 static void
 InitThreadCreated()
 {

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=144875&r1=144874&r2=144875&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Wed Nov 16 19:23:07 2011
@@ -1179,16 +1179,20 @@
     const uint32_t stop_id = GetStopID();
     if (m_thread_list.GetSize(false) == 0 || stop_id != m_thread_list.GetStopID())
     {
-        Mutex::Locker locker (m_thread_list.GetMutex ());
-        ThreadList new_thread_list(this);
-        // Always update the thread list with the protocol specific
-        // thread list
-        UpdateThreadList (m_thread_list, new_thread_list);
-        OperatingSystem *os = GetOperatingSystem ();
-        if (os)
-            os->UpdateThreadList (m_thread_list, new_thread_list);
-        m_thread_list.Update (new_thread_list);
-        m_thread_list.SetStopID (stop_id);
+        const StateType state = GetPrivateState();
+        if (StateIsStoppedState (state, true))
+        {
+            Mutex::Locker locker (m_thread_list.GetMutex ());
+            ThreadList new_thread_list(this);
+            // Always update the thread list with the protocol specific
+            // thread list
+            UpdateThreadList (m_thread_list, new_thread_list);
+            OperatingSystem *os = GetOperatingSystem ();
+            if (os)
+                os->UpdateThreadList (m_thread_list, new_thread_list);
+            m_thread_list.Update (new_thread_list);
+            m_thread_list.SetStopID (stop_id);
+        }
     }
 }
 
@@ -1236,7 +1240,7 @@
     if (state_changed)
     {
         m_private_state.SetValueNoLock (new_state);
-        if (StateIsStoppedState(new_state))
+        if (StateIsStoppedState(new_state, false))
         {
             m_mod_id.BumpStopID();
             m_memory_cache.Clear();
@@ -2167,7 +2171,7 @@
         event_sp.reset();
         state = WaitForStateChangedEventsPrivate (timeout, event_sp);
 
-        if (StateIsStoppedState(state))
+        if (StateIsStoppedState(state, false))
             break;
 
         // If state is invalid, then we timed out
@@ -2683,7 +2687,7 @@
                     }
                     else
                     {
-                        if (StateIsStoppedState (state))
+                        if (StateIsStoppedState (state, false))
                         {
                             // We caused the process to interrupt itself, so mark this
                             // as such in the stop event so clients can tell an interrupted
@@ -4247,7 +4251,7 @@
 Process::GetStatus (Stream &strm)
 {
     const StateType state = GetState();
-    if (StateIsStoppedState(state))
+    if (StateIsStoppedState(state, false))
     {
         if (state == eStateExited)
         {





More information about the lldb-commits mailing list