| 1 | //===-- DWARFBaseDIE.h -----------------------------------------*- C++ -*-===// |
| 2 | // |
| 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 |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFBASEDIE_H |
| 10 | #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFBASEDIE_H |
| 11 | |
| 12 | #include "lldb/Core/dwarf.h" |
| 13 | #include "lldb/lldb-types.h" |
| 14 | |
| 15 | #include "llvm/Support/Error.h" |
| 16 | #include <optional> |
| 17 | |
| 18 | namespace lldb_private::plugin { |
| 19 | namespace dwarf { |
| 20 | class DIERef; |
| 21 | class DWARFASTParser; |
| 22 | class DWARFAttributes; |
| 23 | class DWARFUnit; |
| 24 | class DWARFDebugInfoEntry; |
| 25 | class DWARFDeclContext; |
| 26 | class SymbolFileDWARF; |
| 27 | class DWARFFormValue; |
| 28 | |
| 29 | class DWARFBaseDIE { |
| 30 | public: |
| 31 | using DWARFFormValue = dwarf::DWARFFormValue; |
| 32 | DWARFBaseDIE() = default; |
| 33 | |
| 34 | DWARFBaseDIE(DWARFUnit *cu, DWARFDebugInfoEntry *die) |
| 35 | : m_cu(cu), m_die(die) {} |
| 36 | |
| 37 | DWARFBaseDIE(const DWARFUnit *cu, DWARFDebugInfoEntry *die) |
| 38 | : m_cu(const_cast<DWARFUnit *>(cu)), m_die(die) {} |
| 39 | |
| 40 | DWARFBaseDIE(DWARFUnit *cu, const DWARFDebugInfoEntry *die) |
| 41 | : m_cu(cu), m_die(const_cast<DWARFDebugInfoEntry *>(die)) {} |
| 42 | |
| 43 | DWARFBaseDIE(const DWARFUnit *cu, const DWARFDebugInfoEntry *die) |
| 44 | : m_cu(const_cast<DWARFUnit *>(cu)), |
| 45 | m_die(const_cast<DWARFDebugInfoEntry *>(die)) {} |
| 46 | |
| 47 | // Tests |
| 48 | explicit operator bool() const { return IsValid(); } |
| 49 | |
| 50 | bool IsValid() const { return m_cu && m_die; } |
| 51 | |
| 52 | bool HasChildren() const; |
| 53 | |
| 54 | bool Supports_DW_AT_APPLE_objc_complete_type() const; |
| 55 | |
| 56 | // Accessors |
| 57 | SymbolFileDWARF *GetDWARF() const; |
| 58 | |
| 59 | DWARFUnit *GetCU() const { return m_cu; } |
| 60 | |
| 61 | DWARFDebugInfoEntry *GetDIE() const { return m_die; } |
| 62 | |
| 63 | std::optional<DIERef> GetDIERef() const; |
| 64 | |
| 65 | void Set(DWARFUnit *cu, DWARFDebugInfoEntry *die) { |
| 66 | if (cu && die) { |
| 67 | m_cu = cu; |
| 68 | m_die = die; |
| 69 | } else { |
| 70 | Clear(); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | void Clear() { |
| 75 | m_cu = nullptr; |
| 76 | m_die = nullptr; |
| 77 | } |
| 78 | |
| 79 | // Get the data that contains the attribute values for this DIE. Support |
| 80 | // for .debug_types means that any DIE can have its data either in the |
| 81 | // .debug_info or the .debug_types section; this method will return the |
| 82 | // correct section data. |
| 83 | // |
| 84 | // Clients must validate that this object is valid before calling this. |
| 85 | const DWARFDataExtractor &GetData() const; |
| 86 | |
| 87 | // Accessing information about a DIE |
| 88 | dw_tag_t Tag() const; |
| 89 | |
| 90 | dw_offset_t GetOffset() const; |
| 91 | |
| 92 | // Get the LLDB user ID for this DIE. This is often just the DIE offset, |
| 93 | // but it might have a SymbolFileDWARF::GetID() in the high 32 bits if |
| 94 | // we are doing Darwin DWARF in .o file, or DWARF stand alone debug |
| 95 | // info. |
| 96 | lldb::user_id_t GetID() const; |
| 97 | |
| 98 | const char *GetName() const; |
| 99 | |
| 100 | lldb::ModuleSP GetModule() const; |
| 101 | |
| 102 | // Getting attribute values from the DIE. |
| 103 | // |
| 104 | // GetAttributeValueAsXXX() functions should only be used if you are |
| 105 | // looking for one or two attributes on a DIE. If you are trying to |
| 106 | // parse all attributes, use GetAttributes (...) instead |
| 107 | const char *GetAttributeValueAsString(const dw_attr_t attr, |
| 108 | const char *fail_value) const; |
| 109 | |
| 110 | uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr, |
| 111 | uint64_t fail_value) const; |
| 112 | |
| 113 | std::optional<uint64_t> |
| 114 | GetAttributeValueAsOptionalUnsigned(const dw_attr_t attr) const; |
| 115 | |
| 116 | uint64_t GetAttributeValueAsAddress(const dw_attr_t attr, |
| 117 | uint64_t fail_value) const; |
| 118 | |
| 119 | enum class Recurse : bool { no, yes }; |
| 120 | DWARFAttributes GetAttributes(Recurse recurse = Recurse::yes) const; |
| 121 | |
| 122 | // The following methods use LLVM naming convension in order to be are used by |
| 123 | // LLVM libraries. |
| 124 | dw_tag_t getTag() const { return Tag(); } |
| 125 | |
| 126 | const char *getShortName() const { return GetName(); } |
| 127 | |
| 128 | protected: |
| 129 | DWARFUnit *m_cu = nullptr; |
| 130 | DWARFDebugInfoEntry *m_die = nullptr; |
| 131 | }; |
| 132 | |
| 133 | bool operator==(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs); |
| 134 | bool operator!=(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs); |
| 135 | } // namespace dwarf |
| 136 | } // namespace lldb_private::plugin |
| 137 | |
| 138 | #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFBASEDIE_H |
| 139 | |