diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/DebugInfo/CodeView/CMakeLists.txt | 3 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp | 5 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp | 37 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/CodeView/StringsAndChecksums.cpp | 48 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp | 5 | ||||
-rw-r--r-- | llvm/lib/ObjectYAML/COFFYAML.cpp | 11 | ||||
-rw-r--r-- | llvm/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp | 327 | ||||
-rw-r--r-- | llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp | 40 |
10 files changed, 205 insertions, 275 deletions
diff --git a/llvm/lib/DebugInfo/CodeView/CMakeLists.txt b/llvm/lib/DebugInfo/CodeView/CMakeLists.txt index f916695a843..2f9e8981b69 100644 --- a/llvm/lib/DebugInfo/CodeView/CMakeLists.txt +++ b/llvm/lib/DebugInfo/CodeView/CMakeLists.txt @@ -20,7 +20,6 @@ add_llvm_library(LLVMDebugInfoCodeView LazyRandomTypeCollection.cpp Line.cpp RecordSerialization.cpp - StringsAndChecksums.cpp SymbolRecordMapping.cpp SymbolDumper.cpp SymbolSerializer.cpp @@ -33,7 +32,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 de02525270c..6e647c4b976 100644 --- a/llvm/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp +++ b/llvm/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp @@ -58,10 +58,6 @@ 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(); @@ -72,7 +68,6 @@ 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 334c5e002bb..e9124e68fe8 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::shared_ptr<DebugSubsection> Subsection, CodeViewContainer Container) + std::unique_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 9b824333369..8550107741c 100644 --- a/llvm/lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp +++ b/llvm/lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp @@ -26,9 +26,40 @@ using namespace llvm; using namespace llvm::codeview; -Error llvm::codeview::visitDebugSubsection( - const DebugSubsectionRecord &R, DebugSubsectionVisitor &V, - const StringsAndChecksumsRef &State) { +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) { 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 deleted file mode 100644 index ccd9aba45ea..00000000000 --- a/llvm/lib/DebugInfo/CodeView/StringsAndChecksums.cpp +++ /dev/null @@ -1,48 +0,0 @@ -//===- 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 81a9d3eeec6..396dffaa68b 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::shared_ptr<DebugSubsection> Subsection) { + std::unique_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 90acfadd311..a472181a489 100644 --- a/llvm/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp @@ -52,11 +52,6 @@ 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 c8cbea1490f..7f9f4c1f8c2 100644 --- a/llvm/lib/ObjectYAML/COFFYAML.cpp +++ b/llvm/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/llvm/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp b/llvm/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp index 728079a2a6b..08a4bb715fa 100644 --- a/llvm/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp +++ b/llvm/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/llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp b/llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp index a03b9cd50fa..1302b0713d0 100644 --- a/llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp +++ b/llvm/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; -} |