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.




git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@131769 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 314d51f..d1c51ec 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -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();
+}