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"
24 #include "llvm/Support/Threading.h"
26 #include "lldb/Utility/Flags.h"
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"
39 #include "DWARFDataExtractor.h"
40 #include "DWARFDefines.h"
41 #include "DWARFIndex.h"
42 #include "UniqueDWARFASTType.h"
44 //----------------------------------------------------------------------
45 // Forward Declarations for this DWARF plugin
46 //----------------------------------------------------------------------
48 class DWARFAbbreviationDeclaration;
49 class DWARFAbbreviationDeclarationSet;
51 class DWARFDebugAbbrev;
52 class DWARFDebugAranges;
54 class DWARFDebugInfoEntry;
56 class DWARFDebugRanges;
57 class DWARFDeclContext;
58 class DWARFDIECollection;
60 class SymbolFileDWARFDebugMap;
61 class SymbolFileDWARFDwo;
62 class SymbolFileDWARFDwp;
64 #define DIE_IS_BEING_PARSED ((lldb_private::Type *)1)
66 class SymbolFileDWARF : public lldb_private::SymbolFile,
67 public lldb_private::UserID {
69 friend class SymbolFileDWARFDebugMap;
70 friend class SymbolFileDWARFDwo;
71 friend class DebugMapModule;
73 friend class DWARFUnit;
74 friend class DWARFDIE;
75 friend class DWARFASTParserClang;
76 friend class DWARFASTParserGo;
77 friend class DWARFASTParserJava;
78 friend class DWARFASTParserOCaml;
80 //------------------------------------------------------------------
82 //------------------------------------------------------------------
83 static void Initialize();
85 static void Terminate();
87 static void DebuggerInitialize(lldb_private::Debugger &debugger);
89 static lldb_private::ConstString GetPluginNameStatic();
91 static const char *GetPluginDescriptionStatic();
93 static lldb_private::SymbolFile *
94 CreateInstance(lldb_private::ObjectFile *obj_file);
96 //------------------------------------------------------------------
97 // Constructors and Destructors
98 //------------------------------------------------------------------
100 SymbolFileDWARF(lldb_private::ObjectFile *ofile);
102 ~SymbolFileDWARF() override;
104 uint32_t CalculateAbilities() override;
106 void InitializeObject() override;
108 //------------------------------------------------------------------
109 // Compile Unit function calls
110 //------------------------------------------------------------------
112 uint32_t GetNumCompileUnits() override;
114 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
117 ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) override;
120 ParseCompileUnitFunctions(const lldb_private::SymbolContext &sc) override;
123 ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc) override;
126 ParseCompileUnitDebugMacros(const lldb_private::SymbolContext &sc) override;
128 bool ParseCompileUnitSupportFiles(
129 const lldb_private::SymbolContext &sc,
130 lldb_private::FileSpecList &support_files) override;
133 ParseCompileUnitIsOptimized(const lldb_private::SymbolContext &sc) override;
135 bool ParseImportedModules(
136 const lldb_private::SymbolContext &sc,
137 std::vector<lldb_private::ConstString> &imported_modules) override;
139 size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc) override;
141 size_t ParseTypes(const lldb_private::SymbolContext &sc) override;
144 ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
146 lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
148 bool CompleteType(lldb_private::CompilerType &compiler_type) override;
150 lldb_private::Type *ResolveType(const DWARFDIE &die,
151 bool assert_not_being_parsed = true,
152 bool resolve_function_context = false);
154 SymbolFileDWARF *GetDWARFForUID(lldb::user_id_t uid);
157 GetDIEFromUID(lldb::user_id_t uid);
159 lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override;
161 lldb_private::CompilerDeclContext
162 GetDeclContextForUID(lldb::user_id_t uid) override;
164 lldb_private::CompilerDeclContext
165 GetDeclContextContainingUID(lldb::user_id_t uid) override;
168 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
170 uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
171 uint32_t resolve_scope,
172 lldb_private::SymbolContext &sc) override;
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;
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;
185 uint32_t FindGlobalVariables(const lldb_private::RegularExpression ®ex,
186 uint32_t max_matches,
187 lldb_private::VariableList &variables) override;
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;
195 uint32_t FindFunctions(const lldb_private::RegularExpression ®ex,
196 bool include_inlines, bool append,
197 lldb_private::SymbolContextList &sc_list) override;
199 void GetMangledNamesForFunction(
200 const std::string &scope_qualified_name,
201 std::vector<lldb_private::ConstString> &mangled_names) override;
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;
211 size_t FindTypes(const std::vector<lldb_private::CompilerContext> &context,
212 bool append, lldb_private::TypeMap &types) override;
214 lldb_private::TypeList *GetTypeList() override;
216 size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
218 lldb_private::TypeList &type_list) override;
220 lldb_private::TypeSystem *
221 GetTypeSystemForLanguage(lldb::LanguageType language) override;
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;
228 void PreloadSymbols() override;
230 //------------------------------------------------------------------
231 // PluginInterface protocol
232 //------------------------------------------------------------------
233 lldb_private::ConstString GetPluginName() override;
235 uint32_t GetPluginVersion() override;
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();
255 DWARFDebugAbbrev *DebugAbbrev();
257 const DWARFDebugAbbrev *DebugAbbrev() const;
259 DWARFDebugInfo *DebugInfo();
261 const DWARFDebugInfo *DebugInfo() const;
263 DWARFDebugRanges *DebugRanges();
265 const DWARFDebugRanges *DebugRanges() const;
267 static bool SupportedVersion(uint16_t version);
270 GetDeclContextDIEContainingDIE(const DWARFDIE &die);
273 HasForwardDeclForClangType(const lldb_private::CompilerType &compiler_type);
275 lldb_private::CompileUnit *
276 GetCompUnitForDWARFCompUnit(DWARFUnit *dwarf_cu,
277 uint32_t cu_idx = UINT32_MAX);
279 virtual size_t GetObjCMethodDIEOffsets(lldb_private::ConstString class_name,
280 DIEArray &method_die_offsets);
282 bool Supports_DW_AT_APPLE_objc_complete_type(DWARFUnit *cu);
284 lldb_private::DebugMacrosSP ParseDebugMacros(lldb::offset_t *offset);
286 static DWARFDIE GetParentSymbolContextDIE(const DWARFDIE &die);
288 virtual lldb::CompUnitSP ParseCompileUnit(DWARFUnit *dwarf_cu,
291 virtual lldb_private::DWARFExpression::LocationListFormat
292 GetLocationListFormat() const;
294 lldb::ModuleSP GetDWOModule(lldb_private::ConstString name);
296 typedef std::map<lldb_private::ConstString, lldb::ModuleSP>
297 ExternalTypeModuleMap;
299 /// Return the list of Clang modules imported by this SymbolFile.
300 const ExternalTypeModuleMap& getExternalTypeModules() const {
301 return m_external_type_modules;
304 virtual DWARFDIE GetDIE(const DIERef &die_ref);
306 virtual std::unique_ptr<SymbolFileDWARFDwo>
307 GetDwoSymbolFileForCompileUnit(DWARFUnit &dwarf_cu,
308 const DWARFDebugInfoEntry &cu_die);
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();
316 DIEInDeclContext(const lldb_private::CompilerDeclContext *parent_decl_ctx,
317 const DWARFDIE &die);
319 void Dump(lldb_private::Stream &s) override;
322 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb_private::Type *>
324 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP>
326 typedef llvm::DenseMap<const DWARFDebugInfoEntry *,
327 lldb::opaque_compiler_type_t>
329 typedef llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> ClangTypeToDIE;
331 struct DWARFDataSegment {
332 llvm::once_flag m_flag;
333 lldb_private::DWARFDataExtractor m_data;
336 DISALLOW_COPY_AND_ASSIGN(SymbolFileDWARF);
338 const lldb_private::DWARFDataExtractor &
339 GetCachedSectionData(lldb::SectionType sect_type,
340 DWARFDataSegment &data_segment);
342 virtual void LoadSectionData(lldb::SectionType sect_type,
343 lldb_private::DWARFDataExtractor &data);
345 bool DeclContextMatchesThisSymbolFile(
346 const lldb_private::CompilerDeclContext *decl_ctx);
349 GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit);
351 DWARFUnit *GetNextUnparsedDWARFCompileUnit(DWARFUnit *prev_cu);
353 bool GetFunction(const DWARFDIE &die, lldb_private::SymbolContext &sc);
355 lldb_private::Function *
356 ParseCompileUnitFunction(const lldb_private::SymbolContext &sc,
357 const DWARFDIE &die);
359 size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc,
360 lldb_private::Block *parent_block,
362 lldb::addr_t subprogram_low_pc, uint32_t depth);
364 size_t ParseTypes(const lldb_private::SymbolContext &sc, const DWARFDIE &die,
365 bool parse_siblings, bool parse_children);
367 lldb::TypeSP ParseType(const lldb_private::SymbolContext &sc,
368 const DWARFDIE &die, bool *type_is_new);
370 lldb_private::Type *ResolveTypeUID(const DWARFDIE &die,
371 bool assert_not_being_parsed);
373 lldb_private::Type *ResolveTypeUID(const DIERef &die_ref);
375 lldb::VariableSP ParseVariableDIE(const lldb_private::SymbolContext &sc,
377 const lldb::addr_t func_low_pc);
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,
383 lldb_private::VariableList *cc_variable_list = NULL);
385 bool ClassOrStructIsVirtual(const DWARFDIE &die);
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);
392 FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
394 virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
395 const DWARFDIE &die, const lldb_private::ConstString &type_name,
396 bool must_be_implementation);
398 lldb_private::Symbol *
399 GetObjCClassSymbol(const lldb_private::ConstString &objc_class_name);
401 lldb::TypeSP GetTypeForDIE(const DWARFDIE &die,
402 bool resolve_function_context = false);
404 void SetDebugMapModule(const lldb::ModuleSP &module_sp) {
405 m_debug_map_module_wp = module_sp;
408 SymbolFileDWARFDebugMap *GetDebugMapSymfile();
411 FindBlockContainingSpecification(const DIERef &func_die_ref,
412 dw_offset_t spec_block_die_offset);
415 FindBlockContainingSpecification(const DWARFDIE &die,
416 dw_offset_t spec_block_die_offset);
418 virtual UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap();
420 bool DIEDeclContextsMatch(const DWARFDIE &die1, const DWARFDIE &die2);
422 bool ClassContainsSelector(const DWARFDIE &class_die,
423 const lldb_private::ConstString &selector);
425 bool FixupAddress(lldb_private::Address &addr);
427 typedef std::set<lldb_private::Type *> TypeSet;
429 void GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset,
430 dw_offset_t max_die_offset, uint32_t type_mask,
433 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t,
434 lldb_private::Variable *>
437 GlobalVariableMap &GetGlobalAranges();
439 void UpdateExternalModuleListIfNeeded();
441 virtual DIEToTypePtr &GetDIEToType() { return m_die_to_type; }
443 virtual DIEToVariableSP &GetDIEToVariable() { return m_die_to_variable_sp; }
445 virtual DIEToClangType &GetForwardDeclDieToClangType() {
446 return m_forward_decl_die_to_clang_type;
449 virtual ClangTypeToDIE &GetForwardDeclClangTypeToDie() {
450 return m_forward_decl_clang_type_to_die;
453 SymbolFileDWARFDwp *GetDwpSymbolFile();
455 lldb::ModuleWP m_debug_map_module_wp;
456 SymbolFileDWARFDebugMap *m_debug_map_symfile;
458 llvm::once_flag m_dwp_symfile_once_flag;
459 std::unique_ptr<SymbolFileDWARFDwp> m_dwp_symfile;
461 lldb_private::DWARFDataExtractor m_dwarf_data;
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;
481 // The unique pointer items below are generated on demand if and when someone
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;
489 typedef std::unordered_map<lldb::offset_t, lldb_private::DebugMacrosSP>
491 DebugMacrosMap m_debug_macros_map;
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;
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;
509 #endif // SymbolFileDWARF_SymbolFileDWARF_h_