1 //===-- DWARFIndex.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_DWARFINDEX_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFINDEX_H
11 
12 #include "Plugins/SymbolFile/DWARF/DIERef.h"
13 #include "Plugins/SymbolFile/DWARF/DWARFDIE.h"
14 #include "Plugins/SymbolFile/DWARF/DWARFFormValue.h"
15 
16 #include "lldb/Core/Module.h"
17 #include "lldb/Target/Statistics.h"
18 
19 class DWARFDeclContext;
20 class DWARFDIE;
21 
22 namespace lldb_private {
23 class DWARFIndex {
24 public:
25   DWARFIndex(Module &module) : m_module(module) {}
26   virtual ~DWARFIndex();
27 
28   virtual void Preload() = 0;
29 
30   /// Finds global variables with the given base name. Any additional filtering
31   /// (e.g., to only retrieve variables from a given context) should be done by
32   /// the consumer.
33   virtual void
34   GetGlobalVariables(ConstString basename,
35                      llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
36 
37   virtual void
38   GetGlobalVariables(const RegularExpression &regex,
39                      llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
40   /// \a cu must be the skeleton unit if possible, not GetNonSkeletonUnit().
41   virtual void
42   GetGlobalVariables(DWARFUnit &cu,
43                      llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
44   virtual void
45   GetObjCMethods(ConstString class_name,
46                  llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
47   virtual void
48   GetCompleteObjCClass(ConstString class_name, bool must_be_implementation,
49                        llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
50   virtual void GetTypes(ConstString name,
51                         llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
52   virtual void GetTypes(const DWARFDeclContext &context,
53                         llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
54   virtual void
55   GetNamespaces(ConstString name,
56                 llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
57   virtual void
58   GetFunctions(const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
59                const CompilerDeclContext &parent_decl_ctx,
60                llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
61   virtual void
62   GetFunctions(const RegularExpression &regex,
63                llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
64 
65   virtual void Dump(Stream &s) = 0;
66 
67   StatsDuration::Duration GetIndexTime() { return m_index_time; }
68 
69 protected:
70   Module &m_module;
71   StatsDuration m_index_time;
72 
73   /// Helper function implementing common logic for processing function dies. If
74   /// the function given by "ref" matches search criteria given by
75   /// "parent_decl_ctx" and "name_type_mask", it is inserted into the "dies"
76   /// vector.
77   bool ProcessFunctionDIE(const Module::LookupInfo &lookup_info, DIERef ref,
78                           SymbolFileDWARF &dwarf,
79                           const CompilerDeclContext &parent_decl_ctx,
80                           llvm::function_ref<bool(DWARFDIE die)> callback);
81 
82   class DIERefCallbackImpl {
83   public:
84     DIERefCallbackImpl(const DWARFIndex &index,
85                        llvm::function_ref<bool(DWARFDIE die)> callback,
86                        llvm::StringRef name);
87     bool operator()(DIERef ref) const;
88 
89   private:
90     const DWARFIndex &m_index;
91     SymbolFileDWARF &m_dwarf;
92     const llvm::function_ref<bool(DWARFDIE die)> m_callback;
93     const llvm::StringRef m_name;
94   };
95   DIERefCallbackImpl
96   DIERefCallback(llvm::function_ref<bool(DWARFDIE die)> callback,
97                  llvm::StringRef name = {}) const {
98     return DIERefCallbackImpl(*this, callback, name);
99   }
100 
101   void ReportInvalidDIERef(DIERef ref, llvm::StringRef name) const;
102 };
103 } // namespace lldb_private
104 
105 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFINDEX_H
106