diff options
Diffstat (limited to 'tools/llvm-pdbdump/YAMLOutputStyle.cpp')
-rw-r--r-- | tools/llvm-pdbdump/YAMLOutputStyle.cpp | 177 |
1 files changed, 100 insertions, 77 deletions
diff --git a/tools/llvm-pdbdump/YAMLOutputStyle.cpp b/tools/llvm-pdbdump/YAMLOutputStyle.cpp index b329de265e72..807d7f8b82e1 100644 --- a/tools/llvm-pdbdump/YAMLOutputStyle.cpp +++ b/tools/llvm-pdbdump/YAMLOutputStyle.cpp @@ -9,21 +9,28 @@ #include "YAMLOutputStyle.h" +#include "C13DebugFragmentVisitor.h" #include "PdbYaml.h" #include "llvm-pdbdump.h" #include "llvm/DebugInfo/CodeView/Line.h" -#include "llvm/DebugInfo/CodeView/ModuleSubstream.h" -#include "llvm/DebugInfo/CodeView/ModuleSubstreamVisitor.h" +#include "llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h" +#include "llvm/DebugInfo/CodeView/ModuleDebugFragment.h" +#include "llvm/DebugInfo/CodeView/ModuleDebugFragmentVisitor.h" +#include "llvm/DebugInfo/CodeView/ModuleDebugInlineeLinesFragment.h" +#include "llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h" +#include "llvm/DebugInfo/CodeView/ModuleDebugUnknownFragment.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" #include "llvm/DebugInfo/PDB/Native/InfoStream.h" -#include "llvm/DebugInfo/PDB/Native/ModStream.h" +#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/RawConstants.h" +#include "llvm/DebugInfo/PDB/Native/RawError.h" #include "llvm/DebugInfo/PDB/Native/TpiStream.h" using namespace llvm; +using namespace llvm::codeview; using namespace llvm::pdb; YAMLOutputStyle::YAMLOutputStyle(PDBFile &File) @@ -46,6 +53,12 @@ Error YAMLOutputStyle::dump() { if (opts::pdb2yaml::DbiModuleInfo) opts::pdb2yaml::DbiStream = true; + // Some names from the module source file info get pulled from the string + // table, so if we're writing module source info, we have to write the string + // table as well. + if (opts::pdb2yaml::DbiModuleSourceLineInfo) + opts::pdb2yaml::StringTable = true; + if (auto EC = dumpFileHeaders()) return EC; @@ -75,22 +88,15 @@ Error YAMLOutputStyle::dump() { } namespace { -class C13SubstreamVisitor : public codeview::IModuleSubstreamVisitor { +class C13YamlVisitor : public C13DebugFragmentVisitor { public: - C13SubstreamVisitor(llvm::pdb::yaml::PdbSourceFileInfo &Info, PDBFile &F) - : Info(Info), F(F) {} - - Error visitUnknown(codeview::ModuleSubstreamKind Kind, - BinaryStreamRef Stream) override { - return Error::success(); - } + C13YamlVisitor(llvm::pdb::yaml::PdbSourceFileInfo &Info, PDBFile &F) + : C13DebugFragmentVisitor(F), Info(Info) {} - Error - visitFileChecksums(BinaryStreamRef Data, - const codeview::FileChecksumArray &Checksums) override { - for (const auto &C : Checksums) { + Error handleFileChecksums() override { + for (const auto &C : *Checksums) { llvm::pdb::yaml::PdbSourceFileChecksumEntry Entry; - if (auto Result = getGlobalString(C.FileNameOffset)) + if (auto Result = getNameFromStringTable(C.FileNameOffset)) Entry.FileName = *Result; else return Result.takeError(); @@ -102,80 +108,94 @@ public: return Error::success(); } - Error visitLines(BinaryStreamRef Data, - const codeview::LineSubstreamHeader *Header, - const codeview::LineInfoArray &Lines) override { - - Info.Lines.CodeSize = Header->CodeSize; - Info.Lines.Flags = - static_cast<codeview::LineFlags>(uint16_t(Header->Flags)); - Info.Lines.RelocOffset = Header->RelocOffset; - Info.Lines.RelocSegment = Header->RelocSegment; - - for (const auto &L : Lines) { - llvm::pdb::yaml::PdbSourceLineBlock Block; - - if (auto Result = getDbiFileName(L.NameIndex)) - Block.FileName = *Result; - else - return Result.takeError(); + Error handleLines() override { + for (const auto &LF : Lines) { + Info.LineFragments.emplace_back(); + auto &Fragment = Info.LineFragments.back(); + + Fragment.CodeSize = LF.header()->CodeSize; + Fragment.Flags = + static_cast<codeview::LineFlags>(uint16_t(LF.header()->Flags)); + Fragment.RelocOffset = LF.header()->RelocOffset; + Fragment.RelocSegment = LF.header()->RelocSegment; + + for (const auto &L : LF) { + Fragment.Blocks.emplace_back(); + auto &Block = Fragment.Blocks.back(); + + if (auto Result = getNameFromChecksumsBuffer(L.NameIndex)) + Block.FileName = *Result; + else + return Result.takeError(); + + for (const auto &N : L.LineNumbers) { + llvm::pdb::yaml::PdbSourceLineEntry Line; + Line.Offset = N.Offset; + codeview::LineInfo LI(N.Flags); + Line.LineStart = LI.getStartLine(); + Line.EndDelta = LI.getLineDelta(); + Line.IsStatement = LI.isStatement(); + Block.Lines.push_back(Line); + } - for (const auto &N : L.LineNumbers) { - llvm::pdb::yaml::PdbSourceLineEntry Line; - Line.Offset = N.Offset; - codeview::LineInfo LI(N.Flags); - Line.LineStart = LI.getStartLine(); - Line.EndDelta = LI.getEndLine(); - Line.IsStatement = LI.isStatement(); - Block.Lines.push_back(Line); + if (LF.hasColumnInfo()) { + for (const auto &C : L.Columns) { + llvm::pdb::yaml::PdbSourceColumnEntry Column; + Column.StartColumn = C.StartColumn; + Column.EndColumn = C.EndColumn; + Block.Columns.push_back(Column); + } + } } + } + return Error::success(); + } - if (Info.Lines.Flags & codeview::LineFlags::HaveColumns) { - for (const auto &C : L.Columns) { - llvm::pdb::yaml::PdbSourceColumnEntry Column; - Column.StartColumn = C.StartColumn; - Column.EndColumn = C.EndColumn; - Block.Columns.push_back(Column); + Error handleInlineeLines() override { + for (const auto &ILF : InlineeLines) { + Info.Inlinees.emplace_back(); + auto &Inlinee = Info.Inlinees.back(); + + Inlinee.HasExtraFiles = ILF.hasExtraFiles(); + for (const auto &IL : ILF) { + Inlinee.Sites.emplace_back(); + auto &Site = Inlinee.Sites.back(); + if (auto Result = getNameFromChecksumsBuffer(IL.Header->FileID)) + Site.FileName = *Result; + else + return Result.takeError(); + + Site.Inlinee = IL.Header->Inlinee; + Site.SourceLineNum = IL.Header->SourceLineNum; + if (ILF.hasExtraFiles()) { + for (const auto &EF : IL.ExtraFiles) { + if (auto Result = getNameFromChecksumsBuffer(EF)) + Site.ExtraFiles.push_back(*Result); + else + return Result.takeError(); + } } } - - Info.Lines.LineInfo.push_back(Block); } return Error::success(); } private: - Expected<StringRef> getGlobalString(uint32_t Offset) { - auto ST = F.getStringTable(); - if (!ST) - return ST.takeError(); - - return ST->getStringForID(Offset); - } - Expected<StringRef> getDbiFileName(uint32_t Offset) { - auto DS = F.getPDBDbiStream(); - if (!DS) - return DS.takeError(); - return DS->getFileNameForIndex(Offset); - } llvm::pdb::yaml::PdbSourceFileInfo &Info; - PDBFile &F; }; } Expected<Optional<llvm::pdb::yaml::PdbSourceFileInfo>> -YAMLOutputStyle::getFileLineInfo(const pdb::ModStream &ModS) { +YAMLOutputStyle::getFileLineInfo(const pdb::ModuleDebugStreamRef &ModS) { if (!ModS.hasLineInfo()) return None; yaml::PdbSourceFileInfo Info; - bool Error = false; - C13SubstreamVisitor Visitor(Info, File); - for (auto &Substream : ModS.lines(&Error)) { - if (auto E = codeview::visitModuleSubstream(Substream, Visitor)) - return std::move(E); - } + C13YamlVisitor Visitor(Info, File); + if (auto EC = codeview::visitModuleDebugFragments(ModS.linesAndChecksums(), + Visitor)) + return std::move(EC); return Info; } @@ -283,17 +303,22 @@ Error YAMLOutputStyle::dumpDbiStream() { Obj.DbiStream->VerHeader = DS.getDbiVersion(); if (opts::pdb2yaml::DbiModuleInfo) { for (const auto &MI : DS.modules()) { - yaml::PdbDbiModuleInfo DMI; + Obj.DbiStream->ModInfos.emplace_back(); + yaml::PdbDbiModuleInfo &DMI = Obj.DbiStream->ModInfos.back(); + DMI.Mod = MI.Info.getModuleName(); DMI.Obj = MI.Info.getObjFileName(); if (opts::pdb2yaml::DbiModuleSourceFileInfo) DMI.SourceFiles = MI.SourceFiles; + uint16_t ModiStream = MI.Info.getModuleStreamIndex(); + if (ModiStream == kInvalidStreamIndex) + continue; + auto ModStreamData = msf::MappedBlockStream::createIndexedStream( - File.getMsfLayout(), File.getMsfBuffer(), - MI.Info.getModuleStreamIndex()); + File.getMsfLayout(), File.getMsfBuffer(), ModiStream); - pdb::ModStream ModS(MI.Info, std::move(ModStreamData)); + pdb::ModuleDebugStreamRef ModS(MI.Info, std::move(ModStreamData)); if (auto EC = ModS.reload()) return EC; @@ -304,8 +329,7 @@ Error YAMLOutputStyle::dumpDbiStream() { DMI.FileLineInfo = *ExpectedInfo; } - if (opts::pdb2yaml::DbiModuleSyms && - MI.Info.getModuleStreamIndex() != kInvalidStreamIndex) { + if (opts::pdb2yaml::DbiModuleSyms) { DMI.Modi.emplace(); DMI.Modi->Signature = ModS.signature(); @@ -315,7 +339,6 @@ Error YAMLOutputStyle::dumpDbiStream() { DMI.Modi->Symbols.push_back(Record); } } - Obj.DbiStream->ModInfos.push_back(DMI); } } return Error::success(); |