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