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 #include <list> 14 #include <map> 15 #include <mutex> 16 #include <set> 17 #include <unordered_map> 18 #include <vector> 19 20 #include "llvm/ADT/DenseMap.h" 21 #include "llvm/Support/Threading.h" 22 23 #include "lldb/Utility/Flags.h" 24 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" 34 35 #include "DWARFDataExtractor.h" 36 #include "DWARFDefines.h" 37 #include "DWARFIndex.h" 38 #include "UniqueDWARFASTType.h" 39 40 //---------------------------------------------------------------------- 41 // Forward Declarations for this DWARF plugin 42 //---------------------------------------------------------------------- 43 class DebugMapModule; 44 class DWARFAbbreviationDeclaration; 45 class DWARFAbbreviationDeclarationSet; 46 class DWARFileUnit; 47 class DWARFDebugAbbrev; 48 class DWARFDebugAranges; 49 class DWARFDebugInfo; 50 class DWARFDebugInfoEntry; 51 class DWARFDebugLine; 52 class DWARFDebugRangesBase; 53 class DWARFDeclContext; 54 class DWARFDIECollection; 55 class DWARFFormValue; 56 class SymbolFileDWARFDebugMap; 57 class SymbolFileDWARFDwo; 58 class SymbolFileDWARFDwp; 59 60 #define DIE_IS_BEING_PARSED ((lldb_private::Type *)1) 61 62 class SymbolFileDWARF : public lldb_private::SymbolFile, 63 public lldb_private::UserID { 64 public: 65 friend class SymbolFileDWARFDebugMap; 66 friend class SymbolFileDWARFDwo; 67 friend class DebugMapModule; 68 friend struct DIERef; 69 friend class DWARFUnit; 70 friend class DWARFDIE; 71 friend class DWARFASTParserClang; 72 73 //------------------------------------------------------------------ 74 // Static Functions 75 //------------------------------------------------------------------ 76 static void Initialize(); 77 78 static void Terminate(); 79 80 static void DebuggerInitialize(lldb_private::Debugger &debugger); 81 82 static lldb_private::ConstString GetPluginNameStatic(); 83 84 static const char *GetPluginDescriptionStatic(); 85 86 static lldb_private::SymbolFile * 87 CreateInstance(lldb_private::ObjectFile *obj_file); 88 89 //------------------------------------------------------------------ 90 // Constructors and Destructors 91 //------------------------------------------------------------------ 92 93 SymbolFileDWARF(lldb_private::ObjectFile *ofile); 94 95 ~SymbolFileDWARF() override; 96 97 uint32_t CalculateAbilities() override; 98 99 void InitializeObject() override; 100 101 //------------------------------------------------------------------ 102 // Compile Unit function calls 103 //------------------------------------------------------------------ 104 105 uint32_t GetNumCompileUnits() override; 106 107 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override; 108 109 lldb::LanguageType 110 ParseLanguage(lldb_private::CompileUnit &comp_unit) override; 111 112 size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override; 113 114 bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override; 115 116 bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override; 117 118 bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit, 119 lldb_private::FileSpecList &support_files) override; 120 121 bool ParseIsOptimized(lldb_private::CompileUnit &comp_unit) override; 122 123 size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override; 124 125 bool ParseImportedModules( 126 const lldb_private::SymbolContext &sc, 127 std::vector<lldb_private::ConstString> &imported_modules) override; 128 129 size_t ParseBlocksRecursive(lldb_private::Function &func) override; 130 131 size_t 132 ParseVariablesForContext(const lldb_private::SymbolContext &sc) override; 133 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; 138 139 bool CompleteType(lldb_private::CompilerType &compiler_type) override; 140 141 lldb_private::Type *ResolveType(const DWARFDIE &die, 142 bool assert_not_being_parsed = true, 143 bool resolve_function_context = false); 144 145 SymbolFileDWARF *GetDWARFForUID(lldb::user_id_t uid); 146 147 DWARFDIE 148 GetDIEFromUID(lldb::user_id_t uid); 149 150 lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override; 151 152 lldb_private::CompilerDeclContext 153 GetDeclContextForUID(lldb::user_id_t uid) override; 154 155 lldb_private::CompilerDeclContext 156 GetDeclContextContainingUID(lldb::user_id_t uid) override; 157 158 void 159 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override; 160 161 uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr, 162 lldb::SymbolContextItem resolve_scope, 163 lldb_private::SymbolContext &sc) override; 164 165 uint32_t 166 ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line, 167 bool check_inlines, 168 lldb::SymbolContextItem resolve_scope, 169 lldb_private::SymbolContextList &sc_list) override; 170 171 uint32_t 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; 176 177 uint32_t FindGlobalVariables(const lldb_private::RegularExpression ®ex, 178 uint32_t max_matches, 179 lldb_private::VariableList &variables) override; 180 181 uint32_t 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; 186 187 uint32_t FindFunctions(const lldb_private::RegularExpression ®ex, 188 bool include_inlines, bool append, 189 lldb_private::SymbolContextList &sc_list) override; 190 191 void GetMangledNamesForFunction( 192 const std::string &scope_qualified_name, 193 std::vector<lldb_private::ConstString> &mangled_names) override; 194 195 uint32_t 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; 201 202 size_t FindTypes(const std::vector<lldb_private::CompilerContext> &context, 203 bool append, lldb_private::TypeMap &types) override; 204 205 lldb_private::TypeList *GetTypeList() override; 206 207 size_t GetTypes(lldb_private::SymbolContextScope *sc_scope, 208 lldb::TypeClass type_mask, 209 lldb_private::TypeList &type_list) override; 210 211 lldb_private::TypeSystem * 212 GetTypeSystemForLanguage(lldb::LanguageType language) override; 213 214 lldb_private::CompilerDeclContext FindNamespace( 215 const lldb_private::ConstString &name, 216 const lldb_private::CompilerDeclContext *parent_decl_ctx) override; 217 218 void PreloadSymbols() override; 219 220 std::recursive_mutex &GetModuleMutex() const override; 221 222 //------------------------------------------------------------------ 223 // PluginInterface protocol 224 //------------------------------------------------------------------ 225 lldb_private::ConstString GetPluginName() override; 226 227 uint32_t GetPluginVersion() override; 228 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(); 249 250 DWARFDebugAbbrev *DebugAbbrev(); 251 252 const DWARFDebugAbbrev *DebugAbbrev() const; 253 254 DWARFDebugInfo *DebugInfo(); 255 256 const DWARFDebugInfo *DebugInfo() const; 257 258 DWARFDebugRangesBase *DebugRanges(); 259 260 const DWARFDebugRangesBase *DebugRanges() const; 261 262 const lldb_private::DWARFDataExtractor &DebugLocData(); 263 264 static bool SupportedVersion(uint16_t version); 265 266 DWARFDIE 267 GetDeclContextDIEContainingDIE(const DWARFDIE &die); 268 269 bool 270 HasForwardDeclForClangType(const lldb_private::CompilerType &compiler_type); 271 272 lldb_private::CompileUnit * 273 GetCompUnitForDWARFCompUnit(DWARFUnit *dwarf_cu, 274 uint32_t cu_idx = UINT32_MAX); 275 276 virtual size_t GetObjCMethodDIEOffsets(lldb_private::ConstString class_name, 277 DIEArray &method_die_offsets); 278 279 bool Supports_DW_AT_APPLE_objc_complete_type(DWARFUnit *cu); 280 281 lldb_private::DebugMacrosSP ParseDebugMacros(lldb::offset_t *offset); 282 283 static DWARFDIE GetParentSymbolContextDIE(const DWARFDIE &die); 284 285 virtual lldb::CompUnitSP ParseCompileUnit(DWARFUnit *dwarf_cu, 286 uint32_t cu_idx); 287 288 virtual lldb_private::DWARFExpression::LocationListFormat 289 GetLocationListFormat() const; 290 291 lldb::ModuleSP GetDWOModule(lldb_private::ConstString name); 292 293 typedef std::map<lldb_private::ConstString, lldb::ModuleSP> 294 ExternalTypeModuleMap; 295 296 /// Return the list of Clang modules imported by this SymbolFile. getExternalTypeModules()297 const ExternalTypeModuleMap& getExternalTypeModules() const { 298 return m_external_type_modules; 299 } 300 301 virtual DWARFDIE GetDIE(const DIERef &die_ref); 302 303 virtual std::unique_ptr<SymbolFileDWARFDwo> 304 GetDwoSymbolFileForCompileUnit(DWARFUnit &dwarf_cu, 305 const DWARFDebugInfoEntry &cu_die); 306 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(); 311 312 static bool 313 DIEInDeclContext(const lldb_private::CompilerDeclContext *parent_decl_ctx, 314 const DWARFDIE &die); 315 316 std::vector<lldb_private::CallEdge> 317 ParseCallEdgesInFunction(UserID func_id) override; 318 319 void Dump(lldb_private::Stream &s) override; 320 321 void DumpClangAST(lldb_private::Stream &s) override; 322 323 protected: 324 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb_private::Type *> 325 DIEToTypePtr; 326 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP> 327 DIEToVariableSP; 328 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, 329 lldb::opaque_compiler_type_t> 330 DIEToClangType; 331 typedef llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> ClangTypeToDIE; 332 333 struct DWARFDataSegment { 334 llvm::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, 342 DWARFDataSegment &data_segment); 343 344 virtual void LoadSectionData(lldb::SectionType sect_type, 345 lldb_private::DWARFDataExtractor &data); 346 347 bool DeclContextMatchesThisSymbolFile( 348 const lldb_private::CompilerDeclContext *decl_ctx); 349 350 virtual DWARFUnit * 351 GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit); 352 353 DWARFUnit *GetNextUnparsedDWARFCompileUnit(DWARFUnit *prev_cu); 354 355 bool GetFunction(const DWARFDIE &die, lldb_private::SymbolContext &sc); 356 357 lldb_private::Function *ParseFunction(lldb_private::CompileUnit &comp_unit, 358 const DWARFDIE &die); 359 360 size_t ParseBlocksRecursive(lldb_private::CompileUnit &comp_unit, 361 lldb_private::Block *parent_block, 362 const DWARFDIE &die, 363 lldb::addr_t subprogram_low_pc, uint32_t depth); 364 365 size_t ParseTypes(const lldb_private::SymbolContext &sc, const DWARFDIE &die, 366 bool parse_siblings, bool parse_children); 367 368 lldb::TypeSP ParseType(const lldb_private::SymbolContext &sc, 369 const DWARFDIE &die, bool *type_is_new); 370 371 lldb_private::Type *ResolveTypeUID(const DWARFDIE &die, 372 bool assert_not_being_parsed); 373 374 lldb_private::Type *ResolveTypeUID(const DIERef &die_ref); 375 376 lldb::VariableSP ParseVariableDIE(const lldb_private::SymbolContext &sc, 377 const DWARFDIE &die, 378 const lldb::addr_t func_low_pc); 379 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, 383 bool parse_children, 384 lldb_private::VariableList *cc_variable_list = NULL); 385 386 bool ClassOrStructIsVirtual(const DWARFDIE &die); 387 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); 391 392 virtual lldb::TypeSP 393 FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx); 394 395 virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE( 396 const DWARFDIE &die, const lldb_private::ConstString &type_name, 397 bool must_be_implementation); 398 399 lldb_private::Symbol * 400 GetObjCClassSymbol(const lldb_private::ConstString &objc_class_name); 401 402 lldb::TypeSP GetTypeForDIE(const DWARFDIE &die, 403 bool resolve_function_context = false); 404 SetDebugMapModule(const lldb::ModuleSP & module_sp)405 void SetDebugMapModule(const lldb::ModuleSP &module_sp) { 406 m_debug_map_module_wp = module_sp; 407 } 408 409 SymbolFileDWARFDebugMap *GetDebugMapSymfile(); 410 411 DWARFDIE 412 FindBlockContainingSpecification(const DIERef &func_die_ref, 413 dw_offset_t spec_block_die_offset); 414 415 DWARFDIE 416 FindBlockContainingSpecification(const DWARFDIE &die, 417 dw_offset_t spec_block_die_offset); 418 419 virtual UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap(); 420 421 bool DIEDeclContextsMatch(const DWARFDIE &die1, const DWARFDIE &die2); 422 423 bool ClassContainsSelector(const DWARFDIE &class_die, 424 const lldb_private::ConstString &selector); 425 426 bool FixupAddress(lldb_private::Address &addr); 427 428 typedef std::set<lldb_private::Type *> TypeSet; 429 430 void GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset, 431 dw_offset_t max_die_offset, uint32_t type_mask, 432 TypeSet &type_set); 433 434 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, 435 lldb_private::Variable *> 436 GlobalVariableMap; 437 438 GlobalVariableMap &GetGlobalAranges(); 439 440 void UpdateExternalModuleListIfNeeded(); 441 GetDIEToType()442 virtual DIEToTypePtr &GetDIEToType() { return m_die_to_type; } 443 GetDIEToVariable()444 virtual DIEToVariableSP &GetDIEToVariable() { return m_die_to_variable_sp; } 445 GetForwardDeclDieToClangType()446 virtual DIEToClangType &GetForwardDeclDieToClangType() { 447 return m_forward_decl_die_to_clang_type; 448 } 449 GetForwardDeclClangTypeToDie()450 virtual ClangTypeToDIE &GetForwardDeclClangTypeToDie() { 451 return m_forward_decl_clang_type_to_die; 452 } 453 454 SymbolFileDWARFDwp *GetDwpSymbolFile(); 455 456 lldb::ModuleWP m_debug_map_module_wp; 457 SymbolFileDWARFDebugMap *m_debug_map_symfile; 458 459 llvm::once_flag m_dwp_symfile_once_flag; 460 std::unique_ptr<SymbolFileDWARFDwp> m_dwp_symfile; 461 462 lldb_private::DWARFDataExtractor m_dwarf_data; 463 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; 484 485 // The unique pointer items below are generated on demand if and when someone 486 // accesses 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; 492 493 typedef std::unordered_map<lldb::offset_t, lldb_private::DebugMacrosSP> 494 DebugMacrosMap; 495 DebugMacrosMap m_debug_macros_map; 496 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; 501 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; 511 }; 512 513 #endif // SymbolFileDWARF_SymbolFileDWARF_h_ 514