[Lldb-commits] [lldb] r203748 - Add a SBQueue::GetKind() method to retrieve the type of libdispatch queue (serial or concurrent).

Jason Molenda jmolenda at apple.com
Wed Mar 12 19:54:55 PDT 2014


Author: jmolenda
Date: Wed Mar 12 21:54:54 2014
New Revision: 203748

URL: http://llvm.org/viewvc/llvm-project?rev=203748&view=rev
Log:
Add a SBQueue::GetKind() method to retrieve the type of libdispatch queue (serial or concurrent).
<rdar://problem/7964505>

Modified:
    lldb/trunk/include/lldb/API/SBQueue.h
    lldb/trunk/include/lldb/Target/Queue.h
    lldb/trunk/include/lldb/Target/SystemRuntime.h
    lldb/trunk/include/lldb/Target/Thread.h
    lldb/trunk/include/lldb/lldb-enumerations.h
    lldb/trunk/scripts/Python/interface/SBQueue.i
    lldb/trunk/source/API/SBQueue.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
    lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
    lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h
    lldb/trunk/source/Target/Queue.cpp

Modified: lldb/trunk/include/lldb/API/SBQueue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBQueue.h?rev=203748&r1=203747&r2=203748&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBQueue.h (original)
+++ lldb/trunk/include/lldb/API/SBQueue.h Wed Mar 12 21:54:54 2014
@@ -65,6 +65,9 @@ public:
     uint32_t
     GetNumRunningItems ();
 
+    lldb::QueueKind
+    GetKind ();
+
 protected:
     friend class SBProcess;
 

Modified: lldb/trunk/include/lldb/Target/Queue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Queue.h?rev=203748&r1=203747&r2=203748&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Queue.h (original)
+++ lldb/trunk/include/lldb/Target/Queue.h Wed Mar 12 21:54:54 2014
@@ -168,6 +168,18 @@ public:
         m_pending_items.push_back (item);
     }
 
+    //------------------------------------------------------------------
+    /// Return the kind (serial, concurrent) of this queue
+    ///
+    /// @return
+    //      Whether this is a serial or a concurrent queue
+    //------------------------------------------------------------------
+    lldb::QueueKind
+    GetKind ();
+
+    void
+    SetKind (lldb::QueueKind kind);
+
 private:
     //------------------------------------------------------------------
     // For Queue only
@@ -180,6 +192,7 @@ private:
     uint32_t                        m_pending_work_items_count;
     std::vector<lldb::QueueItemSP>  m_pending_items;
     lldb::addr_t                    m_dispatch_queue_t_addr;  // address of libdispatch dispatch_queue_t for this Queue
+    lldb::QueueKind                 m_kind;
 
     DISALLOW_COPY_AND_ASSIGN (Queue);
 };

Modified: lldb/trunk/include/lldb/Target/SystemRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/SystemRuntime.h?rev=203748&r1=203747&r2=203748&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/SystemRuntime.h (original)
+++ lldb/trunk/include/lldb/Target/SystemRuntime.h Wed Mar 12 21:54:54 2014
@@ -222,7 +222,7 @@ public:
     /// get the queue name and return it.
     ///
     /// @param [in] dispatch_qaddr
-    ///     The address of the dispatch_queue_t structure for this thread.
+    ///     The address of the dispatch_qaddr pointer for this thread.
     ///
     /// @return
     ///     The string of this queue's name.  An empty string is returned if the
@@ -244,7 +244,7 @@ public:
     /// get the queue ID and return it.
     /// 
     /// @param [in] dispatch_qaddr
-    ///     The address of the dispatch_queue_t structure for this thread.
+    ///     The address of the dispatch_qaddr pointer for this thread.
     ///
     /// @return
     ///     The queue ID, or if it could not be retrieved, LLDB_INVALID_QUEUE_ID.
@@ -256,6 +256,26 @@ public:
     }
 
     //------------------------------------------------------------------
