[DebugInfoPDB] Add source / line number accessors for PDB.

This patch adds a variety of different methods to query source
and line number information from PDB files.

llvm-svn: 261239
This commit is contained in:
Zachary Turner 2016-02-18 18:47:29 +00:00
parent 75734f87a6
commit 43ec3af952
9 changed files with 161 additions and 6 deletions

View File

@ -32,9 +32,25 @@ public:
std::unique_ptr<PDBSymbol>
findSymbolByAddress(uint64_t Address, PDB_SymType Type) const override;
std::unique_ptr<IPDBEnumLineNumbers>
findLineNumbers(const PDBSymbolCompiland &Compiland,
const IPDBSourceFile &File) const override;
std::unique_ptr<IPDBEnumLineNumbers>
findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override;
std::unique_ptr<IPDBEnumSourceFiles>
findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern,
PDB_NameSearchFlags Flags) const override;
std::unique_ptr<IPDBSourceFile>
findOneSourceFile(const PDBSymbolCompiland *Compiland,
llvm::StringRef Pattern,
PDB_NameSearchFlags Flags) const override;
std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
findCompilandsForSourceFile(llvm::StringRef Pattern,
PDB_NameSearchFlags Flags) const override;
std::unique_ptr<PDBSymbolCompiland>
findOneCompilandForSourceFile(llvm::StringRef Pattern,
PDB_NameSearchFlags Flags) const override;
std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override;
std::unique_ptr<IPDBEnumSourceFiles> getSourceFilesForCompiland(
const PDBSymbolCompiland &Compiland) const override;

View File

@ -25,7 +25,10 @@ public:
uint32_t getUniqueId() const override;
std::string getChecksum() const override;
PDB_Checksum getChecksumType() const override;
std::unique_ptr<IPDBEnumSymbols> getCompilands() const override;
std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
getCompilands() const override;
CComPtr<IDiaSourceFile> getDiaFile() const { return SourceFile; }
private:
const DIASession &Session;

View File

@ -45,9 +45,27 @@ public:
virtual std::unique_ptr<PDBSymbol>
findSymbolByAddress(uint64_t Address, PDB_SymType Type) const = 0;
virtual std::unique_ptr<IPDBEnumLineNumbers>
findLineNumbers(const PDBSymbolCompiland &Compiland,
const IPDBSourceFile &File) const = 0;
virtual std::unique_ptr<IPDBEnumLineNumbers>
findLineNumbersByAddress(uint64_t Address, uint32_t Length) const = 0;
virtual std::unique_ptr<IPDBEnumSourceFiles>
findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern,
PDB_NameSearchFlags Flags) const = 0;
virtual std::unique_ptr<IPDBSourceFile>
findOneSourceFile(const PDBSymbolCompiland *Compiland,
llvm::StringRef Pattern,
PDB_NameSearchFlags Flags) const = 0;
virtual std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
findCompilandsForSourceFile(llvm::StringRef Pattern,
PDB_NameSearchFlags Flags) const = 0;
virtual std::unique_ptr<PDBSymbolCompiland>
findOneCompilandForSourceFile(llvm::StringRef Pattern,
PDB_NameSearchFlags Flags) const = 0;
virtual std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const = 0;
virtual std::unique_ptr<IPDBEnumSourceFiles>
getSourceFilesForCompiland(const PDBSymbolCompiland &Compiland) const = 0;

View File

@ -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<IPDBEnumSymbols> getCompilands() const = 0;
virtual std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
getCompilands() const = 0;
};
}

View File

@ -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;
};
}

View File

