1 //===-- DebugNamesDWARFIndex.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_DEBUGNAMESDWARFINDEX_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DEBUGNAMESDWARFINDEX_H
11 
12 #include "Plugins/SymbolFile/DWARF/DWARFIndex.h"
13 #include "Plugins/SymbolFile/DWARF/LogChannelDWARF.h"
14 #include "Plugins/SymbolFile/DWARF/ManualDWARFIndex.h"
15 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
16 #include "lldb/Utility/ConstString.h"
17 #include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
18 
19 namespace lldb_private {
20 class DebugNamesDWARFIndex : public DWARFIndex {
21 public:
22   static llvm::Expected<std::unique_ptr<DebugNamesDWARFIndex>>
23   Create(Module &module, DWARFDataExtractor debug_names,
24          DWARFDataExtractor debug_str, SymbolFileDWARF &dwarf);
25 
26   void Preload() override { m_fallback.Preload(); }
27 
28   void
29   GetGlobalVariables(ConstString basename,
30                      llvm::function_ref<bool(DIERef ref)> callback) override;
31   void
32   GetGlobalVariables(const RegularExpression &regex,
33                      llvm::function_ref<bool(DIERef ref)> callback) override;
34   void
35   GetGlobalVariables(const DWARFUnit &cu,
36                      llvm::function_ref<bool(DIERef ref)> callback) override;
37   void GetObjCMethods(ConstString class_name,
38                       llvm::function_ref<bool(DIERef ref)> callback) override {}
39   void
40   GetCompleteObjCClass(ConstString class_name, bool must_be_implementation,
41                        llvm::function_ref<bool(DIERef ref)> callback) override;
42   void GetTypes(ConstString name,
43                 llvm::function_ref<bool(DIERef ref)> callback) override;
44   void GetTypes(const DWARFDeclContext &context,
45                 llvm::function_ref<bool(DIERef ref)> callback) override;
46   void GetNamespaces(ConstString name,
47                      llvm::function_ref<bool(DIERef ref)> callback) override;
48   void GetFunctions(ConstString name, SymbolFileDWARF &dwarf,
49                     const CompilerDeclContext &parent_decl_ctx,
50                     uint32_t name_type_mask,
51                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
52   void GetFunctions(const RegularExpression &regex,
53                     llvm::function_ref<bool(DIERef ref)> callback) override;
54 
55   void ReportInvalidDIERef(const DIERef &ref, llvm::StringRef name) override {}
56   void Dump(Stream &s) override;
57 
58 private:
59   DebugNamesDWARFIndex(Module &module,
60                        std::unique_ptr<llvm::DWARFDebugNames> debug_names_up,
61                        DWARFDataExtractor debug_names_data,
62                        DWARFDataExtractor debug_str_data,
63                        SymbolFileDWARF &dwarf)
64       : DWARFIndex(module), m_debug_info(dwarf.DebugInfo()),
65         m_debug_names_data(debug_names_data), m_debug_str_data(debug_str_data),
66         m_debug_names_up(std::move(debug_names_up)),
67         m_fallback(module, dwarf, GetUnits(*m_debug_names_up)) {}
68 
69   DWARFDebugInfo &m_debug_info;
70 
71   // LLVM DWARFDebugNames will hold a non-owning reference to this data, so keep
72   // track of the ownership here.
73   DWARFDataExtractor m_debug_names_data;
74   DWARFDataExtractor m_debug_str_data;
75 
76   using DebugNames = llvm::DWARFDebugNames;
77   std::unique_ptr<DebugNames> m_debug_names_up;
78   ManualDWARFIndex m_fallback;
79 
80   llvm::Optional<DIERef> ToDIERef(const DebugNames::Entry &entry);
81   bool ProcessEntry(const DebugNames::Entry &entry,
82                     llvm::function_ref<bool(DIERef ref)> callback);
83 
84   static void MaybeLogLookupError(llvm::Error error,
85                                   const DebugNames::NameIndex &ni,
86                                   llvm::StringRef name);
87 
88   static llvm::DenseSet<dw_offset_t> GetUnits(const DebugNames &debug_names);
89 };
90 
91 } // namespace lldb_private
92 
93 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DEBUGNAMESDWARFINDEX_H
94