LLDB mainline
DWARFDIE.h
Go to the documentation of this file.
1//===-- DWARFDIE.h ----------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDIE_H
10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDIE_H
11
12#include "DWARFBaseDIE.h"
13#include "llvm/ADT/SmallSet.h"
14#include "llvm/ADT/iterator_range.h"
15#include "llvm/DebugInfo/DWARF/DWARFAddressRange.h"
16
17namespace lldb_private::plugin {
18namespace dwarf {
19class DWARFDIE : public DWARFBaseDIE {
20public:
21 class child_iterator;
23
24 // Tests
25 bool IsStructUnionOrClass() const;
26
27 bool IsMethod() const;
28
29 // Accessors
30
31 // Accessing information about a DIE
32 const char *GetMangledName(bool substitute_name_allowed = true) const;
33
34 const char *GetPubname() const;
35
37 void GetName(Stream &s) const;
38
39 void AppendTypeName(Stream &s) const;
40
41 Type *ResolveType() const;
42
43 // Resolve a type by UID using this DIE's DWARF file
44 Type *ResolveTypeUID(const DWARFDIE &die) const;
45
46 // Functions for obtaining DIE relations and references
47
49 GetParent() const;
50
52 GetFirstChild() const;
53
55 GetSibling() const;
56
58 GetReferencedDIE(const dw_attr_t attr) const;
59
60 // Get a another DIE from the same DWARF file as this DIE. This will
61 // check the current DIE's compile unit first to see if "die_offset" is
62 // in the same compile unit, and fall back to checking the DWARF file.
64 GetDIE(dw_offset_t die_offset) const;
66
68 LookupDeepestBlock(lldb::addr_t file_addr) const;
69
72
73 /// Return this DIE's decl context as it is needed to look up types
74 /// in Clang modules. This context will include any modules or functions that
75 /// the type is declared in so an exact module match can be efficiently made.
76 std::vector<CompilerContext> GetDeclContext() const;
77
78 /// Get a context to a type so it can be looked up.
79 ///
80 /// This function uses the current DIE to fill in a CompilerContext array
81 /// that is suitable for type lookup for comparison to a TypeQuery's compiler
82 /// context (TypeQuery::GetContextRef()). If this DIE represents a named type,
83 /// it should fill out the compiler context with the type itself as the last
84 /// entry. The declaration context should be above the type and stop at an
85 /// appropriate time, like either the translation unit or at a function
86 /// context. This is designed to allow users to efficiently look for types
87 /// using a full or partial CompilerContext array.
88 std::vector<CompilerContext> GetTypeLookupContext() const;
89
91
92 // Getting attribute values from the DIE.
93 //
94 // GetAttributeValueAsXXX() functions should only be used if you are
95 // looking for one or two attributes on a DIE. If you are trying to
96 // parse all attributes, use GetAttributes (...) instead
99
101 const char *&name, const char *&mangled,
102 llvm::DWARFAddressRangesVector &ranges, std::optional<int> &decl_file,
103 std::optional<int> &decl_line, std::optional<int> &decl_column,
104 std::optional<int> &call_file, std::optional<int> &call_line,
105 std::optional<int> &call_column, DWARFExpressionList *frame_base) const;
106
107 // The following methods use LLVM naming convension in order to be are used by
108 // LLVM libraries.
109 std::optional<uint64_t> getLanguage() const;
110
111 DWARFDIE getParent() const { return GetParent(); }
112
114
116
118
119 std::optional<DWARFFormValue> find(const dw_attr_t attr) const;
120
121 /// The range of all the children of this DIE.
122 llvm::iterator_range<child_iterator> children() const;
123
124 child_iterator begin() const;
125 child_iterator end() const;
126};
127
129 : public llvm::iterator_facade_base<DWARFDIE::child_iterator,
130 std::forward_iterator_tag, DWARFDIE> {
131 /// The current child or an invalid DWARFDie.
133
134public:
135 child_iterator() = default;
136 child_iterator(const DWARFDIE &parent) : m_die(parent.GetFirstChild()) {}
137 bool operator==(const child_iterator &it) const {
138 // DWARFDIE's operator== differentiates between an invalid DWARFDIE that
139 // has a CU but no DIE and one that has neither CU nor DIE. The 'end'
140 // iterator could be default constructed, so explicitly allow
141 // (CU, (DIE)nullptr) == (nullptr, nullptr) -> true
142 if (!m_die.IsValid() && !it.m_die.IsValid())
143 return true;
144 return m_die == it.m_die;
145 }
146 const DWARFDIE &operator*() const {
147 assert(m_die.IsValid() && "Derefencing invalid iterator?");
148 return m_die;
149 }
151 assert(m_die.IsValid() && "Derefencing invalid iterator?");
152 return m_die;
153 }
155 assert(m_die.IsValid() && "Incrementing invalid iterator?");
157 return *this;
158 }
159};
160} // namespace dwarf
161} // namespace lldb_private::plugin
162
163#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDIE_H
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
DWARFDebugInfoEntry * GetDIE() const
Definition: DWARFBaseDIE.h:61
DWARFDIE m_die
The current child or an invalid DWARFDie.
Definition: DWARFDIE.h:132
bool operator==(const child_iterator &it) const
Definition: DWARFDIE.h:137
const char * GetMangledName(bool substitute_name_allowed=true) const
Definition: DWARFDIE.cpp:210
DWARFDIE resolveTypeUnitReference() const
Definition: DWARFDIE.cpp:619
bool GetDIENamesAndRanges(const char *&name, const char *&mangled, llvm::DWARFAddressRangesVector &ranges, std::optional< int > &decl_file, std::optional< int > &decl_line, std::optional< int > &decl_column, std::optional< int > &call_file, std::optional< int > &call_line, std::optional< int > &call_column, DWARFExpressionList *frame_base) const
Definition: DWARFDIE.cpp:569
DWARFDIE resolveReferencedType(dw_attr_t attr) const
Definition: DWARFDIE.cpp:609
std::vector< CompilerContext > GetDeclContext() const
Return this DIE's decl context as it is needed to look up types in Clang modules.
Definition: DWARFDIE.cpp:428
llvm::iterator_range< child_iterator > children() const
The range of all the children of this DIE.
Definition: DWARFDIE.cpp:586
DWARFDIE GetParentDeclContextDIE() const
Definition: DWARFDIE.cpp:552
Type * ResolveTypeUID(const DWARFDIE &die) const
Definition: DWARFDIE.cpp:373
DWARFDIE LookupDeepestBlock(lldb::addr_t file_addr) const
Definition: DWARFDIE.cpp:145
std::optional< DWARFFormValue > find(const dw_attr_t attr) const
Definition: DWARFDIE.cpp:596
DWARFDIE GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const
Definition: DWARFDIE.cpp:132
DWARFDebugInfoEntry * GetDIE() const
Definition: DWARFBaseDIE.h:61
DWARFDeclContext GetDWARFDeclContext() const
Definition: DWARFDIE.cpp:511
std::optional< uint64_t > getLanguage() const
Definition: DWARFDIE.cpp:603
void AppendTypeName(Stream &s) const
Definition: DWARFDIE.cpp:247
child_iterator begin() const
Definition: DWARFDIE.cpp:590
DWARFDIE GetReferencedDIE(const dw_attr_t attr) const
Definition: DWARFDIE.cpp:116
std::vector< CompilerContext > GetTypeLookupContext() const
Get a context to a type so it can be looked up.
Definition: DWARFDIE.cpp:488
uint64_t dw_offset_t
Definition: dwarf.h:30
llvm::dwarf::Attribute dw_attr_t
Definition: dwarf.h:23
uint64_t addr_t
Definition: lldb-types.h:80