[all-commits] [llvm/llvm-project] 6eaedb: Make CompilerType safe

Adrian Prantl via All-commits all-commits at lists.llvm.org
Wed Nov 16 15:52:02 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6eaedbb52f2a616e644e5acc7279c8b07c4cfe82
      https://github.com/llvm/llvm-project/commit/6eaedbb52f2a616e644e5acc7279c8b07c4cfe82
  Author: Adrian Prantl <aprantl at apple.com>
  Date:   2022-11-16 (Wed, 16 Nov 2022)

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

  Log Message:
  -----------
  Make CompilerType safe

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.

This patch changes CompilerType to store a std::weak_ptr<TypeSystem>.
Most of the std::weak_ptr<TypeSystem>* uglyness is hidden by
introducing a wrapper class CompilerType::WrappedTypeSystem that has a
dyn_cast_or_null() method. The only sites that need to know about the
weak pointer implementation detail are the ones that deal with
creating TypeSystems.

rdar://101505232

Differential Revision: https://reviews.llvm.org/D136650




More information about the All-commits mailing list