[Lldb-commits] [lldb] r357963 - Get the run locker before you ask if your thread is valid.

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Mon Apr 8 18:33:23 PDT 2019


Author: jingham
Date: Mon Apr  8 18:33:23 2019
New Revision: 357963

URL: http://llvm.org/viewvc/llvm-project?rev=357963&view=rev
Log:
Get the run locker before you ask if your thread is valid.

I have occasional crashes coming from SBThread::GetExtendedBacktraceThread.  The 
symptom is that we got true back from HasThreadScope - so we should have a valid
live thread, but then when we go to use the thread, it is not good anymore and we
crash.
I can't spot any obvious cause for this crash, but in looking for same I noticed
that in the current code we check that the thread is valid, THEN we take the stop 
locker.  We really should do that in the other order, and ensure that the process 
will stay stopped before we check our thread is still good.  That's what this patch does.

<rdar://problem/47478205>

Modified:
    lldb/trunk/source/API/SBThread.cpp

Modified: lldb/trunk/source/API/SBThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBThread.cpp?rev=357963&r1=357962&r2=357963&view=diff
==============================================================================
--- lldb/trunk/source/API/SBThread.cpp (original)
+++ lldb/trunk/source/API/SBThread.cpp Mon Apr  8 18:33:23 2019
@@ -1329,9 +1329,9 @@ SBThread SBThread::GetExtendedBacktraceT
   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
   SBThread sb_origin_thread;
 
-  if (exe_ctx.HasThreadScope()) {
-    Process::StopLocker stop_locker;
-    if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
+  Process::StopLocker stop_locker;
+  if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
+    if (exe_ctx.HasThreadScope()) {
       ThreadSP real_thread(exe_ctx.GetThreadSP());
       if (real_thread) {
         ConstString type_const(type);




More information about the lldb-commits mailing list