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_
17 #include <unordered_map>
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/Support/Threading.h"
23 #include "lldb/Utility/Flags.h"
25 #include "lldb/Core/RangeMap.h"
26 #include "lldb/Core/UniqueCStringMap.h"
27 #include "lldb/Core/dwarf.h"
28 #include "lldb/Expression/DWARFExpression.h"
29 #include "lldb/Symbol/DebugMacros.h"
30 #include "lldb/Symbol/SymbolContext.h"
31 #include "lldb/Symbol/SymbolFile.h"
32 #include "lldb/Utility/ConstString.h"
33 #include "lldb/lldb-private.h"
35 #include "DWARFDataExtractor.h"
36 #include "DWARFDefines.h"
37 #include "DWARFIndex.h"
38 #include "UniqueDWARFASTType.h"
40 //----------------------------------------------------------------------
41 // Forward Declarations for this DWARF plugin
42 //----------------------------------------------------------------------
44 class DWARFAbbreviationDeclaration;
45 class DWARFAbbreviationDeclarationSet;
47 class DWARFDebugAbbrev;
48 class DWARFDebugAranges;
50 class DWARFDebugInfoEntry;
52 class DWARFDebugRangesBase;
53 class DWARFDeclContext;
54 class DWARFDIECollection;
56 class SymbolFileDWARFDebugMap;
57 class SymbolFileDWARFDwo;
58 class SymbolFileDWARFDwp;
60 #define DIE_IS_BEING_PARSED ((lldb_private::Type *)1)
62 class SymbolFileDWARF : public lldb_private::SymbolFile,
63 public lldb_private::UserID {
65 friend class SymbolFileDWARFDebugMap;
66 friend class SymbolFileDWARFDwo;
67 friend class DebugMapModule;
69 friend class DWARFUnit;
70 friend class DWARFDIE;
71 friend class DWARFASTParserClang;
73 //------------------------------------------------------------------
75 //------------------------------------------------------------------
76 static void Initialize();
78 static void Terminate();
80 static void DebuggerInitialize(lldb_private::Debugger &debugger);
82 static lldb_private::ConstString GetPluginNameStatic();
84 static const char *GetPluginDescriptionStatic();
86 static lldb_private::SymbolFile *
87 CreateInstance(lldb_private::ObjectFile *obj_file);
89 //------------------------------------------------------------------
90 // Constructors and Destructors
91 //------------------------------------------------------------------
93 SymbolFileDWARF(lldb_private::ObjectFile *ofile);
95 ~SymbolFileDWARF() override;
97 uint32_t CalculateAbilities() override;
99 void InitializeObject() override;
101 //------------------------------------------------------------------
102 // Compile Unit function calls
103 //------------------------------------------------------------------
105 uint32_t GetNumCompileUnits() override;
107 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
110 ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
112 size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
114 bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
116 bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override;
118 bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit,
119 lldb_private::FileSpecList &support_files) override;
121 bool ParseIsOptimized(lldb_private::CompileUnit &comp_unit) override;
123 size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
125 bool ParseImportedModules(
126 const lldb_private::SymbolContext &sc,
127 std::vector<lldb_private::ConstString> &imported_modules) override;
129 size_t ParseBlocksRecursive(lldb_private::Function &func) override;
132 ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
134 lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
135 llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID(
136 lldb::user_id_t type_uid,
137 const lldb_private::ExecutionContext *exe_ctx) override;
139 bool CompleteType(lldb_private::CompilerType &compiler_type) override;
141 lldb_private::Type *ResolveType(const DWARFDIE &die,
142 bool assert_not_being_parsed = true,
143 bool resolve_function_context = false);
145 SymbolFileDWARF *GetDWARFForUID(lldb::user_id_t uid);
148 GetDIEFromUID(lldb::user_id_t uid);
150 lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override;
152 lldb_private::CompilerDeclContext
153 GetDeclContextForUID(lldb::user_id_t uid) override;
155 lldb_private::CompilerDeclContext
156 GetDeclContextContainingUID(lldb::user_id_t uid) override;
159 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
161 uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
162 lldb::SymbolContextItem resolve_scope,
163 lldb_private::SymbolContext &sc) override;
166 ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line,
168 lldb::SymbolContextItem resolve_scope,
169 lldb_private::SymbolContextList &sc_list) override;
172 FindGlobalVariables(const lldb_private::ConstString &name,
173 const lldb_private::CompilerDeclContext *parent_decl_ctx,
174 uint32_t max_matches,
175 lldb_private::VariableList &variables) override;
177 uint32_t FindGlobalVariables(const lldb_private::RegularExpression ®ex,
178 uint32_t max_matches,
179 lldb_private::VariableList &variables) override;
182 FindFunctions(const lldb_private::ConstString &name,
183 const lldb_private::CompilerDeclContext *parent_decl_ctx,
184 lldb::FunctionNameType name_type_mask, bool include_inlines,
185 bool append, lldb_private::SymbolContextList &sc_list) override;
187 uint32_t FindFunctions(const lldb_private::RegularExpression ®ex,
188 bool include_inlines, bool append,
189 lldb_private::SymbolContextList &sc_list) override;
191 void GetMangledNamesForFunction(
192 const std::string &scope_qualified_name,
193 std::vector<lldb_private::ConstString> &mangled_names) override;
196 FindTypes(const lldb_private::ConstString &name,
197 const lldb_private::CompilerDeclContext *parent_decl_ctx,
198 bool append, uint32_t max_matches,
199 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
200 lldb_private::TypeMap &types) override;
202 size_t FindTypes(const std::vector<lldb_private::CompilerContext> &context,
203 bool append, lldb_private::TypeMap &types) override;
205 lldb_private::TypeList *GetTypeList() override;
207 size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
208 lldb::TypeClass type_mask,
209 lldb_private::TypeList &type_list) override;
211 lldb_private::TypeSystem *
212 GetTypeSystemForLanguage(lldb::LanguageType language) override;
214 lldb_private::CompilerDeclContext FindNamespace(
215 const lldb_private::ConstString &name,
216 const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
218 void PreloadSymbols() override;
220 std::recursive_mutex &GetModuleMutex() const override;
222 //------------------------------------------------------------------
223 // PluginInterface protocol
224 //------------------------------------------------------------------
225 lldb_private::ConstString GetPluginName() override;
227 uint32_t GetPluginVersion() override;
229 virtual const lldb_private::DWARFDataExtractor &get_debug_abbrev_data();
230 virtual const lldb_private::DWARFDataExtractor &get_debug_addr_data();
231 const lldb_private::DWARFDataExtractor &get_debug_aranges_data();
232 const lldb_private::DWARFDataExtractor &get_debug_frame_data();
233 virtual const lldb_private::DWARFDataExtractor &get_debug_info_data();
234 const lldb_private::DWARFDataExtractor &get_debug_line_data();
235 const lldb_private::DWARFDataExtractor &get_debug_line_str_data();
236 const lldb_private::DWARFDataExtractor &get_debug_macro_data();
237 const lldb_private::DWARFDataExtractor &get_debug_loc_data();
238 const lldb_private::DWARFDataExtractor &get_debug_loclists_data();
239 const lldb_private::DWARFDataExtractor &get_debug_ranges_data();
240 const lldb_private::DWARFDataExtractor &get_debug_rnglists_data();
241 virtual const lldb_private::DWARFDataExtractor &get_debug_str_data();
242 virtual const lldb_private::DWARFDataExtractor &get_debug_str_offsets_data();
243 const lldb_private::DWARFDataExtractor &get_debug_types_data();
244 const lldb_private::DWARFDataExtractor &get_apple_names_data();
245 const lldb_private::DWARFDataExtractor &get_apple_types_data();
246 const lldb_private::DWARFDataExtractor &get_apple_namespaces_data();
247 const lldb_private::DWARFDataExtractor &get_apple_objc_data();
248 const lldb_private::DWARFDataExtractor &get_gnu_debugaltlink();
250 DWARFDebugAbbrev *DebugAbbrev();
252 const DWARFDebugAbbrev *DebugAbbrev() const;
254 DWARFDebugInfo *DebugInfo();
256 const DWARFDebugInfo *DebugInfo() const;
258 DWARFDebugRangesBase *DebugRanges();
260 const DWARFDebugRangesBase *DebugRanges() const;
262 const lldb_private::DWARFDataExtractor &DebugLocData();
264 static bool SupportedVersion(uint16_t version);
267 GetDeclContextDIEContainingDIE(const DWARFDIE &die);
270 HasForwardDeclForClangType(const lldb_private::CompilerType &compiler_type);
272 lldb_private::CompileUnit *
273 GetCompUnitForDWARFCompUnit(DWARFUnit *dwarf_cu,
274 uint32_t cu_idx = UINT32_MAX);
276 virtual size_t GetObjCMethodDIEOffsets(lldb_private::ConstString class_name,
277 DIEArray &method_die_offsets);
279 bool Supports_DW_AT_APPLE_objc_complete_type(DWARFUnit *cu);
281 lldb_private::DebugMacrosSP ParseDebugMacros(lldb::offset_t *offset);
283 static DWARFDIE GetParentSymbolContextDIE(const DWARFDIE &die);
285 virtual lldb::CompUnitSP ParseCompileUnit(DWARFUnit *dwarf_cu,
288 virtual lldb_private::DWARFExpression::LocationListFormat
289 GetLocationListFormat() const;
291 lldb::ModuleSP GetDWOModule(lldb_private::ConstString name);
293 typedef std::map<lldb_private::ConstString, lldb::ModuleSP>
294 ExternalTypeModuleMap;
296 /// Return the list of Clang modules imported by this SymbolFile.
297 const ExternalTypeModuleMap& getExternalTypeModules() const {
298 return m_external_type_modules;
301 virtual DWARFDIE GetDIE(const DIERef &die_ref);
303 virtual std::unique_ptr<SymbolFileDWARFDwo>
304 GetDwoSymbolFileForCompileUnit(DWARFUnit &dwarf_cu,
305 const DWARFDebugInfoEntry &cu_die);
307 // For regular SymbolFileDWARF instances the method returns nullptr,
308 // for the instances of the subclass SymbolFileDWARFDwo
309 // the method returns a pointer to the base compile unit.
310 virtual DWARFUnit *GetBaseCompileUnit();
313 DIEInDeclContext(const lldb_private::CompilerDeclContext *parent_decl_ctx,
314 const DWARFDIE &die);
316 std::vector<lldb_private::CallEdge>
317 ParseCallEdgesInFunction(UserID func_id) override;
319 void Dump(lldb_private::Stream &s) override;
321 void DumpClangAST(lldb_private::Stream &s) override;
324 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb_private::Type *>
326 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP>
328 typedef llvm::DenseMap<const DWARFDebugInfoEntry *,
329 lldb::opaque_compiler_type_t>
331 typedef llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> ClangTypeToDIE;
333 struct DWARFDataSegment {
334 llvm::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,
342 DWARFDataSegment &data_segment);
344 virtual void LoadSectionData(lldb::SectionType sect_type,
345 lldb_private::DWARFDataExtractor &data);
347 bool DeclContextMatchesThisSymbolFile(
348 const lldb_private::CompilerDeclContext *decl_ctx);
351 GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit);
353 DWARFUnit *GetNextUnparsedDWARFCompileUnit(DWARFUnit *prev_cu);
355 bool GetFunction(const DWARFDIE &die, lldb_private::SymbolContext &sc);
357 lldb_private::Function *ParseFunction(lldb_private::CompileUnit &comp_unit,
358 const DWARFDIE &die);
360 size_t ParseBlocksRecursive(lldb_private::CompileUnit &comp_unit,
361 lldb_private::Block *parent_block,
363 lldb::addr_t subprogram_low_pc, uint32_t depth);
365 size_t ParseTypes(const lldb_private::SymbolContext &sc, const DWARFDIE &die,
366 bool parse_siblings, bool parse_children);
368 lldb::TypeSP ParseType(const lldb_private::SymbolContext &sc,
369 const DWARFDIE &die, bool *type_is_new);
371 lldb_private::Type *ResolveTypeUID(const DWARFDIE &die,
372 bool assert_not_being_parsed);
374 lldb_private::Type *ResolveTypeUID(const DIERef &die_ref);
376 lldb::VariableSP ParseVariableDIE(const lldb_private::SymbolContext &sc,
378 const lldb::addr_t func_low_pc);
380 size_t ParseVariables(const lldb_private::SymbolContext &sc,
381 const DWARFDIE &orig_die,
382 const lldb::addr_t func_low_pc, bool parse_siblings,
384 lldb_private::VariableList *cc_variable_list = NULL);
386 bool ClassOrStructIsVirtual(const DWARFDIE &die);
388 // Given a die_offset, figure out the symbol context representing that die.
389 bool ResolveFunction(const DWARFDIE &die, bool include_inlines,
390 lldb_private::SymbolContextList &sc_list);
393 FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
395 virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
396 const DWARFDIE &die, const lldb_private::ConstString &type_name,
397 bool must_be_implementation);
399 lldb_private::Symbol *
400 GetObjCClassSymbol(const lldb_private::ConstString &objc_class_name);
402 lldb::TypeSP GetTypeForDIE(const DWARFDIE &die,
403 bool resolve_function_context = false);
405 void SetDebugMapModule(const lldb::ModuleSP &module_sp) {
406 m_debug_map_module_wp = module_sp;
409 SymbolFileDWARFDebugMap *GetDebugMapSymfile();
412 FindBlockContainingSpecification(const DIERef &func_die_ref,
413 dw_offset_t spec_block_die_offset);
416 FindBlockContainingSpecification(const DWARFDIE &die,
417 dw_offset_t spec_block_die_offset);
419 virtual UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap();
421 bool DIEDeclContextsMatch(const DWARFDIE &die1, const DWARFDIE &die2);
423 bool ClassContainsSelector(const DWARFDIE &class_die,
424 const lldb_private::ConstString &selector);
426 bool FixupAddress(lldb_private::Address &addr);
428 typedef std::set<lldb_private::Type *> TypeSet;
430 void GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset,
431 dw_offset_t max_die_offset, uint32_t type_mask,
434 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t,
435 lldb_private::Variable *>
438 GlobalVariableMap &GetGlobalAranges();
440 void UpdateExternalModuleListIfNeeded();
442 virtual DIEToTypePtr &GetDIEToType() { return m_die_to_type; }
444 virtual DIEToVariableSP &GetDIEToVariable() { return m_die_to_variable_sp; }
446 virtual DIEToClangType &GetForwardDeclDieToClangType() {
447 return m_forward_decl_die_to_clang_type;
450 virtual ClangTypeToDIE &GetForwardDeclClangTypeToDie() {
451 return m_forward_decl_clang_type_to_die;
454 SymbolFileDWARFDwp *GetDwpSymbolFile();
456 lldb::ModuleWP m_debug_map_module_wp;
457 SymbolFileDWARFDebugMap *m_debug_map_symfile;
459 llvm::once_flag m_dwp_symfile_once_flag;
460 std::unique_ptr<SymbolFileDWARFDwp> m_dwp_symfile;
462 lldb_private::DWARFDataExtractor m_dwarf_data;
464 DWARFDataSegment m_data_debug_abbrev;
465 DWARFDataSegment m_data_debug_addr;
466 DWARFDataSegment m_data_debug_aranges;
467 DWARFDataSegment m_data_debug_frame;
468 DWARFDataSegment m_data_debug_info;
469 DWARFDataSegment m_data_debug_line;
470 DWARFDataSegment m_data_debug_line_str;
471 DWARFDataSegment m_data_debug_macro;
472 DWARFDataSegment m_data_debug_loc;
473 DWARFDataSegment m_data_debug_loclists;
474 DWARFDataSegment m_data_debug_ranges;
475 DWARFDataSegment m_data_debug_rnglists;
476 DWARFDataSegment m_data_debug_str;
477 DWARFDataSegment m_data_debug_str_offsets;
478 DWARFDataSegment m_data_debug_types;
479 DWARFDataSegment m_data_apple_names;
480 DWARFDataSegment m_data_apple_types;
481 DWARFDataSegment m_data_apple_namespaces;
482 DWARFDataSegment m_data_apple_objc;
483 DWARFDataSegment m_data_gnu_debugaltlink;
485 // The unique pointer items below are generated on demand if and when someone
487 // them through a non const version of this class.
488 std::unique_ptr<DWARFDebugAbbrev> m_abbr;
489 std::unique_ptr<DWARFDebugInfo> m_info;
490 std::unique_ptr<DWARFDebugLine> m_line;
491 std::unique_ptr<GlobalVariableMap> m_global_aranges_ap;
493 typedef std::unordered_map<lldb::offset_t, lldb_private::DebugMacrosSP>
495 DebugMacrosMap m_debug_macros_map;
497 ExternalTypeModuleMap m_external_type_modules;
498 std::unique_ptr<lldb_private::DWARFIndex> m_index;
499 bool m_fetched_external_modules : 1;
500 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
502 typedef std::shared_ptr<std::set<DIERef>> DIERefSetSP;
503 typedef std::unordered_map<std::string, DIERefSetSP> NameToOffsetMap;
504 NameToOffsetMap m_function_scope_qualified_name_map;
505 std::unique_ptr<DWARFDebugRangesBase> m_ranges;
506 UniqueDWARFASTTypeMap m_unique_ast_type_map;
507 DIEToTypePtr m_die_to_type;
508 DIEToVariableSP m_die_to_variable_sp;
509 DIEToClangType m_forward_decl_die_to_clang_type;
510 ClangTypeToDIE m_forward_decl_clang_type_to_die;
513 #endif // SymbolFileDWARF_SymbolFileDWARF_h_