[Lldb-commits] [PATCH] D136650: Add a check for TypeSystem use-after-free problems

Adrian Prantl via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 24 16:54:49 PDT 2022


aprantl created this revision.
aprantl added reviewers: kastiglione, jingham, labath.
Herald added a project: All.
aprantl requested review of this revision.

When a process gets restarted TypeSystem objects associated with it may get deleted, and any CompilerType objects holding on to a reference to that type system are a use-after-free in waiting. Because of the SBAPI, we don't have tight control over where CompilerTypes go and when they are used. This is particularly a problem in the Swift plugin, where the scratch TypeSystem can be restarted while the process is still running. The Swift plugin has a lock to prevent abuse, but where there's a lock there can be bugs.

To help diagnose these hard-to-debug problems (and because Halloween is right around the corner) this patch introduces a global TypeSystem graveyard that collects all dead TypeSystem pointers and checks against it in CompilerType::IsValid(). This is intended as a bug-finding tool, which is why this triggers lldbassert(). Compared to everything else LLDB is doing the extra DenseMap lookup and lock should be negligible, which is why this feature is turned on even in release mode.

rdar://101505232


https://reviews.llvm.org/D136650

Files:
  lldb/include/lldb/Symbol/CompilerType.h
  lldb/include/lldb/Symbol/TypeSystem.h
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/source/Symbol/CompilerType.cpp
  lldb/source/Symbol/TypeSystem.cpp
  lldb/unittests/Symbol/TestTypeSystemClang.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136650.470325.patch
Type: text/x-patch
Size: 6002 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20221024/3fa5f0ab/attachment.bin>


More information about the lldb-commits mailing list