+    /// Get the libdispatch_queue_t address for the queue given the thread's dispatch_qaddr.
+    ///
+    /// On systems using libdispatch queues, a thread may be associated with a queue.
+    /// There will be a call to get the thread's dispatch_qaddr.  
+    /// Given the thread's dispatch_qaddr, find the libdispatch_queue_t address and
+    /// return it.
+    /// 
+    /// @param [in] dispatch_qaddr
+    ///     The address of the dispatch_qaddr pointer for this thread.
+    ///
+    /// @return
+    ///     The libdispatch_queue_t address, or LLDB_INVALID_ADDRESS if unavailable/not found.
+    //------------------------------------------------------------------
+    virtual lldb::addr_t
+    GetLibdispatchQueueAddressFromThreadQAddress (lldb::addr_t dispatch_qaddr)
+    {
+        return LLDB_INVALID_ADDRESS;
+    }
+
+    //------------------------------------------------------------------
     /// Get the pending work items for a libdispatch Queue
     ///
     /// If this system/process is using libdispatch and the runtime can do so,

Modified: lldb/trunk/include/lldb/Target/Thread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Thread.h?rev=203748&r1=203747&r2=203748&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Thread.h (original)
+++ lldb/trunk/include/lldb/Target/Thread.h Wed Mar 12 21:54:54 2014
@@ -305,6 +305,21 @@ public:
     {
     }
 
