[Lldb-commits] [lldb] r203088 - When a client asks for a queue pending item's extended backtrace,

Jason Molenda jmolenda at apple.com
Wed Mar 5 22:31:19 PST 2014


Author: jmolenda
Date: Thu Mar  6 00:31:18 2014
New Revision: 203088

URL: http://llvm.org/viewvc/llvm-project?rev=203088&view=rev
Log:
When a client asks for a queue pending item's extended backtrace,
hold a strong pointer to that extended backtrace thread in the Process
just like we do for asking a thread's extended backtrace.
Also, give extended backtrace threads an invalid ThreadIndexID number.
We'll still give them valid thread_id's.  Clients who want to know the
original thread's IndexID can call GetExtendedBacktraceOriginatingIndexID().
<rdar://problem/16126034> 

Modified:
    lldb/trunk/include/lldb/Target/QueueItem.h
    lldb/trunk/include/lldb/Target/Thread.h
    lldb/trunk/source/API/SBQueueItem.cpp
    lldb/trunk/source/Plugins/Process/Utility/HistoryThread.cpp
    lldb/trunk/source/Plugins/Process/Utility/HistoryUnwind.cpp
    lldb/trunk/source/Target/QueueItem.cpp
    lldb/trunk/source/Target/Thread.cpp

Modified: lldb/trunk/include/lldb/Target/QueueItem.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/QueueItem.h?rev=203088&r1=203087&r2=203088&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/QueueItem.h (original)
+++ lldb/trunk/include/lldb/Target/QueueItem.h Thu Mar  6 00:31:18 2014
@@ -14,6 +14,7 @@
 
 #include "lldb/lldb-private.h"
 #include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-forward.h"
 
 #include "lldb/Core/Address.h"
 #include "lldb/Core/ConstString.h"
@@ -213,6 +214,9 @@ public:
         m_target_queue_label = queue_name;
     }
 
+    lldb::ProcessSP
+    GetProcessSP ();
+
 protected:
     lldb::QueueWP           m_queue_wp;
     lldb::QueueItemKind     m_kind;

Modified: lldb/trunk/include/lldb/Target/Thread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Thread.h?rev=203088&r1=203087&r2=203088&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Thread.h (original)
+++ lldb/trunk/include/lldb/Target/Thread.h Thu Mar  6 00:31:18 2014
@@ -153,7 +153,25 @@ public:
     static const ThreadPropertiesSP &
     GetGlobalProperties();
 
-    Thread (Process &process, lldb::tid_t tid);
+    //------------------------------------------------------------------
+    /// Constructor
+    ///
+    /// @param [in] process
+    ///
+    /// @param [in] tid
+    ///
+    /// @param [in] use_invalid_index_id
+    ///     Optional parameter, defaults to false.  The only subclass that
+    ///     is likely to set use_invalid_index_id == true is the HistoryThread
+    ///     class.  In that case, the Thread we are constructing represents
+    ///     a thread from earlier in the program execution.  We may have the 
+    ///     tid of the original thread that they represent but we don't want 
+    ///     to reuse the IndexID of that thread, or create a new one.  If a
+    ///     client wants to know the original thread's IndexID, they should use
+    ///     Thread::GetExtendedBacktraceOriginatingIndexID().
+    //------------------------------------------------------------------
+    Thread (Process &process, lldb::tid_t tid, bool use_invalid_index_id = false);
+
     virtual ~Thread();
 
     lldb::ProcessSP

Modified: lldb/trunk/source/API/SBQueueItem.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBQueueItem.cpp?rev=203088&r1=203087&r2=203088&view=diff
==============================================================================
--- lldb/trunk/source/API/SBQueueItem.cpp (original)
+++ lldb/trunk/source/API/SBQueueItem.cpp Thu Mar  6 00:31:18 2014
@@ -14,6 +14,7 @@
 #include "lldb/API/SBQueueItem.h"
 #include "lldb/API/SBThread.h"
 #include "lldb/Core/Address.h"
+#include "lldb/Target/Process.h"
 #include "lldb/Target/QueueItem.h"
 #include "lldb/Target/Thread.h"
 
