1 //===-- DWARFDIE.h ----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef SymbolFileDWARF_DWARFDIE_h_
11 #define SymbolFileDWARF_DWARFDIE_h_
13 #include "DWARFBaseDIE.h"
14 #include "llvm/ADT/SmallSet.h"
16 class DWARFDIE : public DWARFBaseDIE {
18 class ElaboratingDIEIterator;
20 using DWARFBaseDIE::DWARFBaseDIE;
22 //----------------------------------------------------------------------
24 //----------------------------------------------------------------------
25 bool IsStructUnionOrClass() const;
27 bool IsMethod() const;
29 //----------------------------------------------------------------------
31 //----------------------------------------------------------------------
32 lldb::ModuleSP GetContainingDWOModule() const;
35 GetContainingDWOModuleDIE() const;
37 inline llvm::iterator_range<ElaboratingDIEIterator> elaborating_dies() const;
39 //----------------------------------------------------------------------
40 // Accessing information about a DIE
41 //----------------------------------------------------------------------
42 const char *GetMangledName() const;
44 const char *GetPubname() const;
46 const char *GetQualifiedName(std::string &storage) const;
48 lldb_private::Type *ResolveType() const;
50 //----------------------------------------------------------------------
51 // Resolve a type by UID using this DIE's DWARF file
52 //----------------------------------------------------------------------
53 lldb_private::Type *ResolveTypeUID(const DIERef &die_ref) const;
55 //----------------------------------------------------------------------
56 // Functions for obtaining DIE relations and references
57 //----------------------------------------------------------------------
63 GetFirstChild() const;
69 GetReferencedDIE(const dw_attr_t attr) const;
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 //----------------------------------------------------------------------
77 GetDIE(dw_offset_t die_offset) const;
78 using DWARFBaseDIE::GetDIE;
81 LookupDeepestBlock(lldb::addr_t file_addr) const;
84 GetParentDeclContextDIE() const;
86 //----------------------------------------------------------------------
87 // DeclContext related functions
88 //----------------------------------------------------------------------
89 void GetDeclContextDIEs(DWARFDIECollection &decl_context_dies) const;
91 void GetDWARFDeclContext(DWARFDeclContext &dwarf_decl_ctx) const;
93 /// Return this DIE's decl context as it is needed to look up types
94 /// in Clang's -gmodules debug info format.
96 GetDeclContext(std::vector<lldb_private::CompilerContext> &context) const;
98 //----------------------------------------------------------------------
99 // Getting attribute values from the DIE.
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 //----------------------------------------------------------------------
106 GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const;
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;
114 //----------------------------------------------------------------------
115 // CompilerDecl related functions
116 //----------------------------------------------------------------------
118 lldb_private::CompilerDecl GetDecl() const;
120 lldb_private::CompilerDeclContext GetDeclContext() const;
122 lldb_private::CompilerDeclContext GetContainingDeclContext() const;
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
129 class DWARFDIE::ElaboratingDIEIterator
130 : public std::iterator<std::input_iterator_tag, DWARFDIE> {
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;
144 /// An iterator starting at die d.
145 explicit ElaboratingDIEIterator(DWARFDIE d) : m_worklist(1, d) {}
148 ElaboratingDIEIterator() {}
150 const DWARFDIE &operator*() const { return m_worklist.back(); }
151 ElaboratingDIEIterator &operator++() {
155 ElaboratingDIEIterator operator++(int) {
156 ElaboratingDIEIterator I = *this;
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();
167 friend bool operator!=(const ElaboratingDIEIterator &a,
168 const ElaboratingDIEIterator &b) {
173 llvm::iterator_range<DWARFDIE::ElaboratingDIEIterator>
174 DWARFDIE::elaborating_dies() const {
175 return llvm::make_range(ElaboratingDIEIterator(*this),
176 ElaboratingDIEIterator());
179 #endif // SymbolFileDWARF_DWARFDIE_h_