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