DWARFDebugInfoEntry.h revision 296417
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 "DWARFDebugAbbrev.h"
17#include "DWARFAbbreviationDeclaration.h"
18#include "DWARFDebugRanges.h"
19#include <vector>
20#include <map>
21#include <set>
22
23typedef std::map<const DWARFDebugInfoEntry*, dw_addr_t>     DIEToAddressMap;
24typedef DIEToAddressMap::iterator                           DIEToAddressMapIter;
25typedef DIEToAddressMap::const_iterator                     DIEToAddressMapConstIter;
26
27typedef std::map<dw_addr_t, const DWARFDebugInfoEntry*>     AddressToDIEMap;
28typedef AddressToDIEMap::iterator                           AddressToDIEMapIter;
29typedef AddressToDIEMap::const_iterator                     AddressToDIEMapConstIter;
30
31
32typedef std::map<dw_offset_t, dw_offset_t>                  DIEToDIEMap;
33typedef DIEToDIEMap::iterator                               DIEToDIEMapIter;
34typedef DIEToDIEMap::const_iterator                         DIEToDIEMapConstIter;
35
36typedef std::map<uint32_t, const DWARFDebugInfoEntry*>      UInt32ToDIEMap;
37typedef UInt32ToDIEMap::iterator                            UInt32ToDIEMapIter;
38typedef UInt32ToDIEMap::const_iterator                      UInt32ToDIEMapConstIter;
39
40typedef std::multimap<uint32_t, const DWARFDebugInfoEntry*> UInt32ToDIEMMap;
41typedef UInt32ToDIEMMap::iterator                           UInt32ToDIEMMapIter;
42typedef UInt32ToDIEMMap::const_iterator                     UInt32ToDIEMMapConstIter;
43
44class DWARFDeclContext;
45
46#define DIE_SIBLING_IDX_BITSIZE 31
47#define DIE_ABBR_IDX_BITSIZE 15
48
49class DWARFDebugInfoEntry
50{
51public:
52    typedef std::vector<DWARFDebugInfoEntry>    collection;
53    typedef collection::iterator                iterator;
54    typedef collection::const_iterator          const_iterator;
55
56    typedef std::vector<dw_offset_t>            offset_collection;
57    typedef offset_collection::iterator         offset_collection_iterator;
58    typedef offset_collection::const_iterator   offset_collection_const_iterator;
59
60                DWARFDebugInfoEntry():
61                    m_offset        (DW_INVALID_OFFSET),
62                    m_parent_idx    (0),
63                    m_sibling_idx   (0),
64                    m_empty_children(false),
65                    m_abbr_idx      (0),
66                    m_has_children  (false),
67                    m_tag           (0)
68                {
69                }
70
71    void        Clear ()
72                {
73                    m_offset         = DW_INVALID_OFFSET;
74                    m_parent_idx     = 0;
75                    m_sibling_idx    = 0;
76                    m_empty_children = false;
77                    m_abbr_idx       = 0;
78                    m_has_children   = false;
79                    m_tag            = 0;
80                }
81
82    bool        Contains (const DWARFDebugInfoEntry *die) const;
83
84    void        BuildAddressRangeTable(
85                    SymbolFileDWARF* dwarf2Data,
86                    const DWARFCompileUnit* cu,
87                    DWARFDebugAranges* debug_aranges) const;
88
89    void        BuildFunctionAddressRangeTable(
90                    SymbolFileDWARF* dwarf2Data,
91                    const DWARFCompileUnit* cu,
92                    DWARFDebugAranges* debug_aranges) const;
93
94    bool        FastExtract(
95                    const lldb_private::DWARFDataExtractor& debug_info_data,
96                    const DWARFCompileUnit* cu,
97                    const DWARFFormValue::FixedFormSizes& fixed_form_sizes,
98                    lldb::offset_t* offset_ptr);
99
100    bool        Extract(
101                    SymbolFileDWARF* dwarf2Data,
102                    const DWARFCompileUnit* cu,
103                    lldb::offset_t* offset_ptr);
104
105    bool        LookupAddress(
106                    const dw_addr_t address,
107                    SymbolFileDWARF* dwarf2Data,
108                    const DWARFCompileUnit* cu,
109                    DWARFDebugInfoEntry** function_die,
110                    DWARFDebugInfoEntry** block_die);
111
112    size_t      GetAttributes(
113                    const DWARFCompileUnit* cu,
114                    DWARFFormValue::FixedFormSizes fixed_form_sizes,
115                    DWARFAttributes& attrs,
116                    uint32_t curr_depth = 0) const; // "curr_depth" for internal use only, don't set this yourself!!!
117
118    const char* GetAttributeValueAsString(
119                    SymbolFileDWARF* dwarf2Data,
120                    const DWARFCompileUnit* cu,
121                    const dw_attr_t attr,
122                    const char* fail_value,
123                    bool check_specification_or_abstract_origin = false) const;
124
125    uint64_t    GetAttributeValueAsUnsigned(
126                    SymbolFileDWARF* dwarf2Data,
127                    const DWARFCompileUnit* cu,
128                    const dw_attr_t attr,
129                    uint64_t fail_value,
130                    bool check_specification_or_abstract_origin = false) const;
131
132    uint64_t    GetAttributeValueAsReference(
133                    SymbolFileDWARF* dwarf2Data,
134                    const DWARFCompileUnit* cu,
135                    const dw_attr_t attr,
136                    uint64_t fail_value,
137                    bool check_specification_or_abstract_origin = false) const;
138
139    int64_t     GetAttributeValueAsSigned(
140                    SymbolFileDWARF* dwarf2Data,
141                    const DWARFCompileUnit* cu,
142                    const dw_attr_t attr,
143                    int64_t fail_value,
144                    bool check_specification_or_abstract_origin = false) const;
145
146    uint64_t    GetAttributeValueAsAddress(
147                    SymbolFileDWARF* dwarf2Data,
148                    const DWARFCompileUnit* cu,
149                    const dw_attr_t attr,
150                    uint64_t fail_value,
151                    bool check_specification_or_abstract_origin = false) const;
152
153    dw_addr_t   GetAttributeHighPC(
154                    SymbolFileDWARF* dwarf2Data,
155                    const DWARFCompileUnit* cu,
156                    dw_addr_t lo_pc,
157                    uint64_t fail_value,
158                    bool check_specification_or_abstract_origin = false) const;
159
160    bool        GetAttributeAddressRange(
161                    SymbolFileDWARF* dwarf2Data,
162                    const DWARFCompileUnit* cu,
163                    dw_addr_t& lo_pc,
164                    dw_addr_t& hi_pc,
165                    uint64_t fail_value,
166                    bool check_specification_or_abstract_origin = false) const;
167
168    size_t      GetAttributeAddressRanges (
169                    SymbolFileDWARF* dwarf2Data,
170                    const DWARFCompileUnit* cu,
171                    DWARFRangeList &ranges,
172                    bool check_hi_lo_pc,
173                    bool check_specification_or_abstract_origin = false) const;
174
175    const char* GetName(
176                    SymbolFileDWARF* dwarf2Data,
177                    const DWARFCompileUnit* cu) const;
178
179    const char* GetMangledName(
180                    SymbolFileDWARF* dwarf2Data,
181                    const DWARFCompileUnit* cu,
182                    bool substitute_name_allowed = true) const;
183
184    const char* GetPubname(
185                    SymbolFileDWARF* dwarf2Data,
186                    const DWARFCompileUnit* cu) const;
187
188    static bool GetName(
189                    SymbolFileDWARF* dwarf2Data,
190                    const DWARFCompileUnit* cu,
191                    const dw_offset_t die_offset,
192                    lldb_private::Stream &s);
193
194    static bool AppendTypeName(
195                    SymbolFileDWARF* dwarf2Data,
196                    const DWARFCompileUnit* cu,
197                    const dw_offset_t die_offset,
198                    lldb_private::Stream &s);
199
200    const char * GetQualifiedName (
201                    SymbolFileDWARF* dwarf2Data,
202                    DWARFCompileUnit* cu,
203                    std::string &storage) const;
204
205    const char * GetQualifiedName (
206                    SymbolFileDWARF* dwarf2Data,
207                    DWARFCompileUnit* cu,
208                    const DWARFAttributes& attributes,
209                    std::string &storage) const;
210
211    static bool OffsetLessThan (
212                    const DWARFDebugInfoEntry& a,
213                    const DWARFDebugInfoEntry& b);
214
215    void        Dump(
216                    SymbolFileDWARF* dwarf2Data,
217                    const DWARFCompileUnit* cu,
218                    lldb_private::Stream &s,
219                    uint32_t recurse_depth) const;
220
221    void        DumpAncestry(
222                    SymbolFileDWARF* dwarf2Data,
223                    const DWARFCompileUnit* cu,
224                    const DWARFDebugInfoEntry* oldest,
225                    lldb_private::Stream &s,
226                    uint32_t recurse_depth) const;
227
228    static void DumpAttribute(
229                    SymbolFileDWARF* dwarf2Data,
230                    const DWARFCompileUnit* cu,
231                    const lldb_private::DWARFDataExtractor& debug_info_data,
232                    lldb::offset_t *offset_ptr,
233                    lldb_private::Stream &s,
234                    dw_attr_t attr,
235                    dw_form_t form);
236    // This one dumps the comp unit name, objfile name and die offset for this die so the stream S.
237    void          DumpLocation(
238                    SymbolFileDWARF* dwarf2Data,
239                    DWARFCompileUnit* cu,
240                    lldb_private::Stream &s) const;
241
242    bool        GetDIENamesAndRanges(
243                    SymbolFileDWARF* dwarf2Data,
244                    const DWARFCompileUnit* cu,
245                    const char * &name,
246                    const char * &mangled,
247                    DWARFRangeList& rangeList,
248                    int& decl_file,
249                    int& decl_line,
250                    int& decl_column,
251                    int& call_file,
252                    int& call_line,
253                    int& call_column,
254                    lldb_private::DWARFExpression *frame_base = NULL) const;
255
256    const DWARFAbbreviationDeclaration*
257    GetAbbreviationDeclarationPtr (SymbolFileDWARF* dwarf2Data,
258                                   const DWARFCompileUnit *cu,
259                                   lldb::offset_t &offset) const;
260
261    dw_tag_t
262    Tag () const
263    {
264        return m_tag;
265    }
266
267    bool
268    IsNULL() const
269    {
270        return m_abbr_idx == 0;
271    }
272
273    dw_offset_t
274    GetOffset () const
275    {
276        return m_offset;
277    }
278
279    void
280    SetOffset (dw_offset_t offset)
281    {
282        m_offset = offset;
283    }
284
285    bool
286    HasChildren () const
287    {
288        return m_has_children;
289    }
290
291    void
292    SetHasChildren (bool b)
293    {
294        m_has_children = b;
295    }
296
297            // We know we are kept in a vector of contiguous entries, so we know
298            // our parent will be some index behind "this".
299            DWARFDebugInfoEntry*    GetParent()             { return m_parent_idx > 0 ? this - m_parent_idx : NULL;  }
300    const   DWARFDebugInfoEntry*    GetParent()     const   { return m_parent_idx > 0 ? this - m_parent_idx : NULL;  }
301            // We know we are kept in a vector of contiguous entries, so we know
302            // our sibling will be some index after "this".
303            DWARFDebugInfoEntry*    GetSibling()            { return m_sibling_idx > 0 ? this + m_sibling_idx : NULL;  }
304    const   DWARFDebugInfoEntry*    GetSibling()    const   { return m_sibling_idx > 0 ? this + m_sibling_idx : NULL;  }
305            // We know we are kept in a vector of contiguous entries, so we know
306            // we don't need to store our child pointer, if we have a child it will
307            // be the next entry in the list...
308            DWARFDebugInfoEntry*    GetFirstChild()         { return (HasChildren() && !m_empty_children) ? this + 1 : NULL; }
309    const   DWARFDebugInfoEntry*    GetFirstChild() const   { return (HasChildren() && !m_empty_children) ? this + 1 : NULL; }
310
311
312    void                            GetDeclContextDIEs (DWARFCompileUnit* cu,
313                                                        DWARFDIECollection &decl_context_dies) const;
314
315    void                            GetDWARFDeclContext (SymbolFileDWARF* dwarf2Data,
316                                                         DWARFCompileUnit* cu,
317                                                         DWARFDeclContext &dwarf_decl_ctx) const;
318
319
320    bool                            MatchesDWARFDeclContext(SymbolFileDWARF* dwarf2Data,
321                                                            DWARFCompileUnit* cu,
322                                                            const DWARFDeclContext &dwarf_decl_ctx) const;
323
324            DWARFDIE                GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data,
325                                                             DWARFCompileUnit* cu) const;
326            DWARFDIE                GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data,
327                                                             DWARFCompileUnit* cu,
328                                                             const DWARFAttributes& attributes) const;
329
330    void
331    SetParent (DWARFDebugInfoEntry* parent)
332    {
333        if (parent)
334        {
335            // We know we are kept in a vector of contiguous entries, so we know
336            // our parent will be some index behind "this".
337            m_parent_idx = this - parent;
338        }
339        else
340            m_parent_idx = 0;
341    }
342    void
343    SetSibling (DWARFDebugInfoEntry* sibling)
344    {
345        if (sibling)
346        {
347            // We know we are kept in a vector of contiguous entries, so we know
348            // our sibling will be some index after "this".
349            m_sibling_idx = sibling - this;
350            sibling->SetParent(GetParent());
351        }
352        else
353            m_sibling_idx = 0;
354    }
355
356    void
357    SetSiblingIndex (uint32_t idx)
358    {
359        m_sibling_idx = idx;
360    }
361
362    void
363    SetParentIndex (uint32_t idx)
364    {
365        m_parent_idx = idx;
366    }
367
368    bool
369    GetEmptyChildren () const
370    {
371        return m_empty_children;
372    }
373
374    void
375    SetEmptyChildren (bool b)
376    {
377        m_empty_children = b;
378    }
379
380    static void
381    DumpDIECollection (lldb_private::Stream &strm,
382                       DWARFDebugInfoEntry::collection &die_collection);
383
384protected:
385    dw_offset_t GetAttributeValue(SymbolFileDWARF* dwarf2Data,
386                                  const DWARFCompileUnit* cu,
387                                  const dw_attr_t attr,
388                                  DWARFFormValue& formValue,
389                                  dw_offset_t* end_attr_offset_ptr = nullptr,
390                                  bool check_specification_or_abstract_origin = false) const;
391
392    dw_offset_t m_offset;           // Offset within the .debug_info of the start of this entry
393    uint32_t    m_parent_idx;       // How many to subtract from "this" to get the parent. If zero this die has no parent
394    uint32_t    m_sibling_idx:31,   // How many to add to "this" to get the sibling.
395                m_empty_children:1; // If a DIE says it had children, yet it just contained a NULL tag, this will be set.
396    uint32_t    m_abbr_idx:DIE_ABBR_IDX_BITSIZE,
397                m_has_children:1,   // Set to 1 if this DIE has children
398                m_tag:16;           // A copy of the DW_TAG value so we don't have to go through the compile unit abbrev table
399};
400
401#endif  // SymbolFileDWARF_DWARFDebugInfoEntry_h_
402