From b78094abcf526e78c14867e94c3fe1d2ad666590 Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Tue, 9 Apr 2019 01:33:23 +0000 Subject: [PATCH] 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. llvm-svn: 357963 --- lldb/source/API/SBThread.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp index 978f2929..4d2cf33 100644 --- a/lldb/source/API/SBThread.cpp +++ b/lldb/source/API/SBThread.cpp @@ -1329,9 +1329,9 @@ SBThread SBThread::GetExtendedBacktraceThread(const char *type) { 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); -- 2.7.4