This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Tighten lock in Language::ForEach
ClosedPublic

Authored by bulbazord on Aug 31 2021, 11:53 AM.

Details

Summary

It is easy to accidentally introduce a deadlock by having the callback
passed to Language::ForEach also attempt to acquire the same lock. It
is easy enough to disallow the callback from calling anything in
Language directly, but it may happen through a series of other
function/method calls.

The solution I am proposing is to tighten the lock in Language::ForEach
so that it is only held as we gather the currently loaded language
plugins. We store them in a vector and then iterate through them with
the callback so that the callback can't introduce a callback.

Diff Detail

Event Timeline

bulbazord requested review of this revision.Aug 31 2021, 11:53 AM
bulbazord created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptAug 31 2021, 11:53 AM

For further context, I encountered this when debugging the test failures from D108229. BreakpointResolverName::AddNameLookup constructs a Module::LookupInfo in a callback that it passes to Language::ForEach.

The language map is a global that contains unique pointers to a "Language *", so the language objects are intentionally leaked because the language map is kept alive due to C++ destructor chain issues, so this should be safe.

LGTM. Anyone else have any objections?

clayborg accepted this revision.Aug 31 2021, 2:34 PM
This revision is now accepted and ready to land.Aug 31 2021, 2:34 PM
teemperor accepted this revision.Aug 31 2021, 2:46 PM

Yay! It's probably worth adding comment that callback might end up calling back into ForEach :)

This revision was landed with ongoing or failed builds.Aug 31 2021, 3:47 PM
This revision was automatically updated to reflect the committed changes.