[Lldb-commits] [lldb] r195104 - Add logging for the SB API which creates extended

Jason Molenda jmolenda at apple.com
Mon Nov 18 21:44:41 PST 2013


Author: jmolenda
Date: Mon Nov 18 23:44:41 2013
New Revision: 195104

URL: http://llvm.org/viewvc/llvm-project?rev=195104&view=rev
Log:
Add logging for the SB API which creates extended
threads.

Take a stab at fixing the too-soon freeing of the extended
backtrace thread list in Process.
<rdar://problem/15496603> 

Modified:
    lldb/trunk/include/lldb/Target/Thread.h
    lldb/trunk/source/API/SBThread.cpp
    lldb/trunk/source/Plugins/Process/Utility/HistoryThread.cpp
    lldb/trunk/source/Plugins/Process/Utility/HistoryThread.h
    lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
    lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h
    lldb/trunk/source/Target/Process.cpp

Modified: lldb/trunk/include/lldb/Target/Thread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Thread.h?rev=195104&r1=195103&r2=195104&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Thread.h (original)
+++ lldb/trunk/include/lldb/Target/Thread.h Mon Nov 18 23:44:41 2013
@@ -284,6 +284,11 @@ public:
         return LLDB_INVALID_QUEUE_ID;
     }
 
+    virtual void
+    SetQueueID (lldb::queue_id_t new_val)
+    {
+    }
+
     virtual const char *
     GetQueueName ()
     {

Modified: lldb/trunk/source/API/SBThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBThread.cpp?rev=195104&r1=195103&r2=195104&view=diff
==============================================================================
--- lldb/trunk/source/API/SBThread.cpp (original)
+++ lldb/trunk/source/API/SBThread.cpp Mon Nov 18 23:44:41 2013
@@ -1305,10 +1305,20 @@ SBThread::GetExtendedBacktraceThread (co
                     if (runtime)
                     {
                         ThreadSP new_thread_sp (runtime->GetExtendedBacktraceThread (real_thread, type_const));
-                        // Save this in the Process' ExtendedThreadList so a strong pointer retains the
-                        // object.
-                        process->GetExtendedThreadList().AddThread (new_thread_sp);
-                        sb_origin_thread.SetThread (new_thread_sp);
+                        if (new_thread_sp)
+                        {
+                            // Save this in the Process' ExtendedThreadList so a strong pointer retains the
+                            // object.
+                            process->GetExtendedThreadList().AddThread (new_thread_sp);
+                            sb_origin_thread.SetThread (new_thread_sp);
+                            if (log)
+                            {
+                                const char *queue_name = new_thread_sp->GetQueueName();
+                                if (queue_name == NULL)
+                                    queue_name = "";
+                                log->Printf ("SBThread(%p)::GetExtendedBacktraceThread() => new extended Thread created (%p) with queue_id 0x%" PRIx64 " queue name '%s'", exe_ctx.GetThreadPtr(), new_thread_sp.get(), new_thread_sp->GetQueueID(), queue_name);
+                            }
+                        }
                     }
                 }
             }
@@ -1316,7 +1326,7 @@ SBThread::GetExtendedBacktraceThread (co
         else
         {
             if (log)
-                log->Printf ("SBThread(%p)::GetExtendedBacktrace() => error: process is running", exe_ctx.GetThreadPtr());
+                log->Printf ("SBThread(%p)::GetExtendedBacktraceThread() => error: process is running", exe_ctx.GetThreadPtr());
         }
     }
 

Modified: lldb/trunk/source/Plugins/Process/Utility/HistoryThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/HistoryThread.cpp?rev=195104&r1=195103&r2=195104&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/HistoryThread.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/HistoryThread.cpp Mon Nov 18 23:44:41 2013
@@ -34,7 +34,8 @@ HistoryThread::HistoryThread (lldb_priva
         m_extended_unwind_token (LLDB_INVALID_ADDRESS),
         m_queue_name (),
         m_thread_name (),
-        m_originating_unique_thread_id (tid)
+        m_originating_unique_thread_id (tid),
+        m_queue_id (LLDB_INVALID_QUEUE_ID)
 {
     m_unwinder_ap.reset (new HistoryUnwind (*this, pcs, stop_id, stop_id_is_valid));
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));

Modified: lldb/trunk/source/Plugins/Process/Utility/HistoryThread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/HistoryThread.h?rev=195104&r1=195103&r2=195104&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/HistoryThread.h (original)
+++ lldb/trunk/source/Plugins/Process/Utility/HistoryThread.h Mon Nov 18 23:44:41 2013
@@ -65,6 +65,18 @@ public:
         m_queue_name = name;
     }
 
+    lldb::queue_id_t
+    GetQueueID ()
+    {
+        return m_queue_id;
+    }
+
+    void
+    SetQueueID (lldb::queue_id_t queue)
+    {
+        m_queue_id = queue;
+    }
+
     const char *
     GetThreadName ()
     {
@@ -94,6 +106,7 @@ protected:
     std::string                 m_queue_name;
     std::string                 m_thread_name;
     lldb::tid_t                 m_originating_unique_thread_id;
+    lldb::queue_id_t            m_queue_id;
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp?rev=195104&r1=195103&r2=195104&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp (original)
+++ lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp Mon Nov 18 23:44:41 2013
@@ -198,7 +198,15 @@ SystemRuntimeMacOSX::ParseLdiHeaders ()
                     m_ldi_header.item_offsets.pthread_id = ldi_extractor.GetU16(&offset);
                     m_ldi_header.item_offsets.enqueueing_thread_dispatch_queue_t = ldi_extractor.GetU16(&offset);
                     m_ldi_header.item_offsets.enqueueing_thread_dispatch_block_ptr = ldi_extractor.GetU16(&offset);
-                    
+
+                    if (ldi_header.GetByteSize () > offset)
+                    {
+                        m_ldi_header.item_offsets.queue_id_from_thread_info = ldi_extractor.GetU16(&offset);
+                    }
+                    else
+                    {
+                        m_ldi_header.item_offsets.queue_id_from_thread_info = 0xffff;
+                    }
                 }
             }
         }
