diff --git a/llvm/include/llvm/DebugInfo/PDB/DIA/DIASession.h b/llvm/include/llvm/DebugInfo/PDB/DIA/DIASession.h index 9a8600fb85ec..d887e9033f33 100644 --- a/llvm/include/llvm/DebugInfo/PDB/DIA/DIASession.h +++ b/llvm/include/llvm/DebugInfo/PDB/DIA/DIASession.h @@ -32,9 +32,25 @@ public: std::unique_ptr findSymbolByAddress(uint64_t Address, PDB_SymType Type) const override; + std::unique_ptr + findLineNumbers(const PDBSymbolCompiland &Compiland, + const IPDBSourceFile &File) const override; std::unique_ptr findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override; + std::unique_ptr + findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const override; + std::unique_ptr + findOneSourceFile(const PDBSymbolCompiland *Compiland, + llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const override; + std::unique_ptr> + findCompilandsForSourceFile(llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const override; + std::unique_ptr + findOneCompilandForSourceFile(llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const override; std::unique_ptr getAllSourceFiles() const override; std::unique_ptr getSourceFilesForCompiland( const PDBSymbolCompiland &Compiland) const override; diff --git a/llvm/include/llvm/DebugInfo/PDB/DIA/DIASourceFile.h b/llvm/include/llvm/DebugInfo/PDB/DIA/DIASourceFile.h index c424e27493c1..66b0c7db93f8 100644 --- a/llvm/include/llvm/DebugInfo/PDB/DIA/DIASourceFile.h +++ b/llvm/include/llvm/DebugInfo/PDB/DIA/DIASourceFile.h @@ -25,7 +25,10 @@ public: uint32_t getUniqueId() const override; std::string getChecksum() const override; PDB_Checksum getChecksumType() const override; - std::unique_ptr getCompilands() const override; + std::unique_ptr> + getCompilands() const override; + + CComPtr getDiaFile() const { return SourceFile; } private: const DIASession &Session; diff --git a/llvm/include/llvm/DebugInfo/PDB/IPDBSession.h b/llvm/include/llvm/DebugInfo/PDB/IPDBSession.h index a130a38a6538..b6bccbeb8842 100644 --- a/llvm/include/llvm/DebugInfo/PDB/IPDBSession.h +++ b/llvm/include/llvm/DebugInfo/PDB/IPDBSession.h @@ -45,9 +45,27 @@ public: virtual std::unique_ptr findSymbolByAddress(uint64_t Address, PDB_SymType Type) const = 0; + + virtual std::unique_ptr + findLineNumbers(const PDBSymbolCompiland &Compiland, + const IPDBSourceFile &File) const = 0; virtual std::unique_ptr findLineNumbersByAddress(uint64_t Address, uint32_t Length) const = 0; + virtual std::unique_ptr + findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const = 0; + virtual std::unique_ptr + findOneSourceFile(const PDBSymbolCompiland *Compiland, + llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const = 0; + virtual std::unique_ptr> + findCompilandsForSourceFile(llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const = 0; + virtual std::unique_ptr + findOneCompilandForSourceFile(llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const = 0; + virtual std::unique_ptr getAllSourceFiles() const = 0; virtual std::unique_ptr getSourceFilesForCompiland(const PDBSymbolCompiland &Compiland) const = 0; diff --git a/llvm/include/llvm/DebugInfo/PDB/IPDBSourceFile.h b/llvm/include/llvm/DebugInfo/PDB/IPDBSourceFile.h index 55000eff02f0..3e4394387105 100644 --- a/llvm/include/llvm/DebugInfo/PDB/IPDBSourceFile.h +++ b/llvm/include/llvm/DebugInfo/PDB/IPDBSourceFile.h @@ -30,7 +30,8 @@ public: virtual uint32_t getUniqueId() const = 0; virtual std::string getChecksum() const = 0; virtual PDB_Checksum getChecksumType() const = 0; - virtual std::unique_ptr getCompilands() const = 0; + virtual std::unique_ptr> + getCompilands() const = 0; }; } diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCompiland.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCompiland.h index 7a2430df695d..ade807f64630 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCompiland.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCompiland.h @@ -30,7 +30,8 @@ public: FORWARD_SYMBOL_METHOD(getLexicalParentId) FORWARD_SYMBOL_METHOD(getLibraryName) FORWARD_SYMBOL_METHOD(getName) - FORWARD_SYMBOL_METHOD(getSourceFileName) + + std::string getSourceFileName() const; }; } diff --git a/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp b/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp index 99fe750ebac6..5e58bb4008f5 100644 --- a/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp +++ b/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp @@ -157,6 +157,22 @@ DIASession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const { return PDBSymbol::create(*this, std::move(RawSymbol)); } +std::unique_ptr +DIASession::findLineNumbers(const PDBSymbolCompiland &Compiland, + const IPDBSourceFile &File) const { + const DIARawSymbol &RawCompiland = + static_cast(Compiland.getRawSymbol()); + const DIASourceFile &RawFile = static_cast(File); + + CComPtr LineNumbers; + if (S_OK != + Session->findLines(RawCompiland.getDiaSymbol(), RawFile.getDiaFile(), + &LineNumbers)) + return nullptr; + + return llvm::make_unique(LineNumbers); +} + std::unique_ptr DIASession::findLineNumbersByAddress(uint64_t Address, uint32_t Length) const { CComPtr LineNumbers; @@ -166,6 +182,56 @@ DIASession::findLineNumbersByAddress(uint64_t Address, uint32_t Length) const { return llvm::make_unique(LineNumbers); } +std::unique_ptr +DIASession::findSourceFiles(const PDBSymbolCompiland *Compiland, + llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const { + IDiaSymbol *DiaCompiland = nullptr; + CComBSTR Utf16Pattern; + if (!Pattern.empty()) + Utf16Pattern = CComBSTR(Pattern.data()); + + if (Compiland) + DiaCompiland = static_cast(Compiland->getRawSymbol()) + .getDiaSymbol(); + + Flags = static_cast( + Flags | PDB_NameSearchFlags::NS_FileNameExtMatch); + CComPtr SourceFiles; + if (S_OK != + Session->findFile(DiaCompiland, Utf16Pattern.m_str, Flags, &SourceFiles)) + return nullptr; + return llvm::make_unique(*this, SourceFiles); +} + +std::unique_ptr +DIASession::findOneSourceFile(const PDBSymbolCompiland *Compiland, + llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const { + auto SourceFiles = findSourceFiles(Compiland, Pattern, Flags); + if (!SourceFiles || SourceFiles->getChildCount() == 0) + return nullptr; + return SourceFiles->getNext(); +} + +std::unique_ptr> +DIASession::findCompilandsForSourceFile(llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const { + auto File = findOneSourceFile(nullptr, Pattern, Flags); + if (!File) + return nullptr; + return File->getCompilands(); +} + +std::unique_ptr +DIASession::findOneCompilandForSourceFile(llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const { + auto Compilands = findCompilandsForSourceFile(Pattern, Flags); + if (!Compilands || Compilands->getChildCount() == 0) + return nullptr; + return Compilands->getNext(); +} + std::unique_ptr DIASession::getAllSourceFiles() const { CComPtr Files; if (S_OK != Session->findFile(nullptr, nullptr, nsNone, &Files)) diff --git a/llvm/lib/DebugInfo/PDB/DIA/DIASourceFile.cpp b/llvm/lib/DebugInfo/PDB/DIA/DIASourceFile.cpp index 0a9c444f5e6e..9600a1972ea5 100644 --- a/llvm/lib/DebugInfo/PDB/DIA/DIASourceFile.cpp +++ b/llvm/lib/DebugInfo/PDB/DIA/DIASourceFile.cpp @@ -7,9 +7,11 @@ // //===----------------------------------------------------------------------===// +#include "llvm/DebugInfo/PDB/DIA/DIASourceFile.h" +#include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h" #include "llvm/DebugInfo/PDB/DIA/DIAEnumSymbols.h" #include "llvm/DebugInfo/PDB/DIA/DIASession.h" -#include "llvm/DebugInfo/PDB/DIA/DIASourceFile.h" +#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" #include "llvm/Support/ConvertUTF.h" using namespace llvm; @@ -56,12 +58,15 @@ PDB_Checksum DIASourceFile::getChecksumType() const { return static_cast(Type); } -std::unique_ptr DIASourceFile::getCompilands() const { +std::unique_ptr> +DIASourceFile::getCompilands() const { CComPtr DiaEnumerator; HRESULT Result = SourceFile->get_compilands(&DiaEnumerator); if (S_OK != Result) return nullptr; - return std::unique_ptr( + auto Enumerator = std::unique_ptr( new DIAEnumSymbols(Session, DiaEnumerator)); + return std::unique_ptr>( + new ConcreteSymbolEnumerator(std::move(Enumerator))); } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp index 74369148e26e..8393b5cdfd1a 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" +#include "llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h" #include "llvm/DebugInfo/PDB/PDBSymDumper.h" @@ -22,3 +23,21 @@ PDBSymbolCompiland::PDBSymbolCompiland(const IPDBSession &PDBSession, void PDBSymbolCompiland::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); } + +std::string PDBSymbolCompiland::getSourceFileName() const +{ + std::string Result = RawSymbol->getSourceFileName(); + if (!Result.empty()) + return Result; + auto Envs = findAllChildren(); + if (!Envs) + return std::string(); + while (auto Env = Envs->getNext()) { + std::string Var = Env->getName(); + if (Var != "src") + continue; + std::string Value = Env->getValue(); + return Value; + } + return std::string(); +} diff --git a/llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp b/llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp index ebd3d7bb6b3c..736a6ccb0de3 100644 --- a/llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp +++ b/llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp @@ -78,9 +78,35 @@ class MockSession : public IPDBSession { return nullptr; } std::unique_ptr + findLineNumbers(const PDBSymbolCompiland &Compiland, + const IPDBSourceFile &File) const override { + return nullptr; + } + std::unique_ptr findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override { return nullptr; } + std::unique_ptr + findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const override { + return nullptr; + } + std::unique_ptr + findOneSourceFile(const PDBSymbolCompiland *Compiland, + llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const override { + return nullptr; + } + std::unique_ptr> + findCompilandsForSourceFile(llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const override { + return nullptr; + } + std::unique_ptr + findOneCompilandForSourceFile(llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const override { + return nullptr; + } std::unique_ptr getAllSourceFiles() const override { return nullptr;