1 //===------ dwarf2yaml.cpp - obj2yaml conversion tool -----------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "Error.h" 11 #include "llvm/DebugInfo/DWARF/DWARFContext.h" 12 #include "llvm/ObjectYAML/DWARFYAML.h" 13 14 using namespace llvm; 15 16 void dumpDebugAbbrev(DWARFContextInMemory &DCtx, DWARFYAML::Data &Y) { 17 auto AbbrevSetPtr = DCtx.getDebugAbbrev(); 18 if (AbbrevSetPtr) { 19 for (auto AbbrvDeclSet : *AbbrevSetPtr) { 20 for (auto AbbrvDecl : AbbrvDeclSet.second) { 21 DWARFYAML::Abbrev Abbrv; 22 Abbrv.Code = AbbrvDecl.getCode(); 23 Abbrv.Tag = AbbrvDecl.getTag(); 24 Abbrv.Children = AbbrvDecl.hasChildren() ? dwarf::DW_CHILDREN_yes 25 : dwarf::DW_CHILDREN_no; 26 for (auto Attribute : AbbrvDecl.attributes()) { 27 DWARFYAML::AttributeAbbrev AttAbrv; 28 AttAbrv.Attribute = Attribute.Attr; 29 AttAbrv.Form = Attribute.Form; 30 Abbrv.Attributes.push_back(AttAbrv); 31 } 32 Y.AbbrevDecls.push_back(Abbrv); 33 } 34 } 35 } 36 } 37 38 void dumpDebugStrings(DWARFContextInMemory &DCtx, DWARFYAML::Data &Y) { 39 StringRef RemainingTable = DCtx.getStringSection(); 40 while (RemainingTable.size() > 0) { 41 auto SymbolPair = RemainingTable.split('\0'); 42 RemainingTable = SymbolPair.second; 43 Y.DebugStrings.push_back(SymbolPair.first); 44 } 45 } 46 47 std::error_code dwarf2yaml(DWARFContextInMemory &DCtx, 48 DWARFYAML::Data &Y) { 49 dumpDebugAbbrev(DCtx, Y); 50 dumpDebugStrings(DCtx, Y); 51 52 return obj2yaml_error::success; 53 } 54