LLDB  mainline
DWARFDebugInfoEntry.h
Go to the documentation of this file.
1 //===-- DWARFDebugInfoEntry.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_DWARFDEBUGINFOENTRY_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGINFOENTRY_H
11 
12 #include "SymbolFileDWARF.h"
13 #include "llvm/ADT/SmallVector.h"
14 
16 #include "DWARFDebugAbbrev.h"
17 #include "DWARFDebugRanges.h"
18 #include <map>
19 #include <set>
20 #include <vector>
21 
22 class DWARFDeclContext;
23 
24 #define DIE_SIBLING_IDX_BITSIZE 31
25 
26 /// DWARFDebugInfoEntry objects assume that they are living in one big
27 /// vector and do pointer arithmetic on their this pointers. Don't
28 /// pass them by value. Due to the way they are constructed in a
29 /// std::vector, we cannot delete the copy constructor.
31 public:
32  typedef std::vector<DWARFDebugInfoEntry> collection;
33  typedef collection::iterator iterator;
34  typedef collection::const_iterator const_iterator;
35 
38  m_has_children(false), m_abbr_idx(0), m_tag(llvm::dwarf::DW_TAG_null) {}
39 
40  explicit operator bool() const { return m_offset != DW_INVALID_OFFSET; }
41  bool operator==(const DWARFDebugInfoEntry &rhs) const;
42  bool operator!=(const DWARFDebugInfoEntry &rhs) const;
43 
45  DWARFDebugAranges *debug_aranges) const;
46 
48  const DWARFUnit *cu, lldb::offset_t *offset_ptr);
49 
50  size_t GetAttributes(const DWARFUnit *cu,
51  DWARFAttributes &attrs,
52  uint32_t curr_depth = 0)
53  const; // "curr_depth" for internal use only, don't set this yourself!!!
54 
56  GetAttributeValue(const DWARFUnit *cu, const dw_attr_t attr,
57  DWARFFormValue &formValue,
58  dw_offset_t *end_attr_offset_ptr = nullptr,
59  bool check_specification_or_abstract_origin = false) const;
60 
61  const char *GetAttributeValueAsString(
62  const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value,
63  bool check_specification_or_abstract_origin = false) const;
64 
66  const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value,
67  bool check_specification_or_abstract_origin = false) const;
68 
70  const DWARFUnit *cu, const dw_attr_t attr,
71  bool check_specification_or_abstract_origin = false) const;
72 
74  const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value,
75  bool check_specification_or_abstract_origin = false) const;
76 
77  dw_addr_t
78  GetAttributeHighPC(const DWARFUnit *cu, dw_addr_t lo_pc, uint64_t fail_value,
79  bool check_specification_or_abstract_origin = false) const;
80 
82  const DWARFUnit *cu, dw_addr_t &lo_pc, dw_addr_t &hi_pc,
83  uint64_t fail_value,
84  bool check_specification_or_abstract_origin = false) const;
85 
87  DWARFUnit *cu, DWARFRangeList &ranges, bool check_hi_lo_pc,
88  bool check_specification_or_abstract_origin = false) const;
89 
90  const char *GetName(const DWARFUnit *cu) const;
91 
92  const char *GetMangledName(const DWARFUnit *cu,
93  bool substitute_name_allowed = true) const;
94 
95  const char *GetPubname(const DWARFUnit *cu) const;
96 
97  const char *GetQualifiedName(DWARFUnit *cu, std::string &storage) const;
98 
99  const char *GetQualifiedName(DWARFUnit *cu, const DWARFAttributes &attributes,
100  std::string &storage) const;
101 
103  DWARFUnit *cu, const char *&name, const char *&mangled,
104  DWARFRangeList &rangeList, int &decl_file, int &decl_line,
105  int &decl_column, int &call_file, int &call_line, int &call_column,
106  lldb_private::DWARFExpression *frame_base = nullptr) const;
107 
109  GetAbbreviationDeclarationPtr(const DWARFUnit *cu) const;
110 
112 
113  dw_tag_t Tag() const { return m_tag; }
114 
115  bool IsNULL() const { return m_abbr_idx == 0; }
116 
117  dw_offset_t GetOffset() const { return m_offset; }
118 
119  bool HasChildren() const { return m_has_children; }
120 
121  void SetHasChildren(bool b) { m_has_children = b; }
122 
123  // We know we are kept in a vector of contiguous entries, so we know
124  // our parent will be some index behind "this".
126  return m_parent_idx > 0 ? this - m_parent_idx : nullptr;
127  }
129  return m_parent_idx > 0 ? this - m_parent_idx : nullptr;
130  }
131  // We know we are kept in a vector of contiguous entries, so we know
132  // our sibling will be some index after "this".
134  return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;
135  }
137  return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;
138  }
139  // We know we are kept in a vector of contiguous entries, so we know
140  // we don't need to store our child pointer, if we have a child it will
141  // be the next entry in the list...
143  return HasChildren() ? this + 1 : nullptr;
144  }
146  return HasChildren() ? this + 1 : nullptr;
147  }
148 
150 
153  const DWARFAttributes &attributes) const;
154 
156  void SetParentIndex(uint32_t idx) { m_parent_idx = idx; }
157 
158  // This function returns true if the variable scope is either
159  // global or (file-static). It will return false for static variables
160  // that are local to a function, as they have local scope.
161  bool IsGlobalOrStaticScopeVariable() const;
162 
163 protected:
164  static DWARFDeclContext
166 
167  dw_offset_t m_offset; // Offset within the .debug_info/.debug_types
168  uint32_t m_parent_idx; // How many to subtract from "this" to get the parent.
169  // If zero this die has no parent
170  uint32_t m_sibling_idx : 31, // How many to add to "this" to get the sibling.
171  // If it is zero, then the DIE doesn't have children, or the
172  // DWARF claimed it had children but the DIE only contained
173  // a single NULL terminating child.
174  m_has_children : 1;
176  /// A copy of the DW_TAG value so we don't have to go through the compile
177  /// unit abbrev table
178  dw_tag_t m_tag = llvm::dwarf::DW_TAG_null;
179 };
180 
181 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGINFOENTRY_H
DWARFDIE GetAttributeValueAsReference(const DWARFUnit *cu, const dw_attr_t attr, bool check_specification_or_abstract_origin=false) const
static DWARFDeclContext GetDWARFDeclContextStatic(const DWARFDebugInfoEntry *die, DWARFUnit *cu)
uint64_t GetAttributeValueAsAddress(const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
Definition: Debugger.h:49
DWARFDIE GetParentDeclContextDIE(DWARFUnit *cu) const
const char * GetAttributeValueAsString(const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value, bool check_specification_or_abstract_origin=false) const
"lldb/Expression/DWARFExpression.h" Encapsulates a DWARF location expression and interprets it...
collection::iterator iterator
lldb::offset_t GetFirstAttributeOffset() const
uint64_t dw_addr_t
Definition: dwarf.h:26
const DWARFDebugInfoEntry * GetSibling() const
bool GetDIENamesAndRanges(DWARFUnit *cu, const char *&name, const char *&mangled, DWARFRangeList &rangeList, int &decl_file, int &decl_line, int &decl_column, int &call_file, int &call_line, int &call_column, lldb_private::DWARFExpression *frame_base=nullptr) const
const char * GetQualifiedName(DWARFUnit *cu, std::string &storage) const
dw_addr_t GetAttributeHighPC(const DWARFUnit *cu, dw_addr_t lo_pc, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
DWARFDebugInfoEntry objects assume that they are living in one big vector and do pointer arithmetic o...
DWARFDebugInfoEntry * GetFirstChild()
void SetParentIndex(uint32_t idx)
uint64_t offset_t
Definition: lldb-types.h:87
const DWARFDebugInfoEntry * GetFirstChild() const
DWARFDebugInfoEntry * GetParent()
uint64_t GetAttributeValueAsUnsigned(const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
llvm::dwarf::Tag dw_tag_t
Definition: dwarf.h:25
dw_offset_t GetOffset() const
bool operator!=(const DWARFDebugInfoEntry &rhs) const
size_t GetAttributeAddressRanges(DWARFUnit *cu, DWARFRangeList &ranges, bool check_hi_lo_pc, bool check_specification_or_abstract_origin=false) const
std::vector< DWARFDebugInfoEntry > collection
const char * GetName(const DWARFUnit *cu) const
void SetSiblingIndex(uint32_t idx)
const char * GetPubname(const DWARFUnit *cu) const
bool Extract(const lldb_private::DWARFDataExtractor &data, const DWARFUnit *cu, lldb::offset_t *offset_ptr)
const DWARFAbbreviationDeclaration * GetAbbreviationDeclarationPtr(const DWARFUnit *cu) const
dw_offset_t GetAttributeValue(const DWARFUnit *cu, const dw_attr_t attr, DWARFFormValue &formValue, dw_offset_t *end_attr_offset_ptr=nullptr, bool check_specification_or_abstract_origin=false) const
bool IsGlobalOrStaticScopeVariable() const
const DWARFDebugInfoEntry * GetParent() const
DWARFDebugInfoEntry * GetSibling()
#define DW_INVALID_OFFSET
Definition: dwarf.h:34
size_t GetAttributes(const DWARFUnit *cu, DWARFAttributes &attrs, uint32_t curr_depth=0) const
const char * GetMangledName(const DWARFUnit *cu, bool substitute_name_allowed=true) const
bool GetAttributeAddressRange(const DWARFUnit *cu, dw_addr_t &lo_pc, dw_addr_t &hi_pc, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
dw_tag_t m_tag
A copy of the DW_TAG value so we don&#39;t have to go through the compile unit abbrev table...
bool operator==(const DWARFDebugInfoEntry &rhs) const
collection::const_iterator const_iterator
DWARFDeclContext GetDWARFDeclContext(DWARFUnit *cu) const
void BuildFunctionAddressRangeTable(const DWARFUnit *cu, DWARFDebugAranges *debug_aranges) const
This function is builds a table very similar to the standard .debug_aranges table, except that the actual DIE offset for the function is placed in the table instead of the compile unit offset.