diff options
author | Chris Bieneman <beanz@apple.com> | 2016-12-07 21:47:28 +0000 |
---|---|---|
committer | Chris Bieneman <beanz@apple.com> | 2016-12-07 21:47:28 +0000 |
commit | 26d060fbf9fe5525f06f13c398ad1c564528fe57 (patch) | |
tree | 8544b5262853338ce148e8452a709fb389ba53e5 /llvm/tools/obj2yaml/macho2yaml.cpp | |
parent | c53606ef02fa14e199c2ad65956ea33b5eb698f0 (diff) | |
download | bcm5719-llvm-26d060fbf9fe5525f06f13c398ad1c564528fe57.tar.gz bcm5719-llvm-26d060fbf9fe5525f06f13c398ad1c564528fe57.zip |
[obj2yaml] Refactor and abstract dwarf2yaml
This makes the dwarf2yaml code separated and reusable allowing ELF and COFF to share implementations with MachO.
llvm-svn: 288986
Diffstat (limited to 'llvm/tools/obj2yaml/macho2yaml.cpp')
-rw-r--r-- | llvm/tools/obj2yaml/macho2yaml.cpp | 45 |
1 files changed, 4 insertions, 41 deletions
diff --git a/llvm/tools/obj2yaml/macho2yaml.cpp b/llvm/tools/obj2yaml/macho2yaml.cpp index cc82bbb717a..9cd05463edc 100644 --- a/llvm/tools/obj2yaml/macho2yaml.cpp +++ b/llvm/tools/obj2yaml/macho2yaml.cpp @@ -35,7 +35,6 @@ class MachODumper { ArrayRef<uint8_t> OpcodeBuffer, bool Lazy = false); void dumpExportTrie(std::unique_ptr<MachOYAML::Object> &Y); void dumpSymbols(std::unique_ptr<MachOYAML::Object> &Y); - void dumpDWARF(std::unique_ptr<MachOYAML::Object> &Y); void dumpDebugAbbrev(DWARFContextInMemory &DCtx, std::unique_ptr<MachOYAML::Object> &Y); void dumpDebugStrings(DWARFContextInMemory &DCtx, @@ -169,7 +168,10 @@ Expected<std::unique_ptr<MachOYAML::Object>> MachODumper::dump() { dumpHeader(Y); dumpLoadCommands(Y); dumpLinkEdit(Y); - dumpDWARF(Y); + + DWARFContextInMemory DICtx(Obj); + if(auto Err = dwarf2yaml(DICtx, Y->DWARF)) + return errorCodeToError(Err); return std::move(Y); } @@ -466,45 +468,6 @@ void MachODumper::dumpSymbols(std::unique_ptr<MachOYAML::Object> &Y) { } } -void MachODumper::dumpDWARF(std::unique_ptr<MachOYAML::Object> &Y) { - DWARFContextInMemory DICtx(Obj); - dumpDebugStrings(DICtx, Y); - dumpDebugAbbrev(DICtx, Y); -} - -void MachODumper::dumpDebugStrings(DWARFContextInMemory &DICtx, - std::unique_ptr<MachOYAML::Object> &Y) { - StringRef RemainingTable = DICtx.getStringSection(); - while (RemainingTable.size() > 0) { - auto SymbolPair = RemainingTable.split('\0'); - RemainingTable = SymbolPair.second; - Y->DWARF.DebugStrings.push_back(SymbolPair.first); - } -} - -void MachODumper::dumpDebugAbbrev(DWARFContextInMemory &DCtx, - std::unique_ptr<MachOYAML::Object> &Y) { - auto AbbrevSetPtr = DCtx.getDebugAbbrev(); - if(AbbrevSetPtr) { - for(auto AbbrvDeclSet : *AbbrevSetPtr) { - for(auto AbbrvDecl : AbbrvDeclSet.second) { - DWARFYAML::DWARFAbbrev Abbrv; - Abbrv.Code = AbbrvDecl.getCode(); - Abbrv.Tag = AbbrvDecl.getTag(); - Abbrv.Children = AbbrvDecl.hasChildren() ? dwarf::DW_CHILDREN_yes - : dwarf::DW_CHILDREN_no; - for(auto Attribute : AbbrvDecl.attributes()) { - DWARFYAML::DWARFAttributeAbbrev AttAbrv; - AttAbrv.Attribute = Attribute.Attr; - AttAbrv.Form = Attribute.Form; - Abbrv.Attributes.push_back(AttAbrv); - } - Y->DWARF.AbbrevDecls.push_back(Abbrv); - } - } - } -} - Error macho2yaml(raw_ostream &Out, const object::MachOObjectFile &Obj) { MachODumper Dumper(Obj); Expected<std::unique_ptr<MachOYAML::Object>> YAML = Dumper.dump(); |