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