[Lldb-commits] [lldb] r131769 - in /lldb/trunk/source/Plugins/Process/gdb-remote: GDBRemoteCommunicationClient.cpp GDBRemoteCommunicationClient.h ProcessGDBRemote.cpp

Greg Clayton gclayton at apple.com
Fri May 20 16:38:13 PDT 2011


Author: gclayton
Date: Fri May 20 18:38:13 2011
New Revision: 131769

URL: http://llvm.org/viewvc/llvm-project?rev=131769&view=rev
Log:
Centralize the code that gathers the thread ID list from the remote GDB
server so that it happens in command sequence where no other packets can
sneak between.



Modified:
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp?rev=131769&r1=131768&r2=131769&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Fri May 20 18:38:13 2011
@@ -1649,3 +1649,48 @@
 
     return UINT8_MAX;
 }
+
+size_t
+GDBRemoteCommunicationClient::GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids, 
+                                                   bool &sequence_mutex_unavailable)
+{
+    Mutex::Locker locker;
+    thread_ids.clear();
+    
+    if (GetSequenceMutex (locker))
+    {
+        sequence_mutex_unavailable = false;
+        StringExtractorGDBRemote response;
+        
+        TimeValue timeout_time;
+        timeout_time = TimeValue::Now();
+        timeout_time.OffsetWithSeconds (m_packet_timeout*2); // We will always send at least two packets here...
+
+        for (SendPacketNoLock ("qfThreadInfo", strlen("qfThreadInfo")) && WaitForPacketNoLock (response, &timeout_time);
+             response.IsNormalResponse();
+             SendPacketNoLock ("qsThreadInfo", strlen("qsThreadInfo")) && WaitForPacketNoLock (response, &timeout_time))
+        {
+            char ch = response.GetChar();
+            if (ch == 'l')
+                break;
+            if (ch == 'm')
+            {
+                do
+                {
+                    tid_t tid = response.GetHexMaxU32(false, LLDB_INVALID_THREAD_ID);
+                    
+                    if (tid != LLDB_INVALID_THREAD_ID)
+                    {
+                        thread_ids.push_back (tid);
+                    }
+                    ch = response.GetChar();    // Skip the command separator
+                } while (ch == ',');            // Make sure we got a comma separator
+            }
+        }
+    }
+    else
+    {
+        sequence_mutex_unavailable = true;
+    }
+    return thread_ids.size();
+}

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h?rev=131769&r1=131768&r2=131769&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h Fri May 20 18:38:13 2011
@@ -12,6 +12,8 @@
 
 // C Includes
 // C++ Includes
+#include <vector>
+
 // Other libraries and framework includes
 // Project includes
 #include "lldb/Core/ArchSpec.h"
@@ -311,6 +313,10 @@
         return m_supports_alloc_dealloc_memory;
     }
 
+    size_t
+    GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
+                         bool &sequence_mutex_unavailable);
+    
 protected:
 
     //------------------------------------------------------------------

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=131769&r1=131768&r2=131769&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Fri May 20 18:38:13 2011
@@ -1052,37 +1052,26 @@
         ThreadList curr_thread_list (this);
         curr_thread_list.SetStopID(stop_id);
 
-        Error err;
-        StringExtractorGDBRemote response;
-        for (m_gdb_comm.SendPacketAndWaitForResponse("qfThreadInfo", response, false);
-             response.IsNormalResponse();
-             m_gdb_comm.SendPacketAndWaitForResponse("qsThreadInfo", response, false))
+        std::vector<lldb::tid_t> thread_ids;
+        bool sequence_mutex_unavailable = false;
+        const size_t num_thread_ids = m_gdb_comm.GetCurrentThreadIDs (thread_ids, sequence_mutex_unavailable);
+        if (num_thread_ids > 0)
         {
-            char ch = response.GetChar();
-            if (ch == 'l')
-                break;
-            if (ch == 'm')
+            for (size_t i=0; i<num_thread_ids; ++i)
             {
-                do
-                {
-                    tid_t tid = response.GetHexMaxU32(false, LLDB_INVALID_THREAD_ID);
-
-                    if (tid != LLDB_INVALID_THREAD_ID)
-                    {
-                        ThreadSP thread_sp (GetThreadList().FindThreadByID (tid, false));
-                        if (!thread_sp)
-                            thread_sp.reset (new ThreadGDBRemote (*this, tid));
-                        curr_thread_list.AddThread(thread_sp);
-                    }
-
-                    ch = response.GetChar();
-                } while (ch == ',');
+                tid_t tid = thread_ids[i];
+                ThreadSP thread_sp (GetThreadList().FindThreadByID (tid, false));
+                if (!thread_sp)
+                    thread_sp.reset (new ThreadGDBRemote (*this, tid));
+                curr_thread_list.AddThread(thread_sp);
             }
         }
 
-        m_thread_list = curr_thread_list;
-
-        SetThreadStopInfo (m_last_stop_packet);
+        if (sequence_mutex_unavailable == false)
+        {
+            m_thread_list = curr_thread_list;
+            SetThreadStopInfo (m_last_stop_packet);
+        }
     }
     return GetThreadList().GetSize(false);
 }





More information about the lldb-commits mailing list