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 // C Includes 14 // C++ Includes 15 #include <list> 16 #include <map> 17 #include <set> 18 #include <vector> 19 20 // Other libraries and framework includes 21 #include "llvm/ADT/DenseMap.h" 22 23 #include "lldb/lldb-private.h" 24 #include "lldb/Core/ConstString.h" 25 #include "lldb/Core/dwarf.h" 26 #include "lldb/Core/Flags.h" 27 #include "lldb/Core/RangeMap.h" 28 #include "lldb/Core/UniqueCStringMap.h" 29 #include "lldb/Expression/DWARFExpression.h" 30 #include "lldb/Symbol/SymbolFile.h" 31 #include "lldb/Symbol/SymbolContext.h" 32 33 // Project includes 34 #include "DWARFDefines.h" 35 #include "DWARFDataExtractor.h" 36 #include "HashedNameToDIE.h" 37 #include "NameToDIE.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 DWARFDebugPubnames; 53 class DWARFDebugRanges; 54 class DWARFDeclContext; 55 class DWARFDIECollection; 56 class DWARFFormValue; 57 class SymbolFileDWARFDebugMap; 58 59 #define DIE_IS_BEING_PARSED ((lldb_private::Type*)1) 60 61 class SymbolFileDWARF : public lldb_private::SymbolFile, public lldb_private::UserID 62 { 63 public: 64 friend class SymbolFileDWARFDebugMap; 65 friend class SymbolFileDWARFDwo; 66 friend class DebugMapModule; 67 friend class DWARFCompileUnit; 68 friend class DWARFASTParserClang; 69 friend class DWARFASTParserGo; 70 71 //------------------------------------------------------------------ 72 // Static Functions 73 //------------------------------------------------------------------ 74 static void 75 Initialize(); 76 77 static void 78 Terminate(); 79 80 static void 81 DebuggerInitialize(lldb_private::Debugger &debugger); 82 83 static lldb_private::ConstString 84 GetPluginNameStatic(); 85 86 static const char * 87 GetPluginDescriptionStatic(); 88 89 static lldb_private::SymbolFile* 90 CreateInstance (lldb_private::ObjectFile* obj_file); 91 92 //------------------------------------------------------------------ 93 // Constructors and Destructors 94 //------------------------------------------------------------------ 95 96 SymbolFileDWARF(lldb_private::ObjectFile* ofile); 97 98 ~SymbolFileDWARF() override; 99 100 uint32_t 101 CalculateAbilities () override; 102 103 void 104 InitializeObject() override; 105 106 //------------------------------------------------------------------ 107 // Compile Unit function calls 108 //------------------------------------------------------------------ 109 110 uint32_t 111 GetNumCompileUnits() override; 112 113 lldb::CompUnitSP 114 ParseCompileUnitAtIndex(uint32_t index) override; 115 116 lldb::LanguageType 117 ParseCompileUnitLanguage (const lldb_private::SymbolContext& sc) override; 118 119 size_t 120 ParseCompileUnitFunctions (const lldb_private::SymbolContext& sc) override; 121 122 bool 123 ParseCompileUnitLineTable (const lldb_private::SymbolContext& sc) override; 124 125 bool 126 ParseCompileUnitSupportFiles (const lldb_private::SymbolContext& sc, 127 lldb_private::FileSpecList& support_files) override; 128 129 bool 130 ParseImportedModules (const lldb_private::SymbolContext &sc, 131 std::vector<lldb_private::ConstString> &imported_modules) override; 132 133 size_t 134 ParseFunctionBlocks (const lldb_private::SymbolContext& sc) override; 135 136 size_t 137 ParseTypes (const lldb_private::SymbolContext& sc) override; 138 139 size_t 140 ParseVariablesForContext (const lldb_private::SymbolContext& sc) override; 141 142 lldb_private::Type * 143 ResolveTypeUID(lldb::user_id_t type_uid) override; 144 145 bool 146 CompleteType (lldb_private::CompilerType& clang_type) override; 147 148 lldb_private::Type * 149 ResolveType (const DWARFDIE &die, 150 bool assert_not_being_parsed = true); 151 152 lldb_private::CompilerDecl 153 GetDeclForUID (lldb::user_id_t uid) override; 154 155 lldb_private::CompilerDeclContext 156 GetDeclContextForUID (lldb::user_id_t uid) override; 157 158 lldb_private::CompilerDeclContext 159 GetDeclContextContainingUID (lldb::user_id_t uid) override; 160 161 void 162 ParseDeclsForContext (lldb_private::CompilerDeclContext decl_ctx) override; 163 164 165 uint32_t 166 ResolveSymbolContext (const lldb_private::Address& so_addr, 167 uint32_t resolve_scope, 168 lldb_private::SymbolContext& sc) override; 169 170 uint32_t 171 ResolveSymbolContext (const lldb_private::FileSpec& file_spec, 172 uint32_t line, 173 bool check_inlines, 174 uint32_t resolve_scope, 175 lldb_private::SymbolContextList& sc_list) override; 176 177 uint32_t 178 FindGlobalVariables (const lldb_private::ConstString &name, 179 const lldb_private::CompilerDeclContext *parent_decl_ctx, 180 bool append, 181 uint32_t max_matches, 182 lldb_private::VariableList& variables) override; 183 184 uint32_t 185 FindGlobalVariables (const lldb_private::RegularExpression& regex, 186 bool append, 187 uint32_t max_matches, 188 lldb_private::VariableList& variables) override; 189 190 uint32_t 191 FindFunctions (const lldb_private::ConstString &name, 192 const lldb_private::CompilerDeclContext *parent_decl_ctx, 193 uint32_t name_type_mask, 194 bool include_inlines, 195 bool append, 196 lldb_private::SymbolContextList& sc_list) override; 197 198 uint32_t 199 FindFunctions (const lldb_private::RegularExpression& regex, 200 bool include_inlines, 201 bool append, 202 lldb_private::SymbolContextList& sc_list) override; 203 204 uint32_t 205 FindTypes (const lldb_private::SymbolContext& sc, 206 const lldb_private::ConstString &name, 207 const lldb_private::CompilerDeclContext *parent_decl_ctx, 208 bool append, 209 uint32_t max_matches, 210 lldb_private::TypeList& types) override; 211 212 lldb_private::TypeList * 213 GetTypeList () override; 214 215 size_t 216 GetTypes (lldb_private::SymbolContextScope *sc_scope, 217 uint32_t type_mask, 218 lldb_private::TypeList &type_list) override; 219 220 lldb_private::TypeSystem * 221 GetTypeSystemForLanguage (lldb::LanguageType language) override; 222 223 lldb_private::CompilerDeclContext 224 FindNamespace (const lldb_private::SymbolContext& sc, 225 const lldb_private::ConstString &name, 226 const lldb_private::CompilerDeclContext *parent_decl_ctx) override; 227 228 229 //------------------------------------------------------------------ 230 // PluginInterface protocol 231 //------------------------------------------------------------------ 232 lldb_private::ConstString 233 GetPluginName() override; 234 235 uint32_t 236 GetPluginVersion() override; 237 238 const lldb_private::DWARFDataExtractor& get_debug_abbrev_data (); 239 const lldb_private::DWARFDataExtractor& get_debug_addr_data (); 240 const lldb_private::DWARFDataExtractor& get_debug_aranges_data (); 241 const lldb_private::DWARFDataExtractor& get_debug_frame_data (); 242 const lldb_private::DWARFDataExtractor& get_debug_info_data (); 243 const lldb_private::DWARFDataExtractor& get_debug_line_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_apple_names_data (); 249 const lldb_private::DWARFDataExtractor& get_apple_types_data (); 250 const lldb_private::DWARFDataExtractor& get_apple_namespaces_data (); 251 const lldb_private::DWARFDataExtractor& get_apple_objc_data (); 252 253 254 DWARFDebugAbbrev* 255 DebugAbbrev(); 256 257 const DWARFDebugAbbrev* 258 DebugAbbrev() const; 259 260 DWARFDebugInfo* 261 DebugInfo(); 262 263 const DWARFDebugInfo* 264 DebugInfo() const; 265 266 DWARFDebugRanges* 267 DebugRanges(); 268 const DWARFDebugRanges* 269 DebugRanges() const; 270 271 virtual const lldb_private::DWARFDataExtractor& 272 GetCachedSectionData (uint32_t got_flag, 273 lldb::SectionType sect_type, 274 lldb_private::DWARFDataExtractor &data); 275 276 static bool 277 SupportedVersion(uint16_t version); 278 279 DWARFDIE 280 GetDeclContextDIEContainingDIE (const DWARFDIE &die); 281 282 lldb_private::Flags& 283 GetFlags () 284 { 285 return m_flags; 286 } 287 288 const lldb_private::Flags& 289 GetFlags () const 290 { 291 return m_flags; 292 } 293 294 bool 295 HasForwardDeclForClangType (const lldb_private::CompilerType &clang_type); 296 297 lldb_private::CompileUnit* 298 GetCompUnitForDWARFCompUnit(DWARFCompileUnit* dwarf_cu, 299 uint32_t cu_idx = UINT32_MAX); 300 301 lldb::user_id_t 302 MakeUserID (dw_offset_t die_offset) const 303 { 304 return GetID() | die_offset; 305 } 306 307 size_t 308 GetObjCMethodDIEOffsets (lldb_private::ConstString class_name, 309 DIEArray &method_die_offsets); 310 311 bool 312 Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu); 313 314 static DWARFDIE 315 GetParentSymbolContextDIE(const DWARFDIE &die); 316 317 virtual lldb::CompUnitSP 318 ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx); 319 320 virtual lldb_private::DWARFExpression::LocationListFormat 321 GetLocationListFormat() const; 322 323 protected: 324 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb_private::Type *> DIEToTypePtr; 325 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP> DIEToVariableSP; 326 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::opaque_compiler_type_t> DIEToClangType; 327 typedef llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> ClangTypeToDIE; 328 329 enum 330 { 331 flagsGotDebugAbbrevData = (1 << 0), 332 flagsGotDebugAddrData = (1 << 1), 333 flagsGotDebugArangesData = (1 << 2), 334 flagsGotDebugFrameData = (1 << 3), 335 flagsGotDebugInfoData = (1 << 4), 336 flagsGotDebugLineData = (1 << 5), 337 flagsGotDebugLocData = (1 << 6), 338 flagsGotDebugMacInfoData = (1 << 7), 339 flagsGotDebugPubNamesData = (1 << 8), 340 flagsGotDebugPubTypesData = (1 << 9), 341 flagsGotDebugRangesData = (1 << 10), 342 flagsGotDebugStrData = (1 << 11), 343 flagsGotDebugStrOffsetsData = (1 << 12), 344 flagsGotAppleNamesData = (1 << 13), 345 flagsGotAppleTypesData = (1 << 14), 346 flagsGotAppleNamespacesData = (1 << 15), 347 flagsGotAppleObjCData = (1 << 16) 348 }; 349 350 bool 351 DeclContextMatchesThisSymbolFile (const lldb_private::CompilerDeclContext *decl_ctx); 352 353 bool 354 DIEInDeclContext (const lldb_private::CompilerDeclContext *parent_decl_ctx, 355 const DWARFDIE &die); 356 357 DISALLOW_COPY_AND_ASSIGN (SymbolFileDWARF); 358 359 virtual DWARFCompileUnit* 360 GetDWARFCompileUnit (lldb_private::CompileUnit *comp_unit); 361 362 DWARFCompileUnit* 363 GetNextUnparsedDWARFCompileUnit (DWARFCompileUnit* prev_cu); 364 365 bool 366 GetFunction (const DWARFDIE &die, 367 lldb_private::SymbolContext& sc); 368 369 lldb_private::Function * 370 ParseCompileUnitFunction (const lldb_private::SymbolContext& sc, 371 const DWARFDIE &die); 372 373 size_t 374 ParseFunctionBlocks (const lldb_private::SymbolContext& sc, 375 lldb_private::Block *parent_block, 376 const DWARFDIE &die, 377 lldb::addr_t subprogram_low_pc, 378 uint32_t depth); 379 380 size_t 381 ParseTypes (const lldb_private::SymbolContext& sc, 382 const DWARFDIE &die, 383 bool parse_siblings, 384 bool parse_children); 385 386 lldb::TypeSP 387 ParseType (const lldb_private::SymbolContext& sc, 388 const DWARFDIE &die, 389 bool *type_is_new); 390 391 lldb_private::Type * 392 ResolveTypeUID (const DWARFDIE &die, 393 bool assert_not_being_parsed); 394 395 lldb::VariableSP 396 ParseVariableDIE(const lldb_private::SymbolContext& sc, 397 const DWARFDIE &die, 398 const lldb::addr_t func_low_pc); 399 400 size_t 401 ParseVariables (const lldb_private::SymbolContext& sc, 402 const DWARFDIE &orig_die, 403 const lldb::addr_t func_low_pc, 404 bool parse_siblings, 405 bool parse_children, 406 lldb_private::VariableList* cc_variable_list = NULL); 407 408 bool 409 ClassOrStructIsVirtual (const DWARFDIE &die); 410 411 // Given a die_offset, figure out the symbol context representing that die. 412 bool 413 ResolveFunction (const DIERef& die_ref, 414 bool include_inlines, 415 lldb_private::SymbolContextList& sc_list); 416 417 bool 418 ResolveFunction (const DWARFDIE &die, 419 bool include_inlines, 420 lldb_private::SymbolContextList& sc_list); 421 422 void 423 FindFunctions(const lldb_private::ConstString &name, 424 const NameToDIE &name_to_die, 425 bool include_inlines, 426 lldb_private::SymbolContextList& sc_list); 427 428 void 429 FindFunctions (const lldb_private::RegularExpression ®ex, 430 const NameToDIE &name_to_die, 431 bool include_inlines, 432 lldb_private::SymbolContextList& sc_list); 433 434 void 435 FindFunctions (const lldb_private::RegularExpression ®ex, 436 const DWARFMappedHash::MemoryTable &memory_table, 437 bool include_inlines, 438 lldb_private::SymbolContextList& sc_list); 439 440 virtual lldb::TypeSP 441 FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &die_decl_ctx); 442 443 lldb::TypeSP 444 FindCompleteObjCDefinitionTypeForDIE (const DWARFDIE &die, 445 const lldb_private::ConstString &type_name, 446 bool must_be_implementation); 447 448 lldb::TypeSP 449 FindCompleteObjCDefinitionType (const lldb_private::ConstString &type_name, 450 bool header_definition_ok); 451 452 lldb_private::Symbol * 453 GetObjCClassSymbol (const lldb_private::ConstString &objc_class_name); 454 455 void 456 ParseFunctions (const DIEArray &die_offsets, 457 bool include_inlines, 458 lldb_private::SymbolContextList& sc_list); 459 460 lldb::TypeSP 461 GetTypeForDIE (const DWARFDIE &die); 462 463 void 464 Index(); 465 466 void 467 DumpIndexes(); 468 469 void 470 SetDebugMapModule (const lldb::ModuleSP &module_sp) 471 { 472 m_debug_map_module_wp = module_sp; 473 } 474 475 SymbolFileDWARFDebugMap * 476 GetDebugMapSymfile (); 477 478 DWARFDIE 479 FindBlockContainingSpecification (const DIERef& func_die_ref, dw_offset_t spec_block_die_offset); 480 481 DWARFDIE 482 FindBlockContainingSpecification (const DWARFDIE &die, dw_offset_t spec_block_die_offset); 483 484 UniqueDWARFASTTypeMap & 485 GetUniqueDWARFASTTypeMap (); 486 487 bool 488 UserIDMatches (lldb::user_id_t uid) const 489 { 490 const lldb::user_id_t high_uid = uid & 0xffffffff00000000ull; 491 if (high_uid != 0 && GetID() != 0) 492 return high_uid == GetID(); 493 return true; 494 } 495 496 bool 497 DIEDeclContextsMatch (const DWARFDIE &die1, 498 const DWARFDIE &die2); 499 500 bool 501 ClassContainsSelector (const DWARFDIE &class_die, 502 const lldb_private::ConstString &selector); 503 504 bool 505 FixupAddress (lldb_private::Address &addr); 506 507 typedef std::set<lldb_private::Type *> TypeSet; 508 509 typedef struct { 510 lldb_private::ConstString m_name; 511 lldb::ModuleSP m_module_sp; 512 } ClangModuleInfo; 513 514 typedef std::map<uint64_t, ClangModuleInfo> ExternalTypeModuleMap; 515 516 void 517 GetTypes (const DWARFDIE &die, 518 dw_offset_t min_die_offset, 519 dw_offset_t max_die_offset, 520 uint32_t type_mask, 521 TypeSet &type_set); 522 523 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, lldb_private::Variable *> GlobalVariableMap; 524 525 GlobalVariableMap & 526 GetGlobalAranges(); 527 528 void 529 UpdateExternalModuleListIfNeeded(); 530 531 virtual DIEToTypePtr& 532 GetDIEToType() { return m_die_to_type; } 533 534 virtual DIEToVariableSP& 535 GetDIEToVariable() { return m_die_to_variable_sp; } 536 537 virtual DIEToClangType& 538 GetForwardDeclDieToClangType() { return m_forward_decl_die_to_clang_type; } 539 540 virtual ClangTypeToDIE& 541 GetForwardDeclClangTypeToDie() { return m_forward_decl_clang_type_to_die; } 542 543 lldb::ModuleWP m_debug_map_module_wp; 544 SymbolFileDWARFDebugMap * m_debug_map_symfile; 545 lldb_private::Flags m_flags; 546 lldb_private::DWARFDataExtractor m_dwarf_data; 547 lldb_private::DWARFDataExtractor m_data_debug_abbrev; 548 lldb_private::DWARFDataExtractor m_data_debug_addr; 549 lldb_private::DWARFDataExtractor m_data_debug_aranges; 550 lldb_private::DWARFDataExtractor m_data_debug_frame; 551 lldb_private::DWARFDataExtractor m_data_debug_info; 552 lldb_private::DWARFDataExtractor m_data_debug_line; 553 lldb_private::DWARFDataExtractor m_data_debug_loc; 554 lldb_private::DWARFDataExtractor m_data_debug_ranges; 555 lldb_private::DWARFDataExtractor m_data_debug_str; 556 lldb_private::DWARFDataExtractor m_data_debug_str_offsets; 557 lldb_private::DWARFDataExtractor m_data_apple_names; 558 lldb_private::DWARFDataExtractor m_data_apple_types; 559 lldb_private::DWARFDataExtractor m_data_apple_namespaces; 560 lldb_private::DWARFDataExtractor m_data_apple_objc; 561 562 // The unique pointer items below are generated on demand if and when someone accesses 563 // them through a non const version of this class. 564 std::unique_ptr<DWARFDebugAbbrev> m_abbr; 565 std::unique_ptr<DWARFDebugInfo> m_info; 566 std::unique_ptr<DWARFDebugLine> m_line; 567 std::unique_ptr<DWARFMappedHash::MemoryTable> m_apple_names_ap; 568 std::unique_ptr<DWARFMappedHash::MemoryTable> m_apple_types_ap; 569 std::unique_ptr<DWARFMappedHash::MemoryTable> m_apple_namespaces_ap; 570 std::unique_ptr<DWARFMappedHash::MemoryTable> m_apple_objc_ap; 571 std::unique_ptr<GlobalVariableMap> m_global_aranges_ap; 572 ExternalTypeModuleMap m_external_type_modules; 573 NameToDIE m_function_basename_index; // All concrete functions 574 NameToDIE m_function_fullname_index; // All concrete functions 575 NameToDIE m_function_method_index; // All inlined functions 576 NameToDIE m_function_selector_index; // All method names for functions of classes 577 NameToDIE m_objc_class_selectors_index; // Given a class name, find all selectors for the class 578 NameToDIE m_global_index; // Global and static variables 579 NameToDIE m_type_index; // All type DIE offsets 580 NameToDIE m_namespace_index; // All type DIE offsets 581 bool m_indexed:1, 582 m_using_apple_tables:1, 583 m_fetched_external_modules:1; 584 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type; 585 586 std::unique_ptr<DWARFDebugRanges> m_ranges; 587 UniqueDWARFASTTypeMap m_unique_ast_type_map; 588 DIEToTypePtr m_die_to_type; 589 DIEToVariableSP m_die_to_variable_sp; 590 DIEToClangType m_forward_decl_die_to_clang_type; 591 ClangTypeToDIE m_forward_decl_clang_type_to_die; 592 }; 593 594 #endif // SymbolFileDWARF_SymbolFileDWARF_h_ 595