DWARFBaseDIE.h revision 341825
1//===-- DWARFBaseDIE.h -----------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef SymbolFileDWARF_DWARFBaseDIE_h_ 11#define SymbolFileDWARF_DWARFBaseDIE_h_ 12 13#include "lldb/Core/dwarf.h" 14#include "lldb/lldb-types.h" 15 16struct DIERef; 17class DWARFASTParser; 18class DWARFAttributes; 19class DWARFUnit; 20class DWARFDebugInfoEntry; 21class DWARFDeclContext; 22class DWARFDIECollection; 23class SymbolFileDWARF; 24 25class DWARFBaseDIE { 26public: 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 //---------------------------------------------------------------------- 43 // Tests 44 //---------------------------------------------------------------------- 45 explicit operator bool() const { return IsValid(); } 46 47 bool IsValid() const { return m_cu && m_die; } 48 49 bool HasChildren() const; 50 51 bool Supports_DW_AT_APPLE_objc_complete_type() const; 52 53 //---------------------------------------------------------------------- 54 // Accessors 55 //---------------------------------------------------------------------- 56 SymbolFileDWARF *GetDWARF() const; 57 58 DWARFUnit *GetCU() const { return m_cu; } 59 60 DWARFDebugInfoEntry *GetDIE() const { return m_die; } 61 62 DIERef GetDIERef() const; 63 64 lldb_private::TypeSystem *GetTypeSystem() const; 65 66 DWARFASTParser *GetDWARFParser() const; 67 68 void Set(DWARFUnit *cu, DWARFDebugInfoEntry *die) { 69 if (cu && die) { 70 m_cu = cu; 71 m_die = die; 72 } else { 73 Clear(); 74 } 75 } 76 77 void Clear() { 78 m_cu = nullptr; 79 m_die = nullptr; 80 } 81 82 //---------------------------------------------------------------------- 83 // Get the data that contains the attribute values for this DIE. Support 84 // for .debug_types means that any DIE can have its data either in the 85 // .debug_info or the .debug_types section; this method will return the 86 // correct section data. 87 // 88 // Clients must validate that this object is valid before calling this. 89 //---------------------------------------------------------------------- 90 const lldb_private::DWARFDataExtractor &GetData() const; 91 92 //---------------------------------------------------------------------- 93 // Accessing information about a DIE 94 //---------------------------------------------------------------------- 95 dw_tag_t Tag() const; 96 97 const char *GetTagAsCString() const; 98 99 dw_offset_t GetOffset() const; 100 101 dw_offset_t GetCompileUnitRelativeOffset() const; 102 103 //---------------------------------------------------------------------- 104 // Get the LLDB user ID for this DIE. This is often just the DIE offset, 105 // but it might have a SymbolFileDWARF::GetID() in the high 32 bits if 106 // we are doing Darwin DWARF in .o file, or DWARF stand alone debug 107 // info. 108 //---------------------------------------------------------------------- 109 lldb::user_id_t GetID() const; 110 111 const char *GetName() const; 112 113 lldb::LanguageType GetLanguage() const; 114 115 lldb::ModuleSP GetModule() const; 116 117 lldb_private::CompileUnit *GetLLDBCompileUnit() const; 118 119 //---------------------------------------------------------------------- 120 // Getting attribute values from the DIE. 121 // 122 // GetAttributeValueAsXXX() functions should only be used if you are 123 // looking for one or two attributes on a DIE. If you are trying to 124 // parse all attributes, use GetAttributes (...) instead 125 //---------------------------------------------------------------------- 126 const char *GetAttributeValueAsString(const dw_attr_t attr, 127 const char *fail_value) const; 128 129 uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr, 130 uint64_t fail_value) const; 131 132 int64_t GetAttributeValueAsSigned(const dw_attr_t attr, 133 int64_t fail_value) const; 134 135 uint64_t GetAttributeValueAsReference(const dw_attr_t attr, 136 uint64_t fail_value) const; 137 138 uint64_t GetAttributeValueAsAddress(const dw_attr_t attr, 139 uint64_t fail_value) const; 140 141 size_t GetAttributes(DWARFAttributes &attributes, uint32_t depth = 0) const; 142 143 //---------------------------------------------------------------------- 144 // Pretty printing 145 //---------------------------------------------------------------------- 146 147 void Dump(lldb_private::Stream *s, const uint32_t recurse_depth) const; 148 149protected: 150 DWARFUnit *m_cu; 151 DWARFDebugInfoEntry *m_die; 152}; 153 154bool operator==(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs); 155bool operator!=(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs); 156 157#endif // SymbolFileDWARF_DWARFBaseDIE_h_ 158