]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
Merge clang 7.0.1 and several follow-up changes
[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 "DWARFIndex.h"
42 #include "UniqueDWARFASTType.h"
43
44 //----------------------------------------------------------------------
45 // Forward Declarations for this DWARF plugin
46 //----------------------------------------------------------------------
47 class DebugMapModule;
48 class DWARFAbbreviationDeclaration;
49 class DWARFAbbreviationDeclarationSet;
50 class DWARFileUnit;
51 class DWARFDebugAbbrev;
52 class DWARFDebugAranges;
53 class DWARFDebugInfo;
54 class DWARFDebugInfoEntry;
55 class DWARFDebugLine;
56 class DWARFDebugRanges;
57 class DWARFDeclContext;
58 class DWARFDIECollection;
59 class DWARFFormValue;
60 class SymbolFileDWARFDebugMap;
61 class SymbolFileDWARFDwo;
62 class SymbolFileDWARFDwp;
63
64 #define DIE_IS_BEING_PARSED ((lldb_private::Type *)1)
65
66 class SymbolFileDWARF : public lldb_private::SymbolFile,
67                         public lldb_private::UserID {
68 public:
69   friend class SymbolFileDWARFDebugMap;
70   friend class SymbolFileDWARFDwo;
71   friend class DebugMapModule;
72   friend struct DIERef;
73   friend class DWARFUnit;
74   friend class DWARFDIE;
75   friend class DWARFASTParserClang;
76   friend class DWARFASTParserGo;
77   friend class DWARFASTParserJava;
78   friend class DWARFASTParserOCaml;
79
80   //------------------------------------------------------------------
81   // Static Functions
82   //------------------------------------------------------------------
83   static void Initialize();
84
85   static void Terminate();
86
87   static void DebuggerInitialize(lldb_private::Debugger &debugger);
88
89   static lldb_private::ConstString GetPluginNameStatic();
90
91   static const char *GetPluginDescriptionStatic();
92
93   static lldb_private::SymbolFile *
94   CreateInstance(lldb_private::ObjectFile *obj_file);
95
96   //------------------------------------------------------------------
97   // Constructors and Destructors
98   //------------------------------------------------------------------
99
100   SymbolFileDWARF(lldb_private::ObjectFile *ofile);
101
102   ~SymbolFileDWARF() override;
103
104   uint32_t CalculateAbilities() override;
105
106   void InitializeObject() override;
107
108   //------------------------------------------------------------------
109   // Compile Unit function calls
110   //------------------------------------------------------------------
111
112   uint32_t GetNumCompileUnits() override;
113
114   lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
115
116   lldb::LanguageType
117   ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) override;
118
119   size_t
120   ParseCompileUnitFunctions(const lldb_private::SymbolContext &sc) override;
121
122   bool
123   ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc) override;
124
125   bool
126   ParseCompileUnitDebugMacros(const lldb_private::SymbolContext &sc) override;
127
128   bool ParseCompileUnitSupportFiles(
129       const lldb_private::SymbolContext &sc,
130       lldb_private::FileSpecList &support_files) override;
131
132   bool
133   ParseCompileUnitIsOptimized(const lldb_private::SymbolContext &sc) override;
134
135   bool ParseImportedModules(
136       const lldb_private::SymbolContext &sc,
137       std::vector<lldb_private::ConstString> &imported_modules) override;
138
139   size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc) override;
140
141   size_t ParseTypes(const lldb_private::SymbolContext &sc) override;
142
143   size_t
144   ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
145
146   lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
147
148   bool CompleteType(lldb_private::CompilerType &compiler_type) override;
149
150   lldb_private::Type *ResolveType(const DWARFDIE &die,
151                                   bool assert_not_being_parsed = true,
152                                   bool resolve_function_context = false);
153
154   SymbolFileDWARF *GetDWARFForUID(lldb::user_id_t uid);
155
156   DWARFDIE
157   GetDIEFromUID(lldb::user_id_t uid);
158
159   lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override;
160
161   lldb_private::CompilerDeclContext
162   GetDeclContextForUID(lldb::user_id_t uid) override;
163
164   lldb_private::CompilerDeclContext
165   GetDeclContextContainingUID(lldb::user_id_t uid) override;
166
167   void
168   ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
169
170   uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
171                                 uint32_t resolve_scope,
172                                 lldb_private::SymbolContext &sc) override;
173
174   uint32_t
175   ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line,
176                        bool check_inlines, uint32_t resolve_scope,
177                        lldb_private::SymbolContextList &sc_list) override;
178
179   uint32_t
180   FindGlobalVariables(const lldb_private::ConstString &name,
181                       const lldb_private::CompilerDeclContext *parent_decl_ctx,
182                       uint32_t max_matches,
183                       lldb_private::VariableList &variables) override;
184
185   uint32_t FindGlobalVariables(const lldb_private::RegularExpression &regex,
186                                uint32_t max_matches,
187                                lldb_private::VariableList &variables) override;
188
189   uint32_t
190   FindFunctions(const lldb_private::ConstString &name,
191                 const lldb_private::CompilerDeclContext *parent_decl_ctx,
192                 uint32_t name_type_mask, bool include_inlines, bool append,
193                 lldb_private::SymbolContextList &sc_list) override;
194
195   uint32_t FindFunctions(const lldb_private::RegularExpression &regex,
196                          bool include_inlines, bool append,
197                          lldb_private::SymbolContextList &sc_list) override;
198
199   void GetMangledNamesForFunction(
200       const std::string &scope_qualified_name,
201       std::vector<lldb_private::ConstString> &mangled_names) override;
202
203   uint32_t
204   FindTypes(const lldb_private::SymbolContext &sc,
205             const lldb_private::ConstString &name,
206             const lldb_private::CompilerDeclContext *parent_decl_ctx,
207             bool append, uint32_t max_matches,
208             llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
209             lldb_private::TypeMap &types) override;
210
211   size_t FindTypes(const std::vector<lldb_private::CompilerContext> &context,
212                    bool append, lldb_private::TypeMap &types) override;
213
214   lldb_private::TypeList *GetTypeList() override;
215
216   size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
217                   uint32_t type_mask,
218                   lldb_private::TypeList &type_list) override;
219
220   lldb_private::TypeSystem *
221   GetTypeSystemForLanguage(lldb::LanguageType language) override;
222
223   lldb_private::CompilerDeclContext FindNamespace(
224       const lldb_private::SymbolContext &sc,
225       const lldb_private::ConstString &name,
226       const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
227
228   void PreloadSymbols() override;
229
230   //------------------------------------------------------------------
231   // PluginInterface protocol
232   //------------------------------------------------------------------
233   lldb_private::ConstString GetPluginName() override;
234
235   uint32_t GetPluginVersion() override;
236
237   const lldb_private::DWARFDataExtractor &get_debug_abbrev_data();
238   const lldb_private::DWARFDataExtractor &get_debug_addr_data();
239   const lldb_private::DWARFDataExtractor &get_debug_aranges_data();
240   const lldb_private::DWARFDataExtractor &get_debug_frame_data();
241   const lldb_private::DWARFDataExtractor &get_debug_info_data();
242   const lldb_private::DWARFDataExtractor &get_debug_line_data();
243   const lldb_private::DWARFDataExtractor &get_debug_macro_data();
244   const lldb_private::DWARFDataExtractor &get_debug_loc_data();
245   const lldb_private::DWARFDataExtractor &get_debug_ranges_data();
246   const lldb_private::DWARFDataExtractor &get_debug_str_data();
247   const lldb_private::DWARFDataExtractor &get_debug_str_offsets_data();
248   const lldb_private::DWARFDataExtractor &get_debug_types_data();
249   const lldb_private::DWARFDataExtractor &get_apple_names_data();
250   const lldb_private::DWARFDataExtractor &get_apple_types_data();
251   const lldb_private::DWARFDataExtractor &get_apple_namespaces_data();
252   const lldb_private::DWARFDataExtractor &get_apple_objc_data();
253   const lldb_private::DWARFDataExtractor &get_gnu_debugaltlink();
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(DWARFUnit *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(DWARFUnit *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(DWARFUnit *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   typedef std::map<lldb_private::ConstString, lldb::ModuleSP>
297       ExternalTypeModuleMap;
298
299   /// Return the list of Clang modules imported by this SymbolFile.
300   const ExternalTypeModuleMap& getExternalTypeModules() const {
301       return m_external_type_modules;
302   }
303
304   virtual DWARFDIE GetDIE(const DIERef &die_ref);
305
306   virtual std::unique_ptr<SymbolFileDWARFDwo>
307   GetDwoSymbolFileForCompileUnit(DWARFUnit &dwarf_cu,
308                                  const DWARFDebugInfoEntry &cu_die);
309
310   // For regular SymbolFileDWARF instances the method returns nullptr,
311   // for the instances of the subclass SymbolFileDWARFDwo
312   // the method returns a pointer to the base compile unit.
313   virtual DWARFUnit *GetBaseCompileUnit();
314
315   static bool
316   DIEInDeclContext(const lldb_private::CompilerDeclContext *parent_decl_ctx,
317                    const DWARFDIE &die);
318
319   void Dump(lldb_private::Stream &s) override;
320
321 protected:
322   typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb_private::Type *>
323       DIEToTypePtr;
324   typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP>
325       DIEToVariableSP;
326   typedef llvm::DenseMap<const DWARFDebugInfoEntry *,
327                          lldb::opaque_compiler_type_t>
328       DIEToClangType;
329   typedef llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> ClangTypeToDIE;
330
331   struct DWARFDataSegment {
332     llvm::once_flag m_flag;
333     lldb_private::DWARFDataExtractor m_data;
334   };
335
336   DISALLOW_COPY_AND_ASSIGN(SymbolFileDWARF);
337
338   const lldb_private::DWARFDataExtractor &
339   GetCachedSectionData(lldb::SectionType sect_type,
340                        DWARFDataSegment &data_segment);
341
342   virtual void LoadSectionData(lldb::SectionType sect_type,
343                                lldb_private::DWARFDataExtractor &data);
344
345   bool DeclContextMatchesThisSymbolFile(
346       const lldb_private::CompilerDeclContext *decl_ctx);
347
348   virtual DWARFUnit *
349   GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit);
350
351   DWARFUnit *GetNextUnparsedDWARFCompileUnit(DWARFUnit *prev_cu);
352
353   bool GetFunction(const DWARFDIE &die, lldb_private::SymbolContext &sc);
354
355   lldb_private::Function *
356   ParseCompileUnitFunction(const lldb_private::SymbolContext &sc,
357                            const DWARFDIE &die);
358
359   size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc,
360                              lldb_private::Block *parent_block,
361                              const DWARFDIE &die,
362                              lldb::addr_t subprogram_low_pc, uint32_t depth);
363
364   size_t ParseTypes(const lldb_private::SymbolContext &sc, const DWARFDIE &die,
365                     bool parse_siblings, bool parse_children);
366
367   lldb::TypeSP ParseType(const lldb_private::SymbolContext &sc,
368                          const DWARFDIE &die, bool *type_is_new);
369
370   lldb_private::Type *ResolveTypeUID(const DWARFDIE &die,
371                                      bool assert_not_being_parsed);
372
373   lldb_private::Type *ResolveTypeUID(const DIERef &die_ref);
374
375   lldb::VariableSP ParseVariableDIE(const lldb_private::SymbolContext &sc,
376                                     const DWARFDIE &die,
377                                     const lldb::addr_t func_low_pc);
378
379   size_t ParseVariables(const lldb_private::SymbolContext &sc,
380                         const DWARFDIE &orig_die,
381                         const lldb::addr_t func_low_pc, bool parse_siblings,
382                         bool parse_children,
383                         lldb_private::VariableList *cc_variable_list = NULL);
384
385   bool ClassOrStructIsVirtual(const DWARFDIE &die);
386
387   // Given a die_offset, figure out the symbol context representing that die.
388   bool ResolveFunction(const DWARFDIE &die, bool include_inlines,
389                        lldb_private::SymbolContextList &sc_list);
390
391   virtual lldb::TypeSP
392   FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
393
394   virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
395       const DWARFDIE &die, const lldb_private::ConstString &type_name,
396       bool must_be_implementation);
397
398   lldb_private::Symbol *
399   GetObjCClassSymbol(const lldb_private::ConstString &objc_class_name);
400
401   lldb::TypeSP GetTypeForDIE(const DWARFDIE &die,
402                              bool resolve_function_context = false);
403
404   void SetDebugMapModule(const lldb::ModuleSP &module_sp) {
405     m_debug_map_module_wp = module_sp;
406   }
407
408   SymbolFileDWARFDebugMap *GetDebugMapSymfile();
409
410   DWARFDIE
411   FindBlockContainingSpecification(const DIERef &func_die_ref,
412                                    dw_offset_t spec_block_die_offset);
413
414   DWARFDIE
415   FindBlockContainingSpecification(const DWARFDIE &die,
416                                    dw_offset_t spec_block_die_offset);
417
418   virtual UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap();
419
420   bool DIEDeclContextsMatch(const DWARFDIE &die1, const DWARFDIE &die2);
421
422   bool ClassContainsSelector(const DWARFDIE &class_die,
423                              const lldb_private::ConstString &selector);
424
425   bool FixupAddress(lldb_private::Address &addr);
426
427   typedef std::set<lldb_private::Type *> TypeSet;
428
429   void GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset,
430                 dw_offset_t max_die_offset, uint32_t type_mask,
431                 TypeSet &type_set);
432
433   typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t,
434                                         lldb_private::Variable *>
435       GlobalVariableMap;
436
437   GlobalVariableMap &GetGlobalAranges();
438
439   void UpdateExternalModuleListIfNeeded();
440
441   virtual DIEToTypePtr &GetDIEToType() { return m_die_to_type; }
442
443   virtual DIEToVariableSP &GetDIEToVariable() { return m_die_to_variable_sp; }
444
445   virtual DIEToClangType &GetForwardDeclDieToClangType() {
446     return m_forward_decl_die_to_clang_type;
447   }
448
449   virtual ClangTypeToDIE &GetForwardDeclClangTypeToDie() {
450     return m_forward_decl_clang_type_to_die;
451   }
452
453   SymbolFileDWARFDwp *GetDwpSymbolFile();
454
455   lldb::ModuleWP m_debug_map_module_wp;
456   SymbolFileDWARFDebugMap *m_debug_map_symfile;
457
458   llvm::once_flag m_dwp_symfile_once_flag;
459   std::unique_ptr<SymbolFileDWARFDwp> m_dwp_symfile;
460
461   lldb_private::DWARFDataExtractor m_dwarf_data;
462
463   DWARFDataSegment m_data_debug_abbrev;
464   DWARFDataSegment m_data_debug_addr;
465   DWARFDataSegment m_data_debug_aranges;
466   DWARFDataSegment m_data_debug_frame;
467   DWARFDataSegment m_data_debug_info;
468   DWARFDataSegment m_data_debug_line;
469   DWARFDataSegment m_data_debug_macro;
470   DWARFDataSegment m_data_debug_loc;
471   DWARFDataSegment m_data_debug_ranges;
472   DWARFDataSegment m_data_debug_str;
473   DWARFDataSegment m_data_debug_str_offsets;
474   DWARFDataSegment m_data_debug_types;
475   DWARFDataSegment m_data_apple_names;
476   DWARFDataSegment m_data_apple_types;
477   DWARFDataSegment m_data_apple_namespaces;
478   DWARFDataSegment m_data_apple_objc;
479   DWARFDataSegment m_data_gnu_debugaltlink;
480
481   // The unique pointer items below are generated on demand if and when someone
482   // accesses
483   // them through a non const version of this class.
484   std::unique_ptr<DWARFDebugAbbrev> m_abbr;
485   std::unique_ptr<DWARFDebugInfo> m_info;
486   std::unique_ptr<DWARFDebugLine> m_line;
487   std::unique_ptr<GlobalVariableMap> m_global_aranges_ap;
488
489   typedef std::unordered_map<lldb::offset_t, lldb_private::DebugMacrosSP>
490       DebugMacrosMap;
491   DebugMacrosMap m_debug_macros_map;
492
493   ExternalTypeModuleMap m_external_type_modules;
494   std::unique_ptr<lldb_private::DWARFIndex> m_index;
495   bool m_fetched_external_modules : 1;
496   lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
497
498   typedef std::shared_ptr<std::set<DIERef>> DIERefSetSP;
499   typedef std::unordered_map<std::string, DIERefSetSP> NameToOffsetMap;
500   NameToOffsetMap m_function_scope_qualified_name_map;
501   std::unique_ptr<DWARFDebugRanges> m_ranges;
502   UniqueDWARFASTTypeMap m_unique_ast_type_map;
503   DIEToTypePtr m_die_to_type;
504   DIEToVariableSP m_die_to_variable_sp;
505   DIEToClangType m_forward_decl_die_to_clang_type;
506   ClangTypeToDIE m_forward_decl_clang_type_to_die;
507 };
508
509 #endif // SymbolFileDWARF_SymbolFileDWARF_h_