summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-06-09 00:28:08 +0000
committerZachary Turner <zturner@google.com>2017-06-09 00:28:08 +0000
commit68ca30aa362b18b755319022898494135be8acb1 (patch)
treee70ccc27c4248d19e2185f1bd5c67935d2b54ad5 /lib
parent9cc66ac05da859f73ef2987764de54384e9f191c (diff)
[CodeView] Support remaining debug subsection types
This adds support for Symbols, StringTable, and FrameData subsection types. Even though these subsections rarely if ever appear in a PDB file (they are usually in object files), there's no theoretical reason why they *couldn't* appear in a PDB. The real issue though is that in order to add support for dumping and writing them (which will be useful for object files), we need a way to test them. And since there is no support for reading and writing them to / from object files yet, making PDB support them is the best way to both add support for the underlying format and add support for tests at the same time. Later, when we go to add support for reading / writing them from object files, we'll need only minimal changes in the underlying read/write code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305037 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp13
-rw-r--r--lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp23
-rw-r--r--lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp22
-rw-r--r--lib/ObjectYAML/CodeViewYAMLDebugSections.cpp311
-rw-r--r--lib/ObjectYAML/CodeViewYAMLTypes.cpp28
5 files changed, 352 insertions, 45 deletions
diff --git a/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp b/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp
index 7b972a1a277..6e647c4b976 100644
--- a/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp
+++ b/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp
@@ -24,7 +24,7 @@ Error DebugStringTableSubsectionRef::initialize(BinaryStreamRef Contents) {
return Error::success();
}
Error DebugStringTableSubsectionRef::initialize(BinaryStreamReader &Reader) {
- return Reader.readStreamRef(Stream, Reader.bytesRemaining());
+ return Reader.readStreamRef(Stream);
}
Expected<StringRef>
@@ -55,20 +55,19 @@ uint32_t DebugStringTableSubsection::calculateSerializedSize() const {
}
Error DebugStringTableSubsection::commit(BinaryStreamWriter &Writer) const {
- assert(Writer.bytesRemaining() == StringSize);
- uint32_t MaxOffset = 1;
+ uint32_t Begin = Writer.getOffset();
+ uint32_t End = Begin + StringSize;
for (auto &Pair : Strings) {
StringRef S = Pair.getKey();
- uint32_t Offset = Pair.getValue();
+ uint32_t Offset = Begin + Pair.getValue();
Writer.setOffset(Offset);
if (auto EC = Writer.writeCString(S))
return EC;
- MaxOffset = std::max<uint32_t>(MaxOffset, Offset + S.size() + 1);
+ assert(Writer.getOffset() <= End);
}
- Writer.setOffset(MaxOffset);
- assert(Writer.bytesRemaining() == 0);
+ Writer.setOffset(End);
return Error::success();
}
diff --git a/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp b/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp
index 0cf31846f25..eed8edac283 100644
--- a/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp
+++ b/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp
@@ -40,6 +40,9 @@ Error DebugSubsectionRecord::initialize(BinaryStreamRef Stream,
case DebugSubsectionKind::InlineeLines:
case DebugSubsectionKind::CrossScopeExports:
case DebugSubsectionKind::CrossScopeImports:
+ case DebugSubsectionKind::Symbols:
+ case DebugSubsectionKind::StringTable:
+ case DebugSubsectionKind::FrameData:
break;
default:
llvm_unreachable("Unexpected debug fragment kind!");
@@ -52,9 +55,7 @@ Error DebugSubsectionRecord::initialize(BinaryStreamRef Stream,
}
uint32_t DebugSubsectionRecord::getRecordLength() const {
- uint32_t Result = sizeof(DebugSubsectionHeader) + Data.getLength();
- assert(Result % alignOf(Container) == 0);
- return Result;
+ return sizeof(DebugSubsectionHeader) + Data.getLength();
}
DebugSubsectionKind DebugSubsectionRecord::kind() const { return Kind; }
@@ -66,25 +67,29 @@ DebugSubsectionRecordBuilder::DebugSubsectionRecordBuilder(
: Subsection(std::move(Subsection)), Container(Container) {}
uint32_t DebugSubsectionRecordBuilder::calculateSerializedLength() {
- uint32_t Size =
- sizeof(DebugSubsectionHeader) +
- alignTo(Subsection->calculateSerializedSize(), alignOf(Container));
+ // The length of the entire subsection is always padded to 4 bytes, regardless
+ // of the container kind.
+ uint32_t Size = sizeof(DebugSubsectionHeader) +
+ alignTo(Subsection->calculateSerializedSize(), 4);
return Size;
}
-Error DebugSubsectionRecordBuilder::commit(BinaryStreamWriter &Writer) {
+Error DebugSubsectionRecordBuilder::commit(BinaryStreamWriter &Writer) const {
assert(Writer.getOffset() % alignOf(Container) == 0 &&
"Debug Subsection not properly aligned");
DebugSubsectionHeader Header;
Header.Kind = uint32_t(Subsection->kind());
- Header.Length = calculateSerializedLength() - sizeof(DebugSubsectionHeader);
+ // The value written into the Header's Length field is only padded to the
+ // container's alignment
+ Header.Length =
+ alignTo(Subsection->calculateSerializedSize(), alignOf(Container));
if (auto EC = Writer.writeObject(Header))
return EC;
if (auto EC = Subsection->commit(Writer))
return EC;
- if (auto EC = Writer.padToAlignment(alignOf(Container)))
+ if (auto EC = Writer.padToAlignment(4))
return EC;
return Error::success();
diff --git a/lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp b/lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp
index ee769d3970f..be56ea19198 100644
--- a/lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp
+++ b/lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp
@@ -1,4 +1,4 @@
-//===- DebugSubsectionVisitor.cpp ---------------------------*- C++ -*-===//
+//===- DebugSubsectionVisitor.cpp -------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -12,10 +12,12 @@
#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugCrossImpSubsection.h"
+#include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
+#include "llvm/DebugInfo/CodeView/DebugSymbolsSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugUnknownSubsection.h"
#include "llvm/Support/BinaryStreamReader.h"
#include "llvm/Support/BinaryStreamRef.h"
@@ -91,6 +93,24 @@ Error llvm::codeview::visitDebugSubsection(const DebugSubsectionRecord &R,
return EC;
return V.visitCrossModuleImports(Section, State);
}
+ case DebugSubsectionKind::Symbols: {
+ DebugSymbolsSubsectionRef Section;
+ if (auto EC = Section.initialize(Reader))
+ return EC;
+ return V.visitSymbols(Section, State);
+ }
+ case DebugSubsectionKind::StringTable: {
+ DebugStringTableSubsectionRef Section;
+ if (auto EC = Section.initialize(Reader))
+ return EC;
+ return V.visitStringTable(Section, State);
+ }
+ case DebugSubsectionKind::FrameData: {
+ DebugFrameDataSubsectionRef Section;
+ if (auto EC = Section.initialize(Reader))
+ return EC;
+ return V.visitFrameData(Section, State);
+ }
default: {
DebugUnknownSubsectionRef Fragment(R.kind(), R.getRecordData());
return V.visitUnknown(Fragment);
diff --git a/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp b/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp
index baf98d1b083..3bcedd02d47 100644
--- a/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp
+++ b/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp
@@ -20,13 +20,17 @@
#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugCrossImpSubsection.h"
+#include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h"
+#include "llvm/DebugInfo/CodeView/DebugSymbolsSubsection.h"
#include "llvm/DebugInfo/CodeView/EnumTables.h"
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
-
+#include "llvm/DebugInfo/CodeView/SymbolSerializer.h"
+#include "llvm/ObjectYAML/CodeViewYAMLSymbols.h"
+#include "llvm/Support/BinaryStreamWriter.h"
using namespace llvm;
using namespace llvm::codeview;
using namespace llvm::CodeViewYAML;
@@ -43,6 +47,7 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(InlineeInfo)
LLVM_YAML_IS_SEQUENCE_VECTOR(CrossModuleExport)
LLVM_YAML_IS_SEQUENCE_VECTOR(YAMLCrossModuleImport)
LLVM_YAML_IS_SEQUENCE_VECTOR(StringRef)
+LLVM_YAML_IS_SEQUENCE_VECTOR(YAMLFrameData)
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint32_t)
LLVM_YAML_DECLARE_SCALAR_TRAITS(HexFormattedString, false)
@@ -51,6 +56,7 @@ LLVM_YAML_DECLARE_ENUM_TRAITS(FileChecksumKind)
LLVM_YAML_DECLARE_BITSET_TRAITS(LineFlags)
LLVM_YAML_DECLARE_MAPPING_TRAITS(CrossModuleExport)
+LLVM_YAML_DECLARE_MAPPING_TRAITS(YAMLFrameData)
LLVM_YAML_DECLARE_MAPPING_TRAITS(YAMLCrossModuleImport)
LLVM_YAML_DECLARE_MAPPING_TRAITS(CrossModuleImportItem)
LLVM_YAML_DECLARE_MAPPING_TRAITS(SourceLineEntry)
@@ -69,7 +75,8 @@ struct YAMLSubsectionBase {
virtual void map(IO &IO) = 0;
virtual std::unique_ptr<DebugSubsection>
- toCodeViewSubsection(DebugStringTableSubsection *UseStrings,
+ toCodeViewSubsection(BumpPtrAllocator &Allocator,
+ DebugStringTableSubsection *UseStrings,
DebugChecksumsSubsection *UseChecksums) const = 0;
};
}
@@ -83,7 +90,8 @@ struct YAMLChecksumsSubsection : public YAMLSubsectionBase {
void map(IO &IO) override;
std::unique_ptr<DebugSubsection>
- toCodeViewSubsection(DebugStringTableSubsection *Strings,
+ toCodeViewSubsection(BumpPtrAllocator &Allocator,
+ DebugStringTableSubsection *Strings,
DebugChecksumsSubsection *Checksums) const override;
static Expected<std::shared_ptr<YAMLChecksumsSubsection>>
fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
@@ -97,7 +105,8 @@ struct YAMLLinesSubsection : public YAMLSubsectionBase {
void map(IO &IO) override;
std::unique_ptr<DebugSubsection>
- toCodeViewSubsection(DebugStringTableSubsection *Strings,
+ toCodeViewSubsection(BumpPtrAllocator &Allocator,
+ DebugStringTableSubsection *Strings,
DebugChecksumsSubsection *Checksums) const override;
static Expected<std::shared_ptr<YAMLLinesSubsection>>
fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
@@ -113,7 +122,8 @@ struct YAMLInlineeLinesSubsection : public YAMLSubsectionBase {
void map(IO &IO) override;
std::unique_ptr<DebugSubsection>
- toCodeViewSubsection(DebugStringTableSubsection *Strings,
+ toCodeViewSubsection(BumpPtrAllocator &Allocator,
+ DebugStringTableSubsection *Strings,
DebugChecksumsSubsection *Checksums) const override;
static Expected<std::shared_ptr<YAMLInlineeLinesSubsection>>
fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
@@ -129,7 +139,8 @@ struct YAMLCrossModuleExportsSubsection : public YAMLSubsectionBase {
void map(IO &IO) override;
std::unique_ptr<DebugSubsection>
- toCodeViewSubsection(DebugStringTableSubsection *Strings,
+ toCodeViewSubsection(BumpPtrAllocator &Allocator,
+ DebugStringTableSubsection *Strings,
DebugChecksumsSubsection *Checksums) const override;
static Expected<std::shared_ptr<YAMLCrossModuleExportsSubsection>>
fromCodeViewSubsection(const DebugCrossModuleExportsSubsectionRef &Exports);
@@ -143,7 +154,8 @@ struct YAMLCrossModuleImportsSubsection : public YAMLSubsectionBase {
void map(IO &IO) override;
std::unique_ptr<DebugSubsection>
- toCodeViewSubsection(DebugStringTableSubsection *Strings,
+ toCodeViewSubsection(BumpPtrAllocator &Allocator,
+ DebugStringTableSubsection *Strings,
DebugChecksumsSubsection *Checksums) const override;
static Expected<std::shared_ptr<YAMLCrossModuleImportsSubsection>>
fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
@@ -151,6 +163,51 @@ struct YAMLCrossModuleImportsSubsection : public YAMLSubsectionBase {
std::vector<YAMLCrossModuleImport> Imports;
};
+
+struct YAMLSymbolsSubsection : public YAMLSubsectionBase {
+ YAMLSymbolsSubsection() : YAMLSubsectionBase(DebugSubsectionKind::Symbols) {}
+
+ void map(IO &IO) override;
+ std::unique_ptr<DebugSubsection>
+ toCodeViewSubsection(BumpPtrAllocator &Allocator,
+ DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const override;
+ static Expected<std::shared_ptr<YAMLSymbolsSubsection>>
+ fromCodeViewSubsection(const DebugSymbolsSubsectionRef &Symbols);
+
+ std::vector<CodeViewYAML::SymbolRecord> Symbols;
+};
+
+struct YAMLStringTableSubsection : public YAMLSubsectionBase {
+ YAMLStringTableSubsection()
+ : YAMLSubsectionBase(DebugSubsectionKind::StringTable) {}
+
+ void map(IO &IO) override;
+ std::unique_ptr<DebugSubsection>
+ toCodeViewSubsection(BumpPtrAllocator &Allocator,
+ DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const override;
+ static Expected<std::shared_ptr<YAMLStringTableSubsection>>
+ fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings);
+
+ std::vector<StringRef> Strings;
+};
+
+struct YAMLFrameDataSubsection : public YAMLSubsectionBase {
+ YAMLFrameDataSubsection()
+ : YAMLSubsectionBase(DebugSubsectionKind::FrameData) {}
+
+ void map(IO &IO) override;
+ std::unique_ptr<DebugSubsection>
+ toCodeViewSubsection(BumpPtrAllocator &Allocator,
+ DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const override;
+ static Expected<std::shared_ptr<YAMLFrameDataSubsection>>
+ fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
+ const DebugFrameDataSubsectionRef &Frames);
+
+ std::vector<YAMLFrameData> Frames;
+};
}
void ScalarBitSetTraits<LineFlags>::bitset(IO &io, LineFlags &Flags) {
@@ -223,6 +280,17 @@ void MappingTraits<InlineeSite>::mapping(IO &IO, InlineeSite &Obj) {
IO.mapOptional("ExtraFiles", Obj.ExtraFiles);
}
+void MappingTraits<YAMLFrameData>::mapping(IO &IO, YAMLFrameData &Obj) {
+ IO.mapRequired("CodeSize", Obj.CodeSize);
+ IO.mapRequired("FrameFunc", Obj.FrameFunc);
+ IO.mapRequired("LocalSize", Obj.LocalSize);
+ IO.mapOptional("MaxStackSize", Obj.MaxStackSize);
+ IO.mapOptional("ParamsSize", Obj.ParamsSize);
+ IO.mapOptional("PrologSize", Obj.PrologSize);
+ IO.mapOptional("RvaStart", Obj.RvaStart);
+ IO.mapOptional("SavedRegsSize", Obj.SavedRegsSize);
+}
+
void YAMLChecksumsSubsection::map(IO &IO) {
IO.mapTag("!FileChecksums", true);
IO.mapRequired("Checksums", Checksums);
@@ -254,6 +322,21 @@ void YAMLCrossModuleImportsSubsection::map(IO &IO) {
IO.mapOptional("Imports", Imports);
}
+void YAMLSymbolsSubsection::map(IO &IO) {
+ IO.mapTag("!Symbols", true);
+ IO.mapRequired("Records", Symbols);
+}
+
+void YAMLStringTableSubsection::map(IO &IO) {
+ IO.mapTag("!StringTable", true);
+ IO.mapRequired("Strings", Strings);
+}
+
+void YAMLFrameDataSubsection::map(IO &IO) {
+ IO.mapTag("!FrameData", true);
+ IO.mapRequired("Frames", Frames);
+}
+
void MappingTraits<YAMLDebugSubsection>::mapping(
IO &IO, YAMLDebugSubsection &Subsection) {
if (!IO.outputting()) {
@@ -270,6 +353,12 @@ void MappingTraits<YAMLDebugSubsection>::mapping(
} else if (IO.mapTag("!CrossModuleImports")) {
Subsection.Subsection =
std::make_shared<YAMLCrossModuleImportsSubsection>();
+ } else if (IO.mapTag("!Symbols")) {
+ Subsection.Subsection = std::make_shared<YAMLSymbolsSubsection>();
+ } else if (IO.mapTag("!StringTable")) {
+ Subsection.Subsection = std::make_shared<YAMLStringTableSubsection>();
+ } else if (IO.mapTag("!FrameData")) {
+ Subsection.Subsection = std::make_shared<YAMLFrameDataSubsection>();
} else {
llvm_unreachable("Unexpected subsection tag!");
}
@@ -289,7 +378,7 @@ findChecksums(ArrayRef<YAMLDebugSubsection> Subsections) {
}
std::unique_ptr<DebugSubsection> YAMLChecksumsSubsection::toCodeViewSubsection(
- DebugStringTableSubsection *UseStrings,
+ BumpPtrAllocator &Allocator, DebugStringTableSubsection *UseStrings,
DebugChecksumsSubsection *UseChecksums) const {
assert(UseStrings && !UseChecksums);
auto Result = llvm::make_unique<DebugChecksumsSubsection>(*UseStrings);
@@ -300,7 +389,7 @@ std::unique_ptr<DebugSubsection> YAMLChecksumsSubsection::toCodeViewSubsection(
}
std::unique_ptr<DebugSubsection> YAMLLinesSubsection::toCodeViewSubsection(
- DebugStringTableSubsection *UseStrings,
+ BumpPtrAllocator &Allocator, DebugStringTableSubsection *UseStrings,
DebugChecksumsSubsection *UseChecksums) const {
assert(UseStrings && UseChecksums);
auto Result =
@@ -331,7 +420,7 @@ std::unique_ptr<DebugSubsection> YAMLLinesSubsection::toCodeViewSubsection(
std::unique_ptr<DebugSubsection>
YAMLInlineeLinesSubsection::toCodeViewSubsection(
- DebugStringTableSubsection *UseStrings,
+ BumpPtrAllocator &Allocator, DebugStringTableSubsection *UseStrings,
DebugChecksumsSubsection *UseChecksums) const {
assert(UseChecksums);
auto Result = llvm::make_unique<DebugInlineeLinesSubsection>(
@@ -352,7 +441,7 @@ YAMLInlineeLinesSubsection::toCodeViewSubsection(
std::unique_ptr<DebugSubsection>
YAMLCrossModuleExportsSubsection::toCodeViewSubsection(
- DebugStringTableSubsection *Strings,
+ BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
DebugChecksumsSubsection *Checksums) const {
auto Result = llvm::make_unique<DebugCrossModuleExportsSubsection>();
for (const auto &M : Exports)
@@ -362,7 +451,7 @@ YAMLCrossModuleExportsSubsection::toCodeViewSubsection(
std::unique_ptr<DebugSubsection>
YAMLCrossModuleImportsSubsection::toCodeViewSubsection(
- DebugStringTableSubsection *Strings,
+ BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
DebugChecksumsSubsection *Checksums) const {
auto Result = llvm::make_unique<DebugCrossModuleImportsSubsection>(*Strings);
for (const auto &M : Imports) {
@@ -372,6 +461,47 @@ YAMLCrossModuleImportsSubsection::toCodeViewSubsection(
return llvm::cast<DebugSubsection>(std::move(Result));
}
+std::unique_ptr<DebugSubsection> YAMLSymbolsSubsection::toCodeViewSubsection(
+ BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const {
+ auto Result = llvm::make_unique<DebugSymbolsSubsection>();
+ for (const auto &Sym : Symbols)
+ Result->addSymbol(
+ Sym.toCodeViewSymbol(Allocator, CodeViewContainer::ObjectFile));
+ return std::move(Result);
+}
+
+std::unique_ptr<DebugSubsection>
+YAMLStringTableSubsection::toCodeViewSubsection(
+ BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const {
+ auto Result = llvm::make_unique<DebugStringTableSubsection>();
+ for (const auto &Str : this->Strings)
+ Result->insert(Str);
+ return std::move(Result);
+}
+
+std::unique_ptr<DebugSubsection> YAMLFrameDataSubsection::toCodeViewSubsection(
+ BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const {
+ assert(Strings);
+ auto Result = llvm::make_unique<DebugFrameDataSubsection>();
+ for (const auto &YF : Frames) {
+ codeview::FrameData F;
+ F.CodeSize = YF.CodeSize;
+ F.Flags = YF.Flags;
+ F.LocalSize = YF.LocalSize;
+ F.MaxStackSize = YF.MaxStackSize;
+ F.ParamsSize = YF.ParamsSize;
+ F.PrologSize = YF.PrologSize;
+ F.RvaStart = YF.RvaStart;
+ F.SavedRegsSize = YF.SavedRegsSize;
+ F.FrameFunc = Strings->insert(YF.FrameFunc);
+ Result->addFrameData(F);
+ }
+ return std::move(Result);
+}
+
static Expected<SourceFileChecksumEntry>
convertOneChecksum(const DebugStringTableSubsectionRef &Strings,
const FileChecksumEntry &CS) {
@@ -503,9 +633,74 @@ YAMLCrossModuleImportsSubsection::fromCodeViewSubsection(
return Result;
}
+Expected<std::shared_ptr<YAMLSymbolsSubsection>>
+YAMLSymbolsSubsection::fromCodeViewSubsection(
+ const DebugSymbolsSubsectionRef &Symbols) {
+ auto Result = std::make_shared<YAMLSymbolsSubsection>();
+ for (const auto &Sym : Symbols) {
+ auto S = CodeViewYAML::SymbolRecord::fromCodeViewSymbol(Sym);
+ if (!S)
+ return joinErrors(make_error<CodeViewError>(
+ cv_error_code::corrupt_record,
+ "Invalid CodeView Symbol Record in SymbolRecord "
+ "subsection of .debug$S while converting to YAML!"),
+ S.takeError());
+
+ Result->Symbols.push_back(*S);
+ }
+ return Result;
+}
+
+Expected<std::shared_ptr<YAMLStringTableSubsection>>
+YAMLStringTableSubsection::fromCodeViewSubsection(
+ const DebugStringTableSubsectionRef &Strings) {
+ auto Result = std::make_shared<YAMLStringTableSubsection>();
+ BinaryStreamReader Reader(Strings.getBuffer());
+ StringRef S;
+ // First item is a single null string, skip it.
+ if (auto EC = Reader.readCString(S))
+ return std::move(EC);
+ assert(S.empty());
+ while (Reader.bytesRemaining() > 0) {
+ if (auto EC = Reader.readCString(S))
+ return std::move(EC);
+ Result->Strings.push_back(S);
+ }
+ return Result;
+}
+
+Expected<std::shared_ptr<YAMLFrameDataSubsection>>
+YAMLFrameDataSubsection::fromCodeViewSubsection(
+ const DebugStringTableSubsectionRef &Strings,
+ const DebugFrameDataSubsectionRef &Frames) {
+ auto Result = std::make_shared<YAMLFrameDataSubsection>();
+ for (const auto &F : Frames) {
+ YAMLFrameData YF;
+ YF.CodeSize = F.CodeSize;
+ YF.Flags = F.Flags;
+ YF.LocalSize = F.LocalSize;
+ YF.MaxStackSize = F.MaxStackSize;
+ YF.ParamsSize = F.ParamsSize;
+ YF.PrologSize = F.PrologSize;
+ YF.RvaStart = F.RvaStart;
+ YF.SavedRegsSize = F.SavedRegsSize;
+
+ auto ES = Strings.getString(F.FrameFunc);
+ if (!ES)
+ return joinErrors(
+ make_error<CodeViewError>(
+ cv_error_code::no_records,
+ "Could not find string for string id while mapping FrameData!"),
+ ES.takeError());
+ YF.FrameFunc = *ES;
+ Result->Frames.push_back(YF);
+ }
+ return Result;
+}
+
Expected<std::vector<std::unique_ptr<DebugSubsection>>>
-llvm::CodeViewYAML::convertSubsectionList(
- ArrayRef<YAMLDebugSubsection> Subsections,
+llvm::CodeViewYAML::toCodeViewSubsectionList(
+ BumpPtrAllocator &Allocator, ArrayRef<YAMLDebugSubsection> Subsections,
DebugStringTableSubsection &Strings) {
std::vector<std::unique_ptr<DebugSubsection>> Result;
if (Subsections.empty())
@@ -514,7 +709,8 @@ llvm::CodeViewYAML::convertSubsectionList(
auto Checksums = findChecksums(Subsections);
std::unique_ptr<DebugSubsection> ChecksumsBase;
if (Checksums)
- ChecksumsBase = Checksums->toCodeViewSubsection(&Strings, nullptr);
+ ChecksumsBase =
+ Checksums->toCodeViewSubsection(Allocator, &Strings, nullptr);
DebugChecksumsSubsection *CS =
static_cast<DebugChecksumsSubsection *>(ChecksumsBase.get());
for (const auto &SS : Subsections) {
@@ -524,7 +720,41 @@ llvm::CodeViewYAML::convertSubsectionList(
if (SS.Subsection->Kind == DebugSubsectionKind::FileChecksums)
CVS = std::move(ChecksumsBase);
else
- CVS = SS.Subsection->toCodeViewSubsection(&Strings, CS);
+ CVS = SS.Subsection->toCodeViewSubsection(Allocator, &Strings, CS);
+ assert(CVS != nullptr);
+ Result.push_back(std::move(CVS));
+ }
+ return std::move(Result);
+}
+
+Expected<std::vector<std::unique_ptr<codeview::DebugSubsection>>>
+llvm::CodeViewYAML::toCodeViewSubsectionList(
+ BumpPtrAllocator &Allocator, ArrayRef<YAMLDebugSubsection> Subsections,
+ std::unique_ptr<DebugStringTableSubsection> &TakeStrings,
+ DebugStringTableSubsection *StringsRef) {
+ std::vector<std::unique_ptr<DebugSubsection>> Result;
+ if (Subsections.empty())
+ return std::move(Result);
+
+ auto Checksums = findChecksums(Subsections);
+
+ std::unique_ptr<DebugSubsection> ChecksumsBase;
+ if (Checksums)
+ ChecksumsBase =
+ Checksums->toCodeViewSubsection(Allocator, StringsRef, nullptr);
+ DebugChecksumsSubsection *CS =
+ static_cast<DebugChecksumsSubsection *>(ChecksumsBase.get());
+ for (const auto &SS : Subsections) {
+ // We've already converted the checksums and string table subsection, don't
+ // do it twice.
+ std::unique_ptr<DebugSubsection> CVS;
+ if (SS.Subsection->Kind == DebugSubsectionKind::FileChecksums)
+ CVS = std::move(ChecksumsBase);
+ else if (SS.Subsection->Kind == DebugSubsectionKind::StringTable) {
+ assert(TakeStrings && "No string table!");
+ CVS = std::move(TakeStrings);
+ } else
+ CVS = SS.Subsection->toCodeViewSubsection(Allocator, StringsRef, CS);
assert(CVS != nullptr);
Result.push_back(std::move(CVS));
}
@@ -546,6 +776,12 @@ struct SubsectionConversionVisitor : public DebugSubsectionVisitor {
const DebugSubsectionState &State) override;
Error visitCrossModuleImports(DebugCrossModuleImportsSubsectionRef &Inlinees,
const DebugSubsectionState &State) override;
+ Error visitStringTable(DebugStringTableSubsectionRef &ST,
+ const DebugSubsectionState &State) override;
+ Error visitSymbols(DebugSymbolsSubsectionRef &Symbols,
+ const DebugSubsectionState &State) override;
+ Error visitFrameData(DebugFrameDataSubsectionRef &Symbols,
+ const DebugSubsectionState &State) override;
YAMLDebugSubsection Subsection;
};
@@ -607,6 +843,34 @@ Error SubsectionConversionVisitor::visitCrossModuleImports(
Subsection.Subsection = *Result;
return Error::success();
}
+
+Error SubsectionConversionVisitor::visitStringTable(
+ DebugStringTableSubsectionRef &Strings, const DebugSubsectionState &State) {
+ auto Result = YAMLStringTableSubsection::fromCodeViewSubsection(Strings);
+ if (!Result)
+ return Result.takeError();
+ Subsection.Subsection = *Result;
+ return Error::success();
+}
+
+Error SubsectionConversionVisitor::visitSymbols(
+ DebugSymbolsSubsectionRef &Symbols, const DebugSubsectionState &State) {
+ auto Result = YAMLSymbolsSubsection::fromCodeViewSubsection(Symbols);
+ if (!Result)
+ return Result.takeError();
+ Subsection.Subsection = *Result;
+ return Error::success();
+}
+
+Error SubsectionConversionVisitor::visitFrameData(
+ DebugFrameDataSubsectionRef &Frames, const DebugSubsectionState &State) {
+ auto Result =
+ YAMLFrameDataSubsection::fromCodeViewSubsection(State.strings(), Frames);
+ if (!Result)
+ return Result.takeError();
+ Subsection.Subsection = *Result;
+ return Error::success();
+}
}
Expected<YAMLDebugSubsection> YAMLDebugSubsection::fromCodeViewSubection(
@@ -620,3 +884,18 @@ Expected<YAMLDebugSubsection> YAMLDebugSubsection::fromCodeViewSubection(
return V.Subsection;
}
+
+std::unique_ptr<DebugStringTableSubsection>
+llvm::CodeViewYAML::findStringTable(ArrayRef<YAMLDebugSubsection> Sections) {
+ for (const auto &SS : Sections) {
+ if (SS.Subsection->Kind != DebugSubsectionKind::StringTable)
+ continue;
+
+ // String Table doesn't use the allocator.
+ BumpPtrAllocator Allocator;
+ auto Result =
+ SS.Subsection->toCodeViewSubsection(Allocator, nullptr, nullptr);
+ return llvm::cast<DebugStringTableSubsection>(std::move(Result));
+ }
+ return nullptr;
+}
diff --git a/lib/ObjectYAML/CodeViewYAMLTypes.cpp b/lib/ObjectYAML/CodeViewYAMLTypes.cpp
index 4e82a299a67..1302b0713d0 100644
--- a/lib/ObjectYAML/CodeViewYAMLTypes.cpp
+++ b/lib/ObjectYAML/CodeViewYAMLTypes.cpp
@@ -20,6 +20,7 @@
#include "llvm/DebugInfo/CodeView/EnumTables.h"
#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
#include "llvm/DebugInfo/CodeView/TypeTableBuilder.h"
+#include "llvm/Support/BinaryStreamWriter.h"
using namespace llvm;
using namespace llvm::codeview;
@@ -66,7 +67,7 @@ struct LeafRecordBase {
virtual ~LeafRecordBase() {}
virtual void map(yaml::IO &io) = 0;
- virtual CVType toCodeViewRecord(BumpPtrAllocator &Allocator) const = 0;
+ virtual CVType toCodeViewRecord(TypeTableBuilder &TTB) const = 0;
virtual Error fromCodeViewRecord(CVType Type) = 0;
};
@@ -80,10 +81,9 @@ template <typename T> struct LeafRecordImpl : public LeafRecordBase {
return TypeDeserializer::deserializeAs<T>(Type, Record);
}
- CVType toCodeViewRecord(BumpPtrAllocator &Allocator) const override {
- TypeTableBuilder Table(Allocator);
- Table.writeKnownType(Record);
- return CVType(Kind, Table.records().front());
+ CVType toCodeViewRecord(TypeTableBuilder &TTB) const override {
+ TTB.writeKnownType(Record);
+ return CVType(Kind, TTB.records().back());
}
mutable T Record;
@@ -93,7 +93,7 @@ template <> struct LeafRecordImpl<FieldListRecord> : public LeafRecordBase {
explicit LeafRecordImpl(TypeLeafKind K) : LeafRecordBase(K) {}
void map(yaml::IO &io) override;
- CVType toCodeViewRecord(BumpPtrAllocator &Allocator) const override;
+ CVType toCodeViewRecord(TypeTableBuilder &TTB) const override;
Error fromCodeViewRecord(CVType Type) override;
std::vector<MemberRecord> Members;
@@ -440,16 +440,15 @@ Error LeafRecordImpl<FieldListRecord>::fromCodeViewRecord(CVType Type) {
return visitMemberRecordStream(Type.content(), V);
}
-CVType LeafRecordImpl<FieldListRecord>::toCodeViewRecord(
- BumpPtrAllocator &Allocator) const {
- TypeTableBuilder TTB(Allocator);
+CVType
+LeafRecordImpl<FieldListRecord>::toCodeViewRecord(TypeTableBuilder &TTB) const {
FieldListRecordBuilder FLRB(TTB);
FLRB.begin();
for (const auto &Member : Members) {
Member.Member->writeTo(FLRB);
}
FLRB.end(true);
- return CVType(Kind, TTB.records().front());
+ return CVType(Kind, TTB.records().back());
}
void MappingTraits<OneMethodRecord>::mapping(IO &io, OneMethodRecord &Record) {
@@ -634,8 +633,13 @@ Expected<LeafRecord> LeafRecord::fromCodeViewRecord(CVType Type) {
return make_error<CodeViewError>(cv_error_code::corrupt_record);
}
-CVType LeafRecord::toCodeViewRecord(BumpPtrAllocator &Allocator) const {
- return Leaf->toCodeViewRecord(Allocator);
+CVType LeafRecord::toCodeViewRecord(BumpPtrAllocator &Alloc) const {
+ TypeTableBuilder TTB(Alloc);
+ return Leaf->toCodeViewRecord(TTB);
+}
+
+CVType LeafRecord::toCodeViewRecord(TypeTableBuilder &TTB) const {
+ return Leaf->toCodeViewRecord(TTB);
}
namespace llvm {