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 "DWARFBaseDIE.h"
17 #include "DWARFDebugAbbrev.h"
18 #include "DWARFDebugRanges.h"
19 #include <map>
20 #include <set>
21 #include <vector>
22 
23 class DWARFDeclContext;
24 
25 #define DIE_SIBLING_IDX_BITSIZE 31
26 
27 /// DWARFDebugInfoEntry objects assume that they are living in one big
28 /// vector and do pointer arithmetic on their this pointers. Don't
29 /// pass them by value. Due to the way they are constructed in a
30 /// std::vector, we cannot delete the copy constructor.
32 public:
33  typedef std::vector<DWARFDebugInfoEntry> collection;
34  typedef collection::iterator iterator;
35  typedef collection::const_iterator const_iterator;
36 
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 
52  Recurse recurse = Recurse::yes) const {
53  return GetAttributes(cu, attrs, recurse, 0 /* curr_depth */);
54  }
55 
57  GetAttributeValue(const DWARFUnit *cu, const dw_attr_t attr,
58  DWARFFormValue &formValue,
59  dw_offset_t *end_attr_offset_ptr = nullptr,
60  bool check_specification_or_abstract_origin = false) const;
61 
62  const char *GetAttributeValueAsString(
63  const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value,
64  bool check_specification_or_abstract_origin = false) const;
65 
67  const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value,
68  bool check_specification_or_abstract_origin = false) const;
69 
70  llvm::Optional<uint64_t> GetAttributeValueAsOptionalUnsigned(
71  const DWARFUnit *cu, const dw_attr_t attr,
72  bool check_specification_or_abstract_origin = false) const;
73 
75  const DWARFUnit *cu, const dw_attr_t attr,
76  bool check_specification_or_abstract_origin = false) const;
77 
79  const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value,
80  bool check_specification_or_abstract_origin = false) const;
81 
82  dw_addr_t
83  GetAttributeHighPC(const DWARFUnit *cu, dw_addr_t lo_pc, uint64_t fail_value,
84  bool check_specification_or_abstract_origin = false) const;
85 
87  const DWARFUnit *cu, dw_addr_t &lo_pc, dw_addr_t &hi_pc,
88  uint64_t fail_value,
89  bool check_specification_or_abstract_origin = false) const;
90 
92  DWARFUnit *cu, DWARFRangeList &ranges, bool check_hi_lo_pc,
93  bool check_specification_or_abstract_origin = false) const;
94 
95  const char *GetName(const DWARFUnit *cu) const;
96 
97  const char *GetMangledName(const DWARFUnit *cu,
98  bool substitute_name_allowed = true) const;
99 
100  const char *GetPubname(const DWARFUnit *cu) 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::DWARFExpressionList *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 = 0; // How many to subtract from "this" to get the
169  // parent. 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.
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 private:
181  size_t GetAttributes(DWARFUnit *cu, DWARFAttributes &attrs, Recurse recurse,
182  uint32_t curr_depth) const;
183 };
184 
185 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGINFOENTRY_H
DWARFDebugInfoEntry::GetAttributeValueAsReference
DWARFDIE GetAttributeValueAsReference(const DWARFUnit *cu, const dw_attr_t attr, bool check_specification_or_abstract_origin=false) const
Definition: DWARFDebugInfoEntry.cpp:565
DWARFDebugInfoEntry::GetAttributeValueAsAddress
uint64_t GetAttributeValueAsAddress(const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
Definition: DWARFDebugInfoEntry.cpp:575
DWARFDebugInfoEntry::GetOffset
dw_offset_t GetOffset() const
Definition: DWARFDebugInfoEntry.h:117
DWARFBaseDIE::Recurse::yes
@ yes
DWARFDebugInfoEntry::GetMangledName
const char * GetMangledName(const DWARFUnit *cu, bool substitute_name_allowed=true) const
Definition: DWARFDebugInfoEntry.cpp:663
DWARFDebugAranges
Definition: DWARFDebugAranges.h:16
DWARFDebugInfoEntry::GetSibling
const DWARFDebugInfoEntry * GetSibling() const
Definition: DWARFDebugInfoEntry.h:136
dw_tag_t
llvm::dwarf::Tag dw_tag_t
Definition: dwarf.h:28
DWARFDebugInfoEntry::HasChildren
bool HasChildren() const
Definition: DWARFDebugInfoEntry.h:119
DWARFDebugInfoEntry::GetFirstChild
const DWARFDebugInfoEntry * GetFirstChild() const
Definition: DWARFDebugInfoEntry.h:145
SymbolFileDWARF.h
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
DWARFDebugInfoEntry::GetSibling
DWARFDebugInfoEntry * GetSibling()
Definition: DWARFDebugInfoEntry.h:133
lldb_private::DWARFDataExtractor
Definition: DWARFDataExtractor.h:18
DWARFDebugInfoEntry
DWARFDebugInfoEntry objects assume that they are living in one big vector and do pointer arithmetic o...
Definition: DWARFDebugInfoEntry.h:31
DW_INVALID_OFFSET
#define DW_INVALID_OFFSET
Definition: dwarf.h:37
DWARFAttributes
Definition: DWARFAttribute.h:44
DWARFDebugInfoEntry::GetFirstAttributeOffset
lldb::offset_t GetFirstAttributeOffset() const
Definition: DWARFDebugInfoEntry.cpp:801
DWARFDIE
Definition: DWARFDIE.h:16
DWARFDebugInfoEntry::m_abbr_idx
uint16_t m_abbr_idx
Definition: DWARFDebugInfoEntry.h:175
DWARFDebugInfoEntry::DWARFDebugInfoEntry
DWARFDebugInfoEntry()
Definition: DWARFDebugInfoEntry.h:37
DWARFDebugInfoEntry::SetSiblingIndex
void SetSiblingIndex(uint32_t idx)
Definition: DWARFDebugInfoEntry.h:155
DWARFDebugInfoEntry::m_offset
dw_offset_t m_offset
Definition: DWARFDebugInfoEntry.h:167
DWARFUnit
Definition: DWARFUnit.h:83
DWARFDebugInfoEntry::GetParentDeclContextDIE
DWARFDIE GetParentDeclContextDIE(DWARFUnit *cu) const
Definition: DWARFDebugInfoEntry.cpp:752
DWARFDebugInfoEntry::GetDWARFDeclContext
DWARFDeclContext GetDWARFDeclContext(DWARFUnit *cu) const
Definition: DWARFDebugInfoEntry.cpp:747
DWARFDebugInfoEntry::SetHasChildren
void SetHasChildren(bool b)
Definition: DWARFDebugInfoEntry.h:121
DWARFDebugInfoEntry::m_tag
dw_tag_t m_tag
A copy of the DW_TAG value so we don't have to go through the compile unit abbrev table.
Definition: DWARFDebugInfoEntry.h:178
DWARFDebugInfoEntry::GetPubname
const char * GetPubname(const DWARFUnit *cu) const
Definition: DWARFDebugInfoEntry.cpp:686
DWARFFormValue
Definition: DWARFFormValue.h:20
DWARFDebugInfoEntry::GetDWARFDeclContextStatic
static DWARFDeclContext GetDWARFDeclContextStatic(const DWARFDebugInfoEntry *die, DWARFUnit *cu)
Definition: DWARFDebugInfoEntry.cpp:728
DWARFDebugInfoEntry::const_iterator
collection::const_iterator const_iterator
Definition: DWARFDebugInfoEntry.h:35
DWARFDebugInfoEntry::Extract
bool Extract(const lldb_private::DWARFDataExtractor &data, const DWARFUnit *cu, lldb::offset_t *offset_ptr)
Definition: DWARFDebugInfoEntry.cpp:40
DWARFDebugInfoEntry::BuildFunctionAddressRangeTable
void BuildFunctionAddressRangeTable(DWARFUnit *cu, DWARFDebugAranges *debug_aranges) const
This function is builds a table very similar to the standard .debug_aranges table,...
Definition: DWARFDebugInfoEntry.cpp:706
DWARFDebugInfoEntry::m_parent_idx
uint32_t m_parent_idx
Definition: DWARFDebugInfoEntry.h:168
lldb_private::RangeVector
Definition: RangeMap.h:136
DWARFDebugInfoEntry::GetAttributeValueAsString
const char * GetAttributeValueAsString(const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value, bool check_specification_or_abstract_origin=false) const
Definition: DWARFDebugInfoEntry.cpp:527
DWARFDebugInfoEntry::operator!=
bool operator!=(const DWARFDebugInfoEntry &rhs) const
Definition: DWARFDebugInfoEntry.cpp:845
DWARFAbbreviationDeclaration.h
DWARFDebugInfoEntry::GetAttributeAddressRange
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
Definition: DWARFDebugInfoEntry.cpp:614
uint32_t
DWARFBaseDIE::Recurse
Recurse
Definition: DWARFBaseDIE.h:116
DWARFDebugInfoEntry::IsGlobalOrStaticScopeVariable
bool IsGlobalOrStaticScopeVariable() const
Definition: DWARFDebugInfoEntry.cpp:815
DWARFDebugRanges.h
DWARFDebugInfoEntry::GetDIENamesAndRanges
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::DWARFExpressionList *frame_base=nullptr) const
Definition: DWARFDebugInfoEntry.cpp:231
DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr
const DWARFAbbreviationDeclaration * GetAbbreviationDeclarationPtr(const DWARFUnit *cu) const
Definition: DWARFDebugInfoEntry.cpp:806
uint16_t
DWARFDebugAbbrev.h
DWARFDebugInfoEntry::SetParentIndex
void SetParentIndex(uint32_t idx)
Definition: DWARFDebugInfoEntry.h:156
DWARFBaseDIE.h
DWARFAbbreviationDeclaration
Definition: DWARFAbbreviationDeclaration.h:17
DWARFDebugInfoEntry::GetParent
const DWARFDebugInfoEntry * GetParent() const
Definition: DWARFDebugInfoEntry.h:128
DWARFDeclContext
Definition: DWARFDeclContext.h:23
DWARFDebugInfoEntry::collection
std::vector< DWARFDebugInfoEntry > collection
Definition: DWARFDebugInfoEntry.h:33
DWARFDebugInfoEntry::Tag
dw_tag_t Tag() const
Definition: DWARFDebugInfoEntry.h:113
DWARFDebugInfoEntry::m_sibling_idx
uint32_t m_sibling_idx
Definition: DWARFDebugInfoEntry.h:170
DWARFDebugInfoEntry::m_has_children
uint32_t m_has_children
Definition: DWARFDebugInfoEntry.h:174
DWARFDebugInfoEntry::GetAttributeAddressRanges
size_t GetAttributeAddressRanges(DWARFUnit *cu, DWARFRangeList &ranges, bool check_hi_lo_pc, bool check_specification_or_abstract_origin=false) const
Definition: DWARFDebugInfoEntry.cpp:630
DWARFDebugInfoEntry::iterator
collection::iterator iterator
Definition: DWARFDebugInfoEntry.h:34
lldb_private::DWARFExpressionList
Definition: DWARFExpressionList.h:24
DWARFDebugInfoEntry::GetAttributes
size_t GetAttributes(DWARFUnit *cu, DWARFAttributes &attrs, Recurse recurse=Recurse::yes) const
Definition: DWARFDebugInfoEntry.h:51
DWARFDebugInfoEntry::IsNULL
bool IsNULL() const
Definition: DWARFDebugInfoEntry.h:115
dw_addr_t
uint64_t dw_addr_t
Definition: dwarf.h:29
DWARFDebugInfoEntry::GetAttributeHighPC
dw_addr_t GetAttributeHighPC(const DWARFUnit *cu, dw_addr_t lo_pc, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
Definition: DWARFDebugInfoEntry.cpp:591
DWARFDebugInfoEntry::GetName
const char * GetName(const DWARFUnit *cu) const
Definition: DWARFDebugInfoEntry.cpp:654
DWARFDebugInfoEntry::GetParent
DWARFDebugInfoEntry * GetParent()
Definition: DWARFDebugInfoEntry.h:125
DWARFDebugInfoEntry::GetAttributeValueAsUnsigned
uint64_t GetAttributeValueAsUnsigned(const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
Definition: DWARFDebugInfoEntry.cpp:540
DWARFDebugInfoEntry::operator==
bool operator==(const DWARFDebugInfoEntry &rhs) const
Definition: DWARFDebugInfoEntry.cpp:838
DWARFDebugInfoEntry::GetAttributeValueAsOptionalUnsigned
llvm::Optional< uint64_t > GetAttributeValueAsOptionalUnsigned(const DWARFUnit *cu, const dw_attr_t attr, bool check_specification_or_abstract_origin=false) const
Definition: DWARFDebugInfoEntry.cpp:551
DWARFDebugInfoEntry::GetAttributeValue
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
Definition: DWARFDebugInfoEntry.cpp:470
DWARFDebugInfoEntry::GetFirstChild
DWARFDebugInfoEntry * GetFirstChild()
Definition: DWARFDebugInfoEntry.h:142