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