1 //===-- SymbolFileDWARFDebugMap.cpp ----------------------------*- 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 #include "SymbolFileDWARFDebugMap.h" 11 12 #include "lldb/Core/Module.h" 13 #include "lldb/Core/ModuleList.h" 14 #include "lldb/Core/PluginManager.h" 15 #include "lldb/Core/RegularExpression.h" 16 #include "lldb/Core/Section.h" 17 #if defined(DEBUG_OSO_DMAP) 18 #include "lldb/Core/StreamFile.h" 19 #endif 20 #include "lldb/Core/Timer.h" 21 22 #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h" 23 #include "lldb/Symbol/CompileUnit.h" 24 #include "lldb/Symbol/ObjectFile.h" 25 #include "lldb/Symbol/SymbolVendor.h" 26 #include "lldb/Symbol/VariableList.h" 27 28 #include "LogChannelDWARF.h" 29 #include "SymbolFileDWARF.h" 30 31 using namespace lldb; 32 using namespace lldb_private; 33 34 // Subclass lldb_private::Module so we can intercept the "Module::GetObjectFile()" 35 // (so we can fixup the object file sections) and also for "Module::GetSymbolVendor()" 36 // (so we can fixup the symbol file id. 37 38 class DebugMapModule : public Module 39 { 40 public: 41 DebugMapModule (const ModuleSP &exe_module_sp, 42 uint32_t cu_idx, 43 const FileSpec& file_spec, 44 const ArchSpec& arch, 45 const ConstString *object_name, 46 off_t object_offset) : 47 Module (file_spec, arch, object_name, object_offset), 48 m_exe_module_wp (exe_module_sp), 49 m_cu_idx (cu_idx) 50 { 51 } 52 53 virtual ObjectFile * 54 GetObjectFile () 55 { 56 Mutex::Locker locker (m_mutex); 57 if (m_did_load_objfile == false) 58 { 59 ModuleSP exe_module_sp (m_exe_module_wp.lock()); 60 if (exe_module_sp) 61 { 62 ObjectFile *exe_objfile = exe_module_sp->GetObjectFile(); 63 ObjectFile *oso_objfile = Module::GetObjectFile(); 64 SymbolVendor *exe_sym_vendor = exe_module_sp->GetSymbolVendor(); 65 66 if (exe_objfile && oso_objfile && exe_sym_vendor) 67 { 68 SymbolFileDWARFDebugMap *exe_symfile = (SymbolFileDWARFDebugMap *)exe_sym_vendor->GetSymbolFile(); 69 if (exe_symfile) 70 { 71 SymbolFileDWARFDebugMap::CompileUnitInfo *comp_unit_info = exe_symfile->GetCompUnitInfo (this); 72 if (comp_unit_info) 73 { 74 // Set the ID of the symbol file DWARF to the index of the OSO 75 // shifted left by 32 bits to provide a unique prefix for any 76 // UserID's that get created in the symbol file. 77 //comp_unit_info->exe_sections_sp.reset(new SectionList); 78 79 Symtab *exe_symtab = exe_objfile->GetSymtab(); 80 ModuleSP oso_module_sp (oso_objfile->GetModule()); 81 Symtab *oso_symtab = oso_objfile->GetSymtab(); 82 //#define DEBUG_OSO_DMAP // Do not check in with this defined... 83 #if defined(DEBUG_OSO_DMAP) 84 StreamFile s(stdout); 85 s << "OSO symtab:\n"; 86 oso_symtab->Dump(&s, NULL); 87 s << "OSO sections before:\n"; 88 oso_objfile->GetSectionList()->Dump(&s, NULL, true); 89 #endif 90 91 ///const uint32_t fun_resolve_flags = SymbolContext::Module | eSymbolContextCompUnit | eSymbolContextFunction; 92 //SectionList *oso_sections = oso_objfile->Sections(); 93 // Now we need to make sections that map from zero based object 94 // file addresses to where things eneded up in the main executable. 95 96 assert (comp_unit_info->first_symbol_index != UINT32_MAX); 97 // End index is one past the last valid symbol index 98 const uint32_t oso_end_idx = comp_unit_info->last_symbol_index + 1; 99 uint32_t sect_id = 0x10000; 100 for (uint32_t idx = comp_unit_info->first_symbol_index + 2; // Skip the N_SO and N_OSO 101 idx < oso_end_idx; 102 ++idx) 103 { 104 Symbol *exe_symbol = exe_symtab->SymbolAtIndex(idx); 105 if (exe_symbol) 106 { 107 if (exe_symbol->IsDebug() == false) 108 continue; 109 110 switch (exe_symbol->GetType()) 111 { 112 default: 113 break; 114 115 case eSymbolTypeCode: 116 { 117 // For each N_FUN, or function that we run into in the debug map 118 // we make a new section that we add to the sections found in the 119 // .o file. This new section has the file address set to what the 120 // addresses are in the .o file, and the load address is adjusted 121 // to match where it ended up in the final executable! We do this 122 // before we parse any dwarf info so that when it goes get parsed 123 // all section/offset addresses that get registered will resolve 124 // correctly to the new addresses in the main executable. 125 126 // First we find the original symbol in the .o file's symbol table 127 Symbol *oso_fun_symbol = oso_symtab->FindFirstSymbolWithNameAndType(exe_symbol->GetMangled().GetName(Mangled::ePreferMangled), eSymbolTypeCode, Symtab::eDebugNo, Symtab::eVisibilityAny); 128 if (oso_fun_symbol) 129 { 130 // If we found the symbol, then we 131 SectionSP exe_fun_section (exe_symbol->GetAddress().GetSection()); 132 SectionSP oso_fun_section (oso_fun_symbol->GetAddress().GetSection()); 133 if (oso_fun_section) 134 { 135 // Now we create a section that we will add as a child of the 136 // section in which the .o symbol (the N_FUN) exists. 137 138 // We use the exe_symbol size because the one in the .o file 139 // will just be a symbol with no size, and the exe_symbol 140 // size will reflect any size changes (ppc has been known to 141 // shrink function sizes when it gets rid of jump islands that 142 // aren't needed anymore). 143 SectionSP oso_fun_section_sp (new Section (oso_fun_symbol->GetAddress().GetSection(), 144 oso_module_sp, // Module (the .o file) 145 sect_id++, // Section ID starts at 0x10000 and increments so the section IDs don't overlap with the standard mach IDs 146 exe_symbol->GetMangled().GetName(Mangled::ePreferMangled), // Name the section the same as the symbol for which is was generated! 147 eSectionTypeDebug, 148 oso_fun_symbol->GetAddress().GetOffset(), // File VM address offset in the current section 149 exe_symbol->GetByteSize(), // File size (we need the size from the executable) 150 0, 0, 0)); 151 152 oso_fun_section_sp->SetLinkedLocation (exe_fun_section, 153 exe_symbol->GetAddress().GetFileAddress() - exe_fun_section->GetFileAddress()); 154 oso_fun_section->GetChildren().AddSection(oso_fun_section_sp); 155 } 156 } 157 } 158 break; 159 160 case eSymbolTypeData: 161 { 162 // For each N_GSYM we remap the address for the global by making 163 // a new section that we add to the sections found in the .o file. 164 // This new section has the file address set to what the 165 // addresses are in the .o file, and the load address is adjusted 166 // to match where it ended up in the final executable! We do this 167 // before we parse any dwarf info so that when it goes get parsed 168 // all section/offset addresses that get registered will resolve 169 // correctly to the new addresses in the main executable. We 170 // initially set the section size to be 1 byte, but will need to 171 // fix up these addresses further after all globals have been 172 // parsed to span the gaps, or we can find the global variable 173 // sizes from the DWARF info as we are parsing. 174 175 // Next we find the non-stab entry that corresponds to the N_GSYM in the .o file 176 Symbol *oso_gsym_symbol = oso_symtab->FindFirstSymbolWithNameAndType (exe_symbol->GetMangled().GetName(), 177 eSymbolTypeData, 178 Symtab::eDebugNo, 179 Symtab::eVisibilityAny); 180 181 if (exe_symbol && oso_gsym_symbol && exe_symbol->ValueIsAddress() && oso_gsym_symbol->ValueIsAddress()) 182 { 183 // If we found the symbol, then we 184 SectionSP exe_gsym_section (exe_symbol->GetAddress().GetSection()); 185 SectionSP oso_gsym_section (oso_gsym_symbol->GetAddress().GetSection()); 186 if (oso_gsym_section) 187 { 188 SectionSP oso_gsym_section_sp (new Section (oso_gsym_symbol->GetAddress().GetSection(), 189 oso_module_sp, // Module (the .o file) 190 sect_id++, // Section ID starts at 0x10000 and increments so the section IDs don't overlap with the standard mach IDs 191 exe_symbol->GetMangled().GetName(Mangled::ePreferMangled), // Name the section the same as the symbol for which is was generated! 192 eSectionTypeDebug, 193 oso_gsym_symbol->GetAddress().GetOffset(), // File VM address offset in the current section 194 1, // We don't know the size of the global, just do the main address for now. 195 0, 0, 0)); 196 197 oso_gsym_section_sp->SetLinkedLocation (exe_gsym_section, 198 exe_symbol->GetAddress().GetFileAddress() - exe_gsym_section->GetFileAddress()); 199 oso_gsym_section->GetChildren().AddSection(oso_gsym_section_sp); 200 } 201 } 202 } 203 break; 204 } 205 } 206 } 207 oso_objfile->GetSectionList()->Finalize(); // Now that we're done adding sections, finalize to build fast-lookup caches 208 #if defined(DEBUG_OSO_DMAP) 209 s << "OSO sections after:\n"; 210 oso_objfile->GetSectionList()->Dump(&s, NULL, true); 211 #endif 212 } 213 } 214 } 215 } 216 } 217 return m_objfile_sp.get(); 218 } 219 220 virtual SymbolVendor* 221 GetSymbolVendor(bool can_create = true) 222 { 223 // Scope for locker 224 if (m_symfile_ap.get() || can_create == false) 225 return m_symfile_ap.get(); 226 227 ModuleSP exe_module_sp (m_exe_module_wp.lock()); 228 if (exe_module_sp) 229 { 230 // Now get the object file outside of a locking scope 231 ObjectFile *oso_objfile = GetObjectFile (); 232 if (oso_objfile) 233 { 234 Mutex::Locker locker (m_mutex); 235 SymbolVendor* symbol_vendor = Module::GetSymbolVendor(can_create); 236 if (symbol_vendor) 237 { 238 // Set a a pointer to this class to set our OSO DWARF file know 239 // that the DWARF is being used along with a debug map and that 240 // it will have the remapped sections that we do below. 241 SymbolFileDWARF *oso_symfile = (SymbolFileDWARF *)symbol_vendor->GetSymbolFile(); 242 243 if (!oso_symfile) 244 return NULL; 245 246 ObjectFile *exe_objfile = exe_module_sp->GetObjectFile(); 247 SymbolVendor *exe_sym_vendor = exe_module_sp->GetSymbolVendor(); 248 249 if (exe_objfile && exe_sym_vendor) 250 { 251 if (oso_symfile->GetNumCompileUnits() == 1) 252 { 253 oso_symfile->SetDebugMapModule(exe_module_sp); 254 // Set the ID of the symbol file DWARF to the index of the OSO 255 // shifted left by 32 bits to provide a unique prefix for any 256 // UserID's that get created in the symbol file. 257 oso_symfile->SetID (((uint64_t)m_cu_idx + 1ull) << 32ull); 258 } 259 else 260 { 261 oso_symfile->SetID (UINT64_MAX); 262 } 263 } 264 return symbol_vendor; 265 } 266 } 267 } 268 return NULL; 269 } 270 271 protected: 272 ModuleWP m_exe_module_wp; 273 const uint32_t m_cu_idx; 274 }; 275 276 void 277 SymbolFileDWARFDebugMap::Initialize() 278 { 279 PluginManager::RegisterPlugin (GetPluginNameStatic(), 280 GetPluginDescriptionStatic(), 281 CreateInstance); 282 } 283 284 void 285 SymbolFileDWARFDebugMap::Terminate() 286 { 287 PluginManager::UnregisterPlugin (CreateInstance); 288 } 289 290 291 const char * 292 SymbolFileDWARFDebugMap::GetPluginNameStatic() 293 { 294 return "dwarf-debugmap"; 295 } 296 297 const char * 298 SymbolFileDWARFDebugMap::GetPluginDescriptionStatic() 299 { 300 return "DWARF and DWARF3 debug symbol file reader (debug map)."; 301 } 302 303 SymbolFile* 304 SymbolFileDWARFDebugMap::CreateInstance (ObjectFile* obj_file) 305 { 306 return new SymbolFileDWARFDebugMap (obj_file); 307 } 308 309 310 SymbolFileDWARFDebugMap::SymbolFileDWARFDebugMap (ObjectFile* ofile) : 311 SymbolFile(ofile), 312 m_flags(), 313 m_compile_unit_infos(), 314 m_func_indexes(), 315 m_glob_indexes(), 316 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate) 317 { 318 } 319 320 321 SymbolFileDWARFDebugMap::~SymbolFileDWARFDebugMap() 322 { 323 } 324 325 void 326 SymbolFileDWARFDebugMap::InitializeObject() 327 { 328 // Install our external AST source callbacks so we can complete Clang types. 329 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap ( 330 new ClangExternalASTSourceCallbacks (SymbolFileDWARFDebugMap::CompleteTagDecl, 331 SymbolFileDWARFDebugMap::CompleteObjCInterfaceDecl, 332 NULL, 333 SymbolFileDWARFDebugMap::LayoutRecordType, 334 this)); 335 336 GetClangASTContext().SetExternalSource (ast_source_ap); 337 } 338 339 340 341 void 342 SymbolFileDWARFDebugMap::InitOSO() 343 { 344 if (m_flags.test(kHaveInitializedOSOs)) 345 return; 346 347 m_flags.set(kHaveInitializedOSOs); 348 // In order to get the abilities of this plug-in, we look at the list of 349 // N_OSO entries (object files) from the symbol table and make sure that 350 // these files exist and also contain valid DWARF. If we get any of that 351 // then we return the abilities of the first N_OSO's DWARF. 352 353 Symtab* symtab = m_obj_file->GetSymtab(); 354 if (symtab) 355 { 356 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_MAP)); 357 358 std::vector<uint32_t> oso_indexes; 359 #if defined(DEBUG_OSO_DMAP) 360 // StreamFile s(stdout); 361 // symtab->Dump(&s, NULL, eSortOrderNone); 362 #endif 363 // When a mach-o symbol is encoded, the n_type field is encoded in bits 364 // 23:16, and the n_desc field is encoded in bits 15:0. 365 // 366 // To find all N_OSO entries that are part of the DWARF + debug map 367 // we find only object file symbols with the flags value as follows: 368 // bits 23:16 == 0x66 (N_OSO) 369 // bits 15: 0 == 0x0001 (specifies this is a debug map object file) 370 const uint32_t k_oso_symbol_flags_value = 0x660001u; 371 372 const uint32_t oso_index_count = symtab->AppendSymbolIndexesWithTypeAndFlagsValue(eSymbolTypeObjectFile, k_oso_symbol_flags_value, oso_indexes); 373 374 if (oso_index_count > 0) 375 { 376 symtab->AppendSymbolIndexesWithType (eSymbolTypeCode, Symtab::eDebugYes, Symtab::eVisibilityAny, m_func_indexes); 377 symtab->AppendSymbolIndexesWithType (eSymbolTypeData, Symtab::eDebugYes, Symtab::eVisibilityAny, m_glob_indexes); 378 379 symtab->SortSymbolIndexesByValue(m_func_indexes, true); 380 symtab->SortSymbolIndexesByValue(m_glob_indexes, true); 381 382 m_compile_unit_infos.resize(oso_index_count); 383 // s.Printf("%s N_OSO symbols:\n", __PRETTY_FUNCTION__); 384 // symtab->Dump(&s, oso_indexes); 385 386 for (uint32_t i=0; i<oso_index_count; ++i) 387 { 388 const Symbol *so_symbol = symtab->SymbolAtIndex(oso_indexes[i] - 1); 389 const Symbol *oso_symbol = symtab->SymbolAtIndex(oso_indexes[i]); 390 assert (so_symbol); 391 assert (oso_symbol); 392 assert (so_symbol->GetType() == eSymbolTypeSourceFile); 393 assert (oso_symbol->GetType() == eSymbolTypeObjectFile); 394 m_compile_unit_infos[i].so_file.SetFile(so_symbol->GetName().AsCString(), true); 395 m_compile_unit_infos[i].oso_file.SetFile(oso_symbol->GetName().AsCString(), true); 396 uint32_t sibling_idx = so_symbol->GetSiblingIndex(); 397 // The sibling index can't be less that or equal to the current index "i" 398 if (sibling_idx <= i) 399 { 400 m_obj_file->GetModule()->ReportError ("N_SO in symbol with UID %u has invalid sibling in debug map, please file a bug and attach the binary listed in this error", so_symbol->GetID()); 401 } 402 else 403 { 404 const Symbol* last_symbol = symtab->SymbolAtIndex (sibling_idx - 1); 405 m_compile_unit_infos[i].first_symbol_index = symtab->GetIndexForSymbol(so_symbol); 406 m_compile_unit_infos[i].last_symbol_index = symtab->GetIndexForSymbol(last_symbol); 407 m_compile_unit_infos[i].first_symbol_id = so_symbol->GetID(); 408 m_compile_unit_infos[i].last_symbol_id = last_symbol->GetID(); 409 410 if (log) 411 log->Printf("Initialized OSO 0x%8.8x: file=%s", i, oso_symbol->GetName().GetCString()); 412 } 413 } 414 } 415 } 416 } 417 418 Module * 419 SymbolFileDWARFDebugMap::GetModuleByOSOIndex (uint32_t oso_idx) 420 { 421 const uint32_t cu_count = GetNumCompileUnits(); 422 if (oso_idx < cu_count) 423 return GetModuleByCompUnitInfo (&m_compile_unit_infos[oso_idx]); 424 return NULL; 425 } 426 427 Module * 428 SymbolFileDWARFDebugMap::GetModuleByCompUnitInfo (CompileUnitInfo *comp_unit_info) 429 { 430 if (comp_unit_info->oso_module_sp.get() == NULL && comp_unit_info->symbol_file_supported) 431 { 432 if (!comp_unit_info->oso_file.Exists()) 433 { 434 char path[PATH_MAX*2]; 435 comp_unit_info->oso_file.GetPath(path, sizeof(path)); 436 if (ObjectFile::SplitArchivePathWithObject (path, 437 comp_unit_info->oso_file, 438 comp_unit_info->oso_object)) 439 { 440 comp_unit_info->oso_file.GetPath(path, sizeof(path)); 441 //printf ("resolved archive '%s' and object '%s'\n", path, comp_unit_info->oso_object.GetCString()); 442 } 443 else 444 { 445 comp_unit_info->symbol_file_supported = false; 446 return false; 447 } 448 } 449 // Always create a new module for .o files. Why? Because we 450 // use the debug map, to add new sections to each .o file and 451 // even though a .o file might not have changed, the sections 452 // that get added to the .o file can change. 453 comp_unit_info->oso_module_sp.reset (new DebugMapModule (GetObjectFile()->GetModule(), 454 GetCompUnitInfoIndex(comp_unit_info), 455 comp_unit_info->oso_file, 456 m_obj_file->GetModule()->GetArchitecture(), 457 comp_unit_info->oso_object ? &comp_unit_info->oso_object : NULL, 458 0)); 459 } 460 return comp_unit_info->oso_module_sp.get(); 461 } 462 463 464 bool 465 SymbolFileDWARFDebugMap::GetFileSpecForSO (uint32_t oso_idx, FileSpec &file_spec) 466 { 467 if (oso_idx < m_compile_unit_infos.size()) 468 { 469 if (m_compile_unit_infos[oso_idx].so_file) 470 { 471 file_spec = m_compile_unit_infos[oso_idx].so_file; 472 return true; 473 } 474 } 475 return false; 476 } 477 478 479 480 ObjectFile * 481 SymbolFileDWARFDebugMap::GetObjectFileByOSOIndex (uint32_t oso_idx) 482 { 483 Module *oso_module = GetModuleByOSOIndex (oso_idx); 484 if (oso_module) 485 return oso_module->GetObjectFile(); 486 return NULL; 487 } 488 489 SymbolFileDWARF * 490 SymbolFileDWARFDebugMap::GetSymbolFile (const SymbolContext& sc) 491 { 492 CompileUnitInfo *comp_unit_info = GetCompUnitInfo (sc); 493 if (comp_unit_info) 494 return GetSymbolFileByCompUnitInfo (comp_unit_info); 495 return NULL; 496 } 497 498 ObjectFile * 499 SymbolFileDWARFDebugMap::GetObjectFileByCompUnitInfo (CompileUnitInfo *comp_unit_info) 500 { 501 Module *oso_module = GetModuleByCompUnitInfo (comp_unit_info); 502 if (oso_module) 503 return oso_module->GetObjectFile(); 504 return NULL; 505 } 506 507 508 uint32_t 509 SymbolFileDWARFDebugMap::GetCompUnitInfoIndex (const CompileUnitInfo *comp_unit_info) 510 { 511 if (!m_compile_unit_infos.empty()) 512 { 513 const CompileUnitInfo *first_comp_unit_info = &m_compile_unit_infos.front(); 514 const CompileUnitInfo *last_comp_unit_info = &m_compile_unit_infos.back(); 515 if (first_comp_unit_info <= comp_unit_info && comp_unit_info <= last_comp_unit_info) 516 return comp_unit_info - first_comp_unit_info; 517 } 518 return UINT32_MAX; 519 } 520 521 SymbolFileDWARF * 522 SymbolFileDWARFDebugMap::GetSymbolFileByOSOIndex (uint32_t oso_idx) 523 { 524 if (oso_idx < m_compile_unit_infos.size()) 525 return GetSymbolFileByCompUnitInfo (&m_compile_unit_infos[oso_idx]); 526 return NULL; 527 } 528 529 SymbolFileDWARF * 530 SymbolFileDWARFDebugMap::GetSymbolFileByCompUnitInfo (CompileUnitInfo *comp_unit_info) 531 { 532 Module *oso_module = GetModuleByCompUnitInfo (comp_unit_info); 533 if (oso_module) 534 { 535 SymbolVendor *sym_vendor = oso_module->GetSymbolVendor(); 536 if (sym_vendor) 537 return (SymbolFileDWARF *)sym_vendor->GetSymbolFile(); 538 } 539 return NULL; 540 } 541 542 uint32_t 543 SymbolFileDWARFDebugMap::CalculateAbilities () 544 { 545 // In order to get the abilities of this plug-in, we look at the list of 546 // N_OSO entries (object files) from the symbol table and make sure that 547 // these files exist and also contain valid DWARF. If we get any of that 548 // then we return the abilities of the first N_OSO's DWARF. 549 550 const uint32_t oso_index_count = GetNumCompileUnits(); 551 if (oso_index_count > 0) 552 { 553 const uint32_t dwarf_abilities = SymbolFile::CompileUnits | 554 SymbolFile::Functions | 555 SymbolFile::Blocks | 556 SymbolFile::GlobalVariables | 557 SymbolFile::LocalVariables | 558 SymbolFile::VariableTypes | 559 SymbolFile::LineTables; 560 561 InitOSO(); 562 if (!m_compile_unit_infos.empty()) 563 return dwarf_abilities; 564 // for (uint32_t oso_idx=0; oso_idx<oso_index_count; ++oso_idx) 565 // { 566 // SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx); 567 // if (oso_dwarf) 568 // { 569 // uint32_t oso_abilities = oso_dwarf->GetAbilities(); 570 // if ((oso_abilities & dwarf_abilities) == dwarf_abilities) 571 // return oso_abilities; 572 // } 573 // } 574 } 575 return 0; 576 } 577 578 uint32_t 579 SymbolFileDWARFDebugMap::GetNumCompileUnits() 580 { 581 InitOSO (); 582 return m_compile_unit_infos.size(); 583 } 584 585 586 CompUnitSP 587 SymbolFileDWARFDebugMap::ParseCompileUnitAtIndex(uint32_t cu_idx) 588 { 589 CompUnitSP comp_unit_sp; 590 const uint32_t cu_count = GetNumCompileUnits(); 591 592 if (cu_idx < cu_count) 593 { 594 if (m_compile_unit_infos[cu_idx].oso_compile_unit_sp.get() == NULL && 595 m_compile_unit_infos[cu_idx].symbol_file_supported) 596 { 597 FileSpec so_file_spec; 598 if (GetFileSpecForSO (cu_idx, so_file_spec)) 599 { 600 Module *oso_module = GetModuleByOSOIndex (cu_idx); 601 if (oso_module) 602 { 603 // User zero as the ID to match the compile unit at offset 604 // zero in each .o file since each .o file can only have 605 // one compile unit for now. 606 lldb::user_id_t cu_id = 0; 607 m_compile_unit_infos[cu_idx].oso_compile_unit_sp.reset (new CompileUnit (oso_module->shared_from_this(), 608 NULL, 609 so_file_spec, 610 cu_id, 611 eLanguageTypeUnknown)); 612 } 613 614 if (!m_compile_unit_infos[cu_idx].oso_compile_unit_sp) 615 { 616 m_compile_unit_infos[cu_idx].oso_compile_unit_sp.reset(new CompileUnit (m_obj_file->GetModule(), 617 NULL, 618 so_file_spec, 619 cu_idx, 620 eLanguageTypeUnknown)); 621 } 622 623 if (m_compile_unit_infos[cu_idx].oso_compile_unit_sp) 624 { 625 // Let our symbol vendor know about this compile unit 626 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex (cu_idx, 627 m_compile_unit_infos[cu_idx].oso_compile_unit_sp); 628 } 629 } 630 } 631 comp_unit_sp = m_compile_unit_infos[cu_idx].oso_compile_unit_sp; 632 } 633 634 return comp_unit_sp; 635 } 636 637 SymbolFileDWARFDebugMap::CompileUnitInfo * 638 SymbolFileDWARFDebugMap::GetCompUnitInfo (const SymbolContext& sc) 639 { 640 const uint32_t cu_count = GetNumCompileUnits(); 641 for (uint32_t i=0; i<cu_count; ++i) 642 { 643 if (sc.comp_unit == m_compile_unit_infos[i].oso_compile_unit_sp.get()) 644 return &m_compile_unit_infos[i]; 645 } 646 return NULL; 647 } 648 649 650 SymbolFileDWARFDebugMap::CompileUnitInfo * 651 SymbolFileDWARFDebugMap::GetCompUnitInfo (const lldb_private::Module *module) 652 { 653 const uint32_t cu_count = GetNumCompileUnits(); 654 for (uint32_t i=0; i<cu_count; ++i) 655 { 656 if (module == m_compile_unit_infos[i].oso_module_sp.get()) 657 return &m_compile_unit_infos[i]; 658 } 659 return NULL; 660 } 661 662 lldb::LanguageType 663 SymbolFileDWARFDebugMap::ParseCompileUnitLanguage (const SymbolContext& sc) 664 { 665 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc); 666 if (oso_dwarf) 667 return oso_dwarf->ParseCompileUnitLanguage (sc); 668 return eLanguageTypeUnknown; 669 } 670 671 size_t 672 SymbolFileDWARFDebugMap::ParseCompileUnitFunctions (const SymbolContext& sc) 673 { 674 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc); 675 if (oso_dwarf) 676 return oso_dwarf->ParseCompileUnitFunctions (sc); 677 return 0; 678 } 679 680 bool 681 SymbolFileDWARFDebugMap::ParseCompileUnitLineTable (const SymbolContext& sc) 682 { 683 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc); 684 if (oso_dwarf) 685 return oso_dwarf->ParseCompileUnitLineTable (sc); 686 return false; 687 } 688 689 bool 690 SymbolFileDWARFDebugMap::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList &support_files) 691 { 692 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc); 693 if (oso_dwarf) 694 return oso_dwarf->ParseCompileUnitSupportFiles (sc, support_files); 695 return false; 696 } 697 698 699 size_t 700 SymbolFileDWARFDebugMap::ParseFunctionBlocks (const SymbolContext& sc) 701 { 702 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc); 703 if (oso_dwarf) 704 return oso_dwarf->ParseFunctionBlocks (sc); 705 return 0; 706 } 707 708 709 size_t 710 SymbolFileDWARFDebugMap::ParseTypes (const SymbolContext& sc) 711 { 712 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc); 713 if (oso_dwarf) 714 return oso_dwarf->ParseTypes (sc); 715 return 0; 716 } 717 718 719 size_t 720 SymbolFileDWARFDebugMap::ParseVariablesForContext (const SymbolContext& sc) 721 { 722 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc); 723 if (oso_dwarf) 724 return oso_dwarf->ParseVariablesForContext (sc); 725 return 0; 726 } 727 728 729 730 Type* 731 SymbolFileDWARFDebugMap::ResolveTypeUID(lldb::user_id_t type_uid) 732 { 733 const uint64_t oso_idx = GetOSOIndexFromUserID (type_uid); 734 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx); 735 if (oso_dwarf) 736 oso_dwarf->ResolveTypeUID (type_uid); 737 return NULL; 738 } 739 740 lldb::clang_type_t 741 SymbolFileDWARFDebugMap::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type) 742 { 743 // We have a struct/union/class/enum that needs to be fully resolved. 744 return NULL; 745 } 746 747 uint32_t 748 SymbolFileDWARFDebugMap::ResolveSymbolContext (const Address& exe_so_addr, uint32_t resolve_scope, SymbolContext& sc) 749 { 750 uint32_t resolved_flags = 0; 751 Symtab* symtab = m_obj_file->GetSymtab(); 752 if (symtab) 753 { 754 const addr_t exe_file_addr = exe_so_addr.GetFileAddress(); 755 sc.symbol = symtab->FindSymbolContainingFileAddress (exe_file_addr, &m_func_indexes[0], m_func_indexes.size()); 756 757 if (sc.symbol != NULL) 758 { 759 resolved_flags |= eSymbolContextSymbol; 760 761 uint32_t oso_idx = 0; 762 CompileUnitInfo* comp_unit_info = GetCompileUnitInfoForSymbolWithID (sc.symbol->GetID(), &oso_idx); 763 if (comp_unit_info) 764 { 765 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx); 766 ObjectFile *oso_objfile = GetObjectFileByOSOIndex (oso_idx); 767 if (oso_dwarf && oso_objfile) 768 { 769 SectionList *oso_section_list = oso_objfile->GetSectionList(); 770 771 SectionSP oso_symbol_section_sp (oso_section_list->FindSectionContainingLinkedFileAddress (exe_file_addr, UINT32_MAX)); 772 773 if (oso_symbol_section_sp) 774 { 775 const addr_t linked_file_addr = oso_symbol_section_sp->GetLinkedFileAddress(); 776 Address oso_so_addr (oso_symbol_section_sp, exe_file_addr - linked_file_addr); 777 if (oso_so_addr.IsSectionOffset()) 778 resolved_flags |= oso_dwarf->ResolveSymbolContext (oso_so_addr, resolve_scope, sc); 779 } 780 } 781 } 782 } 783 } 784 return resolved_flags; 785 } 786 787 788 uint32_t 789 SymbolFileDWARFDebugMap::ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) 790 { 791 const uint32_t initial = sc_list.GetSize(); 792 const uint32_t cu_count = GetNumCompileUnits(); 793 794 for (uint32_t i=0; i<cu_count; ++i) 795 { 796 // If we are checking for inlines, then we need to look through all 797 // compile units no matter if "file_spec" matches. 798 bool resolve = check_inlines; 799 800 if (!resolve) 801 { 802 FileSpec so_file_spec; 803 if (GetFileSpecForSO (i, so_file_spec)) 804 { 805 // Match the full path if the incoming file_spec has a directory (not just a basename) 806 const bool full_match = file_spec.GetDirectory(); 807 resolve = FileSpec::Equal (file_spec, so_file_spec, full_match); 808 } 809 } 810 if (resolve) 811 { 812 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (i); 813 if (oso_dwarf) 814 oso_dwarf->ResolveSymbolContext(file_spec, line, check_inlines, resolve_scope, sc_list); 815 } 816 } 817 return sc_list.GetSize() - initial; 818 } 819 820 uint32_t 821 SymbolFileDWARFDebugMap::PrivateFindGlobalVariables 822 ( 823 const ConstString &name, 824 const ClangNamespaceDecl *namespace_decl, 825 const std::vector<uint32_t> &indexes, // Indexes into the symbol table that match "name" 826 uint32_t max_matches, 827 VariableList& variables 828 ) 829 { 830 const uint32_t original_size = variables.GetSize(); 831 const size_t match_count = indexes.size(); 832 for (size_t i=0; i<match_count; ++i) 833 { 834 uint32_t oso_idx; 835 CompileUnitInfo* comp_unit_info = GetCompileUnitInfoForSymbolWithIndex (indexes[i], &oso_idx); 836 if (comp_unit_info) 837 { 838 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx); 839 if (oso_dwarf) 840 { 841 if (oso_dwarf->FindGlobalVariables(name, namespace_decl, true, max_matches, variables)) 842 if (variables.GetSize() > max_matches) 843 break; 844 } 845 } 846 } 847 return variables.GetSize() - original_size; 848 } 849 850 uint32_t 851 SymbolFileDWARFDebugMap::FindGlobalVariables (const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables) 852 { 853 854 // If we aren't appending the results to this list, then clear the list 855 if (!append) 856 variables.Clear(); 857 858 // Remember how many variables are in the list before we search in case 859 // we are appending the results to a variable list. 860 const uint32_t original_size = variables.GetSize(); 861 862 uint32_t total_matches = 0; 863 SymbolFileDWARF *oso_dwarf; 864 for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx) 865 { 866 const uint32_t oso_matches = oso_dwarf->FindGlobalVariables (name, 867 namespace_decl, 868 true, 869 max_matches, 870 variables); 871 if (oso_matches > 0) 872 { 873 total_matches += oso_matches; 874 875 // Are we getting all matches? 876 if (max_matches == UINT32_MAX) 877 continue; // Yep, continue getting everything 878 879 // If we have found enough matches, lets get out 880 if (max_matches >= total_matches) 881 break; 882 883 // Update the max matches for any subsequent calls to find globals 884 // in any other object files with DWARF 885 max_matches -= oso_matches; 886 } 887 } 888 // Return the number of variable that were appended to the list 889 return variables.GetSize() - original_size; 890 } 891 892 893 uint32_t 894 SymbolFileDWARFDebugMap::FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) 895 { 896 // If we aren't appending the results to this list, then clear the list 897 if (!append) 898 variables.Clear(); 899 900 // Remember how many variables are in the list before we search in case 901 // we are appending the results to a variable list. 902 const uint32_t original_size = variables.GetSize(); 903 904 uint32_t total_matches = 0; 905 SymbolFileDWARF *oso_dwarf; 906 for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx) 907 { 908 const uint32_t oso_matches = oso_dwarf->FindGlobalVariables (regex, 909 true, 910 max_matches, 911 variables); 912 if (oso_matches > 0) 913 { 914 total_matches += oso_matches; 915 916 // Are we getting all matches? 917 if (max_matches == UINT32_MAX) 918 continue; // Yep, continue getting everything 919 920 // If we have found enough matches, lets get out 921 if (max_matches >= total_matches) 922 break; 923 924 // Update the max matches for any subsequent calls to find globals 925 // in any other object files with DWARF 926 max_matches -= oso_matches; 927 } 928 } 929 // Return the number of variable that were appended to the list 930 return variables.GetSize() - original_size; 931 } 932 933 934 int 935 SymbolFileDWARFDebugMap::SymbolContainsSymbolWithIndex (uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) 936 { 937 const uint32_t symbol_idx = *symbol_idx_ptr; 938 939 if (symbol_idx < comp_unit_info->first_symbol_index) 940 return -1; 941 942 if (symbol_idx <= comp_unit_info->last_symbol_index) 943 return 0; 944 945 return 1; 946 } 947 948 949 int 950 SymbolFileDWARFDebugMap::SymbolContainsSymbolWithID (user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) 951 { 952 const user_id_t symbol_id = *symbol_idx_ptr; 953 954 if (symbol_id < comp_unit_info->first_symbol_id) 955 return -1; 956 957 if (symbol_id <= comp_unit_info->last_symbol_id) 958 return 0; 959 960 return 1; 961 } 962 963 964 SymbolFileDWARFDebugMap::CompileUnitInfo* 965 SymbolFileDWARFDebugMap::GetCompileUnitInfoForSymbolWithIndex (uint32_t symbol_idx, uint32_t *oso_idx_ptr) 966 { 967 const uint32_t oso_index_count = m_compile_unit_infos.size(); 968 CompileUnitInfo *comp_unit_info = NULL; 969 if (oso_index_count) 970 { 971 comp_unit_info = (CompileUnitInfo*)bsearch(&symbol_idx, 972 &m_compile_unit_infos[0], 973 m_compile_unit_infos.size(), 974 sizeof(CompileUnitInfo), 975 (ComparisonFunction)SymbolContainsSymbolWithIndex); 976 } 977 978 if (oso_idx_ptr) 979 { 980 if (comp_unit_info != NULL) 981 *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0]; 982 else 983 *oso_idx_ptr = UINT32_MAX; 984 } 985 return comp_unit_info; 986 } 987 988 SymbolFileDWARFDebugMap::CompileUnitInfo* 989 SymbolFileDWARFDebugMap::GetCompileUnitInfoForSymbolWithID (user_id_t symbol_id, uint32_t *oso_idx_ptr) 990 { 991 const uint32_t oso_index_count = m_compile_unit_infos.size(); 992 CompileUnitInfo *comp_unit_info = NULL; 993 if (oso_index_count) 994 { 995 comp_unit_info = (CompileUnitInfo*)::bsearch (&symbol_id, 996 &m_compile_unit_infos[0], 997 m_compile_unit_infos.size(), 998 sizeof(CompileUnitInfo), 999 (ComparisonFunction)SymbolContainsSymbolWithID); 1000 } 1001 1002 if (oso_idx_ptr) 1003 { 1004 if (comp_unit_info != NULL) 1005 *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0]; 1006 else 1007 *oso_idx_ptr = UINT32_MAX; 1008 } 1009 return comp_unit_info; 1010 } 1011 1012 1013 static void 1014 RemoveFunctionsWithModuleNotEqualTo (const ModuleSP &module_sp, SymbolContextList &sc_list, uint32_t start_idx) 1015 { 1016 // We found functions in .o files. Not all functions in the .o files 1017 // will have made it into the final output file. The ones that did 1018 // make it into the final output file will have a section whose module 1019 // matches the module from the ObjectFile for this SymbolFile. When 1020 // the modules don't match, then we have something that was in a 1021 // .o file, but doesn't map to anything in the final executable. 1022 uint32_t i=start_idx; 1023 while (i < sc_list.GetSize()) 1024 { 1025 SymbolContext sc; 1026 sc_list.GetContextAtIndex(i, sc); 1027 if (sc.function) 1028 { 1029 const SectionSP section_sp (sc.function->GetAddressRange().GetBaseAddress().GetSection()); 1030 if (section_sp->GetModule() != module_sp) 1031 { 1032 sc_list.RemoveContextAtIndex(i); 1033 continue; 1034 } 1035 } 1036 ++i; 1037 } 1038 } 1039 1040 uint32_t 1041 SymbolFileDWARFDebugMap::FindFunctions(const ConstString &name, const ClangNamespaceDecl *namespace_decl, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list) 1042 { 1043 Timer scoped_timer (__PRETTY_FUNCTION__, 1044 "SymbolFileDWARFDebugMap::FindFunctions (name = %s)", 1045 name.GetCString()); 1046 1047 uint32_t initial_size = 0; 1048 if (append) 1049 initial_size = sc_list.GetSize(); 1050 else 1051 sc_list.Clear(); 1052 1053 uint32_t oso_idx = 0; 1054 SymbolFileDWARF *oso_dwarf; 1055 while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL) 1056 { 1057 uint32_t sc_idx = sc_list.GetSize(); 1058 if (oso_dwarf->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, true, sc_list)) 1059 { 1060 RemoveFunctionsWithModuleNotEqualTo (m_obj_file->GetModule(), sc_list, sc_idx); 1061 } 1062 } 1063 1064 return sc_list.GetSize() - initial_size; 1065 } 1066 1067 1068 uint32_t 1069 SymbolFileDWARFDebugMap::FindFunctions (const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list) 1070 { 1071 Timer scoped_timer (__PRETTY_FUNCTION__, 1072 "SymbolFileDWARFDebugMap::FindFunctions (regex = '%s')", 1073 regex.GetText()); 1074 1075 uint32_t initial_size = 0; 1076 if (append) 1077 initial_size = sc_list.GetSize(); 1078 else 1079 sc_list.Clear(); 1080 1081 uint32_t oso_idx = 0; 1082 SymbolFileDWARF *oso_dwarf; 1083 while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL) 1084 { 1085 uint32_t sc_idx = sc_list.GetSize(); 1086 1087 if (oso_dwarf->FindFunctions(regex, include_inlines, true, sc_list)) 1088 { 1089 RemoveFunctionsWithModuleNotEqualTo (m_obj_file->GetModule(), sc_list, sc_idx); 1090 } 1091 } 1092 1093 return sc_list.GetSize() - initial_size; 1094 } 1095 1096 TypeSP 1097 SymbolFileDWARFDebugMap::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &die_decl_ctx) 1098 { 1099 TypeSP type_sp; 1100 SymbolFileDWARF *oso_dwarf; 1101 for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx) 1102 { 1103 type_sp = oso_dwarf->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); 1104 if (type_sp) 1105 break; 1106 } 1107 return type_sp; 1108 } 1109 1110 1111 1112 bool 1113 SymbolFileDWARFDebugMap::Supports_DW_AT_APPLE_objc_complete_type (SymbolFileDWARF *skip_dwarf_oso) 1114 { 1115 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) 1116 { 1117 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; 1118 SymbolFileDWARF *oso_dwarf; 1119 for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx) 1120 { 1121 if (skip_dwarf_oso != oso_dwarf && oso_dwarf->Supports_DW_AT_APPLE_objc_complete_type(NULL)) 1122 { 1123 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; 1124 break; 1125 } 1126 } 1127 } 1128 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; 1129 } 1130 1131 TypeSP 1132 SymbolFileDWARFDebugMap::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, 1133 const ConstString &type_name, 1134 bool must_be_implementation) 1135 { 1136 TypeSP type_sp; 1137 SymbolFileDWARF *oso_dwarf; 1138 for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx) 1139 { 1140 type_sp = oso_dwarf->FindCompleteObjCDefinitionTypeForDIE (die, type_name, must_be_implementation); 1141 if (type_sp) 1142 break; 1143 } 1144 return type_sp; 1145 } 1146 1147 uint32_t 1148 SymbolFileDWARFDebugMap::FindTypes 1149 ( 1150 const SymbolContext& sc, 1151 const ConstString &name, 1152 const ClangNamespaceDecl *namespace_decl, 1153 bool append, 1154 uint32_t max_matches, 1155 TypeList& types 1156 ) 1157 { 1158 if (!append) 1159 types.Clear(); 1160 1161 const uint32_t initial_types_size = types.GetSize(); 1162 SymbolFileDWARF *oso_dwarf; 1163 1164 if (sc.comp_unit) 1165 { 1166 oso_dwarf = GetSymbolFile (sc); 1167 if (oso_dwarf) 1168 return oso_dwarf->FindTypes (sc, name, namespace_decl, append, max_matches, types); 1169 } 1170 else 1171 { 1172 uint32_t oso_idx = 0; 1173 while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL) 1174 oso_dwarf->FindTypes (sc, name, namespace_decl, append, max_matches, types); 1175 } 1176 1177 return types.GetSize() - initial_types_size; 1178 } 1179 1180 // 1181 //uint32_t 1182 //SymbolFileDWARFDebugMap::FindTypes (const SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, Type::Encoding encoding, lldb::user_id_t udt_uid, TypeList& types) 1183 //{ 1184 // SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc); 1185 // if (oso_dwarf) 1186 // return oso_dwarf->FindTypes (sc, regex, append, max_matches, encoding, udt_uid, types); 1187 // return 0; 1188 //} 1189 1190 1191 ClangNamespaceDecl 1192 SymbolFileDWARFDebugMap::FindNamespace (const lldb_private::SymbolContext& sc, 1193 const lldb_private::ConstString &name, 1194 const ClangNamespaceDecl *parent_namespace_decl) 1195 { 1196 ClangNamespaceDecl matching_namespace; 1197 SymbolFileDWARF *oso_dwarf; 1198 1199 if (sc.comp_unit) 1200 { 1201 oso_dwarf = GetSymbolFile (sc); 1202 if (oso_dwarf) 1203 matching_namespace = oso_dwarf->FindNamespace (sc, name, parent_namespace_decl); 1204 } 1205 else 1206 { 1207 for (uint32_t oso_idx = 0; 1208 ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); 1209 ++oso_idx) 1210 { 1211 matching_namespace = oso_dwarf->FindNamespace (sc, name, parent_namespace_decl); 1212 1213 if (matching_namespace) 1214 break; 1215 } 1216 } 1217 1218 return matching_namespace; 1219 } 1220 1221 //------------------------------------------------------------------ 1222 // PluginInterface protocol 1223 //------------------------------------------------------------------ 1224 const char * 1225 SymbolFileDWARFDebugMap::GetPluginName() 1226 { 1227 return "SymbolFileDWARFDebugMap"; 1228 } 1229 1230 const char * 1231 SymbolFileDWARFDebugMap::GetShortPluginName() 1232 { 1233 return GetPluginNameStatic(); 1234 } 1235 1236 uint32_t 1237 SymbolFileDWARFDebugMap::GetPluginVersion() 1238 { 1239 return 1; 1240 } 1241 1242 lldb::CompUnitSP 1243 SymbolFileDWARFDebugMap::GetCompileUnit (SymbolFileDWARF *oso_dwarf) 1244 { 1245 if (oso_dwarf) 1246 { 1247 const uint32_t cu_count = GetNumCompileUnits(); 1248 for (uint32_t cu_idx=0; cu_idx<cu_count; ++cu_idx) 1249 { 1250 SymbolFileDWARF *oso_symfile = GetSymbolFileByCompUnitInfo (&m_compile_unit_infos[cu_idx]); 1251 if (oso_symfile == oso_dwarf) 1252 { 1253 if (!m_compile_unit_infos[cu_idx].oso_compile_unit_sp) 1254 m_compile_unit_infos[cu_idx].oso_compile_unit_sp = ParseCompileUnitAtIndex (cu_idx); 1255 1256 return m_compile_unit_infos[cu_idx].oso_compile_unit_sp; 1257 } 1258 } 1259 } 1260 assert(!"this shouldn't happen"); 1261 return lldb::CompUnitSP(); 1262 } 1263 1264 1265 void 1266 SymbolFileDWARFDebugMap::SetCompileUnit (SymbolFileDWARF *oso_dwarf, const CompUnitSP &cu_sp) 1267 { 1268 if (oso_dwarf) 1269 { 1270 const uint32_t cu_count = GetNumCompileUnits(); 1271 for (uint32_t cu_idx=0; cu_idx<cu_count; ++cu_idx) 1272 { 1273 SymbolFileDWARF *oso_symfile = GetSymbolFileByCompUnitInfo (&m_compile_unit_infos[cu_idx]); 1274 if (oso_symfile == oso_dwarf) 1275 { 1276 if (m_compile_unit_infos[cu_idx].oso_compile_unit_sp) 1277 { 1278 assert (m_compile_unit_infos[cu_idx].oso_compile_unit_sp.get() == cu_sp.get()); 1279 } 1280 else 1281 { 1282 m_compile_unit_infos[cu_idx].oso_compile_unit_sp = cu_sp; 1283 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp); 1284 } 1285 } 1286 } 1287 } 1288 } 1289 1290 1291 void 1292 SymbolFileDWARFDebugMap::CompleteTagDecl (void *baton, clang::TagDecl *decl) 1293 { 1294 SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton; 1295 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); 1296 if (clang_type) 1297 { 1298 SymbolFileDWARF *oso_dwarf; 1299 1300 for (uint32_t oso_idx = 0; ((oso_dwarf = symbol_file_dwarf->GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx) 1301 { 1302 if (oso_dwarf->HasForwardDeclForClangType (clang_type)) 1303 { 1304 oso_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); 1305 return; 1306 } 1307 } 1308 } 1309 } 1310 1311 void 1312 SymbolFileDWARFDebugMap::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) 1313 { 1314 SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton; 1315 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); 1316 if (clang_type) 1317 { 1318 SymbolFileDWARF *oso_dwarf; 1319 1320 for (uint32_t oso_idx = 0; ((oso_dwarf = symbol_file_dwarf->GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx) 1321 { 1322 if (oso_dwarf->HasForwardDeclForClangType (clang_type)) 1323 { 1324 oso_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); 1325 return; 1326 } 1327 } 1328 } 1329 } 1330 1331 bool 1332 SymbolFileDWARFDebugMap::LayoutRecordType (void *baton, 1333 const clang::RecordDecl *record_decl, 1334 uint64_t &size, 1335 uint64_t &alignment, 1336 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, 1337 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, 1338 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) 1339 { 1340 SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton; 1341 SymbolFileDWARF *oso_dwarf; 1342 for (uint32_t oso_idx = 0; ((oso_dwarf = symbol_file_dwarf->GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx) 1343 { 1344 if (oso_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets)) 1345 return true; 1346 } 1347 return false; 1348 } 1349 1350 1351 1352 clang::DeclContext* 1353 SymbolFileDWARFDebugMap::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) 1354 { 1355 const uint64_t oso_idx = GetOSOIndexFromUserID (type_uid); 1356 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx); 1357 if (oso_dwarf) 1358 return oso_dwarf->GetClangDeclContextContainingTypeUID (type_uid); 1359 return NULL; 1360 } 1361 1362 clang::DeclContext* 1363 SymbolFileDWARFDebugMap::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) 1364 { 1365 const uint64_t oso_idx = GetOSOIndexFromUserID (type_uid); 1366 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx); 1367 if (oso_dwarf) 1368 return oso_dwarf->GetClangDeclContextForTypeUID (sc, type_uid); 1369 return NULL; 1370 } 1371 1372 1373