Mercurial > hg > CbC > CbC_llvm
diff tools/obj2yaml/coff2yaml.cpp @ 121:803732b1fca8
LLVM 5.0
author | kono |
---|---|
date | Fri, 27 Oct 2017 17:07:41 +0900 |
parents | 1172e4bd9c6f |
children | 3a76565eade5 |
line wrap: on
line diff
--- a/tools/obj2yaml/coff2yaml.cpp Fri Nov 25 19:14:25 2016 +0900 +++ b/tools/obj2yaml/coff2yaml.cpp Fri Oct 27 17:07:41 2017 +0900 @@ -8,8 +8,13 @@ //===----------------------------------------------------------------------===// #include "obj2yaml.h" +#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" +#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h" +#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h" #include "llvm/Object/COFF.h" #include "llvm/ObjectYAML/COFFYAML.h" +#include "llvm/ObjectYAML/CodeViewYAMLSymbols.h" +#include "llvm/ObjectYAML/CodeViewYAMLTypes.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/YAMLTraits.h" @@ -99,8 +104,45 @@ YAMLObj.Header.Characteristics = Obj.getCharacteristics(); } +static void +initializeFileAndStringTable(const llvm::object::COFFObjectFile &Obj, + codeview::StringsAndChecksumsRef &SC) { + + ExitOnError Err("Invalid .debug$S section!"); + // Iterate all .debug$S sections looking for the checksums and string table. + // Exit as soon as both sections are found. + for (const auto &S : Obj.sections()) { + if (SC.hasStrings() && SC.hasChecksums()) + break; + + StringRef SectionName; + S.getName(SectionName); + ArrayRef<uint8_t> sectionData; + if (SectionName != ".debug$S") + continue; + + const object::coff_section *COFFSection = Obj.getCOFFSection(S); + + Obj.getSectionContents(COFFSection, sectionData); + + BinaryStreamReader Reader(sectionData, support::little); + uint32_t Magic; + + Err(Reader.readInteger(Magic)); + assert(Magic == COFF::DEBUG_SECTION_MAGIC && "Invalid .debug$S section!"); + + codeview::DebugSubsectionArray Subsections; + Err(Reader.readArray(Subsections, Reader.bytesRemaining())); + + SC.initialize(Subsections); + } +} + void COFFDumper::dumpSections(unsigned NumSections) { std::vector<COFFYAML::Section> &YAMLSections = YAMLObj.Sections; + codeview::StringsAndChecksumsRef SC; + initializeFileAndStringTable(Obj, SC); + for (const auto &ObjSection : Obj.sections()) { const object::coff_section *COFFSection = Obj.getCOFFSection(ObjSection); COFFYAML::Section NewYAMLSection; @@ -108,6 +150,16 @@ NewYAMLSection.Header.Characteristics = COFFSection->Characteristics; NewYAMLSection.Header.VirtualAddress = ObjSection.getAddress(); NewYAMLSection.Header.VirtualSize = COFFSection->VirtualSize; + NewYAMLSection.Header.NumberOfLineNumbers = + COFFSection->NumberOfLinenumbers; + NewYAMLSection.Header.NumberOfRelocations = + COFFSection->NumberOfRelocations; + NewYAMLSection.Header.PointerToLineNumbers = + COFFSection->PointerToLinenumbers; + NewYAMLSection.Header.PointerToRawData = COFFSection->PointerToRawData; + NewYAMLSection.Header.PointerToRelocations = + COFFSection->PointerToRelocations; + NewYAMLSection.Header.SizeOfRawData = COFFSection->SizeOfRawData; NewYAMLSection.Alignment = ObjSection.getAlignment(); assert(NewYAMLSection.Alignment <= 8192); @@ -116,6 +168,11 @@ Obj.getSectionContents(COFFSection, sectionData); NewYAMLSection.SectionData = yaml::BinaryRef(sectionData); + if (NewYAMLSection.Name == ".debug$S") + NewYAMLSection.DebugS = CodeViewYAML::fromDebugS(sectionData, SC); + else if (NewYAMLSection.Name == ".debug$T") + NewYAMLSection.DebugT = CodeViewYAML::fromDebugT(sectionData); + std::vector<COFFYAML::Relocation> Relocations; for (const auto &Reloc : ObjSection.relocations()) { const object::coff_relocation *reloc = Obj.getCOFFRelocation(Reloc);