1 //===-- SymbolFileDWARF.h --------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef SymbolFileDWARF_SymbolFileDWARF_h_
11 #define SymbolFileDWARF_SymbolFileDWARF_h_
19 #include <unordered_map>
22 // Other libraries and framework includes
23 #include "llvm/ADT/DenseMap.h"
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"
37 #include "DWARFDefines.h"
38 #include "DWARFDataExtractor.h"
39 #include "HashedNameToDIE.h"
40 #include "NameToDIE.h"
41 #include "UniqueDWARFASTType.h"
43 //----------------------------------------------------------------------
44 // Forward Declarations for this DWARF plugin
45 //----------------------------------------------------------------------
47 class DWARFAbbreviationDeclaration;
48 class DWARFAbbreviationDeclarationSet;
50 class DWARFDebugAbbrev;
51 class DWARFDebugAranges;
53 class DWARFDebugInfoEntry;
55 class DWARFDebugPubnames;
56 class DWARFDebugRanges;
57 class DWARFDeclContext;
58 class DWARFDIECollection;
60 class SymbolFileDWARFDebugMap;
62 #define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
64 class SymbolFileDWARF : public lldb_private::SymbolFile, public lldb_private::UserID
67 friend class SymbolFileDWARFDebugMap;
68 friend class SymbolFileDWARFDwo;
69 friend class DebugMapModule;
70 friend class DWARFCompileUnit;
71 friend class DWARFASTParserClang;
72 friend class DWARFASTParserGo;
74 //------------------------------------------------------------------
76 //------------------------------------------------------------------
84 DebuggerInitialize(lldb_private::Debugger &debugger);
86 static lldb_private::ConstString
87 GetPluginNameStatic();
90 GetPluginDescriptionStatic();
92 static lldb_private::SymbolFile*
93 CreateInstance (lldb_private::ObjectFile* obj_file);
95 //------------------------------------------------------------------
96 // Constructors and Destructors
97 //------------------------------------------------------------------
99 SymbolFileDWARF(lldb_private::ObjectFile* ofile);
101 ~SymbolFileDWARF() override;
104 CalculateAbilities () override;
107 InitializeObject() override;
109 //------------------------------------------------------------------
110 // Compile Unit function calls
111 //------------------------------------------------------------------
114 GetNumCompileUnits() override;
117 ParseCompileUnitAtIndex(uint32_t index) override;
120 ParseCompileUnitLanguage (const lldb_private::SymbolContext& sc) override;
123 ParseCompileUnitFunctions (const lldb_private::SymbolContext& sc) override;
126 ParseCompileUnitLineTable (const lldb_private::SymbolContext& sc) override;
129 ParseCompileUnitDebugMacros (const lldb_private::SymbolContext& sc) override;
132 ParseCompileUnitSupportFiles (const lldb_private::SymbolContext& sc,
133 lldb_private::FileSpecList& support_files) override;
136 ParseImportedModules (const lldb_private::SymbolContext &sc,
137 std::vector<lldb_private::ConstString> &imported_modules) override;
140 ParseFunctionBlocks (const lldb_private::SymbolContext& sc) override;
143 ParseTypes (const lldb_private::SymbolContext& sc) override;
146 ParseVariablesForContext (const lldb_private::SymbolContext& sc) override;
149 ResolveTypeUID(lldb::user_id_t type_uid) override;
152 CompleteType (lldb_private::CompilerType& compiler_type) override;
155 ResolveType (const DWARFDIE &die,
156 bool assert_not_being_parsed = true,
157 bool resolve_function_context = false);
159 lldb_private::CompilerDecl
160 GetDeclForUID (lldb::user_id_t uid) override;
162 lldb_private::CompilerDeclContext
163 GetDeclContextForUID (lldb::user_id_t uid) override;
165 lldb_private::CompilerDeclContext
166 GetDeclContextContainingUID (lldb::user_id_t uid) override;
169 ParseDeclsForContext (lldb_private::CompilerDeclContext decl_ctx) override;
173 ResolveSymbolContext (const lldb_private::Address& so_addr,
174 uint32_t resolve_scope,
175 lldb_private::SymbolContext& sc) override;
178 ResolveSymbolContext (const lldb_private::FileSpec& file_spec,
181 uint32_t resolve_scope,
182 lldb_private::SymbolContextList& sc_list) override;
185 FindGlobalVariables (const lldb_private::ConstString &name,
186 const lldb_private::CompilerDeclContext *parent_decl_ctx,
188 uint32_t max_matches,
189 lldb_private::VariableList& variables) override;
192 FindGlobalVariables (const lldb_private::RegularExpression& regex,
194 uint32_t max_matches,
195 lldb_private::VariableList& variables) override;
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,
203 lldb_private::SymbolContextList& sc_list) override;
206 FindFunctions (const lldb_private::RegularExpression& regex,
207 bool include_inlines,
209 lldb_private::SymbolContextList& sc_list) override;
212 FindTypes (const lldb_private::SymbolContext& sc,
213 const lldb_private::ConstString &name,
214 const lldb_private::CompilerDeclContext *parent_decl_ctx,
216 uint32_t max_matches,
217 lldb_private::TypeMap& types) override;
220 FindTypes (const std::vector<lldb_private::CompilerContext> &context,
222 lldb_private::TypeMap& types) override;
224 lldb_private::TypeList *
225 GetTypeList () override;
228 GetTypes (lldb_private::SymbolContextScope *sc_scope,
230 lldb_private::TypeList &type_list) override;
232 lldb_private::TypeSystem *
233 GetTypeSystemForLanguage (lldb::LanguageType language) override;
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;
241 //------------------------------------------------------------------
242 // PluginInterface protocol
243 //------------------------------------------------------------------
244 lldb_private::ConstString
245 GetPluginName() override;
248 GetPluginVersion() override;
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 ();
270 const DWARFDebugAbbrev*
276 const DWARFDebugInfo*
282 const DWARFDebugRanges*
286 SupportedVersion(uint16_t version);
289 GetDeclContextDIEContainingDIE (const DWARFDIE &die);
292 HasForwardDeclForClangType (const lldb_private::CompilerType &compiler_type);
294 lldb_private::CompileUnit*
295 GetCompUnitForDWARFCompUnit(DWARFCompileUnit* dwarf_cu,
296 uint32_t cu_idx = UINT32_MAX);
299 MakeUserID (dw_offset_t die_offset) const
301 return GetID() | die_offset;
305 GetObjCMethodDIEOffsets (lldb_private::ConstString class_name,
306 DIEArray &method_die_offsets);
309 Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu);
311 lldb_private::DebugMacrosSP
312 ParseDebugMacros(lldb::offset_t *offset);
315 GetParentSymbolContextDIE(const DWARFDIE &die);
317 virtual lldb::CompUnitSP
318 ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx);
320 virtual lldb_private::DWARFExpression::LocationListFormat
321 GetLocationListFormat() const;
324 GetDWOModule (lldb_private::ConstString name);
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;
332 struct DWARFDataSegment
334 std::once_flag m_flag;
335 lldb_private::DWARFDataExtractor m_data;
338 DISALLOW_COPY_AND_ASSIGN (SymbolFileDWARF);
340 const lldb_private::DWARFDataExtractor&
341 GetCachedSectionData (lldb::SectionType sect_type, DWARFDataSegment& data_segment);
344 LoadSectionData (lldb::SectionType sect_type, lldb_private::DWARFDataExtractor& data);
347 DeclContextMatchesThisSymbolFile (const lldb_private::CompilerDeclContext *decl_ctx);
350 DIEInDeclContext (const lldb_private::CompilerDeclContext *parent_decl_ctx,
351 const DWARFDIE &die);
353 virtual DWARFCompileUnit*
354 GetDWARFCompileUnit (lldb_private::CompileUnit *comp_unit);
357 GetNextUnparsedDWARFCompileUnit (DWARFCompileUnit* prev_cu);
360 GetFunction (const DWARFDIE &die,
361 lldb_private::SymbolContext& sc);
363 lldb_private::Function *
364 ParseCompileUnitFunction (const lldb_private::SymbolContext& sc,
365 const DWARFDIE &die);
368 ParseFunctionBlocks (const lldb_private::SymbolContext& sc,
369 lldb_private::Block *parent_block,
371 lldb::addr_t subprogram_low_pc,
375 ParseTypes (const lldb_private::SymbolContext& sc,
378 bool parse_children);
381 ParseType (const lldb_private::SymbolContext& sc,
386 ResolveTypeUID (const DWARFDIE &die,
387 bool assert_not_being_parsed);
390 ParseVariableDIE(const lldb_private::SymbolContext& sc,
392 const lldb::addr_t func_low_pc);
395 ParseVariables (const lldb_private::SymbolContext& sc,
396 const DWARFDIE &orig_die,
397 const lldb::addr_t func_low_pc,
400 lldb_private::VariableList* cc_variable_list = NULL);
403 ClassOrStructIsVirtual (const DWARFDIE &die);
405 // Given a die_offset, figure out the symbol context representing that die.
407 ResolveFunction (const DIERef& die_ref,
408 bool include_inlines,
409 lldb_private::SymbolContextList& sc_list);
412 ResolveFunction (const DWARFDIE &die,
413 bool include_inlines,
414 lldb_private::SymbolContextList& sc_list);
417 FindFunctions(const lldb_private::ConstString &name,
418 const NameToDIE &name_to_die,
419 bool include_inlines,
420 lldb_private::SymbolContextList& sc_list);
423 FindFunctions (const lldb_private::RegularExpression ®ex,
424 const NameToDIE &name_to_die,
425 bool include_inlines,
426 lldb_private::SymbolContextList& sc_list);
429 FindFunctions (const lldb_private::RegularExpression ®ex,
430 const DWARFMappedHash::MemoryTable &memory_table,
431 bool include_inlines,
432 lldb_private::SymbolContextList& sc_list);
435 FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &die_decl_ctx);
438 FindCompleteObjCDefinitionTypeForDIE (const DWARFDIE &die,
439 const lldb_private::ConstString &type_name,
440 bool must_be_implementation);
443 FindCompleteObjCDefinitionType (const lldb_private::ConstString &type_name,
444 bool header_definition_ok);
446 lldb_private::Symbol *
447 GetObjCClassSymbol (const lldb_private::ConstString &objc_class_name);
450 ParseFunctions (const DIEArray &die_offsets,
451 bool include_inlines,
452 lldb_private::SymbolContextList& sc_list);
455 GetTypeForDIE (const DWARFDIE &die, bool resolve_function_context = false);
464 SetDebugMapModule (const lldb::ModuleSP &module_sp)
466 m_debug_map_module_wp = module_sp;
469 SymbolFileDWARFDebugMap *
470 GetDebugMapSymfile ();
473 FindBlockContainingSpecification (const DIERef& func_die_ref, dw_offset_t spec_block_die_offset);
476 FindBlockContainingSpecification (const DWARFDIE &die, dw_offset_t spec_block_die_offset);
478 virtual UniqueDWARFASTTypeMap &
479 GetUniqueDWARFASTTypeMap ();
482 UserIDMatches (lldb::user_id_t uid) const
484 const lldb::user_id_t high_uid = uid & 0xffffffff00000000ull;
485 if (high_uid != 0 && GetID() != 0)
486 return high_uid == GetID();
491 DIEDeclContextsMatch (const DWARFDIE &die1,
492 const DWARFDIE &die2);
495 ClassContainsSelector (const DWARFDIE &class_die,
496 const lldb_private::ConstString &selector);
499 FixupAddress (lldb_private::Address &addr);
501 typedef std::set<lldb_private::Type *> TypeSet;
503 typedef std::map<lldb_private::ConstString, lldb::ModuleSP> ExternalTypeModuleMap;
506 GetTypes (const DWARFDIE &die,
507 dw_offset_t min_die_offset,
508 dw_offset_t max_die_offset,
512 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, lldb_private::Variable *> GlobalVariableMap;
518 UpdateExternalModuleListIfNeeded();
520 virtual DIEToTypePtr&
521 GetDIEToType() { return m_die_to_type; }
523 virtual DIEToVariableSP&
524 GetDIEToVariable() { return m_die_to_variable_sp; }
526 virtual DIEToClangType&
527 GetForwardDeclDieToClangType() { return m_forward_decl_die_to_clang_type; }
529 virtual ClangTypeToDIE&
530 GetForwardDeclClangTypeToDie() { return m_forward_decl_clang_type_to_die; }
532 lldb::ModuleWP m_debug_map_module_wp;
533 SymbolFileDWARFDebugMap * m_debug_map_symfile;
534 lldb_private::DWARFDataExtractor m_dwarf_data;
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;
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;
563 typedef std::unordered_map<lldb::offset_t, lldb_private::DebugMacrosSP> DebugMacrosMap;
564 DebugMacrosMap m_debug_macros_map;
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
576 m_using_apple_tables:1,
577 m_fetched_external_modules:1;
578 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
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;
588 #endif // SymbolFileDWARF_SymbolFileDWARF_h_