summaryrefslogtreecommitdiff
path: root/lib/ObjectYAML
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-06-14 06:24:24 +0000
committerZachary Turner <zturner@google.com>2017-06-14 06:24:24 +0000
commit76c210df336442c8a8baccc8c8c49349bea0933c (patch)
treeb5c310f1456a80b21546e29e16df1538f00419ca /lib/ObjectYAML
parentf0a6e52293b3094a02bee7215e969833e20f6cf3 (diff)
Revert "[codeview] Make obj2yaml/yaml2obj support .debug$S..."
This is causing failures on linux bots with an invalid stream read. It doesn't repro in any configuration on Windows, so reverting until I have a chance to investigate on Linux. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305371 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ObjectYAML')
-rw-r--r--lib/ObjectYAML/COFFYAML.cpp11
-rw-r--r--lib/ObjectYAML/CodeViewYAMLDebugSections.cpp327
-rw-r--r--lib/ObjectYAML/CodeViewYAMLTypes.cpp40
3 files changed, 168 insertions, 210 deletions
diff --git a/lib/ObjectYAML/COFFYAML.cpp b/lib/ObjectYAML/COFFYAML.cpp
index c8cbea1490f..7f9f4c1f8c2 100644
--- a/lib/ObjectYAML/COFFYAML.cpp
+++ b/lib/ObjectYAML/COFFYAML.cpp
@@ -488,16 +488,7 @@ void MappingTraits<COFFYAML::Section>::mapping(IO &IO, COFFYAML::Section &Sec) {
IO.mapOptional("VirtualAddress", Sec.Header.VirtualAddress, 0U);
IO.mapOptional("VirtualSize", Sec.Header.VirtualSize, 0U);
IO.mapOptional("Alignment", Sec.Alignment, 0U);
-
- // If this is a .debug$S or .debug$T section parse the semantic representation
- // of the symbols/types. If it is any other kind of section, just deal in raw
- // bytes.
- IO.mapOptional("SectionData", Sec.SectionData);
- if (Sec.Name == ".debug$S")
- IO.mapOptional("Subsections", Sec.DebugS);
- else if (Sec.Name == ".debug$T")
- IO.mapOptional("Types", Sec.DebugT);
-
+ IO.mapRequired("SectionData", Sec.SectionData);
IO.mapOptional("Relocations", Sec.Relocations);
}
diff --git a/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp b/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp
index 728079a2a6b..08a4bb715fa 100644
--- a/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp
+++ b/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp
@@ -28,7 +28,6 @@
#include "llvm/DebugInfo/CodeView/DebugSymbolRVASubsection.h"
#include "llvm/DebugInfo/CodeView/DebugSymbolsSubsection.h"
#include "llvm/DebugInfo/CodeView/EnumTables.h"
-#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
#include "llvm/DebugInfo/CodeView/SymbolSerializer.h"
#include "llvm/ObjectYAML/CodeViewYAMLSymbols.h"
@@ -76,9 +75,10 @@ struct YAMLSubsectionBase {
virtual ~YAMLSubsectionBase() {}
virtual void map(IO &IO) = 0;
- virtual std::shared_ptr<DebugSubsection>
+ virtual std::unique_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const = 0;
+ DebugStringTableSubsection *UseStrings,
+ DebugChecksumsSubsection *UseChecksums) const = 0;
};
}
}
@@ -90,9 +90,10 @@ struct YAMLChecksumsSubsection : public YAMLSubsectionBase {
: YAMLSubsectionBase(DebugSubsectionKind::FileChecksums) {}
void map(IO &IO) override;
- std::shared_ptr<DebugSubsection>
+ std::unique_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const override;
+ DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const override;
static Expected<std::shared_ptr<YAMLChecksumsSubsection>>
fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
const DebugChecksumsSubsectionRef &FC);
@@ -104,9 +105,10 @@ struct YAMLLinesSubsection : public YAMLSubsectionBase {
YAMLLinesSubsection() : YAMLSubsectionBase(DebugSubsectionKind::Lines) {}
void map(IO &IO) override;
- std::shared_ptr<DebugSubsection>
+ std::unique_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const override;
+ DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const override;
static Expected<std::shared_ptr<YAMLLinesSubsection>>
fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
const DebugChecksumsSubsectionRef &Checksums,
@@ -120,9 +122,10 @@ struct YAMLInlineeLinesSubsection : public YAMLSubsectionBase {
: YAMLSubsectionBase(DebugSubsectionKind::InlineeLines) {}
void map(IO &IO) override;
- std::shared_ptr<DebugSubsection>
+ std::unique_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const override;
+ DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const override;
static Expected<std::shared_ptr<YAMLInlineeLinesSubsection>>
fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
const DebugChecksumsSubsectionRef &Checksums,
@@ -136,9 +139,10 @@ struct YAMLCrossModuleExportsSubsection : public YAMLSubsectionBase {
: YAMLSubsectionBase(DebugSubsectionKind::CrossScopeExports) {}
void map(IO &IO) override;
- std::shared_ptr<DebugSubsection>
+ std::unique_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const override;
+ DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const override;
static Expected<std::shared_ptr<YAMLCrossModuleExportsSubsection>>
fromCodeViewSubsection(const DebugCrossModuleExportsSubsectionRef &Exports);
@@ -150,9 +154,10 @@ struct YAMLCrossModuleImportsSubsection : public YAMLSubsectionBase {
: YAMLSubsectionBase(DebugSubsectionKind::CrossScopeImports) {}
void map(IO &IO) override;
- std::shared_ptr<DebugSubsection>
+ std::unique_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const override;
+ DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const override;
static Expected<std::shared_ptr<YAMLCrossModuleImportsSubsection>>
fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
const DebugCrossModuleImportsSubsectionRef &Imports);
@@ -164,9 +169,10 @@ struct YAMLSymbolsSubsection : public YAMLSubsectionBase {
YAMLSymbolsSubsection() : YAMLSubsectionBase(DebugSubsectionKind::Symbols) {}
void map(IO &IO) override;
- std::shared_ptr<DebugSubsection>
+ std::unique_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const override;
+ DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const override;
static Expected<std::shared_ptr<YAMLSymbolsSubsection>>
fromCodeViewSubsection(const DebugSymbolsSubsectionRef &Symbols);
@@ -178,9 +184,10 @@ struct YAMLStringTableSubsection : public YAMLSubsectionBase {
: YAMLSubsectionBase(DebugSubsectionKind::StringTable) {}
void map(IO &IO) override;
- std::shared_ptr<DebugSubsection>
+ std::unique_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const override;
+ DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const override;
static Expected<std::shared_ptr<YAMLStringTableSubsection>>
fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings);
@@ -192,9 +199,10 @@ struct YAMLFrameDataSubsection : public YAMLSubsectionBase {
: YAMLSubsectionBase(DebugSubsectionKind::FrameData) {}
void map(IO &IO) override;
- std::shared_ptr<DebugSubsection>
+ std::unique_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const override;
+ DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const override;
static Expected<std::shared_ptr<YAMLFrameDataSubsection>>
fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
const DebugFrameDataSubsectionRef &Frames);
@@ -207,9 +215,10 @@ struct YAMLCoffSymbolRVASubsection : public YAMLSubsectionBase {
: YAMLSubsectionBase(DebugSubsectionKind::CoffSymbolRVA) {}
void map(IO &IO) override;
- std::shared_ptr<DebugSubsection>
+ std::unique_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const override;
+ DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const override;
static Expected<std::shared_ptr<YAMLCoffSymbolRVASubsection>>
fromCodeViewSubsection(const DebugSymbolRVASubsectionRef &RVAs);
@@ -391,23 +400,23 @@ findChecksums(ArrayRef<YAMLDebugSubsection> Subsections) {
return nullptr;
}
-std::shared_ptr<DebugSubsection> YAMLChecksumsSubsection::toCodeViewSubsection(
- BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const {
- assert(SC.hasStrings());
- auto Result = std::make_shared<DebugChecksumsSubsection>(*SC.strings());
+std::unique_ptr<DebugSubsection> YAMLChecksumsSubsection::toCodeViewSubsection(
+ BumpPtrAllocator &Allocator, DebugStringTableSubsection *UseStrings,
+ DebugChecksumsSubsection *UseChecksums) const {
+ assert(UseStrings && !UseChecksums);
+ auto Result = llvm::make_unique<DebugChecksumsSubsection>(*UseStrings);
for (const auto &CS : Checksums) {
Result->addChecksum(CS.FileName, CS.Kind, CS.ChecksumBytes.Bytes);
}
- return Result;
+ return std::move(Result);
}
-std::shared_ptr<DebugSubsection> YAMLLinesSubsection::toCodeViewSubsection(
- BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const {
- assert(SC.hasStrings() && SC.hasChecksums());
+std::unique_ptr<DebugSubsection> YAMLLinesSubsection::toCodeViewSubsection(
+ BumpPtrAllocator &Allocator, DebugStringTableSubsection *UseStrings,
+ DebugChecksumsSubsection *UseChecksums) const {
+ assert(UseStrings && UseChecksums);
auto Result =
- std::make_shared<DebugLinesSubsection>(*SC.checksums(), *SC.strings());
+ llvm::make_unique<DebugLinesSubsection>(*UseChecksums, *UseStrings);
Result->setCodeSize(Lines.CodeSize);
Result->setRelocationAddress(Lines.RelocSegment, Lines.RelocOffset);
Result->setFlags(Lines.Flags);
@@ -429,16 +438,16 @@ std::shared_ptr<DebugSubsection> YAMLLinesSubsection::toCodeViewSubsection(
}
}
}
- return Result;
+ return llvm::cast<DebugSubsection>(std::move(Result));
}
-std::shared_ptr<DebugSubsection>
+std::unique_ptr<DebugSubsection>
YAMLInlineeLinesSubsection::toCodeViewSubsection(
- BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const {
- assert(SC.hasChecksums());
- auto Result = std::make_shared<DebugInlineeLinesSubsection>(
- *SC.checksums(), InlineeLines.HasExtraFiles);
+ BumpPtrAllocator &Allocator, DebugStringTableSubsection *UseStrings,
+ DebugChecksumsSubsection *UseChecksums) const {
+ assert(UseChecksums);
+ auto Result = llvm::make_unique<DebugInlineeLinesSubsection>(
+ *UseChecksums, InlineeLines.HasExtraFiles);
for (const auto &Site : InlineeLines.Sites) {
Result->addInlineSite(TypeIndex(Site.Inlinee), Site.FileName,
@@ -450,60 +459,56 @@ YAMLInlineeLinesSubsection::toCodeViewSubsection(
Result->addExtraFile(EF);
}
}
- return Result;
+ return llvm::cast<DebugSubsection>(std::move(Result));
}
-std::shared_ptr<DebugSubsection>
+std::unique_ptr<DebugSubsection>
YAMLCrossModuleExportsSubsection::toCodeViewSubsection(
- BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const {
- auto Result = std::make_shared<DebugCrossModuleExportsSubsection>();
+ BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const {
+ auto Result = llvm::make_unique<DebugCrossModuleExportsSubsection>();
for (const auto &M : Exports)
Result->addMapping(M.Local, M.Global);
- return Result;
+ return llvm::cast<DebugSubsection>(std::move(Result));
}
-std::shared_ptr<DebugSubsection>
+std::unique_ptr<DebugSubsection>
YAMLCrossModuleImportsSubsection::toCodeViewSubsection(
- BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const {
- assert(SC.hasStrings());
-
- auto Result =
- std::make_shared<DebugCrossModuleImportsSubsection>(*SC.strings());
+ BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const {
+ auto Result = llvm::make_unique<DebugCrossModuleImportsSubsection>(*Strings);
for (const auto &M : Imports) {
for (const auto Id : M.ImportIds)
Result->addImport(M.ModuleName, Id);
}
- return Result;
+ return llvm::cast<DebugSubsection>(std::move(Result));
}
-std::shared_ptr<DebugSubsection> YAMLSymbolsSubsection::toCodeViewSubsection(
- BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const {
- auto Result = std::make_shared<DebugSymbolsSubsection>();
+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 Result;
+ return std::move(Result);
}
-std::shared_ptr<DebugSubsection>
+std::unique_ptr<DebugSubsection>
YAMLStringTableSubsection::toCodeViewSubsection(
- BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const {
- auto Result = std::make_shared<DebugStringTableSubsection>();
+ BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const {
+ auto Result = llvm::make_unique<DebugStringTableSubsection>();
for (const auto &Str : this->Strings)
Result->insert(Str);
- return Result;
+ return std::move(Result);
}
-std::shared_ptr<DebugSubsection> YAMLFrameDataSubsection::toCodeViewSubsection(
- BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const {
- assert(SC.hasStrings());
-
- auto Result = std::make_shared<DebugFrameDataSubsection>();
+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;
@@ -514,20 +519,20 @@ std::shared_ptr<DebugSubsection> YAMLFrameDataSubsection::toCodeViewSubsection(
F.PrologSize = YF.PrologSize;
F.RvaStart = YF.RvaStart;
F.SavedRegsSize = YF.SavedRegsSize;
- F.FrameFunc = SC.strings()->insert(YF.FrameFunc);
+ F.FrameFunc = Strings->insert(YF.FrameFunc);
Result->addFrameData(F);
}
- return Result;
+ return std::move(Result);
}
-std::shared_ptr<DebugSubsection>
+std::unique_ptr<DebugSubsection>
YAMLCoffSymbolRVASubsection::toCodeViewSubsection(
- BumpPtrAllocator &Allocator,
- const codeview::StringsAndChecksums &SC) const {
- auto Result = std::make_shared<DebugSymbolRVASubsection>();
+ BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
+ DebugChecksumsSubsection *Checksums) const {
+ auto Result = llvm::make_unique<DebugSymbolRVASubsection>();
for (const auto &RVA : RVAs)
Result->addRVA(RVA);
- return Result;
+ return std::move(Result);
}
static Expected<SourceFileChecksumEntry>
@@ -736,17 +741,63 @@ YAMLCoffSymbolRVASubsection::fromCodeViewSubsection(
return Result;
}
-Expected<std::vector<std::shared_ptr<DebugSubsection>>>
+Expected<std::vector<std::unique_ptr<DebugSubsection>>>
+llvm::CodeViewYAML::toCodeViewSubsectionList(
+ BumpPtrAllocator &Allocator, ArrayRef<YAMLDebugSubsection> Subsections,
+ DebugStringTableSubsection &Strings) {
+ 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, &Strings, nullptr);
+ DebugChecksumsSubsection *CS =
+ static_cast<DebugChecksumsSubsection *>(ChecksumsBase.get());
+ for (const auto &SS : Subsections) {
+ // We've already converted the checksums subsection, don't do it
+ // twice.
+ std::unique_ptr<DebugSubsection> CVS;
+ if (SS.Subsection->Kind == DebugSubsectionKind::FileChecksums)
+ CVS = std::move(ChecksumsBase);
+ else
+ 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,
- const codeview::StringsAndChecksums &SC) {
- std::vector<std::shared_ptr<DebugSubsection>> Result;
+ 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) {
- std::shared_ptr<DebugSubsection> CVS;
- CVS = SS.Subsection->toCodeViewSubsection(Allocator, SC);
+ // 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));
}
@@ -759,23 +810,23 @@ struct SubsectionConversionVisitor : public DebugSubsectionVisitor {
Error visitUnknown(DebugUnknownSubsectionRef &Unknown) override;
Error visitLines(DebugLinesSubsectionRef &Lines,
- const StringsAndChecksumsRef &State) override;
+ const DebugSubsectionState &State) override;
Error visitFileChecksums(DebugChecksumsSubsectionRef &Checksums,
- const StringsAndChecksumsRef &State) override;
+ const DebugSubsectionState &State) override;
Error visitInlineeLines(DebugInlineeLinesSubsectionRef &Inlinees,
- const StringsAndChecksumsRef &State) override;
+ const DebugSubsectionState &State) override;
Error visitCrossModuleExports(DebugCrossModuleExportsSubsectionRef &Checksums,
- const StringsAndChecksumsRef &State) override;
+ const DebugSubsectionState &State) override;
Error visitCrossModuleImports(DebugCrossModuleImportsSubsectionRef &Inlinees,
- const StringsAndChecksumsRef &State) override;
+ const DebugSubsectionState &State) override;
Error visitStringTable(DebugStringTableSubsectionRef &ST,
- const StringsAndChecksumsRef &State) override;
+ const DebugSubsectionState &State) override;
Error visitSymbols(DebugSymbolsSubsectionRef &Symbols,
- const StringsAndChecksumsRef &State) override;
+ const DebugSubsectionState &State) override;
Error visitFrameData(DebugFrameDataSubsectionRef &Symbols,
- const StringsAndChecksumsRef &State) override;
+ const DebugSubsectionState &State) override;
Error visitCOFFSymbolRVAs(DebugSymbolRVASubsectionRef &Symbols,
- const StringsAndChecksumsRef &State) override;
+ const DebugSubsectionState &State) override;
YAMLDebugSubsection Subsection;
};
@@ -786,7 +837,7 @@ Error SubsectionConversionVisitor::visitUnknown(
}
Error SubsectionConversionVisitor::visitLines(
- DebugLinesSubsectionRef &Lines, const StringsAndChecksumsRef &State) {
+ DebugLinesSubsectionRef &Lines, const DebugSubsectionState &State) {
auto Result = YAMLLinesSubsection::fromCodeViewSubsection(
State.strings(), State.checksums(), Lines);
if (!Result)
@@ -796,8 +847,7 @@ Error SubsectionConversionVisitor::visitLines(
}
Error SubsectionConversionVisitor::visitFileChecksums(
- DebugChecksumsSubsectionRef &Checksums,
- const StringsAndChecksumsRef &State) {
+ DebugChecksumsSubsectionRef &Checksums, const DebugSubsectionState &State) {
auto Result = YAMLChecksumsSubsection::fromCodeViewSubsection(State.strings(),
Checksums);
if (!Result)
@@ -808,7 +858,7 @@ Error SubsectionConversionVisitor::visitFileChecksums(
Error SubsectionConversionVisitor::visitInlineeLines(
DebugInlineeLinesSubsectionRef &Inlinees,
- const StringsAndChecksumsRef &State) {
+ const DebugSubsectionState &State) {
auto Result = YAMLInlineeLinesSubsection::fromCodeViewSubsection(
State.strings(), State.checksums(), Inlinees);
if (!Result)
@@ -819,7 +869,7 @@ Error SubsectionConversionVisitor::visitInlineeLines(
Error SubsectionConversionVisitor::visitCrossModuleExports(
DebugCrossModuleExportsSubsectionRef &Exports,
- const StringsAndChecksumsRef &State) {
+ const DebugSubsectionState &State) {
auto Result =
YAMLCrossModuleExportsSubsection::fromCodeViewSubsection(Exports);
if (!Result)
@@ -830,7 +880,7 @@ Error SubsectionConversionVisitor::visitCrossModuleExports(
Error SubsectionConversionVisitor::visitCrossModuleImports(
DebugCrossModuleImportsSubsectionRef &Imports,
- const StringsAndChecksumsRef &State) {
+ const DebugSubsectionState &State) {
auto Result = YAMLCrossModuleImportsSubsection::fromCodeViewSubsection(
State.strings(), Imports);
if (!Result)
@@ -840,8 +890,7 @@ Error SubsectionConversionVisitor::visitCrossModuleImports(
}
Error SubsectionConversionVisitor::visitStringTable(
- DebugStringTableSubsectionRef &Strings,
- const StringsAndChecksumsRef &State) {
+ DebugStringTableSubsectionRef &Strings, const DebugSubsectionState &State) {
auto Result = YAMLStringTableSubsection::fromCodeViewSubsection(Strings);
if (!Result)
return Result.takeError();
@@ -850,7 +899,7 @@ Error SubsectionConversionVisitor::visitStringTable(
}
Error SubsectionConversionVisitor::visitSymbols(
- DebugSymbolsSubsectionRef &Symbols, const StringsAndChecksumsRef &State) {
+ DebugSymbolsSubsectionRef &Symbols, const DebugSubsectionState &State) {
auto Result = YAMLSymbolsSubsection::fromCodeViewSubsection(Symbols);
if (!Result)
return Result.takeError();
@@ -859,7 +908,7 @@ Error SubsectionConversionVisitor::visitSymbols(
}
Error SubsectionConversionVisitor::visitFrameData(
- DebugFrameDataSubsectionRef &Frames, const StringsAndChecksumsRef &State) {
+ DebugFrameDataSubsectionRef &Frames, const DebugSubsectionState &State) {
auto Result =
YAMLFrameDataSubsection::fromCodeViewSubsection(State.strings(), Frames);
if (!Result)
@@ -869,7 +918,7 @@ Error SubsectionConversionVisitor::visitFrameData(
}
Error SubsectionConversionVisitor::visitCOFFSymbolRVAs(
- DebugSymbolRVASubsectionRef &RVAs, const StringsAndChecksumsRef &State) {
+ DebugSymbolRVASubsectionRef &RVAs, const DebugSubsectionState &State) {
auto Result = YAMLCoffSymbolRVASubsection::fromCodeViewSubsection(RVAs);
if (!Result)
return Result.takeError();
@@ -878,71 +927,29 @@ Error SubsectionConversionVisitor::visitCOFFSymbolRVAs(
}
}
-Expected<YAMLDebugSubsection>
-YAMLDebugSubsection::fromCodeViewSubection(const StringsAndChecksumsRef &SC,
- const DebugSubsectionRecord &SS) {
+Expected<YAMLDebugSubsection> YAMLDebugSubsection::fromCodeViewSubection(
+ const DebugStringTableSubsectionRef &Strings,
+ const DebugChecksumsSubsectionRef &Checksums,
+ const DebugSubsectionRecord &SS) {
+ DebugSubsectionState State(Strings, Checksums);
SubsectionConversionVisitor V;
- if (auto EC = visitDebugSubsection(SS, V, SC))
+ if (auto EC = visitDebugSubsection(SS, V, State))
return std::move(EC);
return V.Subsection;
}
-std::vector<YAMLDebugSubsection>
-llvm::CodeViewYAML::fromDebugS(ArrayRef<uint8_t> Data,
- const StringsAndChecksumsRef &SC) {
- BinaryStreamReader Reader(Data, support::little);
- uint32_t Magic;
-
- ExitOnError Err("Invalid .debug$S section!");
- Err(Reader.readInteger(Magic));
- assert(Magic == COFF::DEBUG_SECTION_MAGIC && "Invalid .debug$S section!");
-
- DebugSubsectionArray Subsections;
- Err(Reader.readArray(Subsections, Reader.bytesRemaining()));
-
- std::vector<YAMLDebugSubsection> Result;
-
- for (const auto &SS : Subsections) {
- auto YamlSS = Err(YAMLDebugSubsection::fromCodeViewSubection(SC, SS));
- Result.push_back(YamlSS);
- }
- return Result;
-}
-
-void llvm::CodeViewYAML::initializeStringsAndChecksums(
- ArrayRef<YAMLDebugSubsection> Sections, codeview::StringsAndChecksums &SC) {
- // String Table and Checksums subsections don't use the allocator.
- BumpPtrAllocator Allocator;
-
- // It's possible for checksums and strings to even appear in different debug$S
- // sections, so we have to make this a stateful function that can build up
- // the strings and checksums field over multiple iterations.
-
- // File Checksums require the string table, but may become before it, so we
- // have to scan for strings first, then scan for checksums again from the
- // beginning.
- if (!SC.hasStrings()) {
- for (const auto &SS : Sections) {
- if (SS.Subsection->Kind != DebugSubsectionKind::StringTable)
- continue;
-
- auto Result = SS.Subsection->toCodeViewSubsection(Allocator, SC);
- SC.setStrings(
- std::static_pointer_cast<DebugStringTableSubsection>(Result));
- break;
- }
- }
-
- if (SC.hasStrings() && !SC.hasChecksums()) {
- for (const auto &SS : Sections) {
- if (SS.Subsection->Kind != DebugSubsectionKind::FileChecksums)
- continue;
+std::unique_ptr<DebugStringTableSubsection>
+llvm::CodeViewYAML::findStringTable(ArrayRef<YAMLDebugSubsection> Sections) {
+ for (const auto &SS : Sections) {
+ if (SS.Subsection->Kind != DebugSubsectionKind::StringTable)
+ continue;
- auto Result = SS.Subsection->toCodeViewSubsection(Allocator, SC);
- SC.setChecksums(
- std::static_pointer_cast<DebugChecksumsSubsection>(Result));
- break;
- }
+ // 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 a03b9cd50fa..1302b0713d0 100644
--- a/lib/ObjectYAML/CodeViewYAMLTypes.cpp
+++ b/lib/ObjectYAML/CodeViewYAMLTypes.cpp
@@ -714,43 +714,3 @@ void MappingTraits<MemberRecord>::mapping(IO &IO, MemberRecord &Obj) {
default: { llvm_unreachable("Unknown member kind!"); }
}
}
-
-std::vector<LeafRecord>
-llvm::CodeViewYAML::fromDebugT(ArrayRef<uint8_t> DebugT) {
- ExitOnError Err("Invalid .debug$T section!");
- BinaryStreamReader Reader(DebugT, support::little);
- CVTypeArray Types;
- uint32_t Magic;
-
- Err(Reader.readInteger(Magic));
- assert(Magic == COFF::DEBUG_SECTION_MAGIC && "Invalid .debug$T section!");
-
- std::vector<LeafRecord> Result;
- Err(Reader.readArray(Types, Reader.bytesRemaining()));
- for (const auto &T : Types) {
- auto CVT = Err(LeafRecord::fromCodeViewRecord(T));
- Result.push_back(CVT);
- }
- return Result;
-}
-
-ArrayRef<uint8_t> llvm::CodeViewYAML::toDebugT(ArrayRef<LeafRecord> Leafs,
- BumpPtrAllocator &Alloc) {
- TypeTableBuilder TTB(Alloc, false);
- uint32_t Size = sizeof(uint32_t);
- for (const auto &Leaf : Leafs) {
- CVType T = Leaf.toCodeViewRecord(TTB);
- Size += T.length();
- assert(T.length() % 4 == 0 && "Improper type record alignment!");
- }
- uint8_t *ResultBuffer = Alloc.Allocate<uint8_t>(Size);
- MutableArrayRef<uint8_t> Output(ResultBuffer, Size);
- BinaryStreamWriter Writer(Output, support::little);
- ExitOnError Err("Error writing type record to .debug$T section");
- Err(Writer.writeInteger<uint32_t>(COFF::DEBUG_SECTION_MAGIC));
- for (const auto &R : TTB.records()) {
- Err(Writer.writeBytes(R));
- }
- assert(Writer.bytesRemaining() == 0 && "Didn't write all type record bytes!");
- return Output;
-}