[Lldb-commits] [lldb] r207160 - Add a new SBThread::GetQueue() method to get the queue that is
Jason Molenda
jmolenda at apple.com
Thu Apr 24 17:01:15 PDT 2014
Author: jmolenda
Date: Thu Apr 24 19:01:15 2014
New Revision: 207160
URL: http://llvm.org/viewvc/llvm-project?rev=207160&view=rev
Log:
Add a new SBThread::GetQueue() method to get the queue that is
currently associated with a given thread, on relevant targets.
Change the queue detection code to verify that the queues
associated with all live threads are included in the list.
<rdar://problem/16411314>
Modified:
lldb/trunk/include/lldb/API/SBDefines.h
lldb/trunk/include/lldb/API/SBQueue.h
lldb/trunk/include/lldb/API/SBQueueItem.h
lldb/trunk/include/lldb/API/SBThread.h
lldb/trunk/include/lldb/Target/Thread.h
lldb/trunk/scripts/Python/interface/SBThread.i
lldb/trunk/source/API/SBQueue.cpp
lldb/trunk/source/API/SBThread.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
lldb/trunk/test/macosx/queues/TestQueues.py
Modified: lldb/trunk/include/lldb/API/SBDefines.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBDefines.h?rev=207160&r1=207159&r2=207160&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBDefines.h (original)
+++ lldb/trunk/include/lldb/API/SBDefines.h Thu Apr 24 19:01:15 2014
@@ -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;
Modified: lldb/trunk/include/lldb/API/SBQueue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBQueue.h?rev=207160&r1=207159&r2=207160&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBQueue.h (original)
+++ lldb/trunk/include/lldb/API/SBQueue.h Thu Apr 24 19:01:15 2014
@@ -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);
Modified: lldb/trunk/include/lldb/API/SBQueueItem.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBQueueItem.h?rev=207160&r1=207159&r2=207160&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBQueueItem.h (original)
+++ lldb/trunk/include/lldb/API/SBQueueItem.h Thu Apr 24 19:01:15 2014
@@ -12,7 +12,6 @@
#include "lldb/API/SBDefines.h"
#include "lldb/API/SBAddress.h"
-#include "lldb/API/SBThread.h"
namespace lldb {
Modified: lldb/trunk/include/lldb/API/SBThread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBThread.h?rev=207160&r1=207159&r2=207160&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBThread.h (original)
+++ lldb/trunk/include/lldb/API/SBThread.h Thu Apr 24 19:01:15 2014
@@ -41,6 +41,9 @@ public:
~SBThread();
+ lldb::SBQueue
+ GetQueue () const;
+
bool
IsValid() const;
Modified: lldb/trunk/include/lldb/Target/Thread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Thread.h?rev=207160&r1=207159&r2=207160&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Thread.h (original)
+++ lldb/trunk/include/lldb/Target/Thread.h Thu Apr 24 19:01:15 2014
@@ -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
///
Modified: lldb/trunk/scripts/Python/interface/SBThread.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBThread.i?rev=207160&r1=207159&r2=207160&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBThread.i (original)
+++ lldb/trunk/scripts/Python/interface/SBThread.i Thu Apr 24 19:01:15 2014
@@ -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);
Modified: lldb/trunk/source/API/SBQueue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBQueue.cpp?rev=207160&r1=207159&r2=207160&view=diff
==============================================================================
--- lldb/trunk/source/API/SBQueue.cpp (original)
+++ lldb/trunk/source/API/SBQueue.cpp Thu Apr 24 19:01:15 2014
@@ -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"
Modified: lldb/trunk/source/API/SBThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBThread.cpp?rev=207160&r1=207159&r2=207160&view=diff
==============================================================================
--- lldb/trunk/source/API/SBThread.cpp (original)
+++ lldb/trunk/source/API/SBThread.cpp Thu Apr 24 19:01:15 2014
@@ -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
{
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp?rev=207160&r1=207159&r2=207160&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp Thu Apr 24 19:01:15 2014
@@ -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 ()
{
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=207160&r1=207159&r2=207160&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp (original)
+++ lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp Thu Apr 24 19:01:15 2014
@@ -524,26 +524,7 @@ SystemRuntimeMacOSX::GetExtendedBacktrac
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 (
}
}
}
+
+ // 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
Modified: lldb/trunk/test/macosx/queues/TestQueues.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/macosx/queues/TestQueues.py?rev=207160&r1=207159&r2=207160&view=diff
==============================================================================
--- lldb/trunk/test/macosx/queues/TestQueues.py (original)
+++ lldb/trunk/test/macosx/queues/TestQueues.py Thu Apr 24 19:01:15 2014
@@ -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."""
More information about the lldb-commits
mailing list