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

Greg Clayton gclayton at apple.com
Wed Apr 4 13:43:48 PDT 2012


Author: gclayton
Date: Wed Apr  4 15:43:47 2012
New Revision: 154048

URL: http://llvm.org/viewvc/llvm-project?rev=154048&view=rev
Log:
<rdar://problem/11184458>

Found an issue where we might still have shared pointer references to lldb_private::Thread objects where the object itself is not valid and has been removed from the Process. When a thread is removed from a process, it will call Thread::DestroyThread() which well set a boolean member variable which is exposed now via:

bool
Thread::IsValid() const;

We then check the thread validity before handing out a shared pointer.


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

Modified: lldb/trunk/include/lldb/Target/Thread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Thread.h?rev=154048&r1=154047&r2=154048&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Thread.h (original)
+++ lldb/trunk/include/lldb/Target/Thread.h Wed Apr  4 15:43:47 2012
@@ -758,6 +758,15 @@
                          uint32_t source_lines_before,
                          uint32_t source_lines_after);
 
+    // We need a way to verify that even though we have a thread in a shared
+    // pointer that the object itself is still valid. Currently this won't be
+    // the case if DestroyThread() was called. DestroyThread is called when
+    // a thread has been removed from the Process' thread list.
+    bool
+    IsValid () const
+    {
+        return m_destroy_called;
+    }
 protected:
 
     friend class ThreadPlan;

Modified: lldb/trunk/source/Target/ExecutionContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ExecutionContext.cpp?rev=154048&r1=154047&r2=154048&view=diff
==============================================================================
--- lldb/trunk/source/Target/ExecutionContext.cpp (original)
+++ lldb/trunk/source/Target/ExecutionContext.cpp Wed Apr  4 15:43:47 2012
@@ -658,13 +658,19 @@
 ExecutionContextRef::GetThreadSP () const
 {
     lldb::ThreadSP thread_sp (m_thread_wp.lock());
-    if (!thread_sp && m_tid != LLDB_INVALID_THREAD_ID)
+    if (m_tid != LLDB_INVALID_THREAD_ID)
     {
-        lldb::ProcessSP process_sp(GetProcessSP());
-        if (process_sp)
+        // We check if the thread has been destroyed in cases where clients
+        // might still have shared pointer to a thread, but the thread is
+        // not valid anymore (not part of the process)
+        if (!thread_sp || !thread_sp->IsValid())
         {
-            thread_sp = process_sp->GetThreadList().FindThreadByID(m_tid);
-            m_thread_wp = thread_sp;
+            lldb::ProcessSP process_sp(GetProcessSP());
+            if (process_sp)
+            {
+                thread_sp = process_sp->GetThreadList().FindThreadByID(m_tid);
+                m_thread_wp = thread_sp;
+            }
         }
     }
     return thread_sp;





More information about the lldb-commits mailing list