summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-06-14 05:31:00 +0000
committerZachary Turner <zturner@google.com>2017-06-14 05:31:00 +0000
commita3da4467fa8ed514130736c6c15f01422159d00d (patch)
tree12356bbf4e58c9d059fb2899b240256e75d75a81 /llvm/lib
parentf4ea23d3a58ee23d13b719e525e0575a29e510da (diff)
downloadbcm5719-llvm-a3da4467fa8ed514130736c6c15f01422159d00d.tar.gz
bcm5719-llvm-a3da4467fa8ed514130736c6c15f01422159d00d.zip
[codeview] Make obj2yaml/yaml2obj support .debug$S/T sections.
This allows us to use yaml2obj and obj2yaml to round-trip CodeView symbol and type information without having to manually specify the bytes of the section. This makes for much easier to maintain tests. See the tests under lld/COFF in this patch for example. Before they just said SectionData: <blob> whereas now we can use meaningful record descriptions. Note that it still supports the SectionData yaml field, which could be useful for initializing a section to invalid bytes for testing, for example. Differential Revision: https://reviews.llvm.org/D34127 llvm-svn: 305366
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/DebugInfo/CodeView/CMakeLists.txt3
-rw-r--r--llvm/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp5
-rw-r--r--llvm/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp2
-rw-r--r--llvm/lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp37
-rw-r--r--llvm/lib/DebugInfo/CodeView/StringsAndChecksums.cpp48
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp2
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp5
-rw-r--r--llvm/lib/ObjectYAML/COFFYAML.cpp11
-rw-r--r--llvm/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp313
-rw-r--r--llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp40
10 files changed, 268 insertions, 198 deletions
diff --git a/llvm/lib/DebugInfo/CodeView/CMakeLists.txt b/llvm/lib/DebugInfo/CodeView/CMakeLists.txt
index 2f9e8981b69..f916695a843 100644
--- a/llvm/lib/DebugInfo/CodeView/CMakeLists.txt
+++ b/llvm/lib/DebugInfo/CodeView/CMakeLists.txt
@@ -20,6 +20,7 @@ add_llvm_library(LLVMDebugInfoCodeView
LazyRandomTypeCollection.cpp
Line.cpp
RecordSerialization.cpp
+ StringsAndChecksums.cpp
SymbolRecordMapping.cpp
SymbolDumper.cpp
SymbolSerializer.cpp
@@ -32,7 +33,7 @@ add_llvm_library(LLVMDebugInfoCodeView
TypeSerializer.cpp
TypeStreamMerger.cpp
TypeTableCollection.cpp
-
+
ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/DebugInfo/CodeView
)
diff --git a/llvm/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp b/llvm/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp
index 6e647c4b976..de02525270c 100644
--- a/llvm/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp
+++ b/llvm/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp
@@ -58,6 +58,10 @@ Error DebugStringTableSubsection::commit(BinaryStreamWriter &Writer) const {
uint32_t Begin = Writer.getOffset();
uint32_t End = Begin + StringSize;
+ // Write a null string at the beginning.
+ if (auto EC = Writer.writeCString(StringRef()))
+ return EC;
+
for (auto &Pair : Strings) {
StringRef S = Pair.getKey();
uint32_t Offset = Begin + Pair.getValue();
@@ -68,6 +72,7 @@ Error DebugStringTableSubsection::commit(BinaryStreamWriter &Writer) const {
}
Writer.setOffset(End);
+ assert((End - Begin) == StringSize);
return Error::success();
}
diff --git a/llvm/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp b/llvm/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp
index e9124e68fe8..334c5e002bb 100644
--- a/llvm/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp
+++ b/llvm/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp
@@ -50,7 +50,7 @@ DebugSubsectionKind DebugSubsectionRecord::kind() const { return Kind; }
BinaryStreamRef DebugSubsectionRecord::getRecordData() const { return Data; }
DebugSubsectionRecordBuilder::DebugSubsectionRecordBuilder(
- std::unique_ptr<DebugSubsection> Subsection, CodeViewContainer Container)
+ std::shared_ptr<DebugSubsection> Subsection, CodeViewContainer Container)
: Subsection(std::move(Subsection)), Container(Container) {}
uint32_t DebugSubsectionRecordBuilder::calculateSerializedLength() {
diff --git a/llvm/lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp b/llvm/lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp
index 8550107741c..9b824333369 100644
--- a/llvm/lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp
+++ b/llvm/lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp
@@ -26,40 +26,9 @@
using namespace llvm;
using namespace llvm::codeview;
-DebugSubsectionState::DebugSubsectionState() {}
-
-DebugSubsectionState::DebugSubsectionState(
- const DebugStringTableSubsectionRef &Strings)
- : Strings(&Strings) {}
-
-DebugSubsectionState::DebugSubsectionState(
- const DebugStringTableSubsectionRef &Strings,
- const DebugChecksumsSubsectionRef &Checksums)
- : Strings(&Strings), Checksums(&Checksums) {}
-
-void DebugSubsectionState::initializeStrings(const DebugSubsectionRecord &SR) {
- assert(SR.kind() == DebugSubsectionKind::StringTable);
- assert(!Strings && "Found a string table even though we already have one!");
-
- OwnedStrings = llvm::make_unique<DebugStringTableSubsectionRef>();
- consumeError(OwnedStrings->initialize(SR.getRecordData()));
- Strings = OwnedStrings.get();
-}
-
-void DebugSubsectionState::initializeChecksums(
- const DebugSubsectionRecord &FCR) {
- assert(FCR.kind() == DebugSubsectionKind::FileChecksums);
- if (Checksums)
- return;
-
- OwnedChecksums = llvm::make_unique<DebugChecksumsSubsectionRef>();
- consumeError(OwnedChecksums->initialize(FCR.getRecordData()));
- Checksums = OwnedChecksums.get();
-}
-
-Error llvm::codeview::visitDebugSubsection(const DebugSubsectionRecord &R,
- DebugSubsectionVisitor &V,
- const DebugSubsectionState &State) {
+Error llvm::codeview::visitDebugSubsection(
+ const DebugSubsectionRecord &R, DebugSubsectionVisitor &V,
+ const StringsAndChecksumsRef &State) {
BinaryStreamReader Reader(R.getRecordData());
switch (R.kind()) {
case DebugSubsectionKind::Lines: {
diff --git a/llvm/lib/DebugInfo/CodeView/StringsAndChecksums.cpp b/llvm/lib/DebugInfo/CodeView/StringsAndChecksums.cpp
new file mode 100644
index 00000000000..ccd9aba45ea
--- /dev/null
+++ b/llvm/lib/DebugInfo/CodeView/StringsAndChecksums.cpp
@@ -0,0 +1,48 @@
+//===- StringsAndChecksums.cpp ----------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
+#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
+#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
+#include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
+
+using namespace llvm;
+using namespace llvm::codeview;
+
+StringsAndChecksumsRef::StringsAndChecksumsRef() {}
+
+StringsAndChecksumsRef::StringsAndChecksumsRef(
+ const DebugStringTableSubsectionRef &Strings)
+ : Strings(&Strings) {}
+
+StringsAndChecksumsRef::StringsAndChecksumsRef(
+ const DebugStringTableSubsectionRef &Strings,
+ const DebugChecksumsSubsectionRef &Checksums)
+ : Strings(&Strings), Checksums(&Checksums) {}
+
+void StringsAndChecksumsRef::initializeStrings(
+ const DebugSubsectionRecord &SR) {
+ assert(SR.kind() == DebugSubsectionKind::StringTable);
+ assert(!Strings && "Found a string table even though we already have one!");
+
+ OwnedStrings = llvm::make_unique<DebugStringTableSubsectionRef>();
+ consumeError(OwnedStrings->initialize(SR.getRecordData()));
+ Strings = OwnedStrings.get();
+}
+
+void StringsAndChecksumsRef::initializeChecksums(
+ const DebugSubsectionRecord &FCR) {
+ assert(FCR.kind() == DebugSubsectionKind::FileChecksums);
+ if (Checksums)
+ return;
+
+ OwnedChecksums = llvm::make_unique<DebugChecksumsSubsectionRef>();
+ consumeError(OwnedChecksums->initialize(FCR.getRecordData()));
+ Checksums = OwnedChecksums.get();
+}
diff --git a/llvm/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp
index 396dffaa68b..81a9d3eeec6 100644
--- a/llvm/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp
@@ -177,7 +177,7 @@ Error DbiModuleDescriptorBuilder::commit(BinaryStreamWriter &ModiWriter,
}
void DbiModuleDescriptorBuilder::addDebugSubsection(
- std::unique_ptr<DebugSubsection> Subsection) {
+ std::shared_ptr<DebugSubsection> Subsection) {
assert(Subsection);
C13Builders.push_back(llvm::make_unique<DebugSubsectionRecordBuilder>(
std::move(Subsection), CodeViewContainer::Pdb));
diff --git a/llvm/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp
index a472181a489..90acfadd311 100644
--- a/llvm/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp
@@ -52,6 +52,11 @@ uint32_t PDBStringTableBuilder::calculateSerializedSize() const {
return Size;
}
+void PDBStringTableBuilder::setStrings(
+ const codeview::DebugStringTableSubsection &Strings) {
+ this->Strings = Strings;
+}
+
Error PDBStringTableBuilder::writeHeader(BinaryStreamWriter &Writer) const {
// Write a header
PDBStringTableHeader H;
diff --git a/llvm/lib/ObjectYAML/COFFYAML.cpp b/llvm/lib/ObjectYAML/COFFYAML.cpp
index 7f9f4c1f8c2..c8cbea1490f 100644
--- a/llvm/lib/ObjectYAML/COFFYAML.cpp
+++ b/llvm/lib/ObjectYAML/COFFYAML.cpp
@@ -488,7 +488,16 @@ 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);
- IO.mapRequired("SectionData", Sec.SectionData);
+
+ // 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.mapOptional("Relocations", Sec.Relocations);
}
diff --git a/llvm/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp b/llvm/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp
index 08a4bb715fa..aa5f3cca10f 100644
--- a/llvm/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp
+++ b/llvm/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp
@@ -28,6 +28,7 @@
#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"
@@ -75,10 +76,9 @@ struct YAMLSubsectionBase {
virtual ~YAMLSubsectionBase() {}
virtual void map(IO &IO) = 0;
- virtual std::unique_ptr<DebugSubsection>
+ virtual std::shared_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- DebugStringTableSubsection *UseStrings,
- DebugChecksumsSubsection *UseChecksums) const = 0;
+ const codeview::StringsAndChecksums &SC) const = 0;
};
}
}
@@ -90,10 +90,9 @@ struct YAMLChecksumsSubsection : public YAMLSubsectionBase {
: YAMLSubsectionBase(DebugSubsectionKind::FileChecksums) {}
void map(IO &IO) override;
- std::unique_ptr<DebugSubsection>
+ std::shared_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- DebugStringTableSubsection *Strings,
- DebugChecksumsSubsection *Checksums) const override;
+ const codeview::StringsAndChecksums &SC) const override;
static Expected<std::shared_ptr<YAMLChecksumsSubsection>>
fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
const DebugChecksumsSubsectionRef &FC);
@@ -105,10 +104,9 @@ struct YAMLLinesSubsection : public YAMLSubsectionBase {
YAMLLinesSubsection() : YAMLSubsectionBase(DebugSubsectionKind::Lines) {}
void map(IO &IO) override;
- std::unique_ptr<DebugSubsection>
+ std::shared_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- DebugStringTableSubsection *Strings,
- DebugChecksumsSubsection *Checksums) const override;
+ const codeview::StringsAndChecksums &SC) const override;
static Expected<std::shared_ptr<YAMLLinesSubsection>>
fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
const DebugChecksumsSubsectionRef &Checksums,
@@ -122,10 +120,9 @@ struct YAMLInlineeLinesSubsection : public YAMLSubsectionBase {
: YAMLSubsectionBase(DebugSubsectionKind::InlineeLines) {}
void map(IO &IO) override;
- std::unique_ptr<DebugSubsection>
+ std::shared_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- DebugStringTableSubsection *Strings,
- DebugChecksumsSubsection *Checksums) const override;
+ const codeview::StringsAndChecksums &SC) const override;
static Expected<std::shared_ptr<YAMLInlineeLinesSubsection>>
fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
const DebugChecksumsSubsectionRef &Checksums,
@@ -139,10 +136,9 @@ struct YAMLCrossModuleExportsSubsection : public YAMLSubsectionBase {
: YAMLSubsectionBase(DebugSubsectionKind::CrossScopeExports) {}
void map(IO &IO) override;
- std::unique_ptr<DebugSubsection>
+ std::shared_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- DebugStringTableSubsection *Strings,
- DebugChecksumsSubsection *Checksums) const override;
+ const codeview::StringsAndChecksums &SC) const override;
static Expected<std::shared_ptr<YAMLCrossModuleExportsSubsection>>
fromCodeViewSubsection(const DebugCrossModuleExportsSubsectionRef &Exports);
@@ -154,10 +150,9 @@ struct YAMLCrossModuleImportsSubsection : public YAMLSubsectionBase {
: YAMLSubsectionBase(DebugSubsectionKind::CrossScopeImports) {}
void map(IO &IO) override;
- std::unique_ptr<DebugSubsection>
+ std::shared_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- DebugStringTableSubsection *Strings,
- DebugChecksumsSubsection *Checksums) const override;
+ const codeview::StringsAndChecksums &SC) const override;
static Expected<std::shared_ptr<YAMLCrossModuleImportsSubsection>>
fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
const DebugCrossModuleImportsSubsectionRef &Imports);
@@ -169,10 +164,9 @@ struct YAMLSymbolsSubsection : public YAMLSubsectionBase {
YAMLSymbolsSubsection() : YAMLSubsectionBase(DebugSubsectionKind::Symbols) {}
void map(IO &IO) override;
- std::unique_ptr<DebugSubsection>
+ std::shared_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- DebugStringTableSubsection *Strings,
- DebugChecksumsSubsection *Checksums) const override;
+ const codeview::StringsAndChecksums &SC) const override;
static Expected<std::shared_ptr<YAMLSymbolsSubsection>>
fromCodeViewSubsection(const DebugSymbolsSubsectionRef &Symbols);
@@ -184,10 +178,9 @@ struct YAMLStringTableSubsection : public YAMLSubsectionBase {
: YAMLSubsectionBase(DebugSubsectionKind::StringTable) {}
void map(IO &IO) override;
- std::unique_ptr<DebugSubsection>
+ std::shared_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- DebugStringTableSubsection *Strings,
- DebugChecksumsSubsection *Checksums) const override;
+ const codeview::StringsAndChecksums &SC) const override;
static Expected<std::shared_ptr<YAMLStringTableSubsection>>
fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings);
@@ -199,10 +192,9 @@ struct YAMLFrameDataSubsection : public YAMLSubsectionBase {
: YAMLSubsectionBase(DebugSubsectionKind::FrameData) {}
void map(IO &IO) override;
- std::unique_ptr<DebugSubsection>
+ std::shared_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- DebugStringTableSubsection *Strings,
- DebugChecksumsSubsection *Checksums) const override;
+ const codeview::StringsAndChecksums &SC) const override;
static Expected<std::shared_ptr<YAMLFrameDataSubsection>>
fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
const DebugFrameDataSubsectionRef &Frames);
@@ -215,10 +207,9 @@ struct YAMLCoffSymbolRVASubsection : public YAMLSubsectionBase {
: YAMLSubsectionBase(DebugSubsectionKind::CoffSymbolRVA) {}
void map(IO &IO) override;
- std::unique_ptr<DebugSubsection>
+ std::shared_ptr<DebugSubsection>
toCodeViewSubsection(BumpPtrAllocator &Allocator,
- DebugStringTableSubsection *Strings,
- DebugChecksumsSubsection *Checksums) const override;
+ const codeview::StringsAndChecksums &SC) const override;
static Expected<std::shared_ptr<YAMLCoffSymbolRVASubsection>>
fromCodeViewSubsection(const DebugSymbolRVASubsectionRef &RVAs);
@@ -400,23 +391,23 @@ findChecksums(ArrayRef<YAMLDebugSubsection> Subsections) {
return nullptr;
}
-std::unique_ptr<DebugSubsection> YAMLChecksumsSubsection::toCodeViewSubsection(
- BumpPtrAllocator &Allocator, DebugStringTableSubsection *UseStrings,
- DebugChecksumsSubsection *UseChecksums) const {
- assert(UseStrings && !UseChecksums);
- auto Result = llvm::make_unique<DebugChecksumsSubsection>(*UseStrings);
+std::shared_ptr<DebugSubsection> YAMLChecksumsSubsection::toCodeViewSubsection(
+ BumpPtrAllocator &Allocator,
+ const codeview::StringsAndChecksums &SC) const {
+ assert(SC.hasStrings());
+ auto Result = std::make_shared<DebugChecksumsSubsection>(*SC.strings());
for (const auto &CS : Checksums) {
Result->addChecksum(CS.FileName, CS.Kind, CS.ChecksumBytes.Bytes);
}
return std::move(Result);
}
-std::unique_ptr<DebugSubsection> YAMLLinesSubsection::toCodeViewSubsection(
- BumpPtrAllocator &Allocator, DebugStringTableSubsection *UseStrings,
- DebugChecksumsSubsection *UseChecksums) const {
- assert(UseStrings && UseChecksums);
+std::shared_ptr<DebugSubsection> YAMLLinesSubsection::toCodeViewSubsection(
+ BumpPtrAllocator &Allocator,
+ const codeview::StringsAndChecksums &SC) const {
+ assert(SC.hasStrings() && SC.hasChecksums());
auto Result =
- llvm::make_unique<DebugLinesSubsection>(*UseChecksums, *UseStrings);
+ std::make_shared<DebugLinesSubsection>(*SC.checksums(), *SC.strings());
Result->setCodeSize(Lines.CodeSize);
Result->setRelocationAddress(Lines.RelocSegment, Lines.RelocOffset);
Result->setFlags(Lines.Flags);
@@ -438,16 +429,16 @@ std::unique_ptr<DebugSubsection> YAMLLinesSubsection::toCodeViewSubsection(
}
}
}
- return llvm::cast<DebugSubsection>(std::move(Result));
+ return std::move(Result);
}
-std::unique_ptr<DebugSubsection>
+std::shared_ptr<DebugSubsection>
YAMLInlineeLinesSubsection::toCodeViewSubsection(
- BumpPtrAllocator &Allocator, DebugStringTableSubsection *UseStrings,
- DebugChecksumsSubsection *UseChecksums) const {
- assert(UseChecksums);
- auto Result = llvm::make_unique<DebugInlineeLinesSubsection>(
- *UseChecksums, InlineeLines.HasExtraFiles);
+ BumpPtrAllocator &Allocator,
+ const codeview::StringsAndChecksums &SC) const {
+ assert(SC.hasChecksums());
+ auto Result = std::make_shared<DebugInlineeLinesSubsection>(
+ *SC.checksums(), InlineeLines.HasExtraFiles);
for (const auto &Site : InlineeLines.Sites) {
Result->addInlineSite(TypeIndex(Site.Inlinee), Site.FileName,
@@ -459,55 +450,59 @@ YAMLInlineeLinesSubsection::toCodeViewSubsection(
Result->addExtraFile(EF);
}
}
- return llvm::cast<DebugSubsection>(std::move(Result));
+ return std::move(Result);
}
-std::unique_ptr<DebugSubsection>
+std::shared_ptr<DebugSubsection>
YAMLCrossModuleExportsSubsection::toCodeViewSubsection(
- BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
- DebugChecksumsSubsection *Checksums) const {
- auto Result = llvm::make_unique<DebugCrossModuleExportsSubsection>();
+ BumpPtrAllocator &Allocator,
+ const codeview::StringsAndChecksums &SC) const {
+ auto Result = std::make_shared<DebugCrossModuleExportsSubsection>();
for (const auto &M : Exports)
Result->addMapping(M.Local, M.Global);
- return llvm::cast<DebugSubsection>(std::move(Result));
+ return std::move(Result);
}
-std::unique_ptr<DebugSubsection>
+std::shared_ptr<DebugSubsection>
YAMLCrossModuleImportsSubsection::toCodeViewSubsection(
- BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
- DebugChecksumsSubsection *Checksums) const {
- auto Result = llvm::make_unique<DebugCrossModuleImportsSubsection>(*Strings);
+ BumpPtrAllocator &Allocator,
+ const codeview::StringsAndChecksums &SC) const {
+ assert(SC.hasStrings());
+
+ auto Result =
+ std::make_shared<DebugCrossModuleImportsSubsection>(*SC.strings());
for (const auto &M : Imports) {
for (const auto Id : M.ImportIds)
Result->addImport(M.ModuleName, Id);
}
- return llvm::cast<DebugSubsection>(std::move(Result));
+ return std::move(Result);
}
-std::unique_ptr<DebugSubsection> YAMLSymbolsSubsection::toCodeViewSubsection(
- BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
- DebugChecksumsSubsection *Checksums) const {
- auto Result = llvm::make_unique<DebugSymbolsSubsection>();
+std::shared_ptr<DebugSubsection> YAMLSymbolsSubsection::toCodeViewSubsection(
+ BumpPtrAllocator &Allocator,
+ const codeview::StringsAndChecksums &SC) const {
+ auto Result = std::make_shared<DebugSymbolsSubsection>();
for (const auto &Sym : Symbols)
Result->addSymbol(
Sym.toCodeViewSymbol(Allocator, CodeViewContainer::ObjectFile));
return std::move(Result);
}
-std::unique_ptr<DebugSubsection>
+std::shared_ptr<DebugSubsection>
YAMLStringTableSubsection::toCodeViewSubsection(
- BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
- DebugChecksumsSubsection *Checksums) const {
- auto Result = llvm::make_unique<DebugStringTableSubsection>();
+ BumpPtrAllocator &Allocator,
+ const codeview::StringsAndChecksums &SC) const {
+ auto Result = std::make_shared<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);
+std::shared_ptr<DebugSubsection> YAMLFrameDataSubsection::toCodeViewSubsection(
+ BumpPtrAllocator &Allocator,
+ const codeview::StringsAndChecksums &SC) const {
+ assert(SC.hasStrings());
+
auto Result = llvm::make_unique<DebugFrameDataSubsection>();
for (const auto &YF : Frames) {
codeview::FrameData F;
@@ -519,16 +514,16 @@ std::unique_ptr<DebugSubsection> YAMLFrameDataSubsection::toCodeViewSubsection(
F.PrologSize = YF.PrologSize;
F.RvaStart = YF.RvaStart;
F.SavedRegsSize = YF.SavedRegsSize;
- F.FrameFunc = Strings->insert(YF.FrameFunc);
+ F.FrameFunc = SC.strings()->insert(YF.FrameFunc);
Result->addFrameData(F);
}
return std::move(Result);
}
-std::unique_ptr<DebugSubsection>
+std::shared_ptr<DebugSubsection>
YAMLCoffSymbolRVASubsection::toCodeViewSubsection(
- BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
- DebugChecksumsSubsection *Checksums) const {
+ BumpPtrAllocator &Allocator,
+ const codeview::StringsAndChecksums &SC) const {
auto Result = llvm::make_unique<DebugSymbolRVASubsection>();
for (const auto &RVA : RVAs)
Result->addRVA(RVA);
@@ -741,63 +736,17 @@ YAMLCoffSymbolRVASubsection::fromCodeViewSubsection(
return Result;
}
-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>>>
+Expected<std::vector<std::shared_ptr<DebugSubsection>>>
llvm::CodeViewYAML::toCodeViewSubsectionList(
BumpPtrAllocator &Allocator, ArrayRef<YAMLDebugSubsection> Subsections,
- std::unique_ptr<DebugStringTableSubsection> &TakeStrings,
- DebugStringTableSubsection *StringsRef) {
- std::vector<std::unique_ptr<DebugSubsection>> Result;
+ const codeview::StringsAndChecksums &SC) {
+ std::vector<std::shared_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);
+ std::shared_ptr<DebugSubsection> CVS;
+ CVS = SS.Subsection->toCodeViewSubsection(Allocator, SC);
assert(CVS != nullptr);
Result.push_back(std::move(CVS));
}
@@ -810,23 +759,23 @@ struct SubsectionConversionVisitor : public DebugSubsectionVisitor {
Error visitUnknown(DebugUnknownSubsectionRef &Unknown) override;
Error visitLines(DebugLinesSubsectionRef &Lines,
- const DebugSubsectionState &State) override;
+ const StringsAndChecksumsRef &State) override;
Error visitFileChecksums(DebugChecksumsSubsectionRef &Checksums,
- const DebugSubsectionState &State) override;
+ const StringsAndChecksumsRef &State) override;
Error visitInlineeLines(DebugInlineeLinesSubsectionRef &Inlinees,
- const DebugSubsectionState &State) override;
+ const StringsAndChecksumsRef &State) override;
Error visitCrossModuleExports(DebugCrossModuleExportsSubsectionRef &Checksums,
- const DebugSubsectionState &State) override;
+ const StringsAndChecksumsRef &State) override;
Error visitCrossModuleImports(DebugCrossModuleImportsSubsectionRef &Inlinees,
- const DebugSubsectionState &State) override;
+ const StringsAndChecksumsRef &State) override;
Error visitStringTable(DebugStringTableSubsectionRef &ST,
- const DebugSubsectionState &State) override;
+ const StringsAndChecksumsRef &State) override;
Error visitSymbols(DebugSymbolsSubsectionRef &Symbols,
- const DebugSubsectionState &State) override;
+ const StringsAndChecksumsRef &State) override;
Error visitFrameData(DebugFrameDataSubsectionRef &Symbols,
- const DebugSubsectionState &State) override;
+ const StringsAndChecksumsRef &State) override;
Error visitCOFFSymbolRVAs(DebugSymbolRVASubsectionRef &Symbols,
- const DebugSubsectionState &State) override;
+ const StringsAndChecksumsRef &State) override;
YAMLDebugSubsection Subsection;
};
@@ -837,7 +786,7 @@ Error SubsectionConversionVisitor::visitUnknown(
}
Error SubsectionConversionVisitor::visitLines(
- DebugLinesSubsectionRef &Lines, const DebugSubsectionState &State) {
+ DebugLinesSubsectionRef &Lines, const StringsAndChecksumsRef &State) {
auto Result = YAMLLinesSubsection::fromCodeViewSubsection(
State.strings(), State.checksums(), Lines);
if (!Result)
@@ -847,7 +796,8 @@ Error SubsectionConversionVisitor::visitLines(
}
Error SubsectionConversionVisitor::visitFileChecksums(
- DebugChecksumsSubsectionRef &Checksums, const DebugSubsectionState &State) {
+ DebugChecksumsSubsectionRef &Checksums,
+ const StringsAndChecksumsRef &State) {
auto Result = YAMLChecksumsSubsection::fromCodeViewSubsection(State.strings(),
Checksums);
if (!Result)
@@ -858,7 +808,7 @@ Error SubsectionConversionVisitor::visitFileChecksums(
Error SubsectionConversionVisitor::visitInlineeLines(
DebugInlineeLinesSubsectionRef &Inlinees,
- const DebugSubsectionState &State) {
+ const StringsAndChecksumsRef &State) {
auto Result = YAMLInlineeLinesSubsection::fromCodeViewSubsection(
State.strings(), State.checksums(), Inlinees);
if (!Result)
@@ -869,7 +819,7 @@ Error SubsectionConversionVisitor::visitInlineeLines(
Error SubsectionConversionVisitor::visitCrossModuleExports(
DebugCrossModuleExportsSubsectionRef &Exports,
- const DebugSubsectionState &State) {
+ const StringsAndChecksumsRef &State) {
auto Result =
YAMLCrossModuleExportsSubsection::fromCodeViewSubsection(Exports);
if (!Result)
@@ -880,7 +830,7 @@ Error SubsectionConversionVisitor::visitCrossModuleExports(
Error SubsectionConversionVisitor::visitCrossModuleImports(
DebugCrossModuleImportsSubsectionRef &Imports,
- const DebugSubsectionState &State) {
+ const StringsAndChecksumsRef &State) {
auto Result = YAMLCrossModuleImportsSubsection::fromCodeViewSubsection(
State.strings(), Imports);
if (!Result)
@@ -890,7 +840,8 @@ Error SubsectionConversionVisitor::visitCrossModuleImports(
}
Error SubsectionConversionVisitor::visitStringTable(
- DebugStringTableSubsectionRef &Strings, const DebugSubsectionState &State) {
+ DebugStringTableSubsectionRef &Strings,
+ const StringsAndChecksumsRef &State) {
auto Result = YAMLStringTableSubsection::fromCodeViewSubsection(Strings);
if (!Result)
return Result.takeError();
@@ -899,7 +850,7 @@ Error SubsectionConversionVisitor::visitStringTable(
}
Error SubsectionConversionVisitor::visitSymbols(
- DebugSymbolsSubsectionRef &Symbols, const DebugSubsectionState &State) {
+ DebugSymbolsSubsectionRef &Symbols, const StringsAndChecksumsRef &State) {
auto Result = YAMLSymbolsSubsection::fromCodeViewSubsection(Symbols);
if (!Result)
return Result.takeError();
@@ -908,7 +859,7 @@ Error SubsectionConversionVisitor::visitSymbols(
}
Error SubsectionConversionVisitor::visitFrameData(
- DebugFrameDataSubsectionRef &Frames, const DebugSubsectionState &State) {
+ DebugFrameDataSubsectionRef &Frames, const StringsAndChecksumsRef &State) {
auto Result =
YAMLFrameDataSubsection::fromCodeViewSubsection(State.strings(), Frames);
if (!Result)
@@ -918,7 +869,7 @@ Error SubsectionConversionVisitor::visitFrameData(
}
Error SubsectionConversionVisitor::visitCOFFSymbolRVAs(
- DebugSymbolRVASubsectionRef &RVAs, const DebugSubsectionState &State) {
+ DebugSymbolRVASubsectionRef &RVAs, const StringsAndChecksumsRef &State) {
auto Result = YAMLCoffSymbolRVASubsection::fromCodeViewSubsection(RVAs);
if (!Result)
return Result.takeError();
@@ -927,29 +878,71 @@ Error SubsectionConversionVisitor::visitCOFFSymbolRVAs(
}
}
-Expected<YAMLDebugSubsection> YAMLDebugSubsection::fromCodeViewSubection(
- const DebugStringTableSubsectionRef &Strings,
- const DebugChecksumsSubsectionRef &Checksums,
- const DebugSubsectionRecord &SS) {
- DebugSubsectionState State(Strings, Checksums);
+Expected<YAMLDebugSubsection>
+YAMLDebugSubsection::fromCodeViewSubection(const StringsAndChecksumsRef &SC,
+ const DebugSubsectionRecord &SS) {
SubsectionConversionVisitor V;
- if (auto EC = visitDebugSubsection(SS, V, State))
+ if (auto EC = visitDebugSubsection(SS, V, SC))
return std::move(EC);
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;
+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()));
- // String Table doesn't use the allocator.
- BumpPtrAllocator Allocator;
- auto Result =
- SS.Subsection->toCodeViewSubsection(Allocator, nullptr, nullptr);
- return llvm::cast<DebugStringTableSubsection>(std::move(Result));
+ std::vector<YAMLDebugSubsection> Result;
+
+ for (const auto &SS : Subsections) {
+ auto YamlSS = Err(YAMLDebugSubsection::fromCodeViewSubection(SC, SS));
+ Result.push_back(YamlSS);
+ }
+ return std::move(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;
+
+ auto Result = SS.Subsection->toCodeViewSubsection(Allocator, SC);
+ SC.setChecksums(
+ std::static_pointer_cast<DebugChecksumsSubsection>(Result));
+ break;
+ }
}
- return nullptr;
}
diff --git a/llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp b/llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp
index 1302b0713d0..aa8653d7e88 100644
--- a/llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp
+++ b/llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp
@@ -714,3 +714,43 @@ 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 std::move(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;
+}
OpenPOWER on IntegriCloud