diff options
Diffstat (limited to 'lldb')
-rw-r--r-- | lldb/include/lldb/API/SBDefines.h | 4 | ||||
-rw-r--r-- | lldb/include/lldb/API/SBQueue.h | 2 | ||||
-rw-r--r-- | lldb/include/lldb/API/SBQueueItem.h | 1 | ||||
-rw-r--r-- | lldb/include/lldb/API/SBThread.h | 3 | ||||
-rw-r--r-- | lldb/include/lldb/Target/Thread.h | 16 | ||||
-rw-r--r-- | lldb/scripts/Python/interface/SBThread.i | 13 | ||||
-rw-r--r-- | lldb/source/API/SBQueue.cpp | 2 | ||||
-rw-r--r-- | lldb/source/API/SBThread.cpp | 37 | ||||
-rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp | 16 | ||||
-rw-r--r-- | lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp | 41 | ||||
-rw-r--r-- | lldb/test/macosx/queues/TestQueues.py | 1 |
11 files changed, 113 insertions, 23 deletions
diff --git a/lldb/include/lldb/API/SBDefines.h b/lldb/include/lldb/API/SBDefines.h index b13a4c52b0b..6171debaf01 100644 --- a/lldb/include/lldb/API/SBDefines.h +++ b/lldb/include/lldb/API/SBDefines.h @@ -59,13 +59,15 @@ class LLDB_API SBModule; class LLDB_API SBModuleSpec; class LLDB_API SBModuleSpecList; class LLDB_API SBProcess; +class LLDB_API SBQueue; +class LLDB_API SBQueueItem; +class LLDB_API SBSection; class LLDB_API SBSourceManager; class LLDB_API SBStream; class LLDB_API SBStringList; class LLDB_API SBSymbol; class LLDB_API SBSymbolContext; class LLDB_API SBSymbolContextList; -class LLDB_API SBSection; class LLDB_API SBTarget; class LLDB_API SBThread; class LLDB_API SBType; diff --git a/lldb/include/lldb/API/SBQueue.h b/lldb/include/lldb/API/SBQueue.h index cd418c037b4..fbb1952902f 100644 --- a/lldb/include/lldb/API/SBQueue.h +++ b/lldb/include/lldb/API/SBQueue.h @@ -14,7 +14,6 @@ #include "lldb/lldb-forward.h" #include "lldb/API/SBDefines.h" -#include "lldb/API/SBQueueItem.h" namespace lldb { @@ -70,6 +69,7 @@ public: protected: friend class SBProcess; + friend class SBThread; void SetQueue (const lldb::QueueSP& queue_sp); diff --git a/lldb/include/lldb/API/SBQueueItem.h b/lldb/include/lldb/API/SBQueueItem.h index 355c5ac90a2..c90f36eeb57 100644 --- a/lldb/include/lldb/API/SBQueueItem.h +++ b/lldb/include/lldb/API/SBQueueItem.h @@ -12,7 +12,6 @@ #include "lldb/API/SBDefines.h" #include "lldb/API/SBAddress.h" -#include "lldb/API/SBThread.h" namespace lldb { diff --git a/lldb/include/lldb/API/SBThread.h b/lldb/include/lldb/API/SBThread.h index 04b6c86e6d8..f3b34728085 100644 --- a/lldb/include/lldb/API/SBThread.h +++ b/lldb/include/lldb/API/SBThread.h @@ -41,6 +41,9 @@ public: ~SBThread(); + lldb::SBQueue + GetQueue () const; + bool IsValid() const; diff --git a/lldb/include/lldb/Target/Thread.h b/lldb/include/lldb/Target/Thread.h index 18141222f85..a7b800a943e 100644 --- a/lldb/include/lldb/Target/Thread.h +++ b/lldb/include/lldb/Target/Thread.h @@ -365,6 +365,22 @@ public: } //------------------------------------------------------------------ + /// Retrieve the Queue for this thread, if any. + /// + /// @return + /// A QueueSP for the queue that is currently associated with this + /// thread. + /// An empty shared pointer indicates that this thread is not + /// associated with a queue, or libdispatch queues are not + /// supported on this target. + //------------------------------------------------------------------ + virtual lldb::QueueSP + GetQueue () + { + return lldb::QueueSP(); + } + + //------------------------------------------------------------------ /// Retrieve the address of the libdispatch_queue_t struct for queue /// currently using this Thread /// diff --git a/lldb/scripts/Python/interface/SBThread.i b/lldb/scripts/Python/interface/SBThread.i index f2517366160..ecf0475dec1 100644 --- a/lldb/scripts/Python/interface/SBThread.i +++ b/lldb/scripts/Python/interface/SBThread.i @@ -165,6 +165,19 @@ public: lldb::queue_id_t GetQueueID() const; + %feature("autodoc", " + Return the SBQueue for this thread. If this thread is not currently associated + with a libdispatch queue, the SBQueue object's IsValid() method will return false. + If this SBThread is actually a HistoryThread, we may be able to provide QueueID + and QueueName, but not provide an SBQueue. Those individual attributes may have + been saved for the HistoryThread without enough information to reconstitute the + entire SBQueue at that time. + This method takes no arguments, returns an SBQueue. + ") GetQueue; + + lldb::SBQueue + GetQueue () const; + void StepOver (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping); diff --git a/lldb/source/API/SBQueue.cpp b/lldb/source/API/SBQueue.cpp index 31867b0dedf..b19ed72543c 100644 --- a/lldb/source/API/SBQueue.cpp +++ b/lldb/source/API/SBQueue.cpp @@ -15,6 +15,8 @@ #include "lldb/API/SBProcess.h" #include "lldb/API/SBThread.h" +#include "lldb/API/SBQueueItem.h" + #include "lldb/Core/Log.h" #include "lldb/Target/Process.h" #include "lldb/Target/Queue.h" diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp index 7c1bbfe9c92..97bd6f4fed7 100644 --- a/lldb/source/API/SBThread.cpp +++ b/lldb/source/API/SBThread.cpp @@ -23,6 +23,7 @@ #include "lldb/Target/SystemRuntime.h" #include "lldb/Target/Thread.h" #include "lldb/Target/Process.h" +#include "lldb/Target/Queue.h" #include "lldb/Symbol/SymbolContext.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Target/StopInfo.h" @@ -88,6 +89,42 @@ SBThread::~SBThread() { } +lldb::SBQueue +SBThread::GetQueue () const +{ + SBQueue sb_queue; + QueueSP queue_sp; + Mutex::Locker api_locker; + ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); + + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + if (exe_ctx.HasThreadScope()) + { + Process::StopLocker stop_locker; + if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) + { + queue_sp = exe_ctx.GetThreadPtr()->GetQueue(); + if (queue_sp) + { + sb_queue.SetQueue (queue_sp); + } + } + else + { + if (log) + log->Printf ("SBThread(%p)::GetQueueKind() => error: process is running", + static_cast<void*>(exe_ctx.GetThreadPtr())); + } + } + + if (log) + log->Printf ("SBThread(%p)::GetQueueKind () => SBQueue(%p)", + static_cast<void*>(exe_ctx.GetThreadPtr()), static_cast<void*>(queue_sp.get())); + + return sb_queue; +} + + bool SBThread::IsValid() const { diff --git a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp index 395f8c6e056..79893cf6612 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp @@ -107,6 +107,22 @@ ThreadGDBRemote::GetQueueID () return LLDB_INVALID_QUEUE_ID; } +QueueSP +ThreadGDBRemote::GetQueue () +{ + queue_id_t queue_id = GetQueueID(); + QueueSP queue; + if (queue_id != LLDB_INVALID_QUEUE_ID) + { + ProcessSP process_sp (GetProcess()); + if (process_sp) + { + queue = process_sp->GetQueueList().FindQueueByID (queue_id); + } + } + return queue; +} + addr_t ThreadGDBRemote::GetQueueLibdispatchQueueAddress () { diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp index b4495fde00c..7ff14fc5e09 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp @@ -524,26 +524,7 @@ SystemRuntimeMacOSX::GetExtendedBacktraceTypes () void SystemRuntimeMacOSX::PopulateQueueList (lldb_private::QueueList &queue_list) { - if (!BacktraceRecordingHeadersInitialized()) - { - // We don't have libBacktraceRecording -- build the list of queues by looking at - // all extant threads, and the queues that they currently belong to. - - for (ThreadSP thread_sp : m_process->Threads()) - { - if (thread_sp->GetQueueID() != LLDB_INVALID_QUEUE_ID) - { - if (queue_list.FindQueueByID (thread_sp->GetQueueID()).get() == NULL) - { - QueueSP queue_sp (new Queue(m_process->shared_from_this(), thread_sp->GetQueueID(), thread_sp->GetQueueName())); - queue_sp->SetKind (GetQueueKind (thread_sp->GetQueueLibdispatchQueueAddress())); - queue_sp->SetLibdispatchQueueAddress (thread_sp->GetQueueLibdispatchQueueAddress()); - queue_list.AddQueue (queue_sp); - } - } - } - } - else + if (BacktraceRecordingHeadersInitialized()) { AppleGetQueuesHandler::GetQueuesReturnInfo queue_info_pointer; ThreadSP cur_thread_sp (m_process->GetThreadList().GetSelectedThread()); @@ -566,6 +547,26 @@ SystemRuntimeMacOSX::PopulateQueueList (lldb_private::QueueList &queue_list) } } } + + // We either didn't have libBacktraceRecording (and need to create the queues list based on threads) + // or we did get the queues list from libBacktraceRecording but some special queues may not be + // included in its information. This is needed because libBacktraceRecording + // will only list queues with pending or running items by default - but the magic com.apple.main-thread + // queue on thread 1 is always around. + + for (ThreadSP thread_sp : m_process->Threads()) + { + if (thread_sp->GetQueueID() != LLDB_INVALID_QUEUE_ID) + { + if (queue_list.FindQueueByID (thread_sp->GetQueueID()).get() == NULL) + { + QueueSP queue_sp (new Queue(m_process->shared_from_this(), thread_sp->GetQueueID(), thread_sp->GetQueueName())); + queue_sp->SetKind (GetQueueKind (thread_sp->GetQueueLibdispatchQueueAddress())); + queue_sp->SetLibdispatchQueueAddress (thread_sp->GetQueueLibdispatchQueueAddress()); + queue_list.AddQueue (queue_sp); + } + } + } } // Returns either an array of introspection_dispatch_item_info_ref's for the pending items on diff --git a/lldb/test/macosx/queues/TestQueues.py b/lldb/test/macosx/queues/TestQueues.py index 77629fa7fe7..dcd88077217 100644 --- a/lldb/test/macosx/queues/TestQueues.py +++ b/lldb/test/macosx/queues/TestQueues.py @@ -63,6 +63,7 @@ class TestQueues(TestBase): self.assertTrue(t.IsValid(), "Queue %s's thread #%d must be valid" % (queue.GetName(), idx)) self.assertTrue(t.GetQueueID() == queue.GetQueueID(), "Queue %s has a QueueID of %d but its thread #%d has a QueueID of %d" % (queue.GetName(), queue.GetQueueID(), idx, t.GetQueueID())) self.assertTrue(t.GetQueueName() == queue.GetName(), "Queue %s has a QueueName of %s but its thread #%d has a QueueName of %s" % (queue.GetName(), queue.GetName(), idx, t.GetQueueName())) + self.assertTrue(t.GetQueue().GetQueueID() == queue.GetQueueID(), "Thread #%d's Queue's QueueID of %d is not the same as the QueueID of its owning queue %d" % (idx, t.GetQueue().GetQueueID(), queue.GetQueueID())) def queues(self): """Test queues inspection SB APIs without libBacktraceRecording.""" |