<div dir="ltr">Hi,<div><br></div><div>I've found a deadlock in lldb (see attached test case, you can build it with just `clang -o test test.s`), but I'm a total newbie and I have no idea what's the right way to fix it.</div><div><br></div><div>The problem happens when an error is found during DIE extraction when preloading symbols. As far as I can tell, it goes like this:</div><div><br></div><div>1. Module::PreloadSymbols locks Module::m_mutex</div><div>2. A few layers below it, we end up in ManualDWARFIndex::Index, which dispatches DIE extractions to a thread pool:</div><div><pre style="font-family:WorkAroundWebKitAndMozilla,monospace;line-height:1.5;background-color:rgb(248,249,250);border-radius:2px;border:1px solid rgb(218,220,224);overflow-x:auto;padding:8px 16px;color:rgb(32,33,36);font-size:13px;letter-spacing:0.185714px"><code style="font-family:WorkAroundWebKitAndMozilla,monospace;border-radius:2px;padding:0px;line-height:1.5">  for (size_t i = 0; i < units_to_index.size(); ++i)
    pool.async(extract_fn, i);
  pool.wait();
</code></pre>3. extract_fn in the snippet above ends up executing DWARFDebugInfoEntry::Extract and when there's an error during extraction, Module::GetDescription is called while generating the error message.</div><div>4. Module::GetDescription tries to acquire Module::m_mutex from a different thread, while the main thread has the mutex already locked and it's waiting for DIE extraction to end, causing a deadlock.</div><div><br></div><div>If we make Module::GetDescription not lock the problem disappears, so the diagnosis looks correct, but I don't know what would be the right way to fix it. Module::GetDescription looks more or less safe to call without locking: it just prints m_arch, m_file, and m_object_name to a string, and those look like fields that wouldn't change after the Module is initialized, so maybe it's okay? But I feel like there must be a better solution anyway. Any advice?</div><div><br></div><div>Best,</div><div>Jorge</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><br></div>