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