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

Adrian Prantl via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 31 17:59:10 PDT 2022


aprantl updated this revision to Diff 472194.
aprantl retitled this revision from "Add a check for TypeSystem use-after-free problems" to "Make CompilerType safe [Was: Add a check for TypeSystem use-after-free problems]".
aprantl added a comment.
Herald added subscribers: arphaman, kbarton, nemanjai, emaste.
Herald added a reviewer: shafik.
Herald added a reviewer: shafik.

All right! After @hawkinsw raised the question whether my previous patch didn't still allow for race conditions and some off-line encouragement from @JDevlieghere, I decided to give it a try and properly design away the issue.

This new patch turns the type system stored by CompilerType into weak pointer. Weak pointers use up two pointers as storage so to avoid blowing up the memory footprint, each TypeSystem is now required to have a canonical weak pointer that is never freed. This is implemented as a vector of unique pointers to weak pointers in TypeSystemMap.

This makes all calls to CompilerType completely safe, and CompilerType::GetTypeSystem now returns a nullable shared pointer to the type system. Calls into CompilerType become slower by one pointer lookup and one atomic increment operation, which will likely not be measurable.

Code that call GetTypeSystem() can remain almost unchanged, it just needs to store the shared pointer in a local variable first.

Code that creates a new ad-hoc TypeSystem gets slightly more complex, and I admit I was surprised at how many places in LLDB actually do this.

Please take another look, I think this is much better!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136650/new/

https://reviews.llvm.org/D136650

Files:
  lldb/include/lldb/Core/Module.h
  lldb/include/lldb/Symbol/CompilerType.h
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/include/lldb/Symbol/SymbolFileOnDemand.h
  lldb/include/lldb/Symbol/TaggedASTType.h
  lldb/include/lldb/Symbol/Type.h
  lldb/include/lldb/Symbol/TypeSystem.h
  lldb/include/lldb/Target/Target.h
  lldb/include/lldb/lldb-enumerations.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/API/SBModule.cpp
  lldb/source/API/SBTarget.cpp
  lldb/source/API/SBType.cpp
  lldb/source/Breakpoint/Watchpoint.cpp
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/source/Core/DumpDataExtractor.cpp
  lldb/source/Core/Module.cpp
  lldb/source/Core/ValueObjectMemory.cpp
  lldb/source/Core/ValueObjectRegister.cpp
  lldb/source/DataFormatters/VectorType.cpp
  lldb/source/Expression/Materializer.cpp
  lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp
  lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUtil.cpp
  lldb/source/Plugins/ExpressionParser/Clang/NameSearchContext.cpp
  lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
  lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
  lldb/source/Plugins/Language/ObjC/CoreMedia.cpp
  lldb/source/Plugins/Language/ObjC/NSArray.cpp
  lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h
  lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
  lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
  lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h
  lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
  lldb/source/Plugins/Platform/Linux/PlatformLinux.h
  lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp
  lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.h
  lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
  lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
  lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
  lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
  lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
  lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
  lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
  lldb/source/Symbol/CompilerType.cpp
  lldb/source/Symbol/SymbolFile.cpp
  lldb/source/Symbol/SymbolFileOnDemand.cpp
  lldb/source/Symbol/Type.cpp
  lldb/source/Symbol/TypeSystem.cpp
  lldb/source/Target/Process.cpp
  lldb/source/Target/StackFrame.cpp
  lldb/source/Target/Target.cpp
  lldb/source/Target/ThreadPlanTracer.cpp
  lldb/tools/lldb-test/lldb-test.cpp
  lldb/unittests/Expression/ClangExpressionDeclMapTest.cpp
  lldb/unittests/Symbol/TestClangASTImporter.cpp
  lldb/unittests/Symbol/TestTypeSystemClang.cpp
  lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
  lldb/unittests/TestingSupport/Symbol/ClangTestUtils.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136650.472194.patch
Type: text/x-patch
Size: 176205 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20221101/a0a558e2/attachment-0001.bin>


More information about the lldb-commits mailing list