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