Index: lld/COFF/PDB.cpp =================================================================== --- lld/COFF/PDB.cpp +++ lld/COFF/PDB.cpp @@ -291,7 +291,8 @@ } static Expected> -tryToLoadPDB(const GUID &GuidFromObj, StringRef TSPath) { +tryToLoadPDB(BumpPtrAllocator &Allocator, const GUID &GuidFromObj, + StringRef TSPath) { ErrorOr> MBOrErr = MemoryBuffer::getFile( TSPath, /*FileSize=*/-1, /*RequiresNullTerminator=*/false); if (!MBOrErr) @@ -301,7 +302,7 @@ if (auto EC = pdb::NativeSession::createFromPdb( MemoryBuffer::getMemBuffer(Driver->takeBuffer(std::move(*MBOrErr)), /*RequiresNullTerminator=*/false), - ThisSession)) + Allocator, ThisSession)) return std::move(EC); std::unique_ptr NS( @@ -345,7 +346,7 @@ // Check for a PDB at: // 1. The given file path // 2. Next to the object file or archive file - auto ExpectedSession = tryToLoadPDB(TSId, TSPath); + auto ExpectedSession = tryToLoadPDB(Alloc, TSId, TSPath); if (!ExpectedSession) { consumeError(ExpectedSession.takeError()); StringRef LocalPath = @@ -353,7 +354,7 @@ SmallString<128> Path = sys::path::parent_path(LocalPath); sys::path::append( Path, sys::path::filename(TSPath, sys::path::Style::windows)); - ExpectedSession = tryToLoadPDB(TSId, Path); + ExpectedSession = tryToLoadPDB(Alloc, TSId, Path); } if (auto E = ExpectedSession.takeError()) { TypeServerIndexMappings.erase(TSId); Index: llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h =================================================================== --- llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h +++ llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h @@ -29,7 +29,9 @@ class NativeSession : public IPDBSession { public: NativeSession(std::unique_ptr PdbFile, - std::unique_ptr Allocator); + BumpPtrAllocator &BorrowedAllocator); + NativeSession(std::unique_ptr PdbFile, + std::unique_ptr OwnedAllocator); ~NativeSession() override; static Error createFromPdb(std::unique_ptr MB, @@ -37,6 +39,12 @@ static Error createFromExe(StringRef Path, std::unique_ptr &Session); + static Error createFromPdb(std::unique_ptr MB, + BumpPtrAllocator &Allocator, + std::unique_ptr &Session); + static Error createFromExe(StringRef Path, BumpPtrAllocator &Allocator, + std::unique_ptr &Session); + std::unique_ptr createCompilandSymbol(DbiModuleDescriptor MI); @@ -90,7 +98,8 @@ private: std::unique_ptr Pdb; - std::unique_ptr Allocator; + std::unique_ptr OwnedAllocator; + BumpPtrAllocator &Allocator; std::vector> SymbolCache; DenseMap TypeIndexToSymbolId; }; Index: llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp =================================================================== --- llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp +++ llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp @@ -63,30 +63,61 @@ } // namespace NativeSession::NativeSession(std::unique_ptr PdbFile, - std::unique_ptr Allocator) - : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)) {} + std::unique_ptr OwnedAllocator) + : Pdb(std::move(PdbFile)), OwnedAllocator(std::move(OwnedAllocator)), + Allocator(*OwnedAllocator) {} +NativeSession::NativeSession(std::unique_ptr PdbFile, + BumpPtrAllocator &BorrowedAllocator) + : Pdb(std::move(PdbFile)), Allocator(BorrowedAllocator) {} NativeSession::~NativeSession() = default; -Error NativeSession::createFromPdb(std::unique_ptr Buffer, - std::unique_ptr &Session) { +static Expected> +createPdbFile(std::unique_ptr Buffer, + BumpPtrAllocator &Allocator) { StringRef Path = Buffer->getBufferIdentifier(); auto Stream = llvm::make_unique( std::move(Buffer), llvm::support::little); - auto Allocator = llvm::make_unique(); - auto File = llvm::make_unique(Path, std::move(Stream), *Allocator); + auto File = llvm::make_unique(Path, std::move(Stream), Allocator); if (auto EC = File->parseFileHeaders()) - return EC; + return std::move(EC); if (auto EC = File->parseStreamData()) - return EC; + return std::move(EC); + return std::move(File); +} + +Error NativeSession::createFromPdb(std::unique_ptr Buffer, + BumpPtrAllocator &Allocator, + std::unique_ptr &Session) { + auto ExpectedFile = createPdbFile(std::move(Buffer), Allocator); + if (!ExpectedFile) + return ExpectedFile.takeError(); Session = - llvm::make_unique(std::move(File), std::move(Allocator)); + llvm::make_unique(std::move(*ExpectedFile), Allocator); + + return Error::success(); +} + +Error NativeSession::createFromPdb(std::unique_ptr Buffer, + std::unique_ptr &Session) { + auto Allocator = llvm::make_unique(); + auto ExpectedFile = createPdbFile(std::move(Buffer), *Allocator); + if (!ExpectedFile) + return ExpectedFile.takeError(); + + Session = llvm::make_unique(std::move(*ExpectedFile), + std::move(Allocator)); return Error::success(); } +Error NativeSession::createFromExe(StringRef Path, BumpPtrAllocator &Allocator, + std::unique_ptr &Session) { + return make_error(raw_error_code::feature_unsupported); +} + Error NativeSession::createFromExe(StringRef Path, std::unique_ptr &Session) { return make_error(raw_error_code::feature_unsupported);