003 File Manager
Current Path:
/usr/src/contrib/llvm-project/llvm/lib/DebugInfo/PDB/Native
usr
/
src
/
contrib
/
llvm-project
/
llvm
/
lib
/
DebugInfo
/
PDB
/
Native
/
📁
..
📄
DbiModuleDescriptor.cpp
(2.5 KB)
📄
DbiModuleDescriptorBuilder.cpp
(6.63 KB)
📄
DbiModuleList.cpp
(8.3 KB)
📄
DbiStream.cpp
(12.8 KB)
📄
DbiStreamBuilder.cpp
(14.82 KB)
📄
EnumTables.cpp
(1.33 KB)
📄
GSIStreamBuilder.cpp
(17.23 KB)
📄
GlobalsStream.cpp
(6.56 KB)
📄
Hash.cpp
(2.39 KB)
📄
HashTable.cpp
(2.55 KB)
📄
InfoStream.cpp
(3.94 KB)
📄
InfoStreamBuilder.cpp
(2.67 KB)
📄
InjectedSourceStream.cpp
(2.31 KB)
📄
ModuleDebugStream.cpp
(4.74 KB)
📄
NamedStreamMap.cpp
(4.2 KB)
📄
NativeCompilandSymbol.cpp
(2.22 KB)
📄
NativeEnumGlobals.cpp
(1.87 KB)
📄
NativeEnumInjectedSources.cpp
(4.05 KB)
📄
NativeEnumLineNumbers.cpp
(1.44 KB)
📄
NativeEnumModules.cpp
(1.36 KB)
📄
NativeEnumTypes.cpp
(2.62 KB)
📄
NativeExeSymbol.cpp
(3.25 KB)
📄
NativeFunctionSymbol.cpp
(2.12 KB)
📄
NativeLineNumber.cpp
(1.88 KB)
📄
NativePublicSymbol.cpp
(1.92 KB)
📄
NativeRawSymbol.cpp
(14.98 KB)
📄
NativeSession.cpp
(12.36 KB)
📄
NativeSourceFile.cpp
(1.47 KB)
📄
NativeSymbolEnumerator.cpp
(4.24 KB)
📄
NativeTypeArray.cpp
(2.6 KB)
📄
NativeTypeBuiltin.cpp
(1.67 KB)
📄
NativeTypeEnum.cpp
(12.55 KB)
📄
NativeTypeFunctionSig.cpp
(7.3 KB)
📄
NativeTypePointer.cpp
(6.41 KB)
📄
NativeTypeTypedef.cpp
(1.05 KB)
📄
NativeTypeUDT.cpp
(6.93 KB)
📄
NativeTypeVTShape.cpp
(1.42 KB)
📄
PDBFile.cpp
(16.2 KB)
📄
PDBFileBuilder.cpp
(11 KB)
📄
PDBStringTable.cpp
(4.53 KB)
📄
PDBStringTableBuilder.cpp
(6.88 KB)
📄
PublicsStream.cpp
(3.89 KB)
📄
RawError.cpp
(2.13 KB)
📄
SymbolCache.cpp
(22.39 KB)
📄
SymbolStream.cpp
(1.4 KB)
📄
TpiHashing.cpp
(4.32 KB)
📄
TpiStream.cpp
(7.85 KB)
📄
TpiStreamBuilder.cpp
(6.32 KB)
Editing: NativeSession.cpp
//===- NativeSession.cpp - Native implementation of IPDBSession -*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "llvm/DebugInfo/PDB/Native/NativeSession.h" #include "llvm/ADT/STLExtras.h" #include "llvm/DebugInfo/CodeView/TypeIndex.h" #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" #include "llvm/DebugInfo/PDB/IPDBSourceFile.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" #include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h" #include "llvm/DebugInfo/PDB/Native/NativeEnumInjectedSources.h" #include "llvm/DebugInfo/PDB/Native/NativeEnumTypes.h" #include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h" #include "llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h" #include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/RawError.h" #include "llvm/DebugInfo/PDB/Native/SymbolCache.h" #include "llvm/DebugInfo/PDB/Native/TpiStream.h" #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" #include "llvm/Object/COFF.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/BinaryByteStream.h" #include "llvm/Support/Error.h" #include "llvm/Support/ErrorOr.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include <algorithm> #include <cassert> #include <memory> #include <utility> using namespace llvm; using namespace llvm::msf; using namespace llvm::pdb; static DbiStream *getDbiStreamPtr(PDBFile &File) { Expected<DbiStream &> DbiS = File.getPDBDbiStream(); if (DbiS) return &DbiS.get(); consumeError(DbiS.takeError()); return nullptr; } NativeSession::NativeSession(std::unique_ptr<PDBFile> PdbFile, std::unique_ptr<BumpPtrAllocator> Allocator) : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)), Cache(*this, getDbiStreamPtr(*Pdb)) {} NativeSession::~NativeSession() = default; Error NativeSession::createFromPdb(std::unique_ptr<MemoryBuffer> Buffer, std::unique_ptr<IPDBSession> &Session) { StringRef Path = Buffer->getBufferIdentifier(); auto Stream = std::make_unique<MemoryBufferByteStream>( std::move(Buffer), llvm::support::little); auto Allocator = std::make_unique<BumpPtrAllocator>(); auto File = std::make_unique<PDBFile>(Path, std::move(Stream), *Allocator); if (auto EC = File->parseFileHeaders()) return EC; if (auto EC = File->parseStreamData()) return EC; Session = std::make_unique<NativeSession>(std::move(File), std::move(Allocator)); return Error::success(); } static Expected<std::unique_ptr<PDBFile>> loadPdbFile(StringRef PdbPath, std::unique_ptr<BumpPtrAllocator> &Allocator) { ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer = MemoryBuffer::getFile(PdbPath, /*FileSize=*/-1, /*RequiresNullTerminator=*/false); if (!ErrorOrBuffer) return make_error<RawError>(ErrorOrBuffer.getError()); std::unique_ptr<llvm::MemoryBuffer> Buffer = std::move(*ErrorOrBuffer); PdbPath = Buffer->getBufferIdentifier(); file_magic Magic; auto EC = identify_magic(PdbPath, Magic); if (EC || Magic != file_magic::pdb) return make_error<RawError>(EC); auto Stream = std::make_unique<MemoryBufferByteStream>(std::move(Buffer), llvm::support::little); auto File = std::make_unique<PDBFile>(PdbPath, std::move(Stream), *Allocator); if (auto EC = File->parseFileHeaders()) return std::move(EC); if (auto EC = File->parseStreamData()) return std::move(EC); return std::move(File); } Error NativeSession::createFromPdbPath(StringRef PdbPath, std::unique_ptr<IPDBSession> &Session) { auto Allocator = std::make_unique<BumpPtrAllocator>(); auto PdbFile = loadPdbFile(PdbPath, Allocator); if (!PdbFile) return PdbFile.takeError(); Session = std::make_unique<NativeSession>(std::move(PdbFile.get()), std::move(Allocator)); return Error::success(); } static Expected<std::string> getPdbPathFromExe(StringRef ExePath) { Expected<object::OwningBinary<object::Binary>> BinaryFile = object::createBinary(ExePath); if (!BinaryFile) return BinaryFile.takeError(); const object::COFFObjectFile *ObjFile = dyn_cast<object::COFFObjectFile>(BinaryFile->getBinary()); if (!ObjFile) return make_error<RawError>(raw_error_code::invalid_format); StringRef PdbPath; const llvm::codeview::DebugInfo *PdbInfo = nullptr; if (Error E = ObjFile->getDebugPDBInfo(PdbInfo, PdbPath)) return std::move(E); return std::string(PdbPath); } Error NativeSession::createFromExe(StringRef ExePath, std::unique_ptr<IPDBSession> &Session) { Expected<std::string> PdbPath = getPdbPathFromExe(ExePath); if (!PdbPath) return PdbPath.takeError(); file_magic Magic; auto EC = identify_magic(PdbPath.get(), Magic); if (EC || Magic != file_magic::pdb) return make_error<RawError>(EC); auto Allocator = std::make_unique<BumpPtrAllocator>(); auto File = loadPdbFile(PdbPath.get(), Allocator); if (!File) return File.takeError(); Session = std::make_unique<NativeSession>(std::move(File.get()), std::move(Allocator)); return Error::success(); } Expected<std::string> NativeSession::searchForPdb(const PdbSearchOptions &Opts) { Expected<std::string> PathOrErr = getPdbPathFromExe(Opts.ExePath); if (!PathOrErr) return PathOrErr.takeError(); StringRef PathFromExe = PathOrErr.get(); sys::path::Style Style = PathFromExe.startswith("/") ? sys::path::Style::posix : sys::path::Style::windows; StringRef PdbName = sys::path::filename(PathFromExe, Style); // Check if pdb exists in the executable directory. SmallString<128> PdbPath = StringRef(Opts.ExePath); sys::path::remove_filename(PdbPath); sys::path::append(PdbPath, PdbName); auto Allocator = std::make_unique<BumpPtrAllocator>(); if (auto File = loadPdbFile(PdbPath, Allocator)) return std::string(PdbPath); else consumeError(File.takeError()); // Check path that was in the executable. if (auto File = loadPdbFile(PathFromExe, Allocator)) return std::string(PathFromExe); else return File.takeError(); return make_error<RawError>("PDB not found"); } uint64_t NativeSession::getLoadAddress() const { return LoadAddress; } bool NativeSession::setLoadAddress(uint64_t Address) { LoadAddress = Address; return true; } std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() { return PDBSymbol::createAs<PDBSymbolExe>(*this, getNativeGlobalScope()); } std::unique_ptr<PDBSymbol> NativeSession::getSymbolById(SymIndexId SymbolId) const { return Cache.getSymbolById(SymbolId); } bool NativeSession::addressForVA(uint64_t VA, uint32_t &Section, uint32_t &Offset) const { uint32_t RVA = VA - getLoadAddress(); return addressForRVA(RVA, Section, Offset); } bool NativeSession::addressForRVA(uint32_t RVA, uint32_t &Section, uint32_t &Offset) const { Section = 0; Offset = 0; auto Dbi = Pdb->getPDBDbiStream(); if (!Dbi) return false; if ((int32_t)RVA < 0) return true; Offset = RVA; for (; Section < Dbi->getSectionHeaders().size(); ++Section) { auto &Sec = Dbi->getSectionHeaders()[Section]; if (RVA < Sec.VirtualAddress) return true; Offset = RVA - Sec.VirtualAddress; } return true; } std::unique_ptr<PDBSymbol> NativeSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) { uint32_t Section; uint32_t Offset; addressForVA(Address, Section, Offset); return findSymbolBySectOffset(Section, Offset, Type); } std::unique_ptr<PDBSymbol> NativeSession::findSymbolByRVA(uint32_t RVA, PDB_SymType Type) { uint32_t Section; uint32_t Offset; addressForRVA(RVA, Section, Offset); return findSymbolBySectOffset(Section, Offset, Type); } std::unique_ptr<PDBSymbol> NativeSession::findSymbolBySectOffset(uint32_t Sect, uint32_t Offset, PDB_SymType Type) { return Cache.findSymbolBySectOffset(Sect, Offset, Type); } std::unique_ptr<IPDBEnumLineNumbers> NativeSession::findLineNumbers(const PDBSymbolCompiland &Compiland, const IPDBSourceFile &File) const { return nullptr; } std::unique_ptr<IPDBEnumLineNumbers> NativeSession::findLineNumbersByAddress(uint64_t Address, uint32_t Length) const { return Cache.findLineNumbersByVA(Address, Length); } std::unique_ptr<IPDBEnumLineNumbers> NativeSession::findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const { return findLineNumbersByAddress(getLoadAddress() + RVA, Length); } std::unique_ptr<IPDBEnumLineNumbers> NativeSession::findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, uint32_t Length) const { uint64_t VA = getVAFromSectOffset(Section, Offset); return findLineNumbersByAddress(VA, Length); } std::unique_ptr<IPDBEnumSourceFiles> NativeSession::findSourceFiles(const PDBSymbolCompiland *Compiland, StringRef Pattern, PDB_NameSearchFlags Flags) const { return nullptr; } std::unique_ptr<IPDBSourceFile> NativeSession::findOneSourceFile(const PDBSymbolCompiland *Compiland, StringRef Pattern, PDB_NameSearchFlags Flags) const { return nullptr; } std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>> NativeSession::findCompilandsForSourceFile(StringRef Pattern, PDB_NameSearchFlags Flags) const { return nullptr; } std::unique_ptr<PDBSymbolCompiland> NativeSession::findOneCompilandForSourceFile(StringRef Pattern, PDB_NameSearchFlags Flags) const { return nullptr; } std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getAllSourceFiles() const { return nullptr; } std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getSourceFilesForCompiland( const PDBSymbolCompiland &Compiland) const { return nullptr; } std::unique_ptr<IPDBSourceFile> NativeSession::getSourceFileById(uint32_t FileId) const { return Cache.getSourceFileById(FileId); } std::unique_ptr<IPDBEnumDataStreams> NativeSession::getDebugStreams() const { return nullptr; } std::unique_ptr<IPDBEnumTables> NativeSession::getEnumTables() const { return nullptr; } std::unique_ptr<IPDBEnumInjectedSources> NativeSession::getInjectedSources() const { auto ISS = Pdb->getInjectedSourceStream(); if (!ISS) { consumeError(ISS.takeError()); return nullptr; } auto Strings = Pdb->getStringTable(); if (!Strings) { consumeError(Strings.takeError()); return nullptr; } return std::make_unique<NativeEnumInjectedSources>(*Pdb, *ISS, *Strings); } std::unique_ptr<IPDBEnumSectionContribs> NativeSession::getSectionContribs() const { return nullptr; } std::unique_ptr<IPDBEnumFrameData> NativeSession::getFrameData() const { return nullptr; } void NativeSession::initializeExeSymbol() { if (ExeSymbol == 0) ExeSymbol = Cache.createSymbol<NativeExeSymbol>(); } NativeExeSymbol &NativeSession::getNativeGlobalScope() const { const_cast<NativeSession &>(*this).initializeExeSymbol(); return Cache.getNativeSymbolById<NativeExeSymbol>(ExeSymbol); } uint32_t NativeSession::getRVAFromSectOffset(uint32_t Section, uint32_t Offset) const { if (Section <= 0) return 0; auto Dbi = getDbiStreamPtr(*Pdb); if (!Dbi) return 0; uint32_t MaxSection = Dbi->getSectionHeaders().size(); if (Section > MaxSection + 1) Section = MaxSection + 1; auto &Sec = Dbi->getSectionHeaders()[Section - 1]; return Sec.VirtualAddress + Offset; } uint64_t NativeSession::getVAFromSectOffset(uint32_t Section, uint32_t Offset) const { return LoadAddress + getRVAFromSectOffset(Section, Offset); }
Upload File
Create Folder