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