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