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
16namespace lldb_private::plugin {
17namespace dwarf {
18class DWARFDIE : public DWARFBaseDIE {
19public:
20 class child_iterator;
22
23 // Tests
24 bool IsStructUnionOrClass() const;
25
26 bool IsMethod() const;
27
28 // Accessors
29
30 // Accessing information about a DIE
31 const char *GetMangledName() const;
32
33 const char *GetPubname() const;
34
36 void GetName(Stream &s) const;
37
38 void AppendTypeName(Stream &s) const;
39
40 Type *ResolveType() const;
41
42 // Resolve a type by UID using this DIE's DWARF file
43 Type *ResolveTypeUID(const DWARFDIE &die) const;
44
45 // Functions for obtaining DIE relations and references
46
48 GetParent() const;
49
51 GetFirstChild() const;
52
54 GetSibling() const;
55
57 GetReferencedDIE(const dw_attr_t attr) const;
58
59 // Get a another DIE from the same DWARF file as this DIE. This will
60 // check the current DIE's compile unit first to see if "die_offset" is
61 // in the same compile unit, and fall back to checking the DWARF file.
63 GetDIE(dw_offset_t die_offset) const;
65
67 LookupDeepestBlock(lldb::addr_t file_addr) const;
68
71
72 // DeclContext related functions
73 std::vector<DWARFDIE> GetDeclContextDIEs() const;
74
75 /// Return this DIE's decl context as it is needed to look up types
76 /// in Clang modules. This context will include any modules or functions that
77 /// the type is declared in so an exact module match can be efficiently made.
78 std::vector<CompilerContext> GetDeclContext() const;
79
80 /// Get a context to a type so it can be looked up.
81 ///
82 /// This function uses the current DIE to fill in a CompilerContext array
83 /// that is suitable for type lookup for comparison to a TypeQuery's compiler
84 /// context (TypeQuery::GetContextRef()). If this DIE represents a named type,
85 /// it should fill out the compiler context with the type itself as the last
86 /// entry. The declaration context should be above the type and stop at an
87 /// appropriate time, like either the translation unit or at a function
88 /// context. This is designed to allow users to efficiently look for types
89 /// using a full or partial CompilerContext array.
90 std::vector<CompilerContext> GetTypeLookupContext() const;
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, DWARFRangeList &ranges,
102 std::optional<int> &decl_file, std::optional<int> &decl_line,
103 std::optional<int> &decl_column, std::optional<int> &call_file,
104 std::optional<int> &call_line, std::optional<int> &call_column,
105 DWARFExpressionList *frame_base) const;
106
107 /// The range of all the children of this DIE.
108 llvm::iterator_range<child_iterator> children() const;
109};
110
112 : public llvm::iterator_facade_base<DWARFDIE::child_iterator,
113 std::forward_iterator_tag, DWARFDIE> {
114 /// The current child or an invalid DWARFDie.
116
117public:
118 child_iterator() = default;
119 child_iterator(const DWARFDIE &parent) : m_die(parent.GetFirstChild()) {}
120 bool operator==(const child_iterator &it) const {
121 // DWARFDIE's operator== differentiates between an invalid DWARFDIE that
122 // has a CU but no DIE and one that has neither CU nor DIE. The 'end'
123 // iterator could be default constructed, so explicitly allow
124 // (CU, (DIE)nullptr) == (nullptr, nullptr) -> true
125 if (!m_die.IsValid() && !it.m_die.IsValid())
126 return true;
127 return m_die == it.m_die;
128 }
129 const DWARFDIE &operator*() const {
130 assert(m_die.IsValid() && "Derefencing invalid iterator?");
131 return m_die;
132 }
134 assert(m_die.IsValid() && "Derefencing invalid iterator?");
135 return m_die;
136 }
138 assert(m_die.IsValid() && "Incrementing invalid iterator?");
140 return *this;
141 }
142};
143} // namespace dwarf
144} // namespace lldb_private::plugin
145
146#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:59
DWARFDIE m_die
The current child or an invalid DWARFDie.
Definition: DWARFDIE.h:115
bool operator==(const child_iterator &it) const
Definition: DWARFDIE.h:120
std::vector< DWARFDIE > GetDeclContextDIEs() const
Definition: DWARFDIE.cpp:368
std::vector< CompilerContext > GetTypeLookupContext() const
Get a context to a type so it can be looked up.
Definition: DWARFDIE.cpp:440
const char * GetMangledName() const
Definition: DWARFDIE.cpp:199
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:434
llvm::iterator_range< child_iterator > children() const
The range of all the children of this DIE.
Definition: DWARFDIE.cpp:522
bool GetDIENamesAndRanges(const char *&name, const char *&mangled, DWARFRangeList &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:508
DWARFDIE GetParentDeclContextDIE() const
Definition: DWARFDIE.cpp:488
Type * ResolveTypeUID(const DWARFDIE &die) const
Definition: DWARFDIE.cpp:362
DWARFDIE LookupDeepestBlock(lldb::addr_t file_addr) const
Definition: DWARFDIE.cpp:140
DWARFDIE GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const
Definition: DWARFDIE.cpp:127
DWARFDebugInfoEntry * GetDIE() const
Definition: DWARFBaseDIE.h:59
void AppendTypeName(Stream &s) const
Definition: DWARFDIE.cpp:236
DWARFDIE GetReferencedDIE(const dw_attr_t attr) const
Definition: DWARFDIE.cpp:111
uint64_t dw_offset_t
Definition: dwarf.h:31
llvm::dwarf::Attribute dw_attr_t
Definition: dwarf.h:24
uint64_t addr_t
Definition: lldb-types.h:79