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