diff options
Diffstat (limited to 'tools/llvm-readobj/COFFDumper.cpp')
-rw-r--r-- | tools/llvm-readobj/COFFDumper.cpp | 113 |
1 files changed, 56 insertions, 57 deletions
diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp index a59caa351e725..663f7b4c8a820 100644 --- a/tools/llvm-readobj/COFFDumper.cpp +++ b/tools/llvm-readobj/COFFDumper.cpp @@ -13,7 +13,6 @@ //===----------------------------------------------------------------------===// #include "ARMWinEHPrinter.h" -#include "CodeView.h" #include "Error.h" #include "ObjDumper.h" #include "StackMapPrinter.h" @@ -24,13 +23,14 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" #include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" +#include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h" +#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h" +#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h" +#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h" #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h" #include "llvm/DebugInfo/CodeView/Line.h" -#include "llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h" -#include "llvm/DebugInfo/CodeView/ModuleDebugInlineeLinesFragment.h" -#include "llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h" #include "llvm/DebugInfo/CodeView/RecordSerialization.h" -#include "llvm/DebugInfo/CodeView/StringTable.h" #include "llvm/DebugInfo/CodeView/SymbolDeserializer.h" #include "llvm/DebugInfo/CodeView/SymbolDumpDelegate.h" #include "llvm/DebugInfo/CodeView/SymbolDumper.h" @@ -157,9 +157,9 @@ private: bool RelocCached = false; RelocMapTy RelocMap; - VarStreamArray<FileChecksumEntry> CVFileChecksumTable; + DebugChecksumsSubsectionRef CVFileChecksumTable; - StringTableRef CVStringTable; + DebugStringTableSubsectionRef CVStringTable; ScopedPrinter &Writer; BinaryByteStream TypeContents; @@ -200,7 +200,9 @@ public: return CD.getFileNameForFileOffset(FileOffset); } - StringTableRef getStringTable() override { return CD.CVStringTable; } + DebugStringTableSubsectionRef getStringTable() override { + return CD.CVStringTable; + } private: COFFDumper &CD; @@ -515,19 +517,19 @@ WeakExternalCharacteristics[] = { }; static const EnumEntry<uint32_t> SubSectionTypes[] = { - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, Symbols), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, Lines), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, StringTable), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, FileChecksums), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, FrameData), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, InlineeLines), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, CrossScopeImports), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, CrossScopeExports), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, ILLines), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, FuncMDTokenMap), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, TypeMDTokenMap), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, MergedAssemblyInput), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, CoffSymbolRVA), + LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, Symbols), + LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, Lines), + LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, StringTable), + LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, FileChecksums), + LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, FrameData), + LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, InlineeLines), + LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, CrossScopeImports), + LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, CrossScopeExports), + LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, ILLines), + LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, FuncMDTokenMap), + LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, TypeMDTokenMap), + LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, MergedAssemblyInput), + LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, CoffSymbolRVA), }; static const EnumEntry<uint32_t> FrameDataFlags[] = { @@ -774,16 +776,14 @@ void COFFDumper::initializeFileAndStringTables(BinaryStreamReader &Reader) { StringRef Contents; error(Reader.readFixedString(Contents, SubSectionSize)); - switch (ModuleDebugFragmentKind(SubType)) { - case ModuleDebugFragmentKind::FileChecksums: { - BinaryStreamReader CSR(Contents, support::little); - error(CSR.readArray(CVFileChecksumTable, CSR.getLength())); + BinaryStreamRef ST(Contents, support::little); + switch (DebugSubsectionKind(SubType)) { + case DebugSubsectionKind::FileChecksums: + error(CVFileChecksumTable.initialize(ST)); break; - } - case ModuleDebugFragmentKind::StringTable: { - BinaryStreamRef ST(Contents, support::little); + case DebugSubsectionKind::StringTable: error(CVStringTable.initialize(ST)); - } break; + break; default: break; } @@ -847,20 +847,20 @@ void COFFDumper::printCodeViewSymbolSection(StringRef SectionName, printBinaryBlockWithRelocs("SubSectionContents", Section, SectionContents, Contents); - switch (ModuleDebugFragmentKind(SubType)) { - case ModuleDebugFragmentKind::Symbols: + switch (DebugSubsectionKind(SubType)) { + case DebugSubsectionKind::Symbols: printCodeViewSymbolsSubsection(Contents, Section, SectionContents); break; - case ModuleDebugFragmentKind::InlineeLines: + case DebugSubsectionKind::InlineeLines: printCodeViewInlineeLines(Contents); break; - case ModuleDebugFragmentKind::FileChecksums: + case DebugSubsectionKind::FileChecksums: printCodeViewFileChecksums(Contents); break; - case ModuleDebugFragmentKind::Lines: { + case DebugSubsectionKind::Lines: { // Holds a PC to file:line table. Some data to parse this subsection is // stored in the other subsections, so just check sanity and store the // pointers for deferred processing. @@ -886,34 +886,33 @@ void COFFDumper::printCodeViewSymbolSection(StringRef SectionName, FunctionNames.push_back(LinkageName); break; } - case ModuleDebugFragmentKind::FrameData: { + case DebugSubsectionKind::FrameData: { // First four bytes is a relocation against the function. BinaryStreamReader SR(Contents, llvm::support::little); - const uint32_t *CodePtr; - error(SR.readObject(CodePtr)); + + DebugFrameDataSubsectionRef FrameData; + error(FrameData.initialize(SR)); + StringRef LinkageName; error(resolveSymbolName(Obj->getCOFFSection(Section), SectionContents, - CodePtr, LinkageName)); + FrameData.getRelocPtr(), LinkageName)); W.printString("LinkageName", LinkageName); // To find the active frame description, search this array for the // smallest PC range that includes the current PC. - while (!SR.empty()) { - const FrameData *FD; - error(SR.readObject(FD)); - - StringRef FrameFunc = error(CVStringTable.getString(FD->FrameFunc)); + for (const auto &FD : FrameData) { + StringRef FrameFunc = error(CVStringTable.getString(FD.FrameFunc)); DictScope S(W, "FrameData"); - W.printHex("RvaStart", FD->RvaStart); - W.printHex("CodeSize", FD->CodeSize); - W.printHex("LocalSize", FD->LocalSize); - W.printHex("ParamsSize", FD->ParamsSize); - W.printHex("MaxStackSize", FD->MaxStackSize); + W.printHex("RvaStart", FD.RvaStart); + W.printHex("CodeSize", FD.CodeSize); + W.printHex("LocalSize", FD.LocalSize); + W.printHex("ParamsSize", FD.ParamsSize); + W.printHex("MaxStackSize", FD.MaxStackSize); W.printString("FrameFunc", FrameFunc); - W.printHex("PrologSize", FD->PrologSize); - W.printHex("SavedRegsSize", FD->SavedRegsSize); - W.printFlags("Flags", FD->Flags, makeArrayRef(FrameDataFlags)); + W.printHex("PrologSize", FD.PrologSize); + W.printHex("SavedRegsSize", FD.SavedRegsSize); + W.printFlags("Flags", FD.Flags, makeArrayRef(FrameDataFlags)); } break; } @@ -934,7 +933,7 @@ void COFFDumper::printCodeViewSymbolSection(StringRef SectionName, BinaryStreamReader Reader(FunctionLineTables[Name], support::little); - ModuleDebugLineFragmentRef LineInfo; + DebugLinesSubsectionRef LineInfo; error(LineInfo.initialize(Reader)); W.printHex("Flags", LineInfo.header()->Flags); @@ -996,9 +995,9 @@ void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection, } void COFFDumper::printCodeViewFileChecksums(StringRef Subsection) { - BinaryStreamReader SR(Subsection, llvm::support::little); - ModuleDebugFileChecksumFragmentRef Checksums; - error(Checksums.initialize(SR)); + BinaryStreamRef Stream(Subsection, llvm::support::little); + DebugChecksumsSubsectionRef Checksums; + error(Checksums.initialize(Stream)); for (auto &FC : Checksums) { DictScope S(W, "FileChecksum"); @@ -1015,7 +1014,7 @@ void COFFDumper::printCodeViewFileChecksums(StringRef Subsection) { void COFFDumper::printCodeViewInlineeLines(StringRef Subsection) { BinaryStreamReader SR(Subsection, llvm::support::little); - ModuleDebugInlineeLineFragmentRef Lines; + DebugInlineeLinesSubsectionRef Lines; error(Lines.initialize(SR)); for (auto &Line : Lines) { @@ -1039,7 +1038,7 @@ StringRef COFFDumper::getFileNameForFileOffset(uint32_t FileOffset) { if (!CVFileChecksumTable.valid() || !CVStringTable.valid()) error(object_error::parse_failed); - auto Iter = CVFileChecksumTable.at(FileOffset); + auto Iter = CVFileChecksumTable.getArray().at(FileOffset); // Check if the file checksum table offset is valid. if (Iter == CVFileChecksumTable.end()) |