1 //===- DWARFYAML.cpp - DWARF YAMLIO implementation ------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file defines classes for handling the YAML representation of DWARF Debug 10 // Info. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "llvm/ObjectYAML/DWARFYAML.h" 15 16 namespace llvm { 17 18 bool DWARFYAML::Data::isEmpty() const { 19 return DebugStrings.empty() && AbbrevDecls.empty() && ARanges.empty() && 20 DebugRanges.empty() && PubNames.Entries.empty() && 21 PubTypes.Entries.empty() && GNUPubNames.Entries.empty() && 22 GNUPubTypes.Entries.empty() && CompileUnits.empty() && 23 DebugLines.empty(); 24 } 25 26 SetVector<StringRef> DWARFYAML::Data::getUsedSectionNames() const { 27 SetVector<StringRef> SecNames; 28 if (!DebugStrings.empty()) 29 SecNames.insert("debug_str"); 30 return SecNames; 31 } 32 33 namespace yaml { 34 35 void MappingTraits<DWARFYAML::Data>::mapping(IO &IO, DWARFYAML::Data &DWARF) { 36 auto oldContext = IO.getContext(); 37 IO.setContext(&DWARF); 38 IO.mapOptional("debug_str", DWARF.DebugStrings); 39 IO.mapOptional("debug_abbrev", DWARF.AbbrevDecls); 40 if (!DWARF.ARanges.empty() || !IO.outputting()) 41 IO.mapOptional("debug_aranges", DWARF.ARanges); 42 if (!DWARF.DebugRanges.empty() || !IO.outputting()) 43 IO.mapOptional("debug_ranges", DWARF.DebugRanges); 44 if (!DWARF.PubNames.Entries.empty() || !IO.outputting()) 45 IO.mapOptional("debug_pubnames", DWARF.PubNames); 46 if (!DWARF.PubTypes.Entries.empty() || !IO.outputting()) 47 IO.mapOptional("debug_pubtypes", DWARF.PubTypes); 48 if (!DWARF.GNUPubNames.Entries.empty() || !IO.outputting()) 49 IO.mapOptional("debug_gnu_pubnames", DWARF.GNUPubNames); 50 if (!DWARF.GNUPubTypes.Entries.empty() || !IO.outputting()) 51 IO.mapOptional("debug_gnu_pubtypes", DWARF.GNUPubTypes); 52 IO.mapOptional("debug_info", DWARF.CompileUnits); 53 IO.mapOptional("debug_line", DWARF.DebugLines); 54 IO.setContext(&oldContext); 55 } 56 57 void MappingTraits<DWARFYAML::Abbrev>::mapping(IO &IO, 58 DWARFYAML::Abbrev &Abbrev) { 59 IO.mapRequired("Code", Abbrev.Code); 60 IO.mapRequired("Tag", Abbrev.Tag); 61 IO.mapRequired("Children", Abbrev.Children); 62 IO.mapRequired("Attributes", Abbrev.Attributes); 63 } 64 65 void MappingTraits<DWARFYAML::AttributeAbbrev>::mapping( 66 IO &IO, DWARFYAML::AttributeAbbrev &AttAbbrev) { 67 IO.mapRequired("Attribute", AttAbbrev.Attribute); 68 IO.mapRequired("Form", AttAbbrev.Form); 69 if(AttAbbrev.Form == dwarf::DW_FORM_implicit_const) 70 IO.mapRequired("Value", AttAbbrev.Value); 71 } 72 73 void MappingTraits<DWARFYAML::ARangeDescriptor>::mapping( 74 IO &IO, DWARFYAML::ARangeDescriptor &Descriptor) { 75 IO.mapRequired("Address", Descriptor.Address); 76 IO.mapRequired("Length", Descriptor.Length); 77 } 78 79 void MappingTraits<DWARFYAML::ARange>::mapping(IO &IO, 80 DWARFYAML::ARange &ARange) { 81 IO.mapRequired("Length", ARange.Length); 82 IO.mapRequired("Version", ARange.Version); 83 IO.mapRequired("CuOffset", ARange.CuOffset); 84 IO.mapRequired("AddrSize", ARange.AddrSize); 85 IO.mapRequired("SegSize", ARange.SegSize); 86 IO.mapRequired("Descriptors", ARange.Descriptors); 87 } 88 89 void MappingTraits<DWARFYAML::RangeEntry>::mapping( 90 IO &IO, DWARFYAML::RangeEntry &Descriptor) { 91 IO.mapRequired("LowOffset", Descriptor.LowOffset); 92 IO.mapRequired("HighOffset", Descriptor.HighOffset); 93 } 94 95 void MappingTraits<DWARFYAML::Ranges>::mapping(IO &IO, 96 DWARFYAML::Ranges &DebugRanges) { 97 IO.mapRequired("Offset", DebugRanges.Offset); 98 IO.mapRequired("AddrSize", DebugRanges.AddrSize); 99 IO.mapRequired("Entries", DebugRanges.Entries); 100 } 101 102 void MappingTraits<DWARFYAML::PubEntry>::mapping(IO &IO, 103 DWARFYAML::PubEntry &Entry) { 104 IO.mapRequired("DieOffset", Entry.DieOffset); 105 if (reinterpret_cast<DWARFYAML::PubSection *>(IO.getContext())->IsGNUStyle) 106 IO.mapRequired("Descriptor", Entry.Descriptor); 107 IO.mapRequired("Name", Entry.Name); 108 } 109 110 void MappingTraits<DWARFYAML::PubSection>::mapping( 111 IO &IO, DWARFYAML::PubSection &Section) { 112 auto OldContext = IO.getContext(); 113 IO.setContext(&Section); 114 115 IO.mapRequired("Length", Section.Length); 116 IO.mapRequired("Version", Section.Version); 117 IO.mapRequired("UnitOffset", Section.UnitOffset); 118 IO.mapRequired("UnitSize", Section.UnitSize); 119 IO.mapRequired("Entries", Section.Entries); 120 121 IO.setContext(OldContext); 122 } 123 124 void MappingTraits<DWARFYAML::Unit>::mapping(IO &IO, DWARFYAML::Unit &Unit) { 125 IO.mapRequired("Length", Unit.Length); 126 IO.mapRequired("Version", Unit.Version); 127 if (Unit.Version >= 5) 128 IO.mapRequired("UnitType", Unit.Type); 129 IO.mapRequired("AbbrOffset", Unit.AbbrOffset); 130 IO.mapRequired("AddrSize", Unit.AddrSize); 131 IO.mapOptional("Entries", Unit.Entries); 132 } 133 134 void MappingTraits<DWARFYAML::Entry>::mapping(IO &IO, DWARFYAML::Entry &Entry) { 135 IO.mapRequired("AbbrCode", Entry.AbbrCode); 136 IO.mapRequired("Values", Entry.Values); 137 } 138 139 void MappingTraits<DWARFYAML::FormValue>::mapping( 140 IO &IO, DWARFYAML::FormValue &FormValue) { 141 IO.mapOptional("Value", FormValue.Value); 142 if (!FormValue.CStr.empty() || !IO.outputting()) 143 IO.mapOptional("CStr", FormValue.CStr); 144 if (!FormValue.BlockData.empty() || !IO.outputting()) 145 IO.mapOptional("BlockData", FormValue.BlockData); 146 } 147 148 void MappingTraits<DWARFYAML::File>::mapping(IO &IO, DWARFYAML::File &File) { 149 IO.mapRequired("Name", File.Name); 150 IO.mapRequired("DirIdx", File.DirIdx); 151 IO.mapRequired("ModTime", File.ModTime); 152 IO.mapRequired("Length", File.Length); 153 } 154 155 void MappingTraits<DWARFYAML::LineTableOpcode>::mapping( 156 IO &IO, DWARFYAML::LineTableOpcode &LineTableOpcode) { 157 IO.mapRequired("Opcode", LineTableOpcode.Opcode); 158 if (LineTableOpcode.Opcode == dwarf::DW_LNS_extended_op) { 159 IO.mapRequired("ExtLen", LineTableOpcode.ExtLen); 160 IO.mapRequired("SubOpcode", LineTableOpcode.SubOpcode); 161 } 162 163 if (!LineTableOpcode.UnknownOpcodeData.empty() || !IO.outputting()) 164 IO.mapOptional("UnknownOpcodeData", LineTableOpcode.UnknownOpcodeData); 165 if (!LineTableOpcode.UnknownOpcodeData.empty() || !IO.outputting()) 166 IO.mapOptional("StandardOpcodeData", LineTableOpcode.StandardOpcodeData); 167 if (!LineTableOpcode.FileEntry.Name.empty() || !IO.outputting()) 168 IO.mapOptional("FileEntry", LineTableOpcode.FileEntry); 169 if (LineTableOpcode.Opcode == dwarf::DW_LNS_advance_line || !IO.outputting()) 170 IO.mapOptional("SData", LineTableOpcode.SData); 171 IO.mapOptional("Data", LineTableOpcode.Data); 172 } 173 174 void MappingTraits<DWARFYAML::LineTable>::mapping( 175 IO &IO, DWARFYAML::LineTable &LineTable) { 176 IO.mapRequired("Length", LineTable.Length); 177 IO.mapRequired("Version", LineTable.Version); 178 IO.mapRequired("PrologueLength", LineTable.PrologueLength); 179 IO.mapRequired("MinInstLength", LineTable.MinInstLength); 180 if(LineTable.Version >= 4) 181 IO.mapRequired("MaxOpsPerInst", LineTable.MaxOpsPerInst); 182 IO.mapRequired("DefaultIsStmt", LineTable.DefaultIsStmt); 183 IO.mapRequired("LineBase", LineTable.LineBase); 184 IO.mapRequired("LineRange", LineTable.LineRange); 185 IO.mapRequired("OpcodeBase", LineTable.OpcodeBase); 186 IO.mapRequired("StandardOpcodeLengths", LineTable.StandardOpcodeLengths); 187 IO.mapRequired("IncludeDirs", LineTable.IncludeDirs); 188 IO.mapRequired("Files", LineTable.Files); 189 IO.mapRequired("Opcodes", LineTable.Opcodes); 190 } 191 192 void MappingTraits<DWARFYAML::InitialLength>::mapping( 193 IO &IO, DWARFYAML::InitialLength &InitialLength) { 194 IO.mapRequired("TotalLength", InitialLength.TotalLength); 195 if (InitialLength.isDWARF64()) 196 IO.mapRequired("TotalLength64", InitialLength.TotalLength64); 197 } 198 199 } // end namespace yaml 200 201 } // end namespace llvm 202