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 "HashedNameToDIE.h"
42 #include "NameToDIE.h"
43 #include "UniqueDWARFASTType.h"
45 //----------------------------------------------------------------------
46 // Forward Declarations for this DWARF plugin
47 //----------------------------------------------------------------------
49 class DWARFAbbreviationDeclaration;
50 class DWARFAbbreviationDeclarationSet;
52 class DWARFDebugAbbrev;
53 class DWARFDebugAranges;
55 class DWARFDebugInfoEntry;
57 class DWARFDebugPubnames;
58 class DWARFDebugRanges;
59 class DWARFDeclContext;
60 class DWARFDIECollection;
62 class SymbolFileDWARFDebugMap;
63 class SymbolFileDWARFDwo;
64 class SymbolFileDWARFDwp;
66 #define DIE_IS_BEING_PARSED ((lldb_private::Type *)1)
68 class SymbolFileDWARF : public lldb_private::SymbolFile,
69 public lldb_private::UserID {
71 friend class SymbolFileDWARFDebugMap;
72 friend class SymbolFileDWARFDwo;
73 friend class DebugMapModule;
75 friend class DWARFCompileUnit;
76 friend class DWARFDIE;
77 friend class DWARFASTParserClang;
78 friend class DWARFASTParserGo;
79 friend class DWARFASTParserJava;
80 friend class DWARFASTParserOCaml;
82 //------------------------------------------------------------------
84 //------------------------------------------------------------------
85 static void Initialize();
87 static void Terminate();
89 static void DebuggerInitialize(lldb_private::Debugger &debugger);
91 static lldb_private::ConstString GetPluginNameStatic();
93 static const char *GetPluginDescriptionStatic();
95 static lldb_private::SymbolFile *
96 CreateInstance(lldb_private::ObjectFile *obj_file);
98 //------------------------------------------------------------------
99 // Constructors and Destructors
100 //------------------------------------------------------------------
102 SymbolFileDWARF(lldb_private::ObjectFile *ofile);
104 ~SymbolFileDWARF() override;
106 uint32_t CalculateAbilities() override;
108 void InitializeObject() override;
110 //------------------------------------------------------------------
111 // Compile Unit function calls
112 //------------------------------------------------------------------
114 uint32_t GetNumCompileUnits() override;
116 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
119 ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) override;
122 ParseCompileUnitFunctions(const lldb_private::SymbolContext &sc) override;
125 ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc) override;
128 ParseCompileUnitDebugMacros(const lldb_private::SymbolContext &sc) override;
130 bool ParseCompileUnitSupportFiles(
131 const lldb_private::SymbolContext &sc,
132 lldb_private::FileSpecList &support_files) override;
135 ParseCompileUnitIsOptimized(const lldb_private::SymbolContext &sc) override;
137 bool ParseImportedModules(
138 const lldb_private::SymbolContext &sc,
139 std::vector<lldb_private::ConstString> &imported_modules) override;
141 size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc) override;
143 size_t ParseTypes(const lldb_private::SymbolContext &sc) override;
146 ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
148 lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
150 bool CompleteType(lldb_private::CompilerType &compiler_type) override;
152 lldb_private::Type *ResolveType(const DWARFDIE &die,
153 bool assert_not_being_parsed = true,
154 bool resolve_function_context = false);
156 SymbolFileDWARF *GetDWARFForUID(lldb::user_id_t uid);
159 GetDIEFromUID(lldb::user_id_t uid);
161 lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override;
163 lldb_private::CompilerDeclContext
164 GetDeclContextForUID(lldb::user_id_t uid) override;
166 lldb_private::CompilerDeclContext
167 GetDeclContextContainingUID(lldb::user_id_t uid) override;
170 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
172 uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
173 uint32_t resolve_scope,
174 lldb_private::SymbolContext &sc) override;
177 ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line,
178 bool check_inlines, uint32_t resolve_scope,
179 lldb_private::SymbolContextList &sc_list) override;
182 FindGlobalVariables(const lldb_private::ConstString &name,
183 const lldb_private::CompilerDeclContext *parent_decl_ctx,
184 bool append, uint32_t max_matches,
185 lldb_private::VariableList &variables) override;
187 uint32_t FindGlobalVariables(const lldb_private::RegularExpression ®ex,
188 bool append, uint32_t max_matches,
189 lldb_private::VariableList &variables) override;
192 FindFunctions(const lldb_private::ConstString &name,
193 const lldb_private::CompilerDeclContext *parent_decl_ctx,
194 uint32_t name_type_mask, bool include_inlines, bool append,
195 lldb_private::SymbolContextList &sc_list) override;
197 uint32_t FindFunctions(const lldb_private::RegularExpression ®ex,
198 bool include_inlines, bool append,
199 lldb_private::SymbolContextList &sc_list) override;
201 void GetMangledNamesForFunction(
202 const std::string &scope_qualified_name,
203 std::vector<lldb_private::ConstString> &mangled_names) override;
206 FindTypes(const lldb_private::SymbolContext &sc,
207 const lldb_private::ConstString &name,
208 const lldb_private::CompilerDeclContext *parent_decl_ctx,
209 bool append, uint32_t max_matches,
210 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
211 lldb_private::TypeMap &types) override;
213 size_t FindTypes(const std::vector<lldb_private::CompilerContext> &context,
214 bool append, lldb_private::TypeMap &types) override;
216 lldb_private::TypeList *GetTypeList() override;
218 size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
220 lldb_private::TypeList &type_list) override;
222 lldb_private::TypeSystem *
223 GetTypeSystemForLanguage(lldb::LanguageType language) override;
225 lldb_private::CompilerDeclContext FindNamespace(
226 const lldb_private::SymbolContext &sc,
227 const lldb_private::ConstString &name,
228 const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
230 void PreloadSymbols() override;
232 //------------------------------------------------------------------
233 // PluginInterface protocol
234 //------------------------------------------------------------------
235 lldb_private::ConstString GetPluginName() override;
237 uint32_t GetPluginVersion() override;
239 const lldb_private::DWARFDataExtractor &get_debug_abbrev_data();
240 const lldb_private::DWARFDataExtractor &get_debug_addr_data();
241 const lldb_private::DWARFDataExtractor &get_debug_aranges_data();
242 const lldb_private::DWARFDataExtractor &get_debug_frame_data();
243 const lldb_private::DWARFDataExtractor &get_debug_info_data();
244 const lldb_private::DWARFDataExtractor &get_debug_line_data();
245 const lldb_private::DWARFDataExtractor &get_debug_macro_data();
246 const lldb_private::DWARFDataExtractor &get_debug_loc_data();
247 const lldb_private::DWARFDataExtractor &get_debug_ranges_data();
248 const lldb_private::DWARFDataExtractor &get_debug_str_data();
249 const lldb_private::DWARFDataExtractor &get_debug_str_offsets_data();
250 const lldb_private::DWARFDataExtractor &get_apple_names_data();
251 const lldb_private::DWARFDataExtractor &get_apple_types_data();
252 const lldb_private::DWARFDataExtractor &get_apple_namespaces_data();
253 const lldb_private::DWARFDataExtractor &get_apple_objc_data();
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(DWARFCompileUnit *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(DWARFCompileUnit *cu);
284 lldb_private::DebugMacrosSP ParseDebugMacros(lldb::offset_t *offset);
286 static DWARFDIE GetParentSymbolContextDIE(const DWARFDIE &die);
288 virtual lldb::CompUnitSP ParseCompileUnit(DWARFCompileUnit *dwarf_cu,
291 virtual lldb_private::DWARFExpression::LocationListFormat
292 GetLocationListFormat() const;
294 lldb::ModuleSP GetDWOModule(lldb_private::ConstString name);
296 virtual DWARFDIE GetDIE(const DIERef &die_ref);
298 virtual std::unique_ptr<SymbolFileDWARFDwo>
299 GetDwoSymbolFileForCompileUnit(DWARFCompileUnit &dwarf_cu,
300 const DWARFDebugInfoEntry &cu_die);
302 // For regular SymbolFileDWARF instances the method returns nullptr,
303 // for the instances of the subclass SymbolFileDWARFDwo
304 // the method returns a pointer to the base compile unit.
305 virtual DWARFCompileUnit *GetBaseCompileUnit();
308 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb_private::Type *>
310 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP>
312 typedef llvm::DenseMap<const DWARFDebugInfoEntry *,
313 lldb::opaque_compiler_type_t>
315 typedef llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> ClangTypeToDIE;
317 struct DWARFDataSegment {
318 llvm::once_flag m_flag;
319 lldb_private::DWARFDataExtractor m_data;
322 DISALLOW_COPY_AND_ASSIGN(SymbolFileDWARF);
324 const lldb_private::DWARFDataExtractor &
325 GetCachedSectionData(lldb::SectionType sect_type,
326 DWARFDataSegment &data_segment);
328 virtual void LoadSectionData(lldb::SectionType sect_type,
329 lldb_private::DWARFDataExtractor &data);
331 bool DeclContextMatchesThisSymbolFile(
332 const lldb_private::CompilerDeclContext *decl_ctx);
335 DIEInDeclContext(const lldb_private::CompilerDeclContext *parent_decl_ctx,
336 const DWARFDIE &die);
338 virtual DWARFCompileUnit *
339 GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit);
341 DWARFCompileUnit *GetNextUnparsedDWARFCompileUnit(DWARFCompileUnit *prev_cu);
343 bool GetFunction(const DWARFDIE &die, lldb_private::SymbolContext &sc);
345 lldb_private::Function *
346 ParseCompileUnitFunction(const lldb_private::SymbolContext &sc,
347 const DWARFDIE &die);
349 size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc,
350 lldb_private::Block *parent_block,
352 lldb::addr_t subprogram_low_pc, uint32_t depth);
354 size_t ParseTypes(const lldb_private::SymbolContext &sc, const DWARFDIE &die,
355 bool parse_siblings, bool parse_children);
357 lldb::TypeSP ParseType(const lldb_private::SymbolContext &sc,
358 const DWARFDIE &die, bool *type_is_new);
360 lldb_private::Type *ResolveTypeUID(const DWARFDIE &die,
361 bool assert_not_being_parsed);
363 lldb_private::Type *ResolveTypeUID(const DIERef &die_ref);
365 lldb::VariableSP ParseVariableDIE(const lldb_private::SymbolContext &sc,
367 const lldb::addr_t func_low_pc);
369 size_t ParseVariables(const lldb_private::SymbolContext &sc,
370 const DWARFDIE &orig_die,
371 const lldb::addr_t func_low_pc, bool parse_siblings,
373 lldb_private::VariableList *cc_variable_list = NULL);
375 bool ClassOrStructIsVirtual(const DWARFDIE &die);
377 // Given a die_offset, figure out the symbol context representing that die.
378 bool ResolveFunction(const DIERef &die_ref, bool include_inlines,
379 lldb_private::SymbolContextList &sc_list);
381 bool ResolveFunction(const DWARFDIE &die, bool include_inlines,
382 lldb_private::SymbolContextList &sc_list);
384 void FindFunctions(const lldb_private::ConstString &name,
385 const NameToDIE &name_to_die, bool include_inlines,
386 lldb_private::SymbolContextList &sc_list);
388 void FindFunctions(const lldb_private::RegularExpression ®ex,
389 const NameToDIE &name_to_die, bool include_inlines,
390 lldb_private::SymbolContextList &sc_list);
392 void FindFunctions(const lldb_private::RegularExpression ®ex,
393 const DWARFMappedHash::MemoryTable &memory_table,
394 bool include_inlines,
395 lldb_private::SymbolContextList &sc_list);
398 FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
400 virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
401 const DWARFDIE &die, const lldb_private::ConstString &type_name,
402 bool must_be_implementation);
404 lldb_private::Symbol *
405 GetObjCClassSymbol(const lldb_private::ConstString &objc_class_name);
407 void ParseFunctions(const DIEArray &die_offsets, bool include_inlines,
408 lldb_private::SymbolContextList &sc_list);
410 lldb::TypeSP GetTypeForDIE(const DWARFDIE &die,
411 bool resolve_function_context = false);
417 void SetDebugMapModule(const lldb::ModuleSP &module_sp) {
418 m_debug_map_module_wp = module_sp;
421 SymbolFileDWARFDebugMap *GetDebugMapSymfile();
424 FindBlockContainingSpecification(const DIERef &func_die_ref,
425 dw_offset_t spec_block_die_offset);
428 FindBlockContainingSpecification(const DWARFDIE &die,
429 dw_offset_t spec_block_die_offset);
431 virtual UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap();
433 bool DIEDeclContextsMatch(const DWARFDIE &die1, const DWARFDIE &die2);
435 bool ClassContainsSelector(const DWARFDIE &class_die,
436 const lldb_private::ConstString &selector);
438 bool FixupAddress(lldb_private::Address &addr);
440 typedef std::set<lldb_private::Type *> TypeSet;
442 typedef std::map<lldb_private::ConstString, lldb::ModuleSP>
443 ExternalTypeModuleMap;
445 void GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset,
446 dw_offset_t max_die_offset, uint32_t type_mask,
449 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t,
450 lldb_private::Variable *>
453 GlobalVariableMap &GetGlobalAranges();
455 void UpdateExternalModuleListIfNeeded();
457 virtual DIEToTypePtr &GetDIEToType() { return m_die_to_type; }
459 virtual DIEToVariableSP &GetDIEToVariable() { return m_die_to_variable_sp; }
461 virtual DIEToClangType &GetForwardDeclDieToClangType() {
462 return m_forward_decl_die_to_clang_type;
465 virtual ClangTypeToDIE &GetForwardDeclClangTypeToDie() {
466 return m_forward_decl_clang_type_to_die;
469 SymbolFileDWARFDwp *GetDwpSymbolFile();
471 lldb::ModuleWP m_debug_map_module_wp;
472 SymbolFileDWARFDebugMap *m_debug_map_symfile;
474 llvm::once_flag m_dwp_symfile_once_flag;
475 std::unique_ptr<SymbolFileDWARFDwp> m_dwp_symfile;
477 lldb_private::DWARFDataExtractor m_dwarf_data;
479 DWARFDataSegment m_data_debug_abbrev;
480 DWARFDataSegment m_data_debug_addr;
481 DWARFDataSegment m_data_debug_aranges;
482 DWARFDataSegment m_data_debug_frame;
483 DWARFDataSegment m_data_debug_info;
484 DWARFDataSegment m_data_debug_line;
485 DWARFDataSegment m_data_debug_macro;
486 DWARFDataSegment m_data_debug_loc;
487 DWARFDataSegment m_data_debug_ranges;
488 DWARFDataSegment m_data_debug_str;
489 DWARFDataSegment m_data_debug_str_offsets;
490 DWARFDataSegment m_data_apple_names;
491 DWARFDataSegment m_data_apple_types;
492 DWARFDataSegment m_data_apple_namespaces;
493 DWARFDataSegment m_data_apple_objc;
495 // The unique pointer items below are generated on demand if and when someone
497 // them through a non const version of this class.
498 std::unique_ptr<DWARFDebugAbbrev> m_abbr;
499 std::unique_ptr<DWARFDebugInfo> m_info;
500 std::unique_ptr<DWARFDebugLine> m_line;
501 std::unique_ptr<DWARFMappedHash::MemoryTable> m_apple_names_ap;
502 std::unique_ptr<DWARFMappedHash::MemoryTable> m_apple_types_ap;
503 std::unique_ptr<DWARFMappedHash::MemoryTable> m_apple_namespaces_ap;
504 std::unique_ptr<DWARFMappedHash::MemoryTable> m_apple_objc_ap;
505 std::unique_ptr<GlobalVariableMap> m_global_aranges_ap;
507 typedef std::unordered_map<lldb::offset_t, lldb_private::DebugMacrosSP>
509 DebugMacrosMap m_debug_macros_map;
511 ExternalTypeModuleMap m_external_type_modules;
512 NameToDIE m_function_basename_index; // All concrete functions
513 NameToDIE m_function_fullname_index; // All concrete functions
514 NameToDIE m_function_method_index; // All inlined functions
516 m_function_selector_index; // All method names for functions of classes
517 NameToDIE m_objc_class_selectors_index; // Given a class name, find all
518 // selectors for the class
519 NameToDIE m_global_index; // Global and static variables
520 NameToDIE m_type_index; // All type DIE offsets
521 NameToDIE m_namespace_index; // All type DIE offsets
522 bool m_indexed : 1, m_using_apple_tables : 1, m_fetched_external_modules : 1;
523 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
525 typedef std::shared_ptr<std::set<DIERef>> DIERefSetSP;
526 typedef std::unordered_map<std::string, DIERefSetSP> NameToOffsetMap;
527 NameToOffsetMap m_function_scope_qualified_name_map;
528 std::unique_ptr<DWARFDebugRanges> m_ranges;
529 UniqueDWARFASTTypeMap m_unique_ast_type_map;
530 DIEToTypePtr m_die_to_type;
531 DIEToVariableSP m_die_to_variable_sp;
532 DIEToClangType m_forward_decl_die_to_clang_type;
533 ClangTypeToDIE m_forward_decl_clang_type_to_die;
536 #endif // SymbolFileDWARF_SymbolFileDWARF_h_