1 //===- DWARFYAML.cpp - DWARF YAMLIO implementation ------------------------===// 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 // This file defines classes for handling the YAML representation of DWARF Debug 11 // Info. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #include "llvm/ObjectYAML/DWARFYAML.h" 16 17 namespace llvm { 18 19 bool DWARFYAML::Data::isEmpty() const { 20 return 0 == DebugStrings.size() + AbbrevDecls.size(); 21 } 22 23 namespace yaml { 24 25 void MappingTraits<DWARFYAML::Data>::mapping(IO &IO, DWARFYAML::Data &DWARF) { 26 auto oldContext = IO.getContext(); 27 IO.setContext(&DWARF); 28 IO.mapOptional("debug_str", DWARF.DebugStrings); 29 IO.mapOptional("debug_abbrev", DWARF.AbbrevDecls); 30 if (!DWARF.ARanges.empty() || !IO.outputting()) 31 IO.mapOptional("debug_aranges", DWARF.ARanges); 32 if (!DWARF.PubNames.Entries.empty() || !IO.outputting()) 33 IO.mapOptional("debug_pubnames", DWARF.PubNames); 34 if (!DWARF.PubTypes.Entries.empty() || !IO.outputting()) 35 IO.mapOptional("debug_pubtypes", DWARF.PubTypes); 36 if (!DWARF.GNUPubNames.Entries.empty() || !IO.outputting()) 37 IO.mapOptional("debug_gnu_pubnames", DWARF.GNUPubNames); 38 if (!DWARF.GNUPubTypes.Entries.empty() || !IO.outputting()) 39 IO.mapOptional("debug_gnu_pubtypes", DWARF.GNUPubTypes); 40 IO.mapOptional("debug_info", DWARF.CompileUnits); 41 IO.mapOptional("debug_line", DWARF.DebugLines); 42 IO.setContext(&oldContext); 43 } 44 45 void MappingTraits<DWARFYAML::Abbrev>::mapping(IO &IO, 46 DWARFYAML::Abbrev &Abbrev) { 47 IO.mapRequired("Code", Abbrev.Code); 48 IO.mapRequired("Tag", Abbrev.Tag); 49 IO.mapRequired("Children", Abbrev.Children); 50 IO.mapRequired("Attributes", Abbrev.Attributes); 51 } 52 53 void MappingTraits<DWARFYAML::AttributeAbbrev>::mapping( 54 IO &IO, DWARFYAML::AttributeAbbrev &AttAbbrev) { 55 IO.mapRequired("Attribute", AttAbbrev.Attribute); 56 IO.mapRequired("Form", AttAbbrev.Form); 57 } 58 59 void MappingTraits<DWARFYAML::ARangeDescriptor>::mapping( 60 IO &IO, DWARFYAML::ARangeDescriptor &Descriptor) { 61 IO.mapRequired("Address", Descriptor.Address); 62 IO.mapRequired("Length", Descriptor.Length); 63 } 64 65 void MappingTraits<DWARFYAML::ARange>::mapping(IO &IO, 66 DWARFYAML::ARange &Range) { 67 IO.mapRequired("Length", Range.Length); 68 IO.mapRequired("Version", Range.Version); 69 IO.mapRequired("CuOffset", Range.CuOffset); 70 IO.mapRequired("AddrSize", Range.AddrSize); 71 IO.mapRequired("SegSize", Range.SegSize); 72 IO.mapRequired("Descriptors", Range.Descriptors); 73 } 74 75 void MappingTraits<DWARFYAML::PubEntry>::mapping(IO &IO, 76 DWARFYAML::PubEntry &Entry) { 77 IO.mapRequired("DieOffset", Entry.DieOffset); 78 if (reinterpret_cast<DWARFYAML::PubSection *>(IO.getContext())->IsGNUStyle) 79 IO.mapRequired("Descriptor", Entry.Descriptor); 80 IO.mapRequired("Name", Entry.Name); 81 } 82 83 void MappingTraits<DWARFYAML::PubSection>::mapping( 84 IO &IO, DWARFYAML::PubSection &Section) { 85 auto OldContext = IO.getContext(); 86 IO.setContext(&Section); 87 88 IO.mapRequired("Length", Section.Length); 89 IO.mapRequired("Version", Section.Version); 90 IO.mapRequired("UnitOffset", Section.UnitOffset); 91 IO.mapRequired("UnitSize", Section.UnitSize); 92 IO.mapRequired("Entries", Section.Entries); 93 94 IO.setContext(OldContext); 95 } 96 97 void MappingTraits<DWARFYAML::Unit>::mapping(IO &IO, DWARFYAML::Unit &Unit) { 98 IO.mapRequired("Length", Unit.Length); 99 IO.mapRequired("Version", Unit.Version); 100 IO.mapRequired("AbbrOffset", Unit.AbbrOffset); 101 IO.mapRequired("AddrSize", Unit.AddrSize); 102 IO.mapOptional("Entries", Unit.Entries); 103 } 104 105 void MappingTraits<DWARFYAML::Entry>::mapping(IO &IO, DWARFYAML::Entry &Entry) { 106 IO.mapRequired("AbbrCode", Entry.AbbrCode); 107 IO.mapRequired("Values", Entry.Values); 108 } 109 110 void MappingTraits<DWARFYAML::FormValue>::mapping( 111 IO &IO, DWARFYAML::FormValue &FormValue) { 112 IO.mapOptional("Value", FormValue.Value); 113 if (!FormValue.CStr.empty() || !IO.outputting()) 114 IO.mapOptional("CStr", FormValue.CStr); 115 if (!FormValue.BlockData.empty() || !IO.outputting()) 116 IO.mapOptional("BlockData", FormValue.BlockData); 117 } 118 119 void MappingTraits<DWARFYAML::File>::mapping(IO &IO, DWARFYAML::File &File) { 120 IO.mapRequired("Name", File.Name); 121 IO.mapRequired("DirIdx", File.DirIdx); 122 IO.mapRequired("ModTime", File.ModTime); 123 IO.mapRequired("Length", File.Length); 124 } 125 126 void MappingTraits<DWARFYAML::LineTableOpcode>::mapping( 127 IO &IO, DWARFYAML::LineTableOpcode &LineTableOpcode) { 128 IO.mapRequired("Opcode", LineTableOpcode.Opcode); 129 if (LineTableOpcode.Opcode == dwarf::DW_LNS_extended_op) { 130 IO.mapRequired("ExtLen", LineTableOpcode.ExtLen); 131 IO.mapRequired("SubOpcode", LineTableOpcode.SubOpcode); 132 } 133 134 if (!LineTableOpcode.UnknownOpcodeData.empty() || !IO.outputting()) 135 IO.mapOptional("UnknownOpcodeData", LineTableOpcode.UnknownOpcodeData); 136 if (!LineTableOpcode.UnknownOpcodeData.empty() || !IO.outputting()) 137 IO.mapOptional("StandardOpcodeData", LineTableOpcode.StandardOpcodeData); 138 if (!LineTableOpcode.FileEntry.Name.empty() || !IO.outputting()) 139 IO.mapOptional("FileEntry", LineTableOpcode.FileEntry); 140 if (LineTableOpcode.Opcode == dwarf::DW_LNS_advance_line || !IO.outputting()) 141 IO.mapOptional("SData", LineTableOpcode.SData); 142 IO.mapOptional("Data", LineTableOpcode.Data); 143 } 144 145 void MappingTraits<DWARFYAML::LineTable>::mapping( 146 IO &IO, DWARFYAML::LineTable &LineTable) { 147 IO.mapRequired("TotalLength", LineTable.TotalLength); 148 if (LineTable.TotalLength == UINT32_MAX) 149 IO.mapRequired("TotalLength64", LineTable.TotalLength64); 150 IO.mapRequired("Version", LineTable.Version); 151 IO.mapRequired("PrologueLength", LineTable.PrologueLength); 152 IO.mapRequired("MinInstLength", LineTable.MinInstLength); 153 if(LineTable.Version >= 4) 154 IO.mapRequired("MaxOpsPerInst", LineTable.MaxOpsPerInst); 155 IO.mapRequired("DefaultIsStmt", LineTable.DefaultIsStmt); 156 IO.mapRequired("LineBase", LineTable.LineBase); 157 IO.mapRequired("LineRange", LineTable.LineRange); 158 IO.mapRequired("OpcodeBase", LineTable.OpcodeBase); 159 IO.mapRequired("StandardOpcodeLengths", LineTable.StandardOpcodeLengths); 160 IO.mapRequired("IncludeDirs", LineTable.IncludeDirs); 161 IO.mapRequired("Files", LineTable.Files); 162 IO.mapRequired("Opcodes", LineTable.Opcodes); 163 } 164 165 } // namespace llvm::yaml 166 167 } // namespace llvm 168