1 //===-- DWARFIndex.h -------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFINDEX_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFINDEX_H
12 #include "Plugins/SymbolFile/DWARF/DIERef.h"
13 #include "Plugins/SymbolFile/DWARF/DWARFDIE.h"
14 #include "Plugins/SymbolFile/DWARF/DWARFFormValue.h"
15 #include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
17 #include "lldb/Core/Module.h"
18 #include "lldb/Target/Statistics.h"
20 namespace lldb_private::plugin
{
22 class DWARFDeclContext
;
27 DWARFIndex(Module
&module
) : m_module(module
) {}
28 virtual ~DWARFIndex();
30 virtual void Preload() = 0;
32 /// Finds global variables with the given base name. Any additional filtering
33 /// (e.g., to only retrieve variables from a given context) should be done by
36 GetGlobalVariables(ConstString basename
,
37 llvm::function_ref
<bool(DWARFDIE die
)> callback
) = 0;
40 GetGlobalVariables(const RegularExpression
®ex
,
41 llvm::function_ref
<bool(DWARFDIE die
)> callback
) = 0;
42 /// \a cu must be the skeleton unit if possible, not GetNonSkeletonUnit().
44 GetGlobalVariables(DWARFUnit
&cu
,
45 llvm::function_ref
<bool(DWARFDIE die
)> callback
) = 0;
47 GetObjCMethods(ConstString class_name
,
48 llvm::function_ref
<bool(DWARFDIE die
)> callback
) = 0;
50 GetCompleteObjCClass(ConstString class_name
, bool must_be_implementation
,
51 llvm::function_ref
<bool(DWARFDIE die
)> callback
) = 0;
52 virtual void GetTypes(ConstString name
,
53 llvm::function_ref
<bool(DWARFDIE die
)> callback
) = 0;
54 virtual void GetTypes(const DWARFDeclContext
&context
,
55 llvm::function_ref
<bool(DWARFDIE die
)> callback
) = 0;
57 /// Finds all DIEs whose fully qualified name matches `context`. A base
58 /// implementation is provided, and it uses the entire CU to check the DIE
59 /// parent hierarchy. Specializations should override this if they are able
60 /// to provide a faster implementation.
62 GetFullyQualifiedType(const DWARFDeclContext
&context
,
63 llvm::function_ref
<bool(DWARFDIE die
)> callback
);
65 GetNamespaces(ConstString name
,
66 llvm::function_ref
<bool(DWARFDIE die
)> callback
) = 0;
67 /// Get type DIEs meeting requires of \a query.
68 /// in its decl parent chain as subset. A base implementation is provided,
69 /// Specializations should override this if they are able to provide a faster
72 GetTypesWithQuery(TypeQuery
&query
,
73 llvm::function_ref
<bool(DWARFDIE die
)> callback
);
74 /// Get namespace DIEs whose base name match \param name with \param
75 /// parent_decl_ctx in its decl parent chain. A base implementation
76 /// is provided. Specializations should override this if they are able to
77 /// provide a faster implementation.
79 GetNamespacesWithParents(ConstString name
,
80 const CompilerDeclContext
&parent_decl_ctx
,
81 llvm::function_ref
<bool(DWARFDIE die
)> callback
);
83 GetFunctions(const Module::LookupInfo
&lookup_info
, SymbolFileDWARF
&dwarf
,
84 const CompilerDeclContext
&parent_decl_ctx
,
85 llvm::function_ref
<bool(DWARFDIE die
)> callback
) = 0;
87 GetFunctions(const RegularExpression
®ex
,
88 llvm::function_ref
<bool(DWARFDIE die
)> callback
) = 0;
90 virtual void Dump(Stream
&s
) = 0;
92 StatsDuration::Duration
GetIndexTime() { return m_index_time
; }
94 void ResetStatistics() { m_index_time
.reset(); }
98 StatsDuration m_index_time
;
100 /// Helper function implementing common logic for processing function dies. If
101 /// the function given by "die" matches search criteria given by
102 /// "parent_decl_ctx" and "name_type_mask", it calls the callback with the
104 bool ProcessFunctionDIE(const Module::LookupInfo
&lookup_info
, DWARFDIE die
,
105 const CompilerDeclContext
&parent_decl_ctx
,
106 llvm::function_ref
<bool(DWARFDIE die
)> callback
);
108 class DIERefCallbackImpl
{
110 DIERefCallbackImpl(const DWARFIndex
&index
,
111 llvm::function_ref
<bool(DWARFDIE die
)> callback
,
112 llvm::StringRef name
);
113 bool operator()(DIERef ref
) const;
114 bool operator()(const llvm::AppleAcceleratorTable::Entry
&entry
) const;
117 const DWARFIndex
&m_index
;
118 SymbolFileDWARF
&m_dwarf
;
119 const llvm::function_ref
<bool(DWARFDIE die
)> m_callback
;
120 const llvm::StringRef m_name
;
123 DIERefCallback(llvm::function_ref
<bool(DWARFDIE die
)> callback
,
124 llvm::StringRef name
= {}) const {
125 return DIERefCallbackImpl(*this, callback
, name
);
128 void ReportInvalidDIERef(DIERef ref
, llvm::StringRef name
) const;
130 /// Implementation of `GetFullyQualifiedType` to check a single entry,
131 /// shareable with derived classes.
133 GetFullyQualifiedTypeImpl(const DWARFDeclContext
&context
, DWARFDIE die
,
134 llvm::function_ref
<bool(DWARFDIE die
)> callback
);
136 /// Check if the type \a die can meet the requirements of \a query.
138 ProcessTypeDIEMatchQuery(TypeQuery
&query
, DWARFDIE die
,
139 llvm::function_ref
<bool(DWARFDIE die
)> callback
);
140 bool ProcessNamespaceDieMatchParents(
141 const CompilerDeclContext
&parent_decl_ctx
, DWARFDIE die
,
142 llvm::function_ref
<bool(DWARFDIE die
)> callback
);
145 } // namespace lldb_private::plugin
147 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFINDEX_H