[PDB/CodeView] Read/write codeview inlinee line information.
Previously we wrote line information and file checksum
information, but we did not write information about inlinee
lines and functions. This patch adds support for that.
llvm-svn: 301936
diff --git a/llvm/tools/llvm-pdbdump/C13DebugFragmentVisitor.cpp b/llvm/tools/llvm-pdbdump/C13DebugFragmentVisitor.cpp
index 940b38c..7c680eb 100644
--- a/llvm/tools/llvm-pdbdump/C13DebugFragmentVisitor.cpp
+++ b/llvm/tools/llvm-pdbdump/C13DebugFragmentVisitor.cpp
@@ -10,6 +10,7 @@
#include "C13DebugFragmentVisitor.h"
#include "llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h"
+#include "llvm/DebugInfo/CodeView/ModuleDebugInlineeLinesFragment.h"
#include "llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/DebugInfo/PDB/Native/RawError.h"
@@ -41,6 +42,12 @@
return Error::success();
}
+Error C13DebugFragmentVisitor::visitInlineeLines(
+ codeview::ModuleDebugInlineeLineFragmentRef &Lines) {
+ this->InlineeLines.push_back(Lines);
+ return Error::success();
+}
+
Error C13DebugFragmentVisitor::finished() {
if (!Checksums.hasValue()) {
assert(Lines.empty());
@@ -52,6 +59,9 @@
if (auto EC = handleLines())
return EC;
+ if (auto EC = handleInlineeLines())
+ return EC;
+
return Error::success();
}
diff --git a/llvm/tools/llvm-pdbdump/C13DebugFragmentVisitor.h b/llvm/tools/llvm-pdbdump/C13DebugFragmentVisitor.h
index f0a536c..1054b0c 100644
--- a/llvm/tools/llvm-pdbdump/C13DebugFragmentVisitor.h
+++ b/llvm/tools/llvm-pdbdump/C13DebugFragmentVisitor.h
@@ -35,16 +35,21 @@
Error visitLines(codeview::ModuleDebugLineFragmentRef &Lines) final;
+ Error
+ visitInlineeLines(codeview::ModuleDebugInlineeLineFragmentRef &Lines) final;
+
Error finished() final;
protected:
virtual Error handleFileChecksums() { return Error::success(); }
virtual Error handleLines() { return Error::success(); }
+ virtual Error handleInlineeLines() { return Error::success(); }
Expected<StringRef> getNameFromStringTable(uint32_t Offset);
Expected<StringRef> getNameFromChecksumsBuffer(uint32_t Offset);
Optional<codeview::ModuleDebugFileChecksumFragmentRef> Checksums;
+ std::vector<codeview::ModuleDebugInlineeLineFragmentRef> InlineeLines;
std::vector<codeview::ModuleDebugLineFragmentRef> Lines;
PDBFile &F;
diff --git a/llvm/tools/llvm-pdbdump/CompactTypeDumpVisitor.cpp b/llvm/tools/llvm-pdbdump/CompactTypeDumpVisitor.cpp
index 1fc8dd5..5ad0bfa 100644
--- a/llvm/tools/llvm-pdbdump/CompactTypeDumpVisitor.cpp
+++ b/llvm/tools/llvm-pdbdump/CompactTypeDumpVisitor.cpp
@@ -31,14 +31,15 @@
CompactTypeDumpVisitor::CompactTypeDumpVisitor(TypeDatabase &TypeDB,
ScopedPrinter *W)
- : W(W), TI(TypeIndex::None()), Offset(0), TypeDB(TypeDB) {}
+ : CompactTypeDumpVisitor(TypeDB, TypeIndex(TypeIndex::FirstNonSimpleIndex),
+ W) {}
+
+CompactTypeDumpVisitor::CompactTypeDumpVisitor(TypeDatabase &TypeDB,
+ TypeIndex FirstTI,
+ ScopedPrinter *W)
+ : W(W), TI(FirstTI), Offset(0), TypeDB(TypeDB) {}
Error CompactTypeDumpVisitor::visitTypeBegin(CVType &Record) {
- if (TI == TypeIndex::None())
- TI.setIndex(TypeIndex::FirstNonSimpleIndex);
- else
- TI.setIndex(TI.getIndex() + 1);
-
return Error::success();
}
@@ -52,6 +53,7 @@
.str());
Offset += Record.length();
+ TI.setIndex(TI.getIndex() + 1);
return Error::success();
}
diff --git a/llvm/tools/llvm-pdbdump/CompactTypeDumpVisitor.h b/llvm/tools/llvm-pdbdump/CompactTypeDumpVisitor.h
index 180eea7..76fafc9 100644
--- a/llvm/tools/llvm-pdbdump/CompactTypeDumpVisitor.h
+++ b/llvm/tools/llvm-pdbdump/CompactTypeDumpVisitor.h
@@ -27,6 +27,8 @@
class CompactTypeDumpVisitor : public codeview::TypeVisitorCallbacks {
public:
CompactTypeDumpVisitor(codeview::TypeDatabase &TypeDB, ScopedPrinter *W);
+ CompactTypeDumpVisitor(codeview::TypeDatabase &TypeDB,
+ codeview::TypeIndex FirstTI, ScopedPrinter *W);
/// Paired begin/end actions for all types. Receives all record data,
/// including the fixed-length record prefix.
diff --git a/llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp b/llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp
index 833cd81..f3e28e0 100644
--- a/llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp
+++ b/llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp
@@ -20,6 +20,7 @@
#include "llvm/DebugInfo/CodeView/Line.h"
#include "llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.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/CodeView/SymbolDumper.h"
@@ -82,10 +83,13 @@
class C13RawVisitor : public C13DebugFragmentVisitor {
public:
- C13RawVisitor(ScopedPrinter &P, PDBFile &F)
- : C13DebugFragmentVisitor(F), P(P) {}
+ C13RawVisitor(ScopedPrinter &P, PDBFile &F, TypeDatabase &IPI)
+ : C13DebugFragmentVisitor(F), P(P), IPI(IPI) {}
Error handleLines() override {
+ if (Lines.empty())
+ return Error::success();
+
DictScope DD(P, "Lines");
for (const auto &Fragment : Lines) {
@@ -126,6 +130,9 @@
}
Error handleFileChecksums() override {
+ if (!Checksums.hasValue())
+ return Error::success();
+
DictScope DD(P, "FileChecksums");
for (const auto &CS : *Checksums) {
DictScope DDD(P, "Checksum");
@@ -139,7 +146,50 @@
return Error::success();
}
+ Error handleInlineeLines() override {
+ if (InlineeLines.empty())
+ return Error::success();
+
+ DictScope D(P, "InlineeLines");
+ for (const auto &IL : InlineeLines) {
+ P.printBoolean("HasExtraFiles", IL.hasExtraFiles());
+ ListScope LS(P, "Lines");
+ for (const auto &L : IL) {
+ DictScope DDD(P, "Inlinee");
+ if (auto EC = printFileName("FileName", L.Header->FileID))
+ return EC;
+
+ if (auto EC = dumpTypeRecord("Function", IPI, L.Header->Inlinee))
+ return EC;
+ P.printNumber("SourceLine", L.Header->SourceLineNum);
+ if (IL.hasExtraFiles()) {
+ ListScope DDDD(P, "ExtraFiles");
+ for (const auto &EF : L.ExtraFiles) {
+ if (auto EC = printFileName("File", EF))
+ return EC;
+ }
+ }
+ }
+ }
+ return Error::success();
+ }
+
private:
+ Error dumpTypeRecord(StringRef Label, TypeDatabase &DB, TypeIndex Index) {
+ CompactTypeDumpVisitor CTDV(DB, Index, &P);
+ CVTypeVisitor Visitor(CTDV);
+ DictScope D(P, Label);
+ if (DB.containsTypeIndex(Index)) {
+ CVType &Type = DB.getTypeRecord(Index);
+ if (auto EC = Visitor.visitTypeRecord(Type))
+ return EC;
+ } else {
+ P.printString(
+ llvm::formatv("Index: {0:x} (unknown function)", Index.getIndex())
+ .str());
+ }
+ return Error::success();
+ }
Error printFileName(StringRef Label, uint32_t Offset) {
if (auto Result = getNameFromChecksumsBuffer(Offset)) {
P.printString(Label, *Result);
@@ -149,6 +199,7 @@
}
ScopedPrinter &P;
+ TypeDatabase &IPI;
};
}
@@ -618,6 +669,7 @@
if (auto EC = Visitor.visitTypeRecord(Type))
return EC;
+ T.setIndex(T.getIndex() + 1);
}
if (HadError)
return make_error<RawError>(raw_error_code::corrupt_file,
@@ -750,7 +802,7 @@
if (opts::raw::DumpLineInfo) {
ListScope SS(P, "LineInfo");
- C13RawVisitor V(P, File);
+ C13RawVisitor V(P, File, ItemDB);
if (auto EC = codeview::visitModuleDebugFragments(
ModS.linesAndChecksums(), V))
return EC;
diff --git a/llvm/tools/llvm-pdbdump/PdbYaml.cpp b/llvm/tools/llvm-pdbdump/PdbYaml.cpp
index 645f2dc..d6ba7d6 100644
--- a/llvm/tools/llvm-pdbdump/PdbYaml.cpp
+++ b/llvm/tools/llvm-pdbdump/PdbYaml.cpp
@@ -41,6 +41,8 @@
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::PdbSourceColumnEntry)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::PdbSourceLineBlock)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::PdbSourceLineInfo)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::PdbInlineeSite)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::PdbInlineeInfo)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::PdbSymbolRecord)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::PdbTpiRecord)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::StreamBlockList)
@@ -336,6 +338,7 @@
mapping(IO &IO, PdbSourceLineInfo &Obj,
pdb::yaml::SerializationContext &Context) {
IO.mapRequired("CodeSize", Obj.CodeSize);
+
IO.mapRequired("Flags", Obj.Flags);
IO.mapRequired("RelocOffset", Obj.RelocOffset);
IO.mapRequired("RelocSegment", Obj.RelocSegment);
@@ -348,6 +351,21 @@
pdb::yaml::SerializationContext &Context) {
IO.mapOptionalWithContext("Checksums", Obj.FileChecksums, Context);
IO.mapOptionalWithContext("Lines", Obj.LineFragments, Context);
+ IO.mapOptionalWithContext("InlineeLines", Obj.Inlinees, Context);
+}
+
+void MappingContextTraits<PdbInlineeSite, SerializationContext>::mapping(
+ IO &IO, PdbInlineeSite &Obj, SerializationContext &Context) {
+ IO.mapRequired("FileName", Obj.FileName);
+ IO.mapRequired("LineNum", Obj.SourceLineNum);
+ IO.mapRequired("Inlinee", Obj.Inlinee);
+ IO.mapOptional("ExtraFiles", Obj.ExtraFiles);
+}
+
+void MappingContextTraits<PdbInlineeInfo, SerializationContext>::mapping(
+ IO &IO, PdbInlineeInfo &Obj, SerializationContext &Context) {
+ IO.mapRequired("HasExtraFiles", Obj.HasExtraFiles);
+ IO.mapRequired("Sites", Obj.Sites, Context);
}
void MappingContextTraits<PdbTpiRecord, pdb::yaml::SerializationContext>::
diff --git a/llvm/tools/llvm-pdbdump/PdbYaml.h b/llvm/tools/llvm-pdbdump/PdbYaml.h
index a998eaf..423845c 100644
--- a/llvm/tools/llvm-pdbdump/PdbYaml.h
+++ b/llvm/tools/llvm-pdbdump/PdbYaml.h
@@ -102,9 +102,22 @@
std::vector<PdbSourceLineBlock> Blocks;
};
+struct PdbInlineeSite {
+ codeview::TypeIndex Inlinee;
+ StringRef FileName;
+ uint32_t SourceLineNum;
+ std::vector<StringRef> ExtraFiles;
+};
+
+struct PdbInlineeInfo {
+ bool HasExtraFiles;
+ std::vector<PdbInlineeSite> Sites;
+};
+
struct PdbSourceFileInfo {
std::vector<PdbSourceFileChecksumEntry> FileChecksums;
std::vector<PdbSourceLineInfo> LineFragments;
+ std::vector<PdbInlineeInfo> Inlinees;
};
struct PdbDbiModuleInfo {
@@ -259,6 +272,20 @@
};
template <>
+struct MappingContextTraits<pdb::yaml::PdbInlineeInfo,
+ pdb::yaml::SerializationContext> {
+ static void mapping(IO &IO, pdb::yaml::PdbInlineeInfo &Obj,
+ pdb::yaml::SerializationContext &Context);
+};
+
+template <>
+struct MappingContextTraits<pdb::yaml::PdbInlineeSite,
+ pdb::yaml::SerializationContext> {
+ static void mapping(IO &IO, pdb::yaml::PdbInlineeSite &Obj,
+ pdb::yaml::SerializationContext &Context);
+};
+
+template <>
struct MappingContextTraits<pdb::yaml::PdbTpiRecord,
pdb::yaml::SerializationContext> {
static void mapping(IO &IO, pdb::yaml::PdbTpiRecord &Obj,
diff --git a/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp b/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp
index 18596a6..807d7f8 100644
--- a/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp
+++ b/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp
@@ -17,6 +17,7 @@
#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"
@@ -150,6 +151,35 @@
return Error::success();
}
+ 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();
+ }
+ }
+ }
+ }
+ return Error::success();
+ }
+
private:
llvm::pdb::yaml::PdbSourceFileInfo &Info;
diff --git a/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp b/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp
index 0bbc49e..642e169 100644
--- a/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp
+++ b/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp
@@ -31,6 +31,9 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Config/config.h"
+#include "llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h"
+#include "llvm/DebugInfo/CodeView/ModuleDebugInlineeLinesFragment.h"
+#include "llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h"
#include "llvm/DebugInfo/MSF/MSFBuilder.h"
#include "llvm/DebugInfo/PDB/GenericError.h"
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
@@ -421,6 +424,21 @@
static ExitOnError ExitOnErr;
+static uint32_t
+getFileChecksumOffset(StringRef FileName,
+ ModuleDebugFileChecksumFragment &Checksums,
+ StringTableBuilder &Strings) {
+ // The offset in the line info record is the offset of the checksum
+ // entry for the corresponding file. That entry then contains an
+ // offset into the global string table of the file name. So to
+ // compute the proper offset to write into the line info record, we
+ // must first get its offset in the global string table, then ask the
+ // checksum builder to find the offset in its serialized buffer that
+ // it mapped that filename string table offset to.
+ uint32_t StringOffset = Strings.insert(FileName);
+ return Checksums.mapChecksumOffset(StringOffset);
+}
+
static void yamlToPdb(StringRef Path) {
BumpPtrAllocator Allocator;
ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
@@ -503,12 +521,19 @@
if (!FLI.FileChecksums.empty()) {
auto &Strings = Builder.getStringTableBuilder();
for (auto &FC : FLI.FileChecksums) {
- uint32_t STOffset = Strings.getStringIndex(FC.FileName);
+ uint32_t STOffset = Strings.insert(FC.FileName);
Checksums->addChecksum(STOffset, FC.Kind, FC.ChecksumBytes.Bytes);
}
}
ModiBuilder.setC13FileChecksums(std::move(Checksums));
+ // FIXME: StringTable / StringTableBuilder should really be in
+ // DebugInfoCodeView. This would allow us to construct the
+ // ModuleDebugLineFragment with a reference to the string table,
+ // and we could just pass strings around rather than having to
+ // remember how to calculate the right offset.
+ auto &Strings = Builder.getStringTableBuilder();
+
for (const auto &Fragment : FLI.LineFragments) {
auto Lines = llvm::make_unique<ModuleDebugLineFragment>();
Lines->setCodeSize(Fragment.CodeSize);
@@ -516,21 +541,8 @@
Fragment.RelocOffset);
Lines->setFlags(Fragment.Flags);
for (const auto &LC : Fragment.Blocks) {
- // FIXME: StringTable / StringTableBuilder should really be in
- // DebugInfoCodeView. This would allow us to construct the
- // ModuleDebugLineFragment with a reference to the string table,
- // and we could just pass strings around rather than having to
- // remember how to calculate the right offset.
- auto &Strings = Builder.getStringTableBuilder();
- // The offset in the line info record is the offset of the checksum
- // entry for the corresponding file. That entry then contains an
- // offset into the global string table of the file name. So to
- // compute the proper offset to write into the line info record, we
- // must first get its offset in the global string table, then ask the
- // checksum builder to find the offset in its serialized buffer that
- // it mapped that filename string table offset to.
- uint32_t StringOffset = Strings.getStringIndex(LC.FileName);
- uint32_t ChecksumOffset = ChecksumRef.mapChecksumOffset(StringOffset);
+ uint32_t ChecksumOffset =
+ getFileChecksumOffset(LC.FileName, ChecksumRef, Strings);
Lines->createBlock(ChecksumOffset);
if (Lines->hasColumnInfo()) {
@@ -550,7 +562,26 @@
}
}
}
- ModiBuilder.addC13LineFragment(std::move(Lines));
+ ModiBuilder.addC13Fragment(std::move(Lines));
+ }
+
+ for (const auto &Inlinee : FLI.Inlinees) {
+ auto Inlinees = llvm::make_unique<ModuleDebugInlineeLineFragment>(
+ Inlinee.HasExtraFiles);
+ for (const auto &Site : Inlinee.Sites) {
+ uint32_t FileOff =
+ getFileChecksumOffset(Site.FileName, ChecksumRef, Strings);
+
+ Inlinees->addInlineSite(Site.Inlinee, FileOff, Site.SourceLineNum);
+ if (!Inlinee.HasExtraFiles)
+ continue;
+
+ for (auto EF : Site.ExtraFiles) {
+ FileOff = getFileChecksumOffset(EF, ChecksumRef, Strings);
+ Inlinees->addExtraFile(FileOff);
+ }
+ }
+ ModiBuilder.addC13Fragment(std::move(Inlinees));
}
}
}