//===- 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/StringRef.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/Support/YAMLTraits.h" #include #include namespace llvm { namespace DWARFYAML { struct InitialLength { uint32_t TotalLength; uint64_t TotalLength64; bool isDWARF64() const { return TotalLength == UINT32_MAX; } uint64_t getLength() const { return isDWARF64() ? TotalLength64 : TotalLength; } void setLength(uint64_t Len) { if (Len >= (uint64_t)UINT32_MAX) { TotalLength64 = Len; TotalLength = UINT32_MAX; } else { TotalLength = Len; } } }; struct AttributeAbbrev { llvm::dwarf::Attribute Attribute; llvm::dwarf::Form Form; llvm::yaml::Hex64 Value; // Some DWARF5 attributes have values }; struct Abbrev { llvm::yaml::Hex32 Code; llvm::dwarf::Tag Tag; llvm::dwarf::Constants Children; std::vector Attributes; // XXX BINARYEN: Represent the binary offset in the abbreviation section for // this abbreviation's list. The abbreviation section has multiple lists, // each null-terminated, and those lists are what are referred to by compile // units by offset. We need to match the offset in a compile unit to the // abbreviation at that offset (which must be the beginning of an // abbreviation list, that is, either the very first element, or after a null // terminator). All abbreviations in the same list have the same offset // (DWARFAbbreviationDeclarationSet does not track anything else, and we don't // need it). uint64_t ListOffset; }; struct ARangeDescriptor { llvm::yaml::Hex64 Address; uint64_t Length; }; struct ARange { InitialLength Length; uint16_t Version; uint32_t CuOffset; uint8_t AddrSize; uint8_t SegSize; std::vector Descriptors; }; // XXX BINARYEN <-- struct Range { uint64_t Start; uint64_t End; uint64_t SectionIndex; // XXX ? }; struct Loc { uint32_t Start; uint32_t End; std::vector Location; uint64_t CompileUnitOffset; }; // XXX BINARYEN --> struct PubEntry { llvm::yaml::Hex32 DieOffset; llvm::yaml::Hex8 Descriptor; StringRef Name; }; struct PubSection { InitialLength Length; uint16_t Version; uint32_t UnitOffset; uint32_t UnitSize; bool IsGNUStyle = false; std::vector Entries; }; struct FormValue { llvm::yaml::Hex64 Value; StringRef CStr; std::vector BlockData; }; struct Entry { llvm::yaml::Hex32 AbbrCode; std::vector Values; }; struct Unit { InitialLength Length; uint16_t Version; llvm::dwarf::UnitType Type; // Added in DWARF 5 uint32_t AbbrOffset; uint8_t AddrSize; bool AddrSizeChanged = false; // XXX BINARYEN std::vector Entries; }; struct File { StringRef Name; uint64_t DirIdx; uint64_t ModTime; uint64_t Length; }; struct LineTableOpcode { dwarf::LineNumberOps Opcode; uint64_t ExtLen; dwarf::LineNumberExtendedOps SubOpcode; uint64_t Data; int64_t SData; File FileEntry; std::vector UnknownOpcodeData; std::vector StandardOpcodeData; }; struct LineTable { InitialLength Length; uint16_t Version; uint64_t PrologueLength; uint8_t MinInstLength; uint8_t MaxOpsPerInst; uint8_t DefaultIsStmt; int8_t LineBase; // XXX BINARYEN uint8_t LineRange; uint8_t OpcodeBase; std::vector StandardOpcodeLengths; std::vector IncludeDirs; std::vector Files; std::vector Opcodes; }; struct Data { bool IsLittleEndian; std::vector AbbrevDecls; std::vector DebugStrings; std::vector ARanges; std::vector Ranges; // XXX BINARYEN std::vector Locs; // XXX BINARYEN PubSection PubNames; PubSection PubTypes; PubSection GNUPubNames; PubSection GNUPubTypes; std::vector CompileUnits; std::vector DebugLines; bool isEmpty() const; }; } // 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::ARangeDescriptor) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::ARange) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Range) // XXX BINARYEN LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Loc) // XXX BINARYEN 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) namespace llvm { namespace yaml { template <> struct MappingTraits { static void mapping(IO &IO, DWARFYAML::Data &DWARF); }; 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 &Range); }; template <> struct MappingTraits { // XXX BINARYEN static void mapping(IO &IO, DWARFYAML::Range &Range); }; template <> struct MappingTraits { // XXX BINARYEN static void mapping(IO &IO, DWARFYAML::Loc &Loc); }; 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::InitialLength &DWARF); }; #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); } }; } // end namespace yaml } // end namespace llvm #endif // LLVM_OBJECTYAML_DWARFYAML_H