+    //------------------------------------------------------------------
+    /// Retrieve the Queue ID for the queue currently using this Thread
+    ///
+    /// If this Thread is doing work on behalf of a libdispatch/GCD queue,
+    /// retrieve the QueueID.
+    ///
+    /// This is a unique identifier for the libdispatch/GCD queue in a 
+    /// process.  Often starting at 1 for the initial system-created 
+    /// queues and incrementing, a QueueID will not be reused for a
+    /// different queue during the lifetime of a proces.
+    ///
+    /// @return
+    ///     A QueueID if the Thread subclass implements this, else
+    ///     LLDB_INVALID_QUEUE_ID.
+    //------------------------------------------------------------------
     virtual lldb::queue_id_t
     GetQueueID ()
     {
@@ -316,6 +331,16 @@ public:
     {
     }
 
+    //------------------------------------------------------------------
+    /// Retrieve the Queue name for the queue currently using this Thread
+    ///
+    /// If this Thread is doing work on behalf of a libdispatch/GCD queue,
+    /// retrieve the Queue name.
+    ///
+    /// @return
+    ///     The Queue name, if the Thread subclass implements this, else
+    ///     NULL.
+    //------------------------------------------------------------------
     virtual const char *
     GetQueueName ()
     {
@@ -327,6 +352,28 @@ public:
     {
     }
 
+    //------------------------------------------------------------------
+    /// Retrieve the address of the libdispatch_queue_t struct for queue
+    /// currently using this Thread
+    ///
+    /// If this Thread is doing work on behalf of a libdispatch/GCD queue,
+    /// retrieve the address of the libdispatch_queue_t structure describing
+    /// the queue.
+    ///
+    /// This address may be reused for different queues later in the Process
+    /// lifetime and should not be used to identify a queue uniquely.  Use
+    /// the GetQueueID() call for that.
+    ///
+    /// @return
+    ///     The Queue's libdispatch_queue_t address if the Thread subclass
+    ///     implements this, else LLDB_INVALID_ADDRESS.
+    //------------------------------------------------------------------
+    virtual lldb::addr_t
+    GetQueueLibdispatchQueueAddress ()
+    {
+        return LLDB_INVALID_ADDRESS;
+    }
+
     virtual uint32_t
     GetStackFrameCount()
     {

Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=203748&r1=203747&r2=203748&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Wed Mar 12 21:54:54 2014
@@ -741,6 +741,18 @@ namespace lldb {
         eQueueItemKindBlock
     } QueueItemKind;
 
+    //----------------------------------------------------------------------
+    // Queue type
+    // libdispatch aka Grand Central Dispatch (GCD) queues can be either serial
+    // (executing on one thread) or concurrent (executing on multiple threads).
+    //----------------------------------------------------------------------
+    typedef enum QueueKind
+    {
+        eQueueKindUnknown = 0,
+        eQueueKindSerial,
+        eQueueKindConcurrent
+    } QueueKind;
+
 } // namespace lldb
 
 

Modified: lldb/trunk/scripts/Python/interface/SBQueue.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBQueue.i?rev=203748&r1=203747&r2=203748&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBQueue.i (original)
+++ lldb/trunk/scripts/Python/interface/SBQueue.i Wed Mar 12 21:54:54 2014
@@ -27,12 +27,30 @@ public:
     lldb::SBProcess
     GetProcess ();
 
+    %feature("autodoc", "
+    Returns an lldb::queue_id_t type unique identifier number for this
+    queue that will not be used by any other queue during this process'
+    execution.  These ID numbers often start at 1 with the first
+    system-created queues and increment from there.
+    ")
+    GetQueueID;
+
     lldb::queue_id_t
     GetQueueID () const;
 
     const char *
     GetName () const;
 
+    %feature("autodoc", "
+    Returns an lldb::QueueKind enumerated value (e.g. eQueueKindUnknown, 
+    eQueueKindSerial, eQueueKindConcurrent) describing the type of this
+    queue.
+    ")
+    GetKind();
+
+    lldb::QueueKind
+    GetKind();
+
     uint32_t
     GetIndexID () const;
 

Modified: lldb/trunk/source/API/SBQueue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBQueue.cpp?rev=203748&r1=203747&r2=203748&view=diff
==============================================================================
--- lldb/trunk/source/API/SBQueue.cpp (original)
+++ lldb/trunk/source/API/SBQueue.cpp Wed Mar 12 21:54:54 2014
@@ -274,6 +274,17 @@ namespace lldb_private
             return result;
         }
 
+        lldb::QueueKind
+        GetKind ()
+        {
+            lldb::QueueKind kind = eQueueKindUnknown;
+            QueueSP queue_sp = m_queue_wp.lock();
+            if (queue_sp)
+                kind = queue_sp->GetKind();
+
+            return kind;
+        }
+
     private:
         lldb::QueueWP                   m_queue_wp;
         std::vector<lldb::ThreadWP>     m_threads;              // threads currently executing this queue's items
@@ -427,3 +438,9 @@ SBQueue::GetProcess ()
 {
     return m_opaque_sp->GetProcess();
 }
+
+lldb::QueueKind
+SBQueue::GetKind ()
+{
+    return m_opaque_sp->GetKind();
+}

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=203748&r1=203747&r2=203748&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp Wed Mar 12 21:54:54 2014
@@ -107,6 +107,25 @@ ThreadGDBRemote::GetQueueID ()
     return LLDB_INVALID_QUEUE_ID;
 }
 
+addr_t
+ThreadGDBRemote::GetQueueLibdispatchQueueAddress ()
+{
+    addr_t dispatch_queue_t_addr = LLDB_INVALID_ADDRESS;
+    if (m_thread_dispatch_qaddr != 0 || m_thread_dispatch_qaddr != LLDB_INVALID_ADDRESS)
+    {
+        ProcessSP process_sp (GetProcess());
+        if (process_sp)
+        {
+            SystemRuntime *runtime = process_sp->GetSystemRuntime ();
+            if (runtime)
+            {
+                dispatch_queue_t_addr = runtime->GetLibdispatchQueueAddressFromThreadQAddress (m_thread_dispatch_qaddr);
+            }
+        }
+    }
+    return dispatch_queue_t_addr;
+}
+
 void
 ThreadGDBRemote::WillResume (StateType resume_state)
 {

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h?rev=203748&r1=203747&r2=203748&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h Wed Mar 12 21:54:54 2014
@@ -41,6 +41,9 @@ public:
     virtual lldb::queue_id_t
     GetQueueID ();
 
+    lldb::addr_t
+    GetQueueLibdispatchQueueAddress ();
+
     virtual lldb::RegisterContextSP
     GetRegisterContext ();
 

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=203748&r1=203747&r2=203748&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp (original)
+++ lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp Wed Mar 12 21:54:54 2014
@@ -174,6 +174,46 @@ SystemRuntimeMacOSX::GetQueueNameFromThr
     return dispatch_queue_name;
 }
 
+lldb::addr_t
+SystemRuntimeMacOSX::GetLibdispatchQueueAddressFromThreadQAddress (addr_t dispatch_qaddr)
+{
+    addr_t libdispatch_queue_t_address = LLDB_INVALID_ADDRESS;
+    Error error;
+    libdispatch_queue_t_address = m_process->ReadPointerFromMemory (dispatch_qaddr, error);
+    if (!error.Success())
+    {
+        libdispatch_queue_t_address = LLDB_INVALID_ADDRESS;
+    }
+    return libdispatch_queue_t_address;
+}
+
+lldb::QueueKind
+SystemRuntimeMacOSX::GetQueueKind (addr_t dispatch_queue_addr)
+{
+    if (dispatch_queue_addr == LLDB_INVALID_ADDRESS || dispatch_queue_addr == 0)
+      return eQueueKindUnknown;
+
+    QueueKind kind = eQueueKindUnknown;
+    ReadLibdispatchOffsets ();
+    if (m_libdispatch_offsets.IsValid () && m_libdispatch_offsets.dqo_version >= 4)
+    {
+        Error error;
+        uint64_t width = m_process->ReadUnsignedIntegerFromMemory (dispatch_queue_addr + m_libdispatch_offsets.dqo_width, m_libdispatch_offsets.dqo_width_size, 0, error);
+        if (error.Success())
+        {
+            if (width == 1)
+            {
+                kind = eQueueKindSerial;
+            }
+            if (width > 1)
+            {
+                kind = eQueueKindConcurrent;
+            }
+        }
+    }
+    return kind;
+}
+
 lldb::queue_id_t
 SystemRuntimeMacOSX::GetQueueIDFromThreadQAddress (lldb::addr_t dispatch_qaddr)
 {
@@ -496,6 +536,8 @@ SystemRuntimeMacOSX::PopulateQueueList (
                 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);
                 }
             }
@@ -716,6 +758,7 @@ SystemRuntimeMacOSX::PopulateQueuesUsing
             queue_sp->SetNumRunningWorkItems (running_work_items_count);
             queue_sp->SetNumPendingWorkItems (pending_work_items_count);
             queue_sp->SetLibdispatchQueueAddress (queue);
+            queue_sp->SetKind (GetQueueKind (queue));
             queue_list.AddQueue (queue_sp);
             queues_read++;
         }

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=203748&r1=203747&r2=203748&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h (original)
+++ lldb/trunk/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h Wed Mar 12 21:54:54 2014
@@ -97,12 +97,18 @@ public:
     lldb::queue_id_t
     GetQueueIDFromThreadQAddress (lldb::addr_t dispatch_qaddr);
 
