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