]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / SymbolFile / DWARF / DWARFDIE.h
1 //===-- DWARFDIE.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_DWARFDIE_h_
11 #define SymbolFileDWARF_DWARFDIE_h_
12
13 #include "DWARFBaseDIE.h"
14 #include "llvm/ADT/SmallSet.h"
15
16 class DWARFDIE : public DWARFBaseDIE {
17 public:
18   class ElaboratingDIEIterator;
19
20   using DWARFBaseDIE::DWARFBaseDIE;
21
22   //----------------------------------------------------------------------
23   // Tests
24   //----------------------------------------------------------------------
25   bool IsStructUnionOrClass() const;
26
27   bool IsMethod() const;
28
29   //----------------------------------------------------------------------
30   // Accessors
31   //----------------------------------------------------------------------
32   lldb::ModuleSP GetContainingDWOModule() const;
33
34   DWARFDIE
35   GetContainingDWOModuleDIE() const;
36
37   inline llvm::iterator_range<ElaboratingDIEIterator> elaborating_dies() const;
38
39   //----------------------------------------------------------------------
40   // Accessing information about a DIE
41   //----------------------------------------------------------------------
42   const char *GetMangledName() const;
43
44   const char *GetPubname() const;
45
46   const char *GetQualifiedName(std::string &storage) const;
47
48   lldb_private::Type *ResolveType() const;
49
50   //----------------------------------------------------------------------
51   // Resolve a type by UID using this DIE's DWARF file
52   //----------------------------------------------------------------------
53   lldb_private::Type *ResolveTypeUID(const DIERef &die_ref) const;
54
55   //----------------------------------------------------------------------
56   // Functions for obtaining DIE relations and references
57   //----------------------------------------------------------------------
58
59   DWARFDIE
60   GetParent() const;
61
62   DWARFDIE
63   GetFirstChild() const;
64
65   DWARFDIE
66   GetSibling() const;
67
68   DWARFDIE
69   GetReferencedDIE(const dw_attr_t attr) const;
70
71   //----------------------------------------------------------------------
72   // Get a another DIE from the same DWARF file as this DIE. This will
73   // check the current DIE's compile unit first to see if "die_offset" is
74   // in the same compile unit, and fall back to checking the DWARF file.
75   //----------------------------------------------------------------------
76   DWARFDIE
77   GetDIE(dw_offset_t die_offset) const;
78   using DWARFBaseDIE::GetDIE;
79
80   DWARFDIE
81   LookupDeepestBlock(lldb::addr_t file_addr) const;
82
83   DWARFDIE
84   GetParentDeclContextDIE() const;
85
86   //----------------------------------------------------------------------
87   // DeclContext related functions
88   //----------------------------------------------------------------------
89   void GetDeclContextDIEs(DWARFDIECollection &decl_context_dies) const;
90
91   void GetDWARFDeclContext(DWARFDeclContext &dwarf_decl_ctx) const;
92
93   /// Return this DIE's decl context as it is needed to look up types
94   /// in Clang's -gmodules debug info format.
95   void
96   GetDeclContext(std::vector<lldb_private::CompilerContext> &context) const;
97
98   //----------------------------------------------------------------------
99   // Getting attribute values from the DIE.
100   //
101   // GetAttributeValueAsXXX() functions should only be used if you are
102   // looking for one or two attributes on a DIE. If you are trying to
103   // parse all attributes, use GetAttributes (...) instead
104   //----------------------------------------------------------------------
105   DWARFDIE
106   GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const;
107
108   bool GetDIENamesAndRanges(const char *&name, const char *&mangled,
109                             DWARFRangeList &ranges, int &decl_file,
110                             int &decl_line, int &decl_column, int &call_file,
111                             int &call_line, int &call_column,
112                             lldb_private::DWARFExpression *frame_base) const;
113
114   //----------------------------------------------------------------------
115   // CompilerDecl related functions
116   //----------------------------------------------------------------------
117
118   lldb_private::CompilerDecl GetDecl() const;
119
120   lldb_private::CompilerDeclContext GetDeclContext() const;
121
122   lldb_private::CompilerDeclContext GetContainingDeclContext() const;
123 };
124
125 /// Iterate through all DIEs elaborating (i.e. reachable by a chain of
126 /// DW_AT_specification and DW_AT_abstract_origin attributes) a given DIE. For
127 /// convenience, the starting die is included in the sequence as the first
128 /// item.
129 class DWARFDIE::ElaboratingDIEIterator
130     : public std::iterator<std::input_iterator_tag, DWARFDIE> {
131
132   // The operating invariant is: top of m_worklist contains the "current" item
133   // and the rest of the list are items yet to be visited. An empty worklist
134   // means we've reached the end.
135   // Infinite recursion is prevented by maintaining a list of seen DIEs.
136   // Container sizes are optimized for the case of following DW_AT_specification
137   // and DW_AT_abstract_origin just once.
138   llvm::SmallVector<DWARFDIE, 2> m_worklist;
139   llvm::SmallSet<lldb::user_id_t, 3> m_seen;
140
141   void Next();
142
143 public:
144   /// An iterator starting at die d.
145   explicit ElaboratingDIEIterator(DWARFDIE d) : m_worklist(1, d) {}
146
147   /// End marker
148   ElaboratingDIEIterator() {}
149
150   const DWARFDIE &operator*() const { return m_worklist.back(); }
151   ElaboratingDIEIterator &operator++() {
152     Next();
153     return *this;
154   }
155   ElaboratingDIEIterator operator++(int) {
156     ElaboratingDIEIterator I = *this;
157     Next();
158     return I;
159   }
160
161   friend bool operator==(const ElaboratingDIEIterator &a,
162                          const ElaboratingDIEIterator &b) {
163     if (a.m_worklist.empty() || b.m_worklist.empty())
164       return a.m_worklist.empty() == b.m_worklist.empty();
165     return a.m_worklist.back() == b.m_worklist.back();
166   }
167   friend bool operator!=(const ElaboratingDIEIterator &a,
168                          const ElaboratingDIEIterator &b) {
169     return !(a == b);
170   }
171 };
172
173 llvm::iterator_range<DWARFDIE::ElaboratingDIEIterator>
174 DWARFDIE::elaborating_dies() const {
175   return llvm::make_range(ElaboratingDIEIterator(*this),
176                           ElaboratingDIEIterator());
177 }
178
179 #endif // SymbolFileDWARF_DWARFDIE_h_