+    lldb::addr_t
+    GetLibdispatchQueueAddressFromThreadQAddress (lldb::addr_t dispatch_qaddr);
+
     void
     PopulatePendingItemsForQueue (lldb_private::Queue *queue);
 
     void
     CompleteQueueItem (lldb_private::QueueItem *queue_item, lldb::addr_t item_ref);
 
+    virtual lldb::QueueKind
+    GetQueueKind (lldb::addr_t dispatch_queue_addr);
+
     //------------------------------------------------------------------
     // PluginInterface protocol
     //------------------------------------------------------------------

Modified: lldb/trunk/source/Target/Queue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Queue.cpp?rev=203748&r1=203747&r2=203748&view=diff
==============================================================================
--- lldb/trunk/source/Target/Queue.cpp (original)
+++ lldb/trunk/source/Target/Queue.cpp Wed Mar 12 21:54:54 2014
@@ -23,7 +23,8 @@ Queue::Queue (ProcessSP process_sp, lldb
     m_running_work_items_count(0),
     m_pending_work_items_count(0),
     m_pending_items(),
-    m_dispatch_queue_t_addr(LLDB_INVALID_ADDRESS)
+    m_dispatch_queue_t_addr(LLDB_INVALID_ADDRESS),
+    m_kind (eQueueKindUnknown)
 {
     if (queue_name)
         m_queue_name = queue_name;
@@ -125,3 +126,15 @@ Queue::GetPendingItems ()
     }
     return m_pending_items;
 }
+
+lldb::QueueKind
+Queue::GetKind ()
+{
+    return m_kind;
+}
+
+void
+Queue::SetKind (lldb::QueueKind kind)
+{
+    m_kind = kind;
+}





More information about the lldb-commits mailing list