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