]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
Import tzdata 2018d
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / SymbolFile / DWARF / SymbolFileDWARF.h
1 //===-- SymbolFileDWARF.h --------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef SymbolFileDWARF_SymbolFileDWARF_h_
11 #define SymbolFileDWARF_SymbolFileDWARF_h_
12
13 // C Includes
14 // C++ Includes
15 #include <list>
16 #include <map>
17 #include <mutex>
18 #include <set>
19 #include <unordered_map>
20 #include <vector>
21
22 // Other libraries and framework includes
23 #include "llvm/ADT/DenseMap.h"
24 #include "llvm/Support/Threading.h"
25
26 #include "lldb/Utility/Flags.h"
27
28 #include "lldb/Core/RangeMap.h"
29 #include "lldb/Core/UniqueCStringMap.h"
30 #include "lldb/Core/dwarf.h"
31 #include "lldb/Expression/DWARFExpression.h"
32 #include "lldb/Symbol/DebugMacros.h"
33 #include "lldb/Symbol/SymbolContext.h"
34 #include "lldb/Symbol/SymbolFile.h"
35 #include "lldb/Utility/ConstString.h"
36 #include "lldb/lldb-private.h"
37
38 // Project includes
39 #include "DWARFDataExtractor.h"
40 #include "DWARFDefines.h"
41 #include "HashedNameToDIE.h"
42 #include "NameToDIE.h"
43 #include "UniqueDWARFASTType.h"
44
45 //----------------------------------------------------------------------
46 // Forward Declarations for this DWARF plugin
47 //----------------------------------------------------------------------
48 class DebugMapModule;
49 class DWARFAbbreviationDeclaration;
50 class DWARFAbbreviationDeclarationSet;
51 class DWARFileUnit;
52 class DWARFDebugAbbrev;
53 class DWARFDebugAranges;
54 class DWARFDebugInfo;
55 class DWARFDebugInfoEntry;
56 class DWARFDebugLine;
57 class DWARFDebugPubnames;
58 class DWARFDebugRanges;
59 class DWARFDeclContext;
60 class DWARFDIECollection;
61 class DWARFFormValue;
62 class SymbolFileDWARFDebugMap;
63 class SymbolFileDWARFDwo;
64 class SymbolFileDWARFDwp;
65
66 #define DIE_IS_BEING_PARSED ((lldb_private::Type *)1)
67
68 class SymbolFileDWARF : public lldb_private::SymbolFile,
69                         public lldb_private::UserID {
70 public:
71   friend class SymbolFileDWARFDebugMap;
72   friend class SymbolFileDWARFDwo;
73   friend class DebugMapModule;
74   friend struct DIERef;
75   friend class DWARFCompileUnit;
76   friend class DWARFDIE;
77   friend class DWARFASTParserClang;
78   friend class DWARFASTParserGo;
79   friend class DWARFASTParserJava;
80   friend class DWARFASTParserOCaml;
81
82   //------------------------------------------------------------------
83   // Static Functions
84   //------------------------------------------------------------------
85   static void Initialize();
86
87   static void Terminate();
88
89   static void DebuggerInitialize(lldb_private::Debugger &debugger);
90
91   static lldb_private::ConstString GetPluginNameStatic();
92
93   static const char *GetPluginDescriptionStatic();
94
95   static lldb_private::SymbolFile *
96   CreateInstance(lldb_private::ObjectFile *obj_file);
97
98   //------------------------------------------------------------------
99   // Constructors and Destructors
100   //------------------------------------------------------------------
101
102   SymbolFileDWARF(lldb_private::ObjectFile *ofile);
103
104   ~SymbolFileDWARF() override;
105
106   uint32_t CalculateAbilities() override;
107
108   void InitializeObject() override;
109
110   //------------------------------------------------------------------
111   // Compile Unit function calls
112   //------------------------------------------------------------------
113
114   uint32_t GetNumCompileUnits() override;
115
116   lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
117
118   lldb::LanguageType
119   ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) override;
120
121   size_t
122   ParseCompileUnitFunctions(const lldb_private::SymbolContext &sc) override;
123
124   bool
125   ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc) override;
126
127   bool
128   ParseCompileUnitDebugMacros(const lldb_private::SymbolContext &sc) override;
129
130   bool ParseCompileUnitSupportFiles(
131       const lldb_private::SymbolContext &sc,
132       lldb_private::FileSpecList &support_files) override;
133
134   bool
135   ParseCompileUnitIsOptimized(const lldb_private::SymbolContext &sc) override;
136
137   bool ParseImportedModules(
138       const lldb_private::SymbolContext &sc,
139       std::vector<lldb_private::ConstString> &imported_modules) override;
140
141   size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc) override;
142
143   size_t ParseTypes(const lldb_private::SymbolContext &sc) override;
144
145   size_t
146   ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
147
148   lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
149
150   bool CompleteType(lldb_private::CompilerType &compiler_type) override;
151
152   lldb_private::Type *ResolveType(const DWARFDIE &die,
153                                   bool assert_not_being_parsed = true,
154                                   bool resolve_function_context = false);
155
156   SymbolFileDWARF *GetDWARFForUID(lldb::user_id_t uid);
157
158   DWARFDIE
159   GetDIEFromUID(lldb::user_id_t uid);
160
161   lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override;
162
163   lldb_private::CompilerDeclContext
164   GetDeclContextForUID(lldb::user_id_t uid) override;
165
166   lldb_private::CompilerDeclContext
167   GetDeclContextContainingUID(lldb::user_id_t uid) override;
168
169   void
170   ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
171
172   uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
173                                 uint32_t resolve_scope,
174                                 lldb_private::SymbolContext &sc) override;
175
176   uint32_t
177   ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line,
178                        bool check_inlines, uint32_t resolve_scope,
179                        lldb_private::SymbolContextList &sc_list) override;
180
181   uint32_t
182   FindGlobalVariables(const lldb_private::ConstString &name,
183                       const lldb_private::CompilerDeclContext *parent_decl_ctx,
184                       bool append, uint32_t max_matches,
185                       lldb_private::VariableList &variables) override;
186
187   uint32_t FindGlobalVariables(const lldb_private::RegularExpression &regex,
188                                bool append, uint32_t max_matches,
189                                lldb_private::VariableList &variables) override;
190
191   uint32_t
192   FindFunctions(const lldb_private::ConstString &name,
193                 const lldb_private::CompilerDeclContext *parent_decl_ctx,
194                 uint32_t name_type_mask, bool include_inlines, bool append,
195                 lldb_private::SymbolContextList &sc_list) override;
196
197   uint32_t FindFunctions(const lldb_private::RegularExpression &regex,
198                          bool include_inlines, bool append,
199                          lldb_private::SymbolContextList &sc_list) override;
200
201   void GetMangledNamesForFunction(
202       const std::string &scope_qualified_name,
203       std::vector<lldb_private::ConstString> &mangled_names) override;
204
205   uint32_t
206   FindTypes(const lldb_private::SymbolContext &sc,
207             const lldb_private::ConstString &name,
208             const lldb_private::CompilerDeclContext *parent_decl_ctx,
209             bool append, uint32_t max_matches,
210             llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
211             lldb_private::TypeMap &types) override;
212
213   size_t FindTypes(const std::vector<lldb_private::CompilerContext> &context,
214                    bool append, lldb_private::TypeMap &types) override;
215
216   lldb_private::TypeList *GetTypeList() override;
217
218   size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
219                   uint32_t type_mask,
220                   lldb_private::TypeList &type_list) override;
221
222   lldb_private::TypeSystem *
223   GetTypeSystemForLanguage(lldb::LanguageType language) override;
224
225   lldb_private::CompilerDeclContext FindNamespace(
226       const lldb_private::SymbolContext &sc,
227       const lldb_private::ConstString &name,
228       const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
229
230   void PreloadSymbols() override;
231
232   //------------------------------------------------------------------
233   // PluginInterface protocol
234   //------------------------------------------------------------------
235   lldb_private::ConstString GetPluginName() override;
236
237   uint32_t GetPluginVersion() override;
238
239   const lldb_private::DWARFDataExtractor &get_debug_abbrev_data();
240   const lldb_private::DWARFDataExtractor &get_debug_addr_data();
241   const lldb_private::DWARFDataExtractor &get_debug_aranges_data();
242   const lldb_private::DWARFDataExtractor &get_debug_frame_data();
243   const lldb_private::DWARFDataExtractor &get_debug_info_data();
244   const lldb_private::DWARFDataExtractor &get_debug_line_data();
245   const lldb_private::DWARFDataExtractor &get_debug_macro_data();
246   const lldb_private::DWARFDataExtractor &get_debug_loc_data();
247   const lldb_private::DWARFDataExtractor &get_debug_ranges_data();
248   const lldb_private::DWARFDataExtractor &get_debug_str_data();
249   const lldb_private::DWARFDataExtractor &get_debug_str_offsets_data();
250   const lldb_private::DWARFDataExtractor &get_apple_names_data();
251   const lldb_private::DWARFDataExtractor &get_apple_types_data();
252   const lldb_private::DWARFDataExtractor &get_apple_namespaces_data();
253   const lldb_private::DWARFDataExtractor &get_apple_objc_data();
254
255   DWARFDebugAbbrev *DebugAbbrev();
256
257   const DWARFDebugAbbrev *DebugAbbrev() const;
258
259   DWARFDebugInfo *DebugInfo();
260
261   const DWARFDebugInfo *DebugInfo() const;
262
263   DWARFDebugRanges *DebugRanges();
264
265   const DWARFDebugRanges *DebugRanges() const;
266
267   static bool SupportedVersion(uint16_t version);
268
269   DWARFDIE
270   GetDeclContextDIEContainingDIE(const DWARFDIE &die);
271
272   bool
273   HasForwardDeclForClangType(const lldb_private::CompilerType &compiler_type);
274
275   lldb_private::CompileUnit *
276   GetCompUnitForDWARFCompUnit(DWARFCompileUnit *dwarf_cu,
277                               uint32_t cu_idx = UINT32_MAX);
278
279   virtual size_t GetObjCMethodDIEOffsets(lldb_private::ConstString class_name,
280                                          DIEArray &method_die_offsets);
281
282   bool Supports_DW_AT_APPLE_objc_complete_type(DWARFCompileUnit *cu);
283
284   lldb_private::DebugMacrosSP ParseDebugMacros(lldb::offset_t *offset);
285
286   static DWARFDIE GetParentSymbolContextDIE(const DWARFDIE &die);
287
288   virtual lldb::CompUnitSP ParseCompileUnit(DWARFCompileUnit *dwarf_cu,
289                                             uint32_t cu_idx);
290
291   virtual lldb_private::DWARFExpression::LocationListFormat
292   GetLocationListFormat() const;
293
294   lldb::ModuleSP GetDWOModule(lldb_private::ConstString name);
295
296   virtual DWARFDIE GetDIE(const DIERef &die_ref);
297
298   virtual std::unique_ptr<SymbolFileDWARFDwo>
299   GetDwoSymbolFileForCompileUnit(DWARFCompileUnit &dwarf_cu,
300                                  const DWARFDebugInfoEntry &cu_die);
301
302   // For regular SymbolFileDWARF instances the method returns nullptr,
303   // for the instances of the subclass SymbolFileDWARFDwo
304   // the method returns a pointer to the base compile unit.
305   virtual DWARFCompileUnit *GetBaseCompileUnit();
306
307 protected:
308   typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb_private::Type *>
309       DIEToTypePtr;
310   typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP>
311       DIEToVariableSP;
312   typedef llvm::DenseMap<const DWARFDebugInfoEntry *,
313                          lldb::opaque_compiler_type_t>
314       DIEToClangType;
315   typedef llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> 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   bool
335   DIEInDeclContext(const lldb_private::CompilerDeclContext *parent_decl_ctx,
336                    const DWARFDIE &die);
337
338   virtual DWARFCompileUnit *
339   GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit);
340
341   DWARFCompileUnit *GetNextUnparsedDWARFCompileUnit(DWARFCompileUnit *prev_cu);
342
343   bool GetFunction(const DWARFDIE &die, lldb_private::SymbolContext &sc);
344
345   lldb_private::Function *
346   ParseCompileUnitFunction(const lldb_private::SymbolContext &sc,
347                            const DWARFDIE &die);
348
349   size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc,
350                              lldb_private::Block *parent_block,
351                              const DWARFDIE &die,
352                              lldb::addr_t subprogram_low_pc, uint32_t depth);
353
354   size_t ParseTypes(const lldb_private::SymbolContext &sc, const DWARFDIE &die,
355                     bool parse_siblings, bool parse_children);
356
357   lldb::TypeSP ParseType(const lldb_private::SymbolContext &sc,
358                          const DWARFDIE &die, bool *type_is_new);
359
360   lldb_private::Type *ResolveTypeUID(const DWARFDIE &die,
361                                      bool assert_not_being_parsed);
362
363   lldb_private::Type *ResolveTypeUID(const DIERef &die_ref);
364
365   lldb::VariableSP ParseVariableDIE(const lldb_private::SymbolContext &sc,
366                                     const DWARFDIE &die,
367                                     const lldb::addr_t func_low_pc);
368
369   size_t ParseVariables(const lldb_private::SymbolContext &sc,
370                         const DWARFDIE &orig_die,
371                         const lldb::addr_t func_low_pc, bool parse_siblings,
372                         bool parse_children,
373                         lldb_private::VariableList *cc_variable_list = NULL);
374
375   bool ClassOrStructIsVirtual(const DWARFDIE &die);
376
377   // Given a die_offset, figure out the symbol context representing that die.
378   bool ResolveFunction(const DIERef &die_ref, bool include_inlines,
379                        lldb_private::SymbolContextList &sc_list);
380
381   bool ResolveFunction(const DWARFDIE &die, bool include_inlines,
382                        lldb_private::SymbolContextList &sc_list);
383
384   void FindFunctions(const lldb_private::ConstString &name,
385                      const NameToDIE &name_to_die, bool include_inlines,
386                      lldb_private::SymbolContextList &sc_list);
387
388   void FindFunctions(const lldb_private::RegularExpression &regex,
389                      const NameToDIE &name_to_die, bool include_inlines,
390                      lldb_private::SymbolContextList &sc_list);
391
392   void FindFunctions(const lldb_private::RegularExpression &regex,
393                      const DWARFMappedHash::MemoryTable &memory_table,
394                      bool include_inlines,
395                      lldb_private::SymbolContextList &sc_list);
396
397   virtual lldb::TypeSP
398   FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
399
400   virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
401       const DWARFDIE &die, const lldb_private::ConstString &type_name,
402       bool must_be_implementation);
403
404   lldb_private::Symbol *
405   GetObjCClassSymbol(const lldb_private::ConstString &objc_class_name);
406
407   void ParseFunctions(const DIEArray &die_offsets, bool include_inlines,
408                       lldb_private::SymbolContextList &sc_list);
409
410   lldb::TypeSP GetTypeForDIE(const DWARFDIE &die,
411                              bool resolve_function_context = false);
412
413   void Index();
414
415   void DumpIndexes();
416
417   void SetDebugMapModule(const lldb::ModuleSP &module_sp) {
418     m_debug_map_module_wp = module_sp;
419   }
420
421   SymbolFileDWARFDebugMap *GetDebugMapSymfile();
422
423   DWARFDIE
424   FindBlockContainingSpecification(const DIERef &func_die_ref,
425                                    dw_offset_t spec_block_die_offset);
426
427   DWARFDIE
428   FindBlockContainingSpecification(const DWARFDIE &die,
429                                    dw_offset_t spec_block_die_offset);
430
431   virtual UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap();
432
433   bool DIEDeclContextsMatch(const DWARFDIE &die1, const DWARFDIE &die2);
434
435   bool ClassContainsSelector(const DWARFDIE &class_die,
436                              const lldb_private::ConstString &selector);
437
438   bool FixupAddress(lldb_private::Address &addr);
439
440   typedef std::set<lldb_private::Type *> TypeSet;
441
442   typedef std::map<lldb_private::ConstString, lldb::ModuleSP>
443       ExternalTypeModuleMap;
444
445   void GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset,
446                 dw_offset_t max_die_offset, uint32_t type_mask,
447                 TypeSet &type_set);
448
449   typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t,
450                                         lldb_private::Variable *>
451       GlobalVariableMap;
452
453   GlobalVariableMap &GetGlobalAranges();
454
455   void UpdateExternalModuleListIfNeeded();
456
457   virtual DIEToTypePtr &GetDIEToType() { return m_die_to_type; }
458
459   virtual DIEToVariableSP &GetDIEToVariable() { return m_die_to_variable_sp; }
460
461   virtual DIEToClangType &GetForwardDeclDieToClangType() {
462     return m_forward_decl_die_to_clang_type;
463   }
464
465   virtual ClangTypeToDIE &GetForwardDeclClangTypeToDie() {
466     return m_forward_decl_clang_type_to_die;
467   }
468
469   SymbolFileDWARFDwp *GetDwpSymbolFile();
470
471   lldb::ModuleWP m_debug_map_module_wp;
472   SymbolFileDWARFDebugMap *m_debug_map_symfile;
473
474   llvm::once_flag m_dwp_symfile_once_flag;
475   std::unique_ptr<SymbolFileDWARFDwp> m_dwp_symfile;
476
477   lldb_private::DWARFDataExtractor m_dwarf_data;
478
479   DWARFDataSegment m_data_debug_abbrev;
480   DWARFDataSegment m_data_debug_addr;
481   DWARFDataSegment m_data_debug_aranges;
482   DWARFDataSegment m_data_debug_frame;
483   DWARFDataSegment m_data_debug_info;
484   DWARFDataSegment m_data_debug_line;
485   DWARFDataSegment m_data_debug_macro;
486   DWARFDataSegment m_data_debug_loc;
487   DWARFDataSegment m_data_debug_ranges;
488   DWARFDataSegment m_data_debug_str;
489   DWARFDataSegment m_data_debug_str_offsets;
490   DWARFDataSegment m_data_apple_names;
491   DWARFDataSegment m_data_apple_types;
492   DWARFDataSegment m_data_apple_namespaces;
493   DWARFDataSegment m_data_apple_objc;
494
495   // The unique pointer items below are generated on demand if and when someone
496   // accesses
497   // them through a non const version of this class.
498   std::unique_ptr<DWARFDebugAbbrev> m_abbr;
499   std::unique_ptr<DWARFDebugInfo> m_info;
500   std::unique_ptr<DWARFDebugLine> m_line;
501   std::unique_ptr<DWARFMappedHash::MemoryTable> m_apple_names_ap;
502   std::unique_ptr<DWARFMappedHash::MemoryTable> m_apple_types_ap;
503   std::unique_ptr<DWARFMappedHash::MemoryTable> m_apple_namespaces_ap;
504   std::unique_ptr<DWARFMappedHash::MemoryTable> m_apple_objc_ap;
505   std::unique_ptr<GlobalVariableMap> m_global_aranges_ap;
506
507   typedef std::unordered_map<lldb::offset_t, lldb_private::DebugMacrosSP>
508       DebugMacrosMap;
509   DebugMacrosMap m_debug_macros_map;
510
511   ExternalTypeModuleMap m_external_type_modules;
512   NameToDIE m_function_basename_index; // All concrete functions
513   NameToDIE m_function_fullname_index; // All concrete functions
514   NameToDIE m_function_method_index;   // All inlined functions
515   NameToDIE
516       m_function_selector_index; // All method names for functions of classes
517   NameToDIE m_objc_class_selectors_index; // Given a class name, find all
518                                           // selectors for the class
519   NameToDIE m_global_index;               // Global and static variables
520   NameToDIE m_type_index;                 // All type DIE offsets
521   NameToDIE m_namespace_index;            // All type DIE offsets
522   bool m_indexed : 1, m_using_apple_tables : 1, m_fetched_external_modules : 1;
523   lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
524
525   typedef std::shared_ptr<std::set<DIERef>> DIERefSetSP;
526   typedef std::unordered_map<std::string, DIERefSetSP> NameToOffsetMap;
527   NameToOffsetMap m_function_scope_qualified_name_map;
528   std::unique_ptr<DWARFDebugRanges> m_ranges;
529   UniqueDWARFASTTypeMap m_unique_ast_type_map;
530   DIEToTypePtr m_die_to_type;
531   DIEToVariableSP m_die_to_variable_sp;
532   DIEToClangType m_forward_decl_die_to_clang_type;
533   ClangTypeToDIE m_forward_decl_clang_type_to_die;
534 };
535
536 #endif // SymbolFileDWARF_SymbolFileDWARF_h_