[Lldb-commits] [PATCH] D18075: Fix deadlock due to thread list locking in 'bt all' with obj-c

Francis Ricci via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 10 17:57:05 PST 2016

fjricci created this revision.
fjricci added reviewers: jingham, clayborg, andrew.w.kaylor.
fjricci added subscribers: lldb-commits, sas.

The gdb-remote async thread cannot modify thread state while the main thread
holds a lock on the state. Don't use locking thread iteration for bt all.

Specifically, the deadlock manifests when lldb attempts to JIT code to
symbolicate objective c while backtracing. As part of this code path,
SetPrivateState() is called on an async thread. This async thread will
block waiting for the thread_list lock held by the main thread in
CommandObjectIterateOverThreads. The main thread will also block on the
async thread during DoResume (although with a timeout), leading to a
deadlock. Due to the timeout, the deadlock is not immediately apparent,
but the inferior will be left in an invalid state after the bt all completes,
and objective-c symbols will not be successfully resolved in the backtrace.



Index: source/Commands/CommandObjectThread.cpp
--- source/Commands/CommandObjectThread.cpp
+++ source/Commands/CommandObjectThread.cpp
@@ -73,8 +73,13 @@
             Process *process = m_exe_ctx.GetProcessPtr();
             uint32_t idx = 0;
-            for (ThreadSP thread_sp : process->Threads())
+            // Manually iterate to avoid locking the threadlist,
+            // which can cause deadlocks when JIT-ing code
+            ThreadList thread_list = process->GetThreadList();
+            for (uint32_t i = 0; i < thread_list.GetSize(); ++i)
+                ThreadSP thread_sp = thread_list.GetThreadAtIndex(i);
                 if (idx != 0 && m_add_return)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18075.50386.patch
Type: text/x-patch
Size: 822 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20160311/872eb931/attachment.bin>

More information about the lldb-commits mailing list