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 @@ -7,11 +7,13 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_DEBUGINFO_PDB_RAW_RAWSESSION_H -#define LLVM_DEBUGINFO_PDB_RAW_RAWSESSION_H +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVESESSION_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVESESSION_H #include "llvm/ADT/StringRef.h" #include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" +#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Error.h" @@ -30,6 +32,9 @@ static Error createFromExe(StringRef Path, std::unique_ptr &Session); + std::unique_ptr + createCompilandSymbol(DbiModuleDescriptor MI); + uint64_t getLoadAddress() const override; void setLoadAddress(uint64_t Address) override; std::unique_ptr getGlobalScope() override; @@ -71,6 +76,7 @@ private: std::unique_ptr Pdb; std::unique_ptr Allocator; + std::vector> SymbolCache; }; } } Index: llvm/lib/DebugInfo/PDB/Native/NativeEnumModules.cpp =================================================================== --- llvm/lib/DebugInfo/PDB/Native/NativeEnumModules.cpp +++ llvm/lib/DebugInfo/PDB/Native/NativeEnumModules.cpp @@ -32,9 +32,7 @@ NativeEnumModules::getChildAtIndex(uint32_t Index) const { if (Index >= Modules.getModuleCount()) return nullptr; - return std::unique_ptr(new PDBSymbolCompiland( - Session, std::unique_ptr(new NativeCompilandSymbol( - Session, 0, Modules.getModuleDescriptor(Index))))); + return Session.createCompilandSymbol(Modules.getModuleDescriptor(Index)); } std::unique_ptr NativeEnumModules::getNext() { Index: llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp =================================================================== --- llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp +++ llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp @@ -13,6 +13,7 @@ #include "llvm/DebugInfo/PDB/GenericError.h" #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" #include "llvm/DebugInfo/PDB/IPDBSourceFile.h" +#include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h" #include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/RawError.h" @@ -23,8 +24,10 @@ #include "llvm/Support/Error.h" #include "llvm/Support/ErrorOr.h" #include "llvm/Support/MemoryBuffer.h" + #include #include +#include using namespace llvm; using namespace llvm::msf; @@ -66,12 +69,23 @@ return make_error(raw_error_code::feature_unsupported); } +std::unique_ptr +NativeSession::createCompilandSymbol(DbiModuleDescriptor MI) { + const auto Id = static_cast(SymbolCache.size()); + SymbolCache.push_back( + llvm::make_unique(*this, Id, MI)); + return llvm::make_unique( + *this, std::unique_ptr(SymbolCache[Id]->clone())); +} + uint64_t NativeSession::getLoadAddress() const { return 0; } void NativeSession::setLoadAddress(uint64_t Address) {} std::unique_ptr NativeSession::getGlobalScope() { - auto RawSymbol = llvm::make_unique(*this, 0); + const auto Id = static_cast(SymbolCache.size()); + SymbolCache.push_back(llvm::make_unique(*this, Id)); + auto RawSymbol = SymbolCache[Id]->clone(); auto PdbSymbol(PDBSymbol::create(*this, std::move(RawSymbol))); std::unique_ptr ExeSymbol( static_cast(PdbSymbol.release())); @@ -80,7 +94,10 @@ std::unique_ptr NativeSession::getSymbolById(uint32_t SymbolId) const { - return nullptr; + // If the caller has a SymbolId, it'd better be in our SymbolCache. + return SymbolId < SymbolCache.size() + ? PDBSymbol::create(*this, SymbolCache[SymbolId]->clone()) + : nullptr; } std::unique_ptr