File indexing completed on 2026-05-10 08:44:21
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LLVM_OBJECTYAML_DWARFYAML_H
0016 #define LLVM_OBJECTYAML_DWARFYAML_H
0017
0018 #include "llvm/ADT/SetVector.h"
0019 #include "llvm/ADT/StringRef.h"
0020 #include "llvm/BinaryFormat/Dwarf.h"
0021 #include "llvm/ObjectYAML/YAML.h"
0022 #include "llvm/Support/YAMLTraits.h"
0023 #include <cstdint>
0024 #include <optional>
0025 #include <unordered_map>
0026 #include <vector>
0027
0028 namespace llvm {
0029 namespace DWARFYAML {
0030
0031 struct AttributeAbbrev {
0032 llvm::dwarf::Attribute Attribute;
0033 llvm::dwarf::Form Form;
0034 llvm::yaml::Hex64 Value;
0035 };
0036
0037 struct Abbrev {
0038 std::optional<yaml::Hex64> Code;
0039 llvm::dwarf::Tag Tag;
0040 llvm::dwarf::Constants Children;
0041 std::vector<AttributeAbbrev> Attributes;
0042 };
0043
0044 struct AbbrevTable {
0045 std::optional<uint64_t> ID;
0046 std::vector<Abbrev> Table;
0047 };
0048
0049 struct ARangeDescriptor {
0050 llvm::yaml::Hex64 Address;
0051 yaml::Hex64 Length;
0052 };
0053
0054 struct ARange {
0055 dwarf::DwarfFormat Format;
0056 std::optional<yaml::Hex64> Length;
0057 uint16_t Version;
0058 yaml::Hex64 CuOffset;
0059 std::optional<yaml::Hex8> AddrSize;
0060 yaml::Hex8 SegSize;
0061 std::vector<ARangeDescriptor> Descriptors;
0062 };
0063
0064
0065
0066 struct RangeEntry {
0067 llvm::yaml::Hex64 LowOffset;
0068 llvm::yaml::Hex64 HighOffset;
0069 };
0070
0071
0072 struct Ranges {
0073 std::optional<llvm::yaml::Hex64> Offset;
0074 std::optional<llvm::yaml::Hex8> AddrSize;
0075 std::vector<RangeEntry> Entries;
0076 };
0077
0078 struct PubEntry {
0079 llvm::yaml::Hex32 DieOffset;
0080 llvm::yaml::Hex8 Descriptor;
0081 StringRef Name;
0082 };
0083
0084 struct PubSection {
0085 dwarf::DwarfFormat Format;
0086 yaml::Hex64 Length;
0087 uint16_t Version;
0088 uint32_t UnitOffset;
0089 uint32_t UnitSize;
0090 std::vector<PubEntry> Entries;
0091 };
0092
0093 struct FormValue {
0094 llvm::yaml::Hex64 Value;
0095 StringRef CStr;
0096 std::vector<llvm::yaml::Hex8> BlockData;
0097 };
0098
0099 struct Entry {
0100 llvm::yaml::Hex32 AbbrCode;
0101 std::vector<FormValue> Values;
0102 };
0103
0104
0105
0106 struct DWARFContext {
0107 bool IsGNUPubSec = false;
0108 };
0109
0110 struct Unit {
0111 dwarf::DwarfFormat Format;
0112 std::optional<yaml::Hex64> Length;
0113 uint16_t Version;
0114 std::optional<uint8_t> AddrSize;
0115 llvm::dwarf::UnitType Type;
0116 std::optional<uint64_t> AbbrevTableID;
0117 std::optional<yaml::Hex64> AbbrOffset;
0118 yaml::Hex64 TypeSignatureOrDwoID;
0119 yaml::Hex64 TypeOffset;
0120
0121 std::vector<Entry> Entries;
0122 };
0123
0124 struct IdxForm {
0125 dwarf::Index Idx;
0126 dwarf::Form Form;
0127 };
0128
0129 struct DebugNameAbbreviation {
0130 yaml::Hex64 Code;
0131 dwarf::Tag Tag;
0132 std::vector<IdxForm> Indices;
0133 };
0134
0135 struct DebugNameEntry {
0136 yaml::Hex32 NameStrp;
0137 yaml::Hex64 Code;
0138 std::vector<yaml::Hex64> Values;
0139 };
0140
0141 struct DebugNamesSection {
0142 std::vector<DebugNameAbbreviation> Abbrevs;
0143 std::vector<DebugNameEntry> Entries;
0144 };
0145
0146 struct File {
0147 StringRef Name;
0148 uint64_t DirIdx;
0149 uint64_t ModTime;
0150 uint64_t Length;
0151 };
0152
0153 struct LineTableOpcode {
0154 dwarf::LineNumberOps Opcode;
0155 std::optional<uint64_t> ExtLen;
0156 dwarf::LineNumberExtendedOps SubOpcode;
0157 uint64_t Data;
0158 int64_t SData;
0159 File FileEntry;
0160 std::vector<llvm::yaml::Hex8> UnknownOpcodeData;
0161 std::vector<llvm::yaml::Hex64> StandardOpcodeData;
0162 };
0163
0164 struct LineTable {
0165 dwarf::DwarfFormat Format;
0166 std::optional<uint64_t> Length;
0167 uint16_t Version;
0168 std::optional<uint64_t> PrologueLength;
0169 uint8_t MinInstLength;
0170 uint8_t MaxOpsPerInst;
0171 uint8_t DefaultIsStmt;
0172 uint8_t LineBase;
0173 uint8_t LineRange;
0174 std::optional<uint8_t> OpcodeBase;
0175 std::optional<std::vector<uint8_t>> StandardOpcodeLengths;
0176 std::vector<StringRef> IncludeDirs;
0177 std::vector<File> Files;
0178 std::vector<LineTableOpcode> Opcodes;
0179 };
0180
0181 struct SegAddrPair {
0182 yaml::Hex64 Segment;
0183 yaml::Hex64 Address;
0184 };
0185
0186 struct AddrTableEntry {
0187 dwarf::DwarfFormat Format;
0188 std::optional<yaml::Hex64> Length;
0189 yaml::Hex16 Version;
0190 std::optional<yaml::Hex8> AddrSize;
0191 yaml::Hex8 SegSelectorSize;
0192 std::vector<SegAddrPair> SegAddrPairs;
0193 };
0194
0195 struct StringOffsetsTable {
0196 dwarf::DwarfFormat Format;
0197 std::optional<yaml::Hex64> Length;
0198 yaml::Hex16 Version;
0199 yaml::Hex16 Padding;
0200 std::vector<yaml::Hex64> Offsets;
0201 };
0202
0203 struct DWARFOperation {
0204 dwarf::LocationAtom Operator;
0205 std::vector<yaml::Hex64> Values;
0206 };
0207
0208 struct RnglistEntry {
0209 dwarf::RnglistEntries Operator;
0210 std::vector<yaml::Hex64> Values;
0211 };
0212
0213 struct LoclistEntry {
0214 dwarf::LoclistEntries Operator;
0215 std::vector<yaml::Hex64> Values;
0216 std::optional<yaml::Hex64> DescriptionsLength;
0217 std::vector<DWARFOperation> Descriptions;
0218 };
0219
0220 template <typename EntryType> struct ListEntries {
0221 std::optional<std::vector<EntryType>> Entries;
0222 std::optional<yaml::BinaryRef> Content;
0223 };
0224
0225 template <typename EntryType> struct ListTable {
0226 dwarf::DwarfFormat Format;
0227 std::optional<yaml::Hex64> Length;
0228 yaml::Hex16 Version;
0229 std::optional<yaml::Hex8> AddrSize;
0230 yaml::Hex8 SegSelectorSize;
0231 std::optional<uint32_t> OffsetEntryCount;
0232 std::optional<std::vector<yaml::Hex64>> Offsets;
0233 std::vector<ListEntries<EntryType>> Lists;
0234 };
0235
0236 struct Data {
0237 bool IsLittleEndian;
0238 bool Is64BitAddrSize;
0239 std::vector<AbbrevTable> DebugAbbrev;
0240 std::optional<std::vector<StringRef>> DebugStrings;
0241 std::optional<std::vector<StringOffsetsTable>> DebugStrOffsets;
0242 std::optional<std::vector<ARange>> DebugAranges;
0243 std::optional<std::vector<Ranges>> DebugRanges;
0244 std::optional<std::vector<AddrTableEntry>> DebugAddr;
0245 std::optional<PubSection> PubNames;
0246 std::optional<PubSection> PubTypes;
0247
0248 std::optional<PubSection> GNUPubNames;
0249 std::optional<PubSection> GNUPubTypes;
0250
0251 std::vector<Unit> Units;
0252
0253 std::vector<LineTable> DebugLines;
0254 std::optional<std::vector<ListTable<RnglistEntry>>> DebugRnglists;
0255 std::optional<std::vector<ListTable<LoclistEntry>>> DebugLoclists;
0256 std::optional<DebugNamesSection> DebugNames;
0257
0258 bool isEmpty() const;
0259
0260 SetVector<StringRef> getNonEmptySectionNames() const;
0261
0262 struct AbbrevTableInfo {
0263 uint64_t Index;
0264 uint64_t Offset;
0265 };
0266 Expected<AbbrevTableInfo> getAbbrevTableInfoByID(uint64_t ID) const;
0267 StringRef getAbbrevTableContentByIndex(uint64_t Index) const;
0268
0269 private:
0270 mutable std::unordered_map<uint64_t, AbbrevTableInfo> AbbrevTableInfoMap;
0271 mutable std::unordered_map<uint64_t, std::string> AbbrevTableContents;
0272 };
0273
0274 }
0275 }
0276
0277 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::AttributeAbbrev)
0278 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Abbrev)
0279 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::AbbrevTable)
0280 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::ARangeDescriptor)
0281 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::ARange)
0282 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::RangeEntry)
0283 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Ranges)
0284 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::PubEntry)
0285 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Unit)
0286 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::FormValue)
0287 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Entry)
0288 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::File)
0289 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::LineTable)
0290 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::LineTableOpcode)
0291 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::SegAddrPair)
0292 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::AddrTableEntry)
0293 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::StringOffsetsTable)
0294 LLVM_YAML_IS_SEQUENCE_VECTOR(
0295 llvm::DWARFYAML::ListTable<DWARFYAML::RnglistEntry>)
0296 LLVM_YAML_IS_SEQUENCE_VECTOR(
0297 llvm::DWARFYAML::ListEntries<DWARFYAML::RnglistEntry>)
0298 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::RnglistEntry)
0299 LLVM_YAML_IS_SEQUENCE_VECTOR(
0300 llvm::DWARFYAML::ListTable<DWARFYAML::LoclistEntry>)
0301 LLVM_YAML_IS_SEQUENCE_VECTOR(
0302 llvm::DWARFYAML::ListEntries<DWARFYAML::LoclistEntry>)
0303 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::LoclistEntry)
0304 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::DWARFOperation)
0305 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::DebugNameEntry)
0306 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::DebugNameAbbreviation)
0307 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::IdxForm)
0308
0309 namespace llvm {
0310 namespace yaml {
0311
0312 template <> struct MappingTraits<DWARFYAML::Data> {
0313 static void mapping(IO &IO, DWARFYAML::Data &DWARF);
0314 };
0315
0316 template <> struct MappingTraits<DWARFYAML::AbbrevTable> {
0317 static void mapping(IO &IO, DWARFYAML::AbbrevTable &AbbrevTable);
0318 };
0319
0320 template <> struct MappingTraits<DWARFYAML::Abbrev> {
0321 static void mapping(IO &IO, DWARFYAML::Abbrev &Abbrev);
0322 };
0323
0324 template <> struct MappingTraits<DWARFYAML::AttributeAbbrev> {
0325 static void mapping(IO &IO, DWARFYAML::AttributeAbbrev &AttAbbrev);
0326 };
0327
0328 template <> struct MappingTraits<DWARFYAML::ARangeDescriptor> {
0329 static void mapping(IO &IO, DWARFYAML::ARangeDescriptor &Descriptor);
0330 };
0331
0332 template <> struct MappingTraits<DWARFYAML::ARange> {
0333 static void mapping(IO &IO, DWARFYAML::ARange &ARange);
0334 };
0335
0336 template <> struct MappingTraits<DWARFYAML::RangeEntry> {
0337 static void mapping(IO &IO, DWARFYAML::RangeEntry &Entry);
0338 };
0339
0340 template <> struct MappingTraits<DWARFYAML::Ranges> {
0341 static void mapping(IO &IO, DWARFYAML::Ranges &Ranges);
0342 };
0343
0344 template <> struct MappingTraits<DWARFYAML::PubEntry> {
0345 static void mapping(IO &IO, DWARFYAML::PubEntry &Entry);
0346 };
0347
0348 template <> struct MappingTraits<DWARFYAML::PubSection> {
0349 static void mapping(IO &IO, DWARFYAML::PubSection &Section);
0350 };
0351
0352 template <> struct MappingTraits<DWARFYAML::Unit> {
0353 static void mapping(IO &IO, DWARFYAML::Unit &Unit);
0354 };
0355
0356 template <> struct MappingTraits<DWARFYAML::DebugNamesSection> {
0357 static void mapping(IO &IO, DWARFYAML::DebugNamesSection &);
0358 };
0359 template <> struct MappingTraits<DWARFYAML::DebugNameEntry> {
0360 static void mapping(IO &IO, DWARFYAML::DebugNameEntry &);
0361 };
0362 template <> struct MappingTraits<DWARFYAML::DebugNameAbbreviation> {
0363 static void mapping(IO &IO, DWARFYAML::DebugNameAbbreviation &);
0364 };
0365 template <> struct MappingTraits<DWARFYAML::IdxForm> {
0366 static void mapping(IO &IO, DWARFYAML::IdxForm &);
0367 };
0368
0369 template <> struct MappingTraits<DWARFYAML::Entry> {
0370 static void mapping(IO &IO, DWARFYAML::Entry &Entry);
0371 };
0372
0373 template <> struct MappingTraits<DWARFYAML::FormValue> {
0374 static void mapping(IO &IO, DWARFYAML::FormValue &FormValue);
0375 };
0376
0377 template <> struct MappingTraits<DWARFYAML::File> {
0378 static void mapping(IO &IO, DWARFYAML::File &File);
0379 };
0380
0381 template <> struct MappingTraits<DWARFYAML::LineTableOpcode> {
0382 static void mapping(IO &IO, DWARFYAML::LineTableOpcode &LineTableOpcode);
0383 };
0384
0385 template <> struct MappingTraits<DWARFYAML::LineTable> {
0386 static void mapping(IO &IO, DWARFYAML::LineTable &LineTable);
0387 };
0388
0389 template <> struct MappingTraits<DWARFYAML::SegAddrPair> {
0390 static void mapping(IO &IO, DWARFYAML::SegAddrPair &SegAddrPair);
0391 };
0392
0393 template <> struct MappingTraits<DWARFYAML::DWARFOperation> {
0394 static void mapping(IO &IO, DWARFYAML::DWARFOperation &DWARFOperation);
0395 };
0396
0397 template <typename EntryType>
0398 struct MappingTraits<DWARFYAML::ListTable<EntryType>> {
0399 static void mapping(IO &IO, DWARFYAML::ListTable<EntryType> &ListTable);
0400 };
0401
0402 template <typename EntryType>
0403 struct MappingTraits<DWARFYAML::ListEntries<EntryType>> {
0404 static void mapping(IO &IO, DWARFYAML::ListEntries<EntryType> &ListEntries);
0405 static std::string validate(IO &IO,
0406 DWARFYAML::ListEntries<EntryType> &ListEntries);
0407 };
0408
0409 template <> struct MappingTraits<DWARFYAML::RnglistEntry> {
0410 static void mapping(IO &IO, DWARFYAML::RnglistEntry &RnglistEntry);
0411 };
0412
0413 template <> struct MappingTraits<DWARFYAML::LoclistEntry> {
0414 static void mapping(IO &IO, DWARFYAML::LoclistEntry &LoclistEntry);
0415 };
0416
0417 template <> struct MappingTraits<DWARFYAML::AddrTableEntry> {
0418 static void mapping(IO &IO, DWARFYAML::AddrTableEntry &AddrTable);
0419 };
0420
0421 template <> struct MappingTraits<DWARFYAML::StringOffsetsTable> {
0422 static void mapping(IO &IO, DWARFYAML::StringOffsetsTable &StrOffsetsTable);
0423 };
0424
0425 template <> struct ScalarEnumerationTraits<dwarf::DwarfFormat> {
0426 static void enumeration(IO &IO, dwarf::DwarfFormat &Format) {
0427 IO.enumCase(Format, "DWARF32", dwarf::DWARF32);
0428 IO.enumCase(Format, "DWARF64", dwarf::DWARF64);
0429 }
0430 };
0431
0432 #define HANDLE_DW_TAG(unused, name, unused2, unused3, unused4) \
0433 io.enumCase(value, "DW_TAG_" #name, dwarf::DW_TAG_##name);
0434
0435 template <> struct ScalarEnumerationTraits<dwarf::Tag> {
0436 static void enumeration(IO &io, dwarf::Tag &value) {
0437 #include "llvm/BinaryFormat/Dwarf.def"
0438 io.enumFallback<Hex16>(value);
0439 }
0440 };
0441
0442 #define HANDLE_DW_LNS(unused, name) \
0443 io.enumCase(value, "DW_LNS_" #name, dwarf::DW_LNS_##name);
0444
0445 template <> struct ScalarEnumerationTraits<dwarf::LineNumberOps> {
0446 static void enumeration(IO &io, dwarf::LineNumberOps &value) {
0447 #include "llvm/BinaryFormat/Dwarf.def"
0448 io.enumFallback<Hex8>(value);
0449 }
0450 };
0451
0452 #define HANDLE_DW_LNE(unused, name) \
0453 io.enumCase(value, "DW_LNE_" #name, dwarf::DW_LNE_##name);
0454
0455 template <> struct ScalarEnumerationTraits<dwarf::LineNumberExtendedOps> {
0456 static void enumeration(IO &io, dwarf::LineNumberExtendedOps &value) {
0457 #include "llvm/BinaryFormat/Dwarf.def"
0458 io.enumFallback<Hex16>(value);
0459 }
0460 };
0461
0462 #define HANDLE_DW_AT(unused, name, unused2, unused3) \
0463 io.enumCase(value, "DW_AT_" #name, dwarf::DW_AT_##name);
0464
0465 template <> struct ScalarEnumerationTraits<dwarf::Attribute> {
0466 static void enumeration(IO &io, dwarf::Attribute &value) {
0467 #include "llvm/BinaryFormat/Dwarf.def"
0468 io.enumFallback<Hex16>(value);
0469 }
0470 };
0471
0472 #define HANDLE_DW_FORM(unused, name, unused2, unused3) \
0473 io.enumCase(value, "DW_FORM_" #name, dwarf::DW_FORM_##name);
0474
0475 template <> struct ScalarEnumerationTraits<dwarf::Form> {
0476 static void enumeration(IO &io, dwarf::Form &value) {
0477 #include "llvm/BinaryFormat/Dwarf.def"
0478 io.enumFallback<Hex16>(value);
0479 }
0480 };
0481
0482 #define HANDLE_DW_IDX(unused, name) \
0483 io.enumCase(value, "DW_IDX_" #name, dwarf::DW_IDX_##name);
0484
0485 template <> struct ScalarEnumerationTraits<dwarf::Index> {
0486 static void enumeration(IO &io, dwarf::Index &value) {
0487 #include "llvm/BinaryFormat/Dwarf.def"
0488 io.enumFallback<Hex16>(value);
0489 }
0490 };
0491
0492 #define HANDLE_DW_UT(unused, name) \
0493 io.enumCase(value, "DW_UT_" #name, dwarf::DW_UT_##name);
0494
0495 template <> struct ScalarEnumerationTraits<dwarf::UnitType> {
0496 static void enumeration(IO &io, dwarf::UnitType &value) {
0497 #include "llvm/BinaryFormat/Dwarf.def"
0498 io.enumFallback<Hex8>(value);
0499 }
0500 };
0501
0502 template <> struct ScalarEnumerationTraits<dwarf::Constants> {
0503 static void enumeration(IO &io, dwarf::Constants &value) {
0504 io.enumCase(value, "DW_CHILDREN_no", dwarf::DW_CHILDREN_no);
0505 io.enumCase(value, "DW_CHILDREN_yes", dwarf::DW_CHILDREN_yes);
0506 io.enumFallback<Hex16>(value);
0507 }
0508 };
0509
0510 #define HANDLE_DW_RLE(unused, name) \
0511 io.enumCase(value, "DW_RLE_" #name, dwarf::DW_RLE_##name);
0512
0513 template <> struct ScalarEnumerationTraits<dwarf::RnglistEntries> {
0514 static void enumeration(IO &io, dwarf::RnglistEntries &value) {
0515 #include "llvm/BinaryFormat/Dwarf.def"
0516 }
0517 };
0518
0519 #define HANDLE_DW_LLE(unused, name) \
0520 io.enumCase(value, "DW_LLE_" #name, dwarf::DW_LLE_##name);
0521
0522 template <> struct ScalarEnumerationTraits<dwarf::LoclistEntries> {
0523 static void enumeration(IO &io, dwarf::LoclistEntries &value) {
0524 #include "llvm/BinaryFormat/Dwarf.def"
0525 }
0526 };
0527
0528 #define HANDLE_DW_OP(id, name, operands, arity, version, vendor) \
0529 io.enumCase(value, "DW_OP_" #name, dwarf::DW_OP_##name);
0530
0531 template <> struct ScalarEnumerationTraits<dwarf::LocationAtom> {
0532 static void enumeration(IO &io, dwarf::LocationAtom &value) {
0533 #include "llvm/BinaryFormat/Dwarf.def"
0534 io.enumFallback<yaml::Hex8>(value);
0535 }
0536 };
0537
0538 }
0539 }
0540
0541 #endif