@@ -108,12 +109,20 @@ SBQueueItem::GetExtendedBacktraceThread
     SBThread result;
     if (m_queue_item_sp)
     {
-        ThreadSP thread_sp;
-        ConstString type_const (type);
-        thread_sp = m_queue_item_sp->GetExtendedBacktraceThread (type_const);
-        if (thread_sp)
+        ProcessSP process_sp = m_queue_item_sp->GetProcessSP();
+        Process::StopLocker stop_locker;
+        if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock()))
         {
-            result.SetThread (thread_sp);
+            ThreadSP thread_sp;
+            ConstString type_const (type);
+            thread_sp = m_queue_item_sp->GetExtendedBacktraceThread (type_const);
+            if (thread_sp)
+            {
+                // Save this in the Process' ExtendedThreadList so a strong pointer retains the
+                // object
+                process_sp->GetExtendedThreadList().AddThread (thread_sp);
+                result.SetThread (thread_sp);
+            }
         }
     }
     return result;

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=203088&r1=203087&r2=203088&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/HistoryThread.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/HistoryThread.cpp Thu Mar  6 00:31:18 2014
@@ -20,12 +20,14 @@
 using namespace lldb;
 using namespace lldb_private;
 
+//  Constructor
+
 HistoryThread::HistoryThread (lldb_private::Process &process, 
                               lldb::tid_t tid,
                               std::vector<lldb::addr_t> pcs, 
                               uint32_t stop_id, 
                               bool stop_id_is_valid) : 
-        Thread (process, tid),
+        Thread (process, tid, true),
         m_framelist_mutex(),
         m_framelist(),
         m_pcs (pcs),
@@ -43,6 +45,8 @@ HistoryThread::HistoryThread (lldb_priva
         log->Printf ("%p HistoryThread::HistoryThread", this);
 }
 
+//  Destructor
+
 HistoryThread::~HistoryThread ()
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));

Modified: lldb/trunk/source/Plugins/Process/Utility/HistoryUnwind.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/HistoryUnwind.cpp?rev=203088&r1=203087&r2=203088&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/HistoryUnwind.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/HistoryUnwind.cpp Thu Mar  6 00:31:18 2014
@@ -20,6 +20,8 @@
 using namespace lldb;
 using namespace lldb_private;
 
+// Constructor 
+
 HistoryUnwind::HistoryUnwind (Thread &thread,
                               std::vector<lldb::addr_t> pcs,
                               uint32_t stop_id,
@@ -31,6 +33,8 @@ HistoryUnwind::HistoryUnwind (Thread &th
 {
 }
 
+// Destructor
+
 HistoryUnwind::~HistoryUnwind ()
 {
 }

Modified: lldb/trunk/source/Target/QueueItem.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/QueueItem.cpp?rev=203088&r1=203087&r2=203088&view=diff
==============================================================================
--- lldb/trunk/source/Target/QueueItem.cpp (original)
+++ lldb/trunk/source/Target/QueueItem.cpp Thu Mar  6 00:31:18 2014
@@ -75,3 +75,15 @@ QueueItem::GetExtendedBacktraceThread (C
     }
     return return_thread;
 }
+
+ProcessSP
+QueueItem::GetProcessSP()
+{
+    ProcessSP process_sp;
+    QueueSP queue_sp = m_queue_wp.lock ();
+    if (queue_sp)
+    {
+        process_sp = queue_sp->GetProcess();
+    }
+    return process_sp;
+}

Modified: lldb/trunk/source/Target/Thread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Thread.cpp?rev=203088&r1=203087&r2=203088&view=diff
==============================================================================
--- lldb/trunk/source/Target/Thread.cpp (original)
+++ lldb/trunk/source/Target/Thread.cpp Thu Mar  6 00:31:18 2014
@@ -250,14 +250,14 @@ Thread::GetStaticBroadcasterClass ()
     return class_name;
 }
 
-Thread::Thread (Process &process, lldb::tid_t tid) :
+Thread::Thread (Process &process, lldb::tid_t tid, bool use_invalid_index_id) :
     ThreadProperties (false),
     UserID (tid),
     Broadcaster(&process.GetTarget().GetDebugger(), Thread::GetStaticBroadcasterClass().AsCString()),
     m_process_wp (process.shared_from_this()),
     m_stop_info_sp (),
     m_stop_info_stop_id (0),
-    m_index_id (process.GetNextThreadIndexID(tid)),
+    m_index_id (use_invalid_index_id ? LLDB_INVALID_INDEX32 : process.GetNextThreadIndexID(tid)),
     m_reg_context_sp (),
     m_state (eStateUnloaded),
     m_state_mutex (Mutex::eMutexTypeRecursive),





More information about the lldb-commits mailing list