@ -157,6 +157,22 @@ DIASession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const {
return PDBSymbol::create(*this, std::move(RawSymbol));
}
std::unique_ptr<IPDBEnumLineNumbers>
DIASession::findLineNumbers(const PDBSymbolCompiland &Compiland,
const IPDBSourceFile &File) const {
const DIARawSymbol &RawCompiland =
static_cast<const DIARawSymbol &>(Compiland.getRawSymbol());
const DIASourceFile &RawFile = static_cast<const DIASourceFile &>(File);
CComPtr<IDiaEnumLineNumbers> LineNumbers;
if (S_OK !=
Session->findLines(RawCompiland.getDiaSymbol(), RawFile.getDiaFile(),
&LineNumbers))
return nullptr;
return llvm::make_unique<DIAEnumLineNumbers>(LineNumbers);
}
std::unique_ptr<IPDBEnumLineNumbers>
DIASession::findLineNumbersByAddress(uint64_t Address, uint32_t Length) const {
CComPtr<IDiaEnumLineNumbers> LineNumbers;
@ -166,6 +182,56 @@ DIASession::findLineNumbersByAddress(uint64_t Address, uint32_t Length) const {
return llvm::make_unique<DIAEnumLineNumbers>(LineNumbers);
}
std::unique_ptr<IPDBEnumSourceFiles>
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<const DIARawSymbol &>(Compiland->getRawSymbol())
.getDiaSymbol();
Flags = static_cast<PDB_NameSearchFlags>(
Flags | PDB_NameSearchFlags::NS_FileNameExtMatch);
CComPtr<IDiaEnumSourceFiles> SourceFiles;
if (S_OK !=
Session->findFile(DiaCompiland, Utf16Pattern.m_str, Flags, &SourceFiles))
return nullptr;
return llvm::make_unique<DIAEnumSourceFiles>(*this, SourceFiles);
}
std::unique_ptr<IPDBSourceFile>
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<IPDBEnumChildren<PDBSymbolCompiland>>
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<PDBSymbolCompiland>
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<IPDBEnumSourceFiles> DIASession::getAllSourceFiles() const {
CComPtr<IDiaEnumSourceFiles> Files;
if (S_OK != Session->findFile(nullptr, nullptr, nsNone, &Files))

View File

@ -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<PDB_Checksum>(Type);
}
std::unique_ptr<IPDBEnumSymbols> DIASourceFile::getCompilands() const {
std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
DIASourceFile::getCompilands() const {
CComPtr<IDiaEnumSymbols> DiaEnumerator;
HRESULT Result = SourceFile->get_compilands(&DiaEnumerator);
if (S_OK != Result)
return nullptr;
return std::unique_ptr<IPDBEnumSymbols>(
auto Enumerator = std::unique_ptr<IPDBEnumSymbols>(
new DIAEnumSymbols(Session, DiaEnumerator));
return std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>(
new ConcreteSymbolEnumerator<PDBSymbolCompiland>(std::move(Enumerator)));
}

View File

@ -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<PDBSymbolCompilandEnv>();
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();
}

View File

@ -78,9 +78,35 @@ class MockSession : public IPDBSession {
return nullptr;
}
std::unique_ptr<IPDBEnumLineNumbers>
findLineNumbers(const PDBSymbolCompiland &Compiland,
const IPDBSourceFile &File) const override {
return nullptr;
}
std::unique_ptr<IPDBEnumLineNumbers>
findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override {
return nullptr;
}
std::unique_ptr<IPDBEnumSourceFiles>
findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern,
PDB_NameSearchFlags Flags) const override {
return nullptr;
}
std::unique_ptr<IPDBSourceFile>
findOneSourceFile(const PDBSymbolCompiland *Compiland,
llvm::StringRef Pattern,
PDB_NameSearchFlags Flags) const override {
return nullptr;
}
std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
findCompilandsForSourceFile(llvm::StringRef Pattern,
PDB_NameSearchFlags Flags) const override {
return nullptr;
}
std::unique_ptr<PDBSymbolCompiland>
findOneCompilandForSourceFile(llvm::StringRef Pattern,
PDB_NameSearchFlags Flags) const override {
return nullptr;
}
std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override {
return nullptr;