//===- DWARFYAML.h - DWARF YAMLIO implementation ----------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// /// \file /// This file declares classes for handling the YAML representation /// of DWARF Debug Info. /// //===----------------------------------------------------------------------===// #ifndef LLVM_OBJECTYAML_DWARFYAML_H #define LLVM_OBJECTYAML_DWARFYAML_H #include "llvm/ADT/SetVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/ObjectYAML/YAML.h" #include "llvm/Support/YAMLTraits.h" #include #include #include namespace llvm { namespace DWARFYAML { struct AttributeAbbrev { llvm::dwarf::Attribute Attribute; llvm::dwarf::Form Form; llvm::yaml::Hex64 Value; // Some DWARF5 attributes have values }; struct Abbrev { Optional Code; llvm::dwarf::Tag Tag; llvm::dwarf::Constants Children; std::vector Attributes; }; struct AbbrevTable { Optional ID; std::vector Table; }; struct ARangeDescriptor { llvm::yaml::Hex64 Address; yaml::Hex64 Length; }; struct ARange { dwarf::DwarfFormat Format; Optional Length; uint16_t Version; yaml::Hex64 CuOffset; Optional AddrSize; yaml::Hex8 SegSize; std::vector Descriptors; }; /// Class that describes a range list entry, or a base address selection entry /// within a range list in the .debug_ranges section. struct RangeEntry { llvm::yaml::Hex64 LowOffset; llvm::yaml::Hex64 HighOffset; }; /// Class that describes a single range list inside the .debug_ranges section. struct Ranges { Optional Offset; Optional AddrSize; std::vector Entries; }; struct PubEntry { llvm::yaml::Hex32 DieOffset; llvm::yaml::Hex8 Descriptor; StringRef Name; }; struct PubSection { dwarf::DwarfFormat Format; yaml::Hex64 Length; uint16_t Version; uint32_t UnitOffset; uint32_t UnitSize; std::vector Entries; }; struct FormValue { llvm::yaml::Hex64 Value; StringRef CStr; std::vector BlockData; }; struct Entry { llvm::yaml::Hex32 AbbrCode; std::vector Values; }; /// Class that contains helpful context information when mapping YAML into DWARF /// data structures. struct DWARFContext { bool IsGNUPubSec = false; }; struct Unit { dwarf::DwarfFormat Format; Optional Length; uint16_t Version; Optional AddrSize; llvm::dwarf::UnitType Type; // Added in DWARF 5 Optional AbbrevTableID; Optional AbbrOffset; std::vector Entries; }; struct File { StringRef Name; uint64_t DirIdx; uint64_t ModTime; uint64_t Length; }; struct LineTableOpcode { dwarf::LineNumberOps Opcode; Optional ExtLen; dwarf::LineNumberExtendedOps SubOpcode; uint64_t Data; int64_t SData; File FileEntry; std::vector UnknownOpcodeData; std::vector StandardOpcodeData; }; struct LineTable { dwarf::DwarfFormat Format; Optional Length; uint16_t Version; Optional PrologueLength; uint8_t MinInstLength; uint8_t MaxOpsPerInst; uint8_t DefaultIsStmt; uint8_t LineBase; uint8_t LineRange; Optional OpcodeBase; Optional> StandardOpcodeLengths; std::vector IncludeDirs; std::vector Files; std::vector Opcodes; }; struct SegAddrPair { yaml::Hex64 Segment; yaml::Hex64 Address; }; struct AddrTableEntry { dwarf::DwarfFormat Format; Optional Length; yaml::Hex16 Version; Optional AddrSize; yaml::Hex8 SegSelectorSize; std::vector SegAddrPairs; }; struct StringOffsetsTable { dwarf::DwarfFormat Format; Optional Length; yaml::Hex16 Version; yaml::Hex16 Padding; std::vector Offsets; }; struct DWARFOperation { dwarf::LocationAtom Operator; std::vector Values; }; struct RnglistEntry { dwarf::RnglistEntries Operator; std::vector Values; }; struct LoclistEntry { dwarf::LoclistEntries Operator; std::vector Values; Optional DescriptionsLength; std::vector Descriptions; }; template struct ListEntries { Optional> Entries; Optional Content; }; template struct ListTable { dwarf::DwarfFormat Format; Optional Length; yaml::Hex16 Version; Optional AddrSize; yaml::Hex8 SegSelectorSize; Optional OffsetEntryCount; Optional> Offsets; std::vector> Lists; }; struct Data { bool IsLittleEndian; bool Is64BitAddrSize; std::vector DebugAbbrev; Optional> DebugStrings; Optional> DebugStrOffsets; Optional> DebugAranges; Optional> DebugRanges; Optional> DebugAddr; Optional PubNames; Optional PubTypes; Optional GNUPubNames; Optional GNUPubTypes; std::vector CompileUnits; std::vector DebugLines; Optional>> DebugRnglists; Optional>> DebugLoclists; bool isEmpty() const; SetVector getNonEmptySectionNames() const; struct AbbrevTableInfo { uint64_t Index; uint64_t Offset; }; Expected getAbbrevTableInfoByID(uint64_t ID) const; StringRef getAbbrevTableContentByIndex(uint64_t Index) const; private: mutable std::unordered_map AbbrevTableInfoMap; mutable std::unordered_map AbbrevTableContents; }; } // end namespace DWARFYAML } // end namespace llvm LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::AttributeAbbrev) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Abbrev) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::AbbrevTable) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::ARangeDescriptor) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::ARange) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::RangeEntry) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Ranges) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::PubEntry) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Unit) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::FormValue) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Entry) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::File) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::LineTable) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::LineTableOpcode) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::SegAddrPair) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::AddrTableEntry) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::StringOffsetsTable) LLVM_YAML_IS_SEQUENCE_VECTOR( llvm::DWARFYAML::ListTable) LLVM_YAML_IS_SEQUENCE_VECTOR( llvm::DWARFYAML::ListEntries) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::RnglistEntry) LLVM_YAML_IS_SEQUENCE_VECTOR( llvm::DWARFYAML::ListTable) LLVM_YAML_IS_SEQUENCE_VECTOR( llvm::DWARFYAML::ListEntries) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::LoclistEntry) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::DWARFOperation) namespace llvm { namespace yaml { template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::Data &DWARF); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::AbbrevTable &AbbrevTable); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::Abbrev &Abbrev); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::AttributeAbbrev &AttAbbrev); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::ARangeDescriptor &Descriptor); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::ARange &ARange); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::RangeEntry &Entry); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::Ranges &Ranges); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::PubEntry &Entry); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::PubSection &Section); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::Unit &Unit); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::Entry &Entry); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::FormValue &FormValue); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::File &File); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::LineTableOpcode &LineTableOpcode); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::LineTable &LineTable); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::SegAddrPair &SegAddrPair); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::DWARFOperation &DWARFOperation); }; template struct MappingTraits> { static void mapping(IO &IO, DWARFYAML::ListTable &ListTable); }; template struct MappingTraits> { static void mapping(IO &IO, DWARFYAML::ListEntries &ListEntries); static std::string validate(IO &IO, DWARFYAML::ListEntries &ListEntries); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::RnglistEntry &RnglistEntry); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::LoclistEntry &LoclistEntry); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::AddrTableEntry &AddrTable); }; template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::StringOffsetsTable &StrOffsetsTable); }; template <> struct ScalarEnumerationTraits { static void enumeration(IO &IO, dwarf::DwarfFormat &Format) { IO.enumCase(Format, "DWARF32", dwarf::DWARF32); IO.enumCase(Format, "DWARF64", dwarf::DWARF64); } }; #define HANDLE_DW_TAG(unused, name, unused2, unused3, unused4) \ io.enumCase(value, "DW_TAG_" #name, dwarf::DW_TAG_##name); template <> struct ScalarEnumerationTraits { static void enumeration(IO &io, dwarf::Tag &value) { #include "llvm/BinaryFormat/Dwarf.def" io.enumFallback(value); } }; #define HANDLE_DW_LNS(unused, name) \ io.enumCase(value, "DW_LNS_" #name, dwarf::DW_LNS_##name); template <> struct ScalarEnumerationTraits { static void enumeration(IO &io, dwarf::LineNumberOps &value) { #include "llvm/BinaryFormat/Dwarf.def" io.enumFallback(value); } }; #define HANDLE_DW_LNE(unused, name) \ io.enumCase(value, "DW_LNE_" #name, dwarf::DW_LNE_##name); template <> struct ScalarEnumerationTraits { static void enumeration(IO &io, dwarf::LineNumberExtendedOps &value) { #include "llvm/BinaryFormat/Dwarf.def" io.enumFallback(value); } }; #define HANDLE_DW_AT(unused, name, unused2, unused3) \ io.enumCase(value, "DW_AT_" #name, dwarf::DW_AT_##name); template <> struct ScalarEnumerationTraits { static void enumeration(IO &io, dwarf::Attribute &value) { #include "llvm/BinaryFormat/Dwarf.def" io.enumFallback(value); } }; #define HANDLE_DW_FORM(unused, name, unused2, unused3) \ io.enumCase(value, "DW_FORM_" #name, dwarf::DW_FORM_##name); template <> struct ScalarEnumerationTraits { static void enumeration(IO &io, dwarf::Form &value) { #include "llvm/BinaryFormat/Dwarf.def" io.enumFallback(value); } }; #define HANDLE_DW_UT(unused, name) \ io.enumCase(value, "DW_UT_" #name, dwarf::DW_UT_##name); template <> struct ScalarEnumerationTraits { static void enumeration(IO &io, dwarf::UnitType &value) { #include "llvm/BinaryFormat/Dwarf.def" io.enumFallback(value); } }; template <> struct ScalarEnumerationTraits { static void enumeration(IO &io, dwarf::Constants &value) { io.enumCase(value, "DW_CHILDREN_no", dwarf::DW_CHILDREN_no); io.enumCase(value, "DW_CHILDREN_yes", dwarf::DW_CHILDREN_yes); io.enumFallback(value); } }; #define HANDLE_DW_RLE(unused, name) \ io.enumCase(value, "DW_RLE_" #name, dwarf::DW_RLE_##name); template <> struct ScalarEnumerationTraits { static void enumeration(IO &io, dwarf::RnglistEntries &value) { #include "llvm/BinaryFormat/Dwarf.def" } }; #define HANDLE_DW_LLE(unused, name) \ io.enumCase(value, "DW_LLE_" #name, dwarf::DW_LLE_##name); template <> struct ScalarEnumerationTraits { static void enumeration(IO &io, dwarf::LoclistEntries &value) { #include "llvm/BinaryFormat/Dwarf.def" } }; #define HANDLE_DW_OP(id, name, version, vendor) \ io.enumCase(value, "DW_OP_" #name, dwarf::DW_OP_##name); template <> struct ScalarEnumerationTraits { static void enumeration(IO &io, dwarf::LocationAtom &value) { #include "llvm/BinaryFormat/Dwarf.def" io.enumFallback(value); } }; } // end namespace yaml } // end namespace llvm #endif // LLVM_OBJECTYAML_DWARFYAML_H