]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / source / Plugins / SymbolFile / DWARF / SymbolFileDWARF.h
1 //===-- SymbolFileDWARF.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 SymbolFileDWARF_SymbolFileDWARF_h_
10 #define SymbolFileDWARF_SymbolFileDWARF_h_
11
12 #include <list>
13 #include <map>
14 #include <mutex>
15 #include <set>
16 #include <unordered_map>
17 #include <vector>
18
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/Support/Threading.h"
21
22 #include "lldb/Core/UniqueCStringMap.h"
23 #include "lldb/Core/dwarf.h"
24 #include "lldb/Expression/DWARFExpression.h"
25 #include "lldb/Symbol/DebugMacros.h"
26 #include "lldb/Symbol/SymbolContext.h"
27 #include "lldb/Symbol/SymbolFile.h"
28 #include "lldb/Utility/ConstString.h"
29 #include "lldb/Utility/Flags.h"
30 #include "lldb/Utility/RangeMap.h"
31 #include "lldb/lldb-private.h"
32
33 #include "DWARFContext.h"
34 #include "DWARFDataExtractor.h"
35 #include "DWARFDefines.h"
36 #include "DWARFIndex.h"
37 #include "UniqueDWARFASTType.h"
38
39 // Forward Declarations for this DWARF plugin
40 class DebugMapModule;
41 class DWARFAbbreviationDeclaration;
42 class DWARFAbbreviationDeclarationSet;
43 class DWARFCompileUnit;
44 class DWARFDebugAbbrev;
45 class DWARFDebugAranges;
46 class DWARFDebugInfo;
47 class DWARFDebugInfoEntry;
48 class DWARFDebugLine;
49 class DWARFDebugRangesBase;
50 class DWARFDeclContext;
51 class DWARFFormValue;
52 class DWARFTypeUnit;
53 class SymbolFileDWARFDebugMap;
54 class SymbolFileDWARFDwo;
55 class SymbolFileDWARFDwp;
56
57 #define DIE_IS_BEING_PARSED ((lldb_private::Type *)1)
58
59 class SymbolFileDWARF : public lldb_private::SymbolFile,
60                         public lldb_private::UserID {
61 public:
62   friend class SymbolFileDWARFDebugMap;
63   friend class SymbolFileDWARFDwo;
64   friend class DebugMapModule;
65   friend class DWARFCompileUnit;
66   friend class DWARFDIE;
67   friend class DWARFASTParserClang;
68
69   // Static Functions
70   static void Initialize();
71
72   static void Terminate();
73
74   static void DebuggerInitialize(lldb_private::Debugger &debugger);
75
76   static lldb_private::ConstString GetPluginNameStatic();
77
78   static const char *GetPluginDescriptionStatic();
79
80   static lldb_private::SymbolFile *
81   CreateInstance(lldb_private::ObjectFile *obj_file);
82
83   static lldb_private::FileSpecList GetSymlinkPaths();
84
85   // Constructors and Destructors
86
87   SymbolFileDWARF(lldb_private::ObjectFile *ofile,
88                   lldb_private::SectionList *dwo_section_list);
89
90   ~SymbolFileDWARF() override;
91
92   uint32_t CalculateAbilities() override;
93
94   void InitializeObject() override;
95
96   // Compile Unit function calls
97
98   uint32_t GetNumCompileUnits() override;
99
100   lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
101
102   lldb::LanguageType
103   ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
104
105   size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
106
107   bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
108
109   bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override;
110
111   bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit,
112                          lldb_private::FileSpecList &support_files) override;
113
114   bool ParseIsOptimized(lldb_private::CompileUnit &comp_unit) override;
115
116   size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
117
118   bool ParseImportedModules(
119       const lldb_private::SymbolContext &sc,
120       std::vector<lldb_private::SourceModule> &imported_modules) override;
121
122   size_t ParseBlocksRecursive(lldb_private::Function &func) override;
123
124   size_t
125   ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
126
127   lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
128   llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID(
129       lldb::user_id_t type_uid,
130       const lldb_private::ExecutionContext *exe_ctx) override;
131
132   bool CompleteType(lldb_private::CompilerType &compiler_type) override;
133
134   lldb_private::Type *ResolveType(const DWARFDIE &die,
135                                   bool assert_not_being_parsed = true,
136                                   bool resolve_function_context = false);
137
138   lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override;
139
140   lldb_private::CompilerDeclContext
141   GetDeclContextForUID(lldb::user_id_t uid) override;
142
143   lldb_private::CompilerDeclContext
144   GetDeclContextContainingUID(lldb::user_id_t uid) override;
145
146   void
147   ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
148
149   uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
150                                 lldb::SymbolContextItem resolve_scope,
151                                 lldb_private::SymbolContext &sc) override;
152
153   uint32_t
154   ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line,
155                        bool check_inlines,
156                        lldb::SymbolContextItem resolve_scope,
157                        lldb_private::SymbolContextList &sc_list) override;
158
159   uint32_t
160   FindGlobalVariables(lldb_private::ConstString name,
161                       const lldb_private::CompilerDeclContext *parent_decl_ctx,
162                       uint32_t max_matches,
163                       lldb_private::VariableList &variables) override;
164
165   uint32_t FindGlobalVariables(const lldb_private::RegularExpression &regex,
166                                uint32_t max_matches,
167                                lldb_private::VariableList &variables) override;
168
169   uint32_t
170   FindFunctions(lldb_private::ConstString name,
171                 const lldb_private::CompilerDeclContext *parent_decl_ctx,
172                 lldb::FunctionNameType name_type_mask, bool include_inlines,
173                 bool append, lldb_private::SymbolContextList &sc_list) override;
174
175   uint32_t FindFunctions(const lldb_private::RegularExpression &regex,
176                          bool include_inlines, bool append,
177                          lldb_private::SymbolContextList &sc_list) override;
178
179   void GetMangledNamesForFunction(
180       const std::string &scope_qualified_name,
181       std::vector<lldb_private::ConstString> &mangled_names) override;
182
183   uint32_t
184   FindTypes(lldb_private::ConstString name,
185             const lldb_private::CompilerDeclContext *parent_decl_ctx,
186             bool append, uint32_t max_matches,
187             llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
188             lldb_private::TypeMap &types) override;
189
190   size_t FindTypes(const std::vector<lldb_private::CompilerContext> &context,
191                    bool append, lldb_private::TypeMap &types) override;
192
193   lldb_private::TypeList *GetTypeList() override;
194
195   size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
196                   lldb::TypeClass type_mask,
197                   lldb_private::TypeList &type_list) override;
198
199   lldb_private::TypeSystem *
200   GetTypeSystemForLanguage(lldb::LanguageType language) override;
201
202   lldb_private::CompilerDeclContext FindNamespace(
203       lldb_private::ConstString name,
204       const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
205
206   void PreloadSymbols() override;
207
208   std::recursive_mutex &GetModuleMutex() const override;
209
210   // PluginInterface protocol
211   lldb_private::ConstString GetPluginName() override;
212
213   uint32_t GetPluginVersion() override;
214
215   const lldb_private::DWARFDataExtractor &get_debug_loc_data();
216   const lldb_private::DWARFDataExtractor &get_debug_loclists_data();
217
218   DWARFDebugAbbrev *DebugAbbrev();
219
220   const DWARFDebugAbbrev *DebugAbbrev() const;
221
222   DWARFDebugInfo *DebugInfo();
223
224   const DWARFDebugInfo *DebugInfo() const;
225
226   DWARFDebugRangesBase *GetDebugRanges();
227   DWARFDebugRangesBase *GetDebugRngLists();
228
229   const lldb_private::DWARFDataExtractor &DebugLocData();
230
231   static bool SupportedVersion(uint16_t version);
232
233   DWARFDIE
234   GetDeclContextDIEContainingDIE(const DWARFDIE &die);
235
236   bool
237   HasForwardDeclForClangType(const lldb_private::CompilerType &compiler_type);
238
239   lldb_private::CompileUnit *
240   GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu);
241
242   virtual size_t GetObjCMethodDIEOffsets(lldb_private::ConstString class_name,
243                                          DIEArray &method_die_offsets);
244
245   bool Supports_DW_AT_APPLE_objc_complete_type(DWARFUnit *cu);
246
247   lldb_private::DebugMacrosSP ParseDebugMacros(lldb::offset_t *offset);
248
249   static DWARFDIE GetParentSymbolContextDIE(const DWARFDIE &die);
250
251   virtual lldb::CompUnitSP ParseCompileUnit(DWARFCompileUnit &dwarf_cu);
252
253   virtual lldb_private::DWARFExpression::LocationListFormat
254   GetLocationListFormat() const;
255
256   lldb::ModuleSP GetDWOModule(lldb_private::ConstString name);
257
258   typedef std::map<lldb_private::ConstString, lldb::ModuleSP>
259       ExternalTypeModuleMap;
260
261   /// Return the list of Clang modules imported by this SymbolFile.
262   const ExternalTypeModuleMap& getExternalTypeModules() const {
263       return m_external_type_modules;
264   }
265
266   virtual DWARFDIE GetDIE(const DIERef &die_ref);
267
268   DWARFDIE GetDIE(lldb::user_id_t uid);
269
270   lldb::user_id_t GetUID(const DWARFBaseDIE &die) {
271     return GetUID(die.GetDIERef());
272   }
273
274   lldb::user_id_t GetUID(const llvm::Optional<DIERef> &ref) {
275     return ref ? GetUID(*ref) : LLDB_INVALID_UID;
276   }
277
278   lldb::user_id_t GetUID(DIERef ref);
279
280   virtual std::unique_ptr<SymbolFileDWARFDwo>
281   GetDwoSymbolFileForCompileUnit(DWARFUnit &dwarf_cu,
282                                  const DWARFDebugInfoEntry &cu_die);
283
284   // For regular SymbolFileDWARF instances the method returns nullptr,
285   // for the instances of the subclass SymbolFileDWARFDwo
286   // the method returns a pointer to the base compile unit.
287   virtual DWARFCompileUnit *GetBaseCompileUnit() { return nullptr; }
288
289   virtual llvm::Optional<uint32_t> GetDwoNum() { return llvm::None; }
290
291   static bool
292   DIEInDeclContext(const lldb_private::CompilerDeclContext *parent_decl_ctx,
293                    const DWARFDIE &die);
294
295   std::vector<lldb_private::CallEdge>
296   ParseCallEdgesInFunction(UserID func_id) override;
297
298   void Dump(lldb_private::Stream &s) override;
299
300   void DumpClangAST(lldb_private::Stream &s) override;
301
302   lldb_private::DWARFContext &GetDWARFContext() { return m_context; }
303
304   lldb_private::FileSpec GetFile(DWARFUnit &unit, size_t file_idx);
305
306 protected:
307   typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb_private::Type *>
308       DIEToTypePtr;
309   typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP>
310       DIEToVariableSP;
311   typedef llvm::DenseMap<const DWARFDebugInfoEntry *,
312                          lldb::opaque_compiler_type_t>
313       DIEToClangType;
314   typedef llvm::DenseMap<lldb::opaque_compiler_type_t, lldb::user_id_t>
315       ClangTypeToDIE;
316
317   struct DWARFDataSegment {
318     llvm::once_flag m_flag;
319     lldb_private::DWARFDataExtractor m_data;
320   };
321
322   DISALLOW_COPY_AND_ASSIGN(SymbolFileDWARF);
323
324   const lldb_private::DWARFDataExtractor &
325   GetCachedSectionData(lldb::SectionType sect_type,
326                        DWARFDataSegment &data_segment);
327
328   virtual void LoadSectionData(lldb::SectionType sect_type,
329                                lldb_private::DWARFDataExtractor &data);
330
331   bool DeclContextMatchesThisSymbolFile(
332       const lldb_private::CompilerDeclContext *decl_ctx);
333
334   virtual DWARFUnit *
335   GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit);
336
337   DWARFUnit *GetNextUnparsedDWARFCompileUnit(DWARFUnit *prev_cu);
338
339   bool GetFunction(const DWARFDIE &die, lldb_private::SymbolContext &sc);
340
341   lldb_private::Function *ParseFunction(lldb_private::CompileUnit &comp_unit,
342                                         const DWARFDIE &die);
343
344   size_t ParseBlocksRecursive(lldb_private::CompileUnit &comp_unit,
345                               lldb_private::Block *parent_block,
346                               const DWARFDIE &die,
347                               lldb::addr_t subprogram_low_pc, uint32_t depth);
348
349   size_t ParseTypes(const lldb_private::SymbolContext &sc, const DWARFDIE &die,
350                     bool parse_siblings, bool parse_children);
351
352   lldb::TypeSP ParseType(const lldb_private::SymbolContext &sc,
353                          const DWARFDIE &die, bool *type_is_new);
354
355   lldb_private::Type *ResolveTypeUID(const DWARFDIE &die,
356                                      bool assert_not_being_parsed);
357
358   lldb_private::Type *ResolveTypeUID(const DIERef &die_ref);
359
360   lldb::VariableSP ParseVariableDIE(const lldb_private::SymbolContext &sc,
361                                     const DWARFDIE &die,
362                                     const lldb::addr_t func_low_pc);
363
364   size_t ParseVariables(const lldb_private::SymbolContext &sc,
365                         const DWARFDIE &orig_die,
366                         const lldb::addr_t func_low_pc, bool parse_siblings,
367                         bool parse_children,
368                         lldb_private::VariableList *cc_variable_list = nullptr);
369
370   bool ClassOrStructIsVirtual(const DWARFDIE &die);
371
372   // Given a die_offset, figure out the symbol context representing that die.
373   bool ResolveFunction(const DWARFDIE &die, bool include_inlines,
374                        lldb_private::SymbolContextList &sc_list);
375
376   virtual lldb::TypeSP
377   FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
378
379   virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
380       const DWARFDIE &die, lldb_private::ConstString type_name,
381       bool must_be_implementation);
382
383   lldb_private::Symbol *
384   GetObjCClassSymbol(lldb_private::ConstString objc_class_name);
385
386   lldb::TypeSP GetTypeForDIE(const DWARFDIE &die,
387                              bool resolve_function_context = false);
388
389   void SetDebugMapModule(const lldb::ModuleSP &module_sp) {
390     m_debug_map_module_wp = module_sp;
391   }
392
393   SymbolFileDWARFDebugMap *GetDebugMapSymfile();
394
395   DWARFDIE
396   FindBlockContainingSpecification(const DIERef &func_die_ref,
397                                    dw_offset_t spec_block_die_offset);
398
399   DWARFDIE
400   FindBlockContainingSpecification(const DWARFDIE &die,
401                                    dw_offset_t spec_block_die_offset);
402
403   virtual UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap();
404
405   bool DIEDeclContextsMatch(const DWARFDIE &die1, const DWARFDIE &die2);
406
407   bool ClassContainsSelector(const DWARFDIE &class_die,
408                              lldb_private::ConstString selector);
409
410   bool FixupAddress(lldb_private::Address &addr);
411
412   typedef std::set<lldb_private::Type *> TypeSet;
413
414   void GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset,
415                 dw_offset_t max_die_offset, uint32_t type_mask,
416                 TypeSet &type_set);
417
418   typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t,
419                                         lldb_private::Variable *>
420       GlobalVariableMap;
421
422   GlobalVariableMap &GetGlobalAranges();
423
424   void UpdateExternalModuleListIfNeeded();
425
426   virtual DIEToTypePtr &GetDIEToType() { return m_die_to_type; }
427
428   virtual DIEToVariableSP &GetDIEToVariable() { return m_die_to_variable_sp; }
429
430   virtual DIEToClangType &GetForwardDeclDieToClangType() {
431     return m_forward_decl_die_to_clang_type;
432   }
433
434   virtual ClangTypeToDIE &GetForwardDeclClangTypeToDie() {
435     return m_forward_decl_clang_type_to_die;
436   }
437
438   void BuildCuTranslationTable();
439   llvm::Optional<uint32_t> GetDWARFUnitIndex(uint32_t cu_idx);
440
441   struct DecodedUID {
442     SymbolFileDWARF &dwarf;
443     DIERef ref;
444   };
445   llvm::Optional<DecodedUID> DecodeUID(lldb::user_id_t uid);
446
447   SymbolFileDWARFDwp *GetDwpSymbolFile();
448
449   const lldb_private::FileSpecList &GetTypeUnitSupportFiles(DWARFTypeUnit &tu);
450
451   lldb::ModuleWP m_debug_map_module_wp;
452   SymbolFileDWARFDebugMap *m_debug_map_symfile;
453
454   llvm::once_flag m_dwp_symfile_once_flag;
455   std::unique_ptr<SymbolFileDWARFDwp> m_dwp_symfile;
456
457   lldb_private::DWARFContext m_context;
458
459   DWARFDataSegment m_data_debug_loc;
460   DWARFDataSegment m_data_debug_loclists;
461
462   // The unique pointer items below are generated on demand if and when someone
463   // accesses them through a non const version of this class.
464   std::unique_ptr<DWARFDebugAbbrev> m_abbr;
465   std::unique_ptr<DWARFDebugInfo> m_info;
466   std::unique_ptr<GlobalVariableMap> m_global_aranges_up;
467
468   typedef std::unordered_map<lldb::offset_t, lldb_private::DebugMacrosSP>
469       DebugMacrosMap;
470   DebugMacrosMap m_debug_macros_map;
471
472   ExternalTypeModuleMap m_external_type_modules;
473   std::unique_ptr<lldb_private::DWARFIndex> m_index;
474   bool m_fetched_external_modules : 1;
475   lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
476
477   typedef std::set<lldb::user_id_t> DIERefSet;
478   typedef llvm::StringMap<DIERefSet> NameToOffsetMap;
479   NameToOffsetMap m_function_scope_qualified_name_map;
480   std::unique_ptr<DWARFDebugRangesBase> m_ranges;
481   std::unique_ptr<DWARFDebugRangesBase> m_rnglists;
482   UniqueDWARFASTTypeMap m_unique_ast_type_map;
483   DIEToTypePtr m_die_to_type;
484   DIEToVariableSP m_die_to_variable_sp;
485   DIEToClangType m_forward_decl_die_to_clang_type;
486   ClangTypeToDIE m_forward_decl_clang_type_to_die;
487   llvm::DenseMap<dw_offset_t, lldb_private::FileSpecList>
488       m_type_unit_support_files;
489   std::vector<uint32_t> m_lldb_cu_to_dwarf_unit;
490 };
491
492 #endif // SymbolFileDWARF_SymbolFileDWARF_h_