@@ -376,8 +384,28 @@ SystemRuntimeMacOSX::SetNewThreadExtende
     }
 }
 
+void
+SystemRuntimeMacOSX::SetNewThreadQueueID (ThreadSP original_thread_sp, ThreadSP new_extended_thread_sp)
+{
+    queue_id_t queue_id = LLDB_INVALID_QUEUE_ID;
+    addr_t enqueued_item_ptr = GetThreadCreatorItem (original_thread_sp);
+    if (enqueued_item_ptr != LLDB_INVALID_ADDRESS && m_ldi_header.item_offsets.queue_id_from_thread_info != 0xffff)
+    {
+        Error error;
+        queue_id = m_process->ReadUnsignedIntegerFromMemory (enqueued_item_ptr + m_ldi_header.item_offsets.queue_id_from_thread_info, 8, LLDB_INVALID_QUEUE_ID, error);
+        if (!error.Success())
+            queue_id = LLDB_INVALID_QUEUE_ID;
+    }
+
+    if (queue_id != LLDB_INVALID_QUEUE_ID)
+    {
+        new_extended_thread_sp->SetQueueID (queue_id);
+    }
+}
+
+
 lldb::tid_t
-SystemRuntimeMacOSX::GetNewThreadUniquethreadID (ThreadSP original_thread_sp)
+SystemRuntimeMacOSX::GetNewThreadUniqueThreadID (ThreadSP original_thread_sp)
 {
     tid_t ret = LLDB_INVALID_THREAD_ID;
     addr_t enqueued_item_ptr = GetThreadCreatorItem (original_thread_sp);
@@ -404,14 +432,14 @@ SystemRuntimeMacOSX::GetExtendedBacktrac
     if (bt.pcs.size() == 0)
         return new_extended_thread_sp;
 
-    tid_t unique_thread_id = GetNewThreadUniquethreadID (original_thread_sp);
+    tid_t unique_thread_id = GetNewThreadUniqueThreadID (original_thread_sp);
 
     new_extended_thread_sp.reset (new HistoryThread (*m_process, unique_thread_id, bt.pcs, bt.stop_id, bt.stop_id_is_valid));
 
-    SetNewThreadThreadName(original_thread_sp, new_extended_thread_sp);
-    SetNewThreadQueueName(original_thread_sp, new_extended_thread_sp);
-    SetNewThreadExtendedBacktraceToken(original_thread_sp, new_extended_thread_sp);
-
+    SetNewThreadThreadName (original_thread_sp, new_extended_thread_sp);
+    SetNewThreadQueueName (original_thread_sp, new_extended_thread_sp);
+    SetNewThreadQueueID (original_thread_sp, new_extended_thread_sp);
+    SetNewThreadExtendedBacktraceToken (original_thread_sp, new_extended_thread_sp);
     return new_extended_thread_sp;
 }
 

Modified: lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h?rev=195104&r1=195103&r2=195104&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h (original)
+++ lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h Mon Nov 18 23:44:41 2013
@@ -126,7 +126,7 @@ private:
     GetThreadCreatorItem (lldb::ThreadSP thread);
 
     lldb::tid_t
-    GetNewThreadUniquethreadID (lldb::ThreadSP original_thread_sp);
+    GetNewThreadUniqueThreadID (lldb::ThreadSP original_thread_sp);
 
     void
     SetNewThreadThreadName (lldb::ThreadSP original_thread_sp, lldb::ThreadSP new_extended_thread_sp);
@@ -137,6 +137,9 @@ private:
     void
     SetNewThreadExtendedBacktraceToken (lldb::ThreadSP original_thread_sp, lldb::ThreadSP new_extended_thread_sp);
 
+    void
+    SetNewThreadQueueID (lldb::ThreadSP original_thread_sp, lldb::ThreadSP new_extended_thread_sp);
+
     struct ldi_queue_offsets {
         uint16_t next;
         uint16_t prev;
@@ -158,6 +161,7 @@ private:
         uint16_t pthread_id;
         uint16_t enqueueing_thread_dispatch_queue_t;
         uint16_t enqueueing_thread_dispatch_block_ptr;
+        uint16_t queue_id_from_thread_info;
     };
 
     struct ldi_header {

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=195104&r1=195103&r2=195104&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Mon Nov 18 23:44:41 2013
@@ -1593,9 +1593,10 @@ Process::UpdateThreadListIfNeeded ()
                 m_thread_list_real.Update(real_thread_list);
                 m_thread_list.Update (new_thread_list);
                 m_thread_list.SetStopID (stop_id);
+
+                // Clear any extended threads that we may have accumulated previously
+                m_extended_thread_list.Clear();
             }
-            // Clear any extended threads that we may have accumulated previously
-            m_extended_thread_list.Clear();
         }
     }
 }





More information about the lldb-commits mailing list