]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / SymbolFile / DWARF / DWARFDebugInfoEntry.h
1 //===-- DWARFDebugInfoEntry.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_DWARFDebugInfoEntry_h_
11 #define SymbolFileDWARF_DWARFDebugInfoEntry_h_
12
13 #include "SymbolFileDWARF.h"
14 #include "llvm/ADT/SmallVector.h"
15
16 #include "DWARFAbbreviationDeclaration.h"
17 #include "DWARFDebugAbbrev.h"
18 #include "DWARFDebugRanges.h"
19 #include <map>
20 #include <set>
21 #include <vector>
22
23 typedef std::map<const DWARFDebugInfoEntry *, dw_addr_t> DIEToAddressMap;
24 typedef DIEToAddressMap::iterator DIEToAddressMapIter;
25 typedef DIEToAddressMap::const_iterator DIEToAddressMapConstIter;
26
27 typedef std::map<dw_addr_t, const DWARFDebugInfoEntry *> AddressToDIEMap;
28 typedef AddressToDIEMap::iterator AddressToDIEMapIter;
29 typedef AddressToDIEMap::const_iterator AddressToDIEMapConstIter;
30
31 typedef std::map<dw_offset_t, dw_offset_t> DIEToDIEMap;
32 typedef DIEToDIEMap::iterator DIEToDIEMapIter;
33 typedef DIEToDIEMap::const_iterator DIEToDIEMapConstIter;
34
35 typedef std::map<uint32_t, const DWARFDebugInfoEntry *> UInt32ToDIEMap;
36 typedef UInt32ToDIEMap::iterator UInt32ToDIEMapIter;
37 typedef UInt32ToDIEMap::const_iterator UInt32ToDIEMapConstIter;
38
39 typedef std::multimap<uint32_t, const DWARFDebugInfoEntry *> UInt32ToDIEMMap;
40 typedef UInt32ToDIEMMap::iterator UInt32ToDIEMMapIter;
41 typedef UInt32ToDIEMMap::const_iterator UInt32ToDIEMMapConstIter;
42
43 class DWARFDeclContext;
44
45 #define DIE_SIBLING_IDX_BITSIZE 31
46 #define DIE_ABBR_IDX_BITSIZE 15
47
48 class DWARFDebugInfoEntry {
49 public:
50   typedef std::vector<DWARFDebugInfoEntry> collection;
51   typedef collection::iterator iterator;
52   typedef collection::const_iterator const_iterator;
53
54   typedef std::vector<dw_offset_t> offset_collection;
55   typedef offset_collection::iterator offset_collection_iterator;
56   typedef offset_collection::const_iterator offset_collection_const_iterator;
57
58   DWARFDebugInfoEntry()
59       : m_offset(DW_INVALID_OFFSET), m_parent_idx(0), m_sibling_idx(0),
60         m_empty_children(false), m_abbr_idx(0), m_has_children(false),
61         m_tag(0) {}
62
63   explicit operator bool() const { return m_offset != DW_INVALID_OFFSET; }
64   bool operator==(const DWARFDebugInfoEntry &rhs) const;
65   bool operator!=(const DWARFDebugInfoEntry &rhs) const;
66
67   void BuildAddressRangeTable(SymbolFileDWARF *dwarf2Data,
68                               const DWARFUnit *cu,
69                               DWARFDebugAranges *debug_aranges) const;
70
71   void BuildFunctionAddressRangeTable(SymbolFileDWARF *dwarf2Data,
72                                       const DWARFUnit *cu,
73                                       DWARFDebugAranges *debug_aranges) const;
74
75   bool FastExtract(const lldb_private::DWARFDataExtractor &debug_info_data,
76                    const DWARFUnit *cu,
77                    const DWARFFormValue::FixedFormSizes &fixed_form_sizes,
78                    lldb::offset_t *offset_ptr);
79
80   bool Extract(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
81                lldb::offset_t *offset_ptr);
82
83   bool LookupAddress(const dw_addr_t address, SymbolFileDWARF *dwarf2Data,
84                      const DWARFUnit *cu,
85                      DWARFDebugInfoEntry **function_die,
86                      DWARFDebugInfoEntry **block_die);
87
88   size_t GetAttributes(const DWARFUnit *cu,
89                        DWARFFormValue::FixedFormSizes fixed_form_sizes,
90                        DWARFAttributes &attrs,
91                        uint32_t curr_depth = 0)
92       const; // "curr_depth" for internal use only, don't set this yourself!!!
93
94   dw_offset_t
95   GetAttributeValue(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
96                     const dw_attr_t attr, DWARFFormValue &formValue,
97                     dw_offset_t *end_attr_offset_ptr = nullptr,
98                     bool check_specification_or_abstract_origin = false) const;
99
100   const char *GetAttributeValueAsString(
101       SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
102       const dw_attr_t attr, const char *fail_value,
103       bool check_specification_or_abstract_origin = false) const;
104
105   uint64_t GetAttributeValueAsUnsigned(
106       SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
107       const dw_attr_t attr, uint64_t fail_value,
108       bool check_specification_or_abstract_origin = false) const;
109
110   uint64_t GetAttributeValueAsReference(
111       SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
112       const dw_attr_t attr, uint64_t fail_value,
113       bool check_specification_or_abstract_origin = false) const;
114
115   int64_t GetAttributeValueAsSigned(
116       SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
117       const dw_attr_t attr, int64_t fail_value,
118       bool check_specification_or_abstract_origin = false) const;
119
120   uint64_t GetAttributeValueAsAddress(
121       SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
122       const dw_attr_t attr, uint64_t fail_value,
123       bool check_specification_or_abstract_origin = false) const;
124
125   dw_addr_t
126   GetAttributeHighPC(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
127                      dw_addr_t lo_pc, uint64_t fail_value,
128                      bool check_specification_or_abstract_origin = false) const;
129
130   bool GetAttributeAddressRange(
131       SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, dw_addr_t &lo_pc,
132       dw_addr_t &hi_pc, uint64_t fail_value,
133       bool check_specification_or_abstract_origin = false) const;
134
135   size_t GetAttributeAddressRanges(
136       SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
137       DWARFRangeList &ranges, bool check_hi_lo_pc,
138       bool check_specification_or_abstract_origin = false) const;
139
140   const char *GetName(SymbolFileDWARF *dwarf2Data,
141                       const DWARFUnit *cu) const;
142
143   const char *GetMangledName(SymbolFileDWARF *dwarf2Data,
144                              const DWARFUnit *cu,
145                              bool substitute_name_allowed = true) const;
146
147   const char *GetPubname(SymbolFileDWARF *dwarf2Data,
148                          const DWARFUnit *cu) const;
149
150   static bool GetName(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
151                       const dw_offset_t die_offset, lldb_private::Stream &s);
152
153   static bool AppendTypeName(SymbolFileDWARF *dwarf2Data,
154                              const DWARFUnit *cu,
155                              const dw_offset_t die_offset,
156                              lldb_private::Stream &s);
157
158   const char *GetQualifiedName(SymbolFileDWARF *dwarf2Data,
159                                DWARFUnit *cu,
160                                std::string &storage) const;
161
162   const char *GetQualifiedName(SymbolFileDWARF *dwarf2Data,
163                                DWARFUnit *cu,
164                                const DWARFAttributes &attributes,
165                                std::string &storage) const;
166
167   static bool OffsetLessThan(const DWARFDebugInfoEntry &a,
168                              const DWARFDebugInfoEntry &b);
169
170   void Dump(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
171             lldb_private::Stream &s, uint32_t recurse_depth) const;
172
173   void DumpAncestry(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
174                     const DWARFDebugInfoEntry *oldest, lldb_private::Stream &s,
175                     uint32_t recurse_depth) const;
176
177   static void
178   DumpAttribute(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
179                 const lldb_private::DWARFDataExtractor &debug_info_data,
180                 lldb::offset_t *offset_ptr, lldb_private::Stream &s,
181                 dw_attr_t attr, dw_form_t form);
182   // This one dumps the comp unit name, objfile name and die offset for this die
183   // so the stream S.
184   void DumpLocation(SymbolFileDWARF *dwarf2Data, DWARFUnit *cu,
185                     lldb_private::Stream &s) const;
186
187   bool
188   GetDIENamesAndRanges(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
189                        const char *&name, const char *&mangled,
190                        DWARFRangeList &rangeList, int &decl_file,
191                        int &decl_line, int &decl_column, int &call_file,
192                        int &call_line, int &call_column,
193                        lldb_private::DWARFExpression *frame_base = NULL) const;
194
195   const DWARFAbbreviationDeclaration *
196   GetAbbreviationDeclarationPtr(SymbolFileDWARF *dwarf2Data,
197                                 const DWARFUnit *cu,
198                                 lldb::offset_t &offset) const;
199
200   dw_tag_t Tag() const { return m_tag; }
201
202   bool IsNULL() const { return m_abbr_idx == 0; }
203
204   dw_offset_t GetOffset() const { return m_offset; }
205
206   bool HasChildren() const { return m_has_children; }
207
208   void SetHasChildren(bool b) { m_has_children = b; }
209
210   // We know we are kept in a vector of contiguous entries, so we know
211   // our parent will be some index behind "this".
212   DWARFDebugInfoEntry *GetParent() {
213     return m_parent_idx > 0 ? this - m_parent_idx : NULL;
214   }
215   const DWARFDebugInfoEntry *GetParent() const {
216     return m_parent_idx > 0 ? this - m_parent_idx : NULL;
217   }
218   // We know we are kept in a vector of contiguous entries, so we know
219   // our sibling will be some index after "this".
220   DWARFDebugInfoEntry *GetSibling() {
221     return m_sibling_idx > 0 ? this + m_sibling_idx : NULL;
222   }
223   const DWARFDebugInfoEntry *GetSibling() const {
224     return m_sibling_idx > 0 ? this + m_sibling_idx : NULL;
225   }
226   // We know we are kept in a vector of contiguous entries, so we know
227   // we don't need to store our child pointer, if we have a child it will
228   // be the next entry in the list...
229   DWARFDebugInfoEntry *GetFirstChild() {
230     return (HasChildren() && !m_empty_children) ? this + 1 : NULL;
231   }
232   const DWARFDebugInfoEntry *GetFirstChild() const {
233     return (HasChildren() && !m_empty_children) ? this + 1 : NULL;
234   }
235
236   void GetDeclContextDIEs(DWARFUnit *cu,
237                           DWARFDIECollection &decl_context_dies) const;
238
239   void GetDWARFDeclContext(SymbolFileDWARF *dwarf2Data, DWARFUnit *cu,
240                            DWARFDeclContext &dwarf_decl_ctx) const;
241
242   bool MatchesDWARFDeclContext(SymbolFileDWARF *dwarf2Data,
243                                DWARFUnit *cu,
244                                const DWARFDeclContext &dwarf_decl_ctx) const;
245
246   DWARFDIE GetParentDeclContextDIE(SymbolFileDWARF *dwarf2Data,
247                                    DWARFUnit *cu) const;
248   DWARFDIE GetParentDeclContextDIE(SymbolFileDWARF *dwarf2Data,
249                                    DWARFUnit *cu,
250                                    const DWARFAttributes &attributes) const;
251
252   void SetParent(DWARFDebugInfoEntry *parent) {
253     if (parent) {
254       // We know we are kept in a vector of contiguous entries, so we know
255       // our parent will be some index behind "this".
256       m_parent_idx = this - parent;
257     } else
258       m_parent_idx = 0;
259   }
260   void SetSibling(DWARFDebugInfoEntry *sibling) {
261     if (sibling) {
262       // We know we are kept in a vector of contiguous entries, so we know
263       // our sibling will be some index after "this".
264       m_sibling_idx = sibling - this;
265       sibling->SetParent(GetParent());
266     } else
267       m_sibling_idx = 0;
268   }
269
270   void SetSiblingIndex(uint32_t idx) { m_sibling_idx = idx; }
271
272   void SetParentIndex(uint32_t idx) { m_parent_idx = idx; }
273
274   bool GetEmptyChildren() const { return m_empty_children; }
275
276   void SetEmptyChildren(bool b) { m_empty_children = b; }
277
278   static void
279   DumpDIECollection(lldb_private::Stream &strm,
280                     DWARFDebugInfoEntry::collection &die_collection);
281
282 protected:
283   dw_offset_t
284       m_offset; // Offset within the .debug_info of the start of this entry
285   uint32_t m_parent_idx; // How many to subtract from "this" to get the parent.
286                          // If zero this die has no parent
287   uint32_t m_sibling_idx : 31, // How many to add to "this" to get the sibling.
288       m_empty_children : 1;    // If a DIE says it had children, yet it just
289                                // contained a NULL tag, this will be set.
290   uint32_t m_abbr_idx : DIE_ABBR_IDX_BITSIZE,
291                         m_has_children : 1, // Set to 1 if this DIE has children
292                         m_tag : 16; // A copy of the DW_TAG value so we don't
293                                     // have to go through the compile unit
294                                     // abbrev table
295 };
296
297 #endif // SymbolFileDWARF_DWARFDebugInfoEntry_h_