Author: gclayton
Date: Fri Jun 10 18:23:34 2016
New Revision: 272444

URL: http://llvm.org/viewvc/llvm-project?rev=272444&view=rev
Log:
On MacOSX, the threads can appear out of order at times depending on the order 
in which the kernel returns thread IDs to debugserver. To avoid thread lists 
changing order between stops, ProcessGDBRemote now makes sure the thread list 
stays sorted by thread index ID.

<rdar://problem/25501013> 


Modified:
    lldb/trunk/include/lldb/Target/ThreadCollection.h
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    lldb/trunk/source/Target/ThreadCollection.cpp

Modified: lldb/trunk/include/lldb/Target/ThreadCollection.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ThreadCollection.h?rev=272444&r1=272443&r2=272444&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ThreadCollection.h (original)
+++ lldb/trunk/include/lldb/Target/ThreadCollection.h Fri Jun 10 18:23:34 2016
@@ -38,7 +38,10 @@ public:
     
     void
     AddThread (const lldb::ThreadSP &thread_sp);
-    
+
+    void
+    AddThreadSortedByIndexID (const lldb::ThreadSP &thread_sp);
+
     void
     InsertThread (const lldb::ThreadSP &thread_sp, uint32_t idx);
     

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=272444&r1=272443&r2=272444&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Fri Jun 
10 18:23:34 2016
@@ -1840,7 +1840,7 @@ ProcessGDBRemote::UpdateThreadList (Thre
                     }
                 }
             }
-            new_thread_list.AddThread(thread_sp);
+            new_thread_list.AddThreadSortedByIndexID (thread_sp);
         }
     }
 

Modified: lldb/trunk/source/Target/ThreadCollection.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadCollection.cpp?rev=272444&r1=272443&r2=272444&view=diff
==============================================================================
--- lldb/trunk/source/Target/ThreadCollection.cpp (original)
+++ lldb/trunk/source/Target/ThreadCollection.cpp Fri Jun 10 18:23:34 2016
@@ -11,6 +11,7 @@
 #include <algorithm>
 
 #include "lldb/Target/ThreadCollection.h"
+#include "lldb/Target/Thread.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -35,6 +36,24 @@ ThreadCollection::AddThread (const Threa
 }
 
 void
+ThreadCollection::AddThreadSortedByIndexID (const ThreadSP &thread_sp)
+{
+    std::lock_guard<std::recursive_mutex> guard(GetMutex());
+    // Make sure we always keep the threads sorted by thread index ID
+    const uint32_t thread_index_id = thread_sp->GetIndexID();
+    if (m_threads.empty() || m_threads.back()->GetIndexID() < thread_index_id)
+        m_threads.push_back (thread_sp);
+    else
+    {
+        m_threads.insert(std::upper_bound(m_threads.begin(), m_threads.end(), 
thread_sp,
+                                          [] (const ThreadSP &lhs, const 
ThreadSP &rhs) -> bool
+                                          {
+                                              return lhs->GetIndexID() < 
rhs->GetIndexID();
+                                          }), thread_sp);
+    }
+}
+
+void
 ThreadCollection::InsertThread (const lldb::ThreadSP &thread_sp, uint32_t idx)
 {
     std::lock_guard<std::recursive_mutex> guard(GetMutex());


_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to