LLDB  mainline
DWARFBaseDIE.h
Go to the documentation of this file.
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 struct DIERef;
16 class DWARFASTParser;
17 class DWARFAttributes;
18 class DWARFUnit;
20 class DWARFDeclContext;
21 class SymbolFileDWARF;
22 
23 class DWARFBaseDIE {
24 public:
25  DWARFBaseDIE() : m_cu(nullptr), m_die(nullptr) {}
26 
28  : m_cu(cu), m_die(die) {}
29 
31  : m_cu(const_cast<DWARFUnit *>(cu)), m_die(die) {}
32 
34  : m_cu(cu), m_die(const_cast<DWARFDebugInfoEntry *>(die)) {}
35 
37  : m_cu(const_cast<DWARFUnit *>(cu)),
38  m_die(const_cast<DWARFDebugInfoEntry *>(die)) {}
39 
40  // Tests
41  explicit operator bool() const { return IsValid(); }
42 
43  bool IsValid() const { return m_cu && m_die; }
44 
45  bool HasChildren() const;
46 
48 
49  // Accessors
50  SymbolFileDWARF *GetDWARF() const;
51 
52  DWARFUnit *GetCU() const { return m_cu; }
53 
54  DWARFDebugInfoEntry *GetDIE() const { return m_die; }
55 
56  DIERef GetDIERef() const;
57 
59 
61 
62  void Set(DWARFUnit *cu, DWARFDebugInfoEntry *die) {
63  if (cu && die) {
64  m_cu = cu;
65  m_die = die;
66  } else {
67  Clear();
68  }
69  }
70 
71  void Clear() {
72  m_cu = nullptr;
73  m_die = nullptr;
74  }
75 
76  // Get the data that contains the attribute values for this DIE. Support
77  // for .debug_types means that any DIE can have its data either in the
78  // .debug_info or the .debug_types section; this method will return the
79  // correct section data.
80  //
81  // Clients must validate that this object is valid before calling this.
83 
84  // Accessing information about a DIE
85  dw_tag_t Tag() const;
86 
87  const char *GetTagAsCString() const;
88 
89  dw_offset_t GetOffset() const;
90 
91  // Get the LLDB user ID for this DIE. This is often just the DIE offset,
92  // but it might have a SymbolFileDWARF::GetID() in the high 32 bits if
93  // we are doing Darwin DWARF in .o file, or DWARF stand alone debug
94  // info.
95  lldb::user_id_t GetID() const;
96 
97  const char *GetName() const;
98 
100 
101  lldb::ModuleSP GetModule() const;
102 
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 GetAttributeValueAsReference(const dw_attr_t attr,
117  uint64_t fail_value) const;
118 
119  uint64_t GetAttributeValueAsAddress(const dw_attr_t attr,
120  uint64_t fail_value) const;
121 
122  size_t GetAttributes(DWARFAttributes &attributes, uint32_t depth = 0) const;
123 
124 protected:
127 };
128 
129 bool operator==(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs);
130 bool operator!=(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs);
131 
132 #endif // SymbolFileDWARF_DWARFBaseDIE_h_
lldb::ModuleSP GetModule() const
DWARFASTParser * GetDWARFParser() const
lldb::LanguageType GetLanguage() const
DWARFDebugInfoEntry * m_die
Definition: DWARFBaseDIE.h:126
SymbolFileDWARF * GetDWARF() const
size_t GetAttributes(DWARFAttributes &attributes, uint32_t depth=0) const
DWARFUnit * GetCU() const
Definition: DWARFBaseDIE.h:52
DWARFBaseDIE(const DWARFUnit *cu, const DWARFDebugInfoEntry *die)
Definition: DWARFBaseDIE.h:36
uint64_t GetAttributeValueAsReference(const dw_attr_t attr, uint64_t fail_value) const
DWARFUnit * m_cu
Definition: DWARFBaseDIE.h:125
uint64_t GetAttributeValueAsAddress(const dw_attr_t attr, uint64_t fail_value) const
Definition: DIERef.h:18
bool operator!=(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs)
const char * GetTagAsCString() const
A class that describes a compilation unit.
Definition: CompileUnit.h:35
const char * GetAttributeValueAsString(const dw_attr_t attr, const char *fail_value) const
uint64_t user_id_t
Definition: lldb-types.h:84
LanguageType
Programming language type.
uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr, uint64_t fail_value) const
DWARFBaseDIE(DWARFUnit *cu, const DWARFDebugInfoEntry *die)
Definition: DWARFBaseDIE.h:33
DIERef GetDIERef() const
void Clear()
Definition: DWARFBaseDIE.h:71
DWARFDebugInfoEntry * GetDIE() const
Definition: DWARFBaseDIE.h:54
bool operator==(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs)
bool IsValid() const
Definition: DWARFBaseDIE.h:43
dw_tag_t Tag() const
bool HasChildren() const
DWARFBaseDIE(const DWARFUnit *cu, DWARFDebugInfoEntry *die)
Definition: DWARFBaseDIE.h:30
lldb_private::TypeSystem * GetTypeSystem() const
dw_offset_t GetOffset() const
const char * GetName() const
bool Supports_DW_AT_APPLE_objc_complete_type() const
const lldb_private::DWARFDataExtractor & GetData() const
lldb::user_id_t GetID() const
DWARFBaseDIE(DWARFUnit *cu, DWARFDebugInfoEntry *die)
Definition: DWARFBaseDIE.h:27
void Set(DWARFUnit *cu, DWARFDebugInfoEntry *die)
Definition: DWARFBaseDIE.h:62
lldb_private::CompileUnit * GetLLDBCompileUnit() const