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(DWARFDIE die)> callback) override;
31   void
32   GetGlobalVariables(const RegularExpression &regex,
33                      llvm::function_ref<bool(DWARFDIE die)> callback) override;
34   void
35   GetGlobalVariables(DWARFUnit &cu,
36                      llvm::function_ref<bool(DWARFDIE die)> callback) override;
37   void
38   GetObjCMethods(ConstString class_name,
39                  llvm::function_ref<bool(DWARFDIE die)> callback) override {}
40   void GetCompleteObjCClass(
41       ConstString class_name, bool must_be_implementation,
42       llvm::function_ref<bool(DWARFDIE die)> callback) override;
43   void GetTypes(ConstString name,
44                 llvm::function_ref<bool(DWARFDIE die)> callback) override;
45   void GetTypes(const DWARFDeclContext &context,
46                 llvm::function_ref<bool(DWARFDIE die)> callback) override;
47   void GetNamespaces(ConstString name,
48                      llvm::function_ref<bool(DWARFDIE die)> callback) override;
49   void GetFunctions(ConstString name, SymbolFileDWARF &dwarf,
50                     const CompilerDeclContext &parent_decl_ctx,
51                     uint32_t name_type_mask,
52                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
53   void GetFunctions(const RegularExpression &regex,
54                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
55 
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(DWARFDIE die)> callback,
83                     llvm::StringRef name);
84 
85   static void MaybeLogLookupError(llvm::Error error,
86                                   const DebugNames::NameIndex &ni,
87                                   llvm::StringRef name);
88 
89   static llvm::DenseSet<dw_offset_t> GetUnits(const DebugNames &debug_names);
90 };
91 
92 } // namespace lldb_private
93 
94 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DEBUGNAMESDWARFINDEX_H
95