1 //===-- DynamicLoaderDarwin.cpp -------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "DynamicLoaderDarwin.h" 10 11 #include "lldb/Breakpoint/StoppointCallbackContext.h" 12 #include "lldb/Core/Debugger.h" 13 #include "lldb/Core/Module.h" 14 #include "lldb/Core/ModuleSpec.h" 15 #include "lldb/Core/PluginManager.h" 16 #include "lldb/Core/Section.h" 17 #include "lldb/Expression/DiagnosticManager.h" 18 #include "lldb/Host/FileSystem.h" 19 #include "lldb/Host/HostInfo.h" 20 #include "lldb/Symbol/Function.h" 21 #include "lldb/Symbol/ObjectFile.h" 22 #include "lldb/Target/ABI.h" 23 #include "lldb/Target/RegisterContext.h" 24 #include "lldb/Target/StackFrame.h" 25 #include "lldb/Target/Target.h" 26 #include "lldb/Target/Thread.h" 27 #include "lldb/Target/ThreadPlanCallFunction.h" 28 #include "lldb/Target/ThreadPlanRunToAddress.h" 29 #include "lldb/Utility/DataBuffer.h" 30 #include "lldb/Utility/DataBufferHeap.h" 31 #include "lldb/Utility/Log.h" 32 #include "lldb/Utility/State.h" 33 34 #include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h" 35 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" 36 37 //#define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN 38 #ifdef ENABLE_DEBUG_PRINTF 39 #include <cstdio> 40 #define DEBUG_PRINTF(fmt, ...) printf(fmt, ##__VA_ARGS__) 41 #else 42 #define DEBUG_PRINTF(fmt, ...) 43 #endif 44 45 #ifndef __APPLE__ 46 #include "Utility/UuidCompatibility.h" 47 #else 48 #include <uuid/uuid.h> 49 #endif 50 51 #include <memory> 52 53 using namespace lldb; 54 using namespace lldb_private; 55 56 // Constructor 57 DynamicLoaderDarwin::DynamicLoaderDarwin(Process *process) 58 : DynamicLoader(process), m_dyld_module_wp(), m_libpthread_module_wp(), 59 m_pthread_getspecific_addr(), m_tid_to_tls_map(), m_dyld_image_infos(), 60 m_dyld_image_infos_stop_id(UINT32_MAX), m_dyld(), m_mutex() {} 61 62 // Destructor 63 DynamicLoaderDarwin::~DynamicLoaderDarwin() = default; 64 65 /// Called after attaching a process. 66 /// 67 /// Allow DynamicLoader plug-ins to execute some code after 68 /// attaching to a process. 69 void DynamicLoaderDarwin::DidAttach() { 70 PrivateInitialize(m_process); 71 DoInitialImageFetch(); 72 SetNotificationBreakpoint(); 73 } 74 75 /// Called after attaching a process. 76 /// 77 /// Allow DynamicLoader plug-ins to execute some code after 78 /// attaching to a process. 79 void DynamicLoaderDarwin::DidLaunch() { 80 PrivateInitialize(m_process); 81 DoInitialImageFetch(); 82 SetNotificationBreakpoint(); 83 } 84 85 // Clear out the state of this class. 86 void DynamicLoaderDarwin::Clear(bool clear_process) { 87 std::lock_guard<std::recursive_mutex> guard(m_mutex); 88 if (clear_process) 89 m_process = nullptr; 90 m_dyld_image_infos.clear(); 91 m_dyld_image_infos_stop_id = UINT32_MAX; 92 m_dyld.Clear(false); 93 } 94 95 ModuleSP DynamicLoaderDarwin::FindTargetModuleForImageInfo( 96 ImageInfo &image_info, bool can_create, bool *did_create_ptr) { 97 if (did_create_ptr) 98 *did_create_ptr = false; 99 100 Target &target = m_process->GetTarget(); 101 const ModuleList &target_images = target.GetImages(); 102 ModuleSpec module_spec(image_info.file_spec); 103 module_spec.GetUUID() = image_info.uuid; 104 105 // macCatalyst support: Request matching os/environment. 106 { 107 auto &target_triple = target.GetArchitecture().GetTriple(); 108 if (target_triple.getOS() == llvm::Triple::IOS && 109 target_triple.getEnvironment() == llvm::Triple::MacABI) { 110 // Request the macCatalyst variant of frameworks that have both 111 // a PLATFORM_MACOS and a PLATFORM_MACCATALYST load command. 112 module_spec.GetArchitecture() = ArchSpec(target_triple); 113 } 114 } 115 116 ModuleSP module_sp(target_images.FindFirstModule(module_spec)); 117 118 if (module_sp && !module_spec.GetUUID().IsValid() && 119 !module_sp->GetUUID().IsValid()) { 120 // No UUID, we must rely upon the cached module modification time and the 121 // modification time of the file on disk 122 if (module_sp->GetModificationTime() != 123 FileSystem::Instance().GetModificationTime(module_sp->GetFileSpec())) 124 module_sp.reset(); 125 } 126 127 if (module_sp || !can_create) 128 return module_sp; 129 130 if (HostInfo::GetArchitecture().IsCompatibleMatch(target.GetArchitecture())) { 131 // When debugging on the host, we are most likely using the same shared 132 // cache as our inferior. The dylibs from the shared cache might not 133 // exist on the filesystem, so let's use the images in our own memory 134 // to create the modules. 135 // Check if the requested image is in our shared cache. 136 SharedCacheImageInfo image_info = 137 HostInfo::GetSharedCacheImageInfo(module_spec.GetFileSpec().GetPath()); 138 139 // If we found it and it has the correct UUID, let's proceed with 140 // creating a module from the memory contents. 141 if (image_info.uuid && 142 (!module_spec.GetUUID() || module_spec.GetUUID() == image_info.uuid)) { 143 ModuleSpec shared_cache_spec(module_spec.GetFileSpec(), image_info.uuid, 144 image_info.data_sp); 145 module_sp = 146 target.GetOrCreateModule(shared_cache_spec, false /* notify */); 147 } 148 } 149 // We'll call Target::ModulesDidLoad after all the modules have been 150 // added to the target, don't let it be called for every one. 151 if (!module_sp) 152 module_sp = target.GetOrCreateModule(module_spec, false /* notify */); 153 if (!module_sp || module_sp->GetObjectFile() == nullptr) 154 module_sp = m_process->ReadModuleFromMemory(image_info.file_spec, 155 image_info.address); 156 157 if (did_create_ptr) 158 *did_create_ptr = (bool)module_sp; 159 160 return module_sp; 161 } 162 163 void DynamicLoaderDarwin::UnloadImages( 164 const std::vector<lldb::addr_t> &solib_addresses) { 165 std::lock_guard<std::recursive_mutex> guard(m_mutex); 166 if (m_process->GetStopID() == m_dyld_image_infos_stop_id) 167 return; 168 169 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); 170 Target &target = m_process->GetTarget(); 171 LLDB_LOGF(log, "Removing %" PRId64 " modules.", 172 (uint64_t)solib_addresses.size()); 173 174 ModuleList unloaded_module_list; 175 176 for (addr_t solib_addr : solib_addresses) { 177 Address header; 178 if (header.SetLoadAddress(solib_addr, &target)) { 179 if (header.GetOffset() == 0) { 180 ModuleSP module_to_remove(header.GetModule()); 181 if (module_to_remove.get()) { 182 LLDB_LOGF(log, "Removing module at address 0x%" PRIx64, solib_addr); 183 // remove the sections from the Target 184 UnloadSections(module_to_remove); 185 // add this to the list of modules to remove 186 unloaded_module_list.AppendIfNeeded(module_to_remove); 187 // remove the entry from the m_dyld_image_infos 188 ImageInfo::collection::iterator pos, end = m_dyld_image_infos.end(); 189 for (pos = m_dyld_image_infos.begin(); pos != end; pos++) { 190 if (solib_addr == (*pos).address) { 191 m_dyld_image_infos.erase(pos); 192 break; 193 } 194 } 195 } 196 } 197 } 198 } 199 200 if (unloaded_module_list.GetSize() > 0) { 201 if (log) { 202 log->PutCString("Unloaded:"); 203 unloaded_module_list.LogUUIDAndPaths( 204 log, "DynamicLoaderDarwin::UnloadModules"); 205 } 206 m_process->GetTarget().GetImages().Remove(unloaded_module_list); 207 m_dyld_image_infos_stop_id = m_process->GetStopID(); 208 } 209 } 210 211 void DynamicLoaderDarwin::UnloadAllImages() { 212 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); 213 ModuleList unloaded_modules_list; 214 215 Target &target = m_process->GetTarget(); 216 const ModuleList &target_modules = target.GetImages(); 217 std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex()); 218 219 ModuleSP dyld_sp(GetDYLDModule()); 220 for (ModuleSP module_sp : target_modules.Modules()) { 221 // Don't remove dyld - else we'll lose our breakpoint notifying us about 222 // libraries being re-loaded... 223 if (module_sp && module_sp != dyld_sp) { 224 UnloadSections(module_sp); 225 unloaded_modules_list.Append(module_sp); 226 } 227 } 228 229 if (unloaded_modules_list.GetSize() != 0) { 230 if (log) { 231 log->PutCString("Unloaded:"); 232 unloaded_modules_list.LogUUIDAndPaths( 233 log, "DynamicLoaderDarwin::UnloadAllImages"); 234 } 235 target.GetImages().Remove(unloaded_modules_list); 236 m_dyld_image_infos.clear(); 237 m_dyld_image_infos_stop_id = m_process->GetStopID(); 238 } 239 } 240 241 // Update the load addresses for all segments in MODULE using the updated INFO 242 // that is passed in. 243 bool DynamicLoaderDarwin::UpdateImageLoadAddress(Module *module, 244 ImageInfo &info) { 245 bool changed = false; 246 if (module) { 247 ObjectFile *image_object_file = module->GetObjectFile(); 248 if (image_object_file) { 249 SectionList *section_list = image_object_file->GetSectionList(); 250 if (section_list) { 251 std::vector<uint32_t> inaccessible_segment_indexes; 252 // We now know the slide amount, so go through all sections and update 253 // the load addresses with the correct values. 254 const size_t num_segments = info.segments.size(); 255 for (size_t i = 0; i < num_segments; ++i) { 256 // Only load a segment if it has protections. Things like __PAGEZERO 257 // don't have any protections, and they shouldn't be slid 258 SectionSP section_sp( 259 section_list->FindSectionByName(info.segments[i].name)); 260 261 if (info.segments[i].maxprot == 0) { 262 inaccessible_segment_indexes.push_back(i); 263 } else { 264 const addr_t new_section_load_addr = 265 info.segments[i].vmaddr + info.slide; 266 static ConstString g_section_name_LINKEDIT("__LINKEDIT"); 267 268 if (section_sp) { 269 // __LINKEDIT sections from files in the shared cache can overlap 270 // so check to see what the segment name is and pass "false" so 271 // we don't warn of overlapping "Section" objects, and "true" for 272 // all other sections. 273 const bool warn_multiple = 274 section_sp->GetName() != g_section_name_LINKEDIT; 275 276 changed = m_process->GetTarget().SetSectionLoadAddress( 277 section_sp, new_section_load_addr, warn_multiple); 278 } 279 } 280 } 281 282 // If the loaded the file (it changed) and we have segments that are 283 // not readable or writeable, add them to the invalid memory region 284 // cache for the process. This will typically only be the __PAGEZERO 285 // segment in the main executable. We might be able to apply this more 286 // generally to more sections that have no protections in the future, 287 // but for now we are going to just do __PAGEZERO. 288 if (changed && !inaccessible_segment_indexes.empty()) { 289 for (uint32_t i = 0; i < inaccessible_segment_indexes.size(); ++i) { 290 const uint32_t seg_idx = inaccessible_segment_indexes[i]; 291 SectionSP section_sp( 292 section_list->FindSectionByName(info.segments[seg_idx].name)); 293 294 if (section_sp) { 295 static ConstString g_pagezero_section_name("__PAGEZERO"); 296 if (g_pagezero_section_name == section_sp->GetName()) { 297 // __PAGEZERO never slides... 298 const lldb::addr_t vmaddr = info.segments[seg_idx].vmaddr; 299 const lldb::addr_t vmsize = info.segments[seg_idx].vmsize; 300 Process::LoadRange pagezero_range(vmaddr, vmsize); 301 m_process->AddInvalidMemoryRegion(pagezero_range); 302 } 303 } 304 } 305 } 306 } 307 } 308 } 309 // We might have an in memory image that was loaded as soon as it was created 310 if (info.load_stop_id == m_process->GetStopID()) 311 changed = true; 312 else if (changed) { 313 // Update the stop ID when this library was updated 314 info.load_stop_id = m_process->GetStopID(); 315 } 316 return changed; 317 } 318 319 // Unload the segments in MODULE using the INFO that is passed in. 320 bool DynamicLoaderDarwin::UnloadModuleSections(Module *module, 321 ImageInfo &info) { 322 bool changed = false; 323 if (module) { 324 ObjectFile *image_object_file = module->GetObjectFile(); 325 if (image_object_file) { 326 SectionList *section_list = image_object_file->GetSectionList(); 327 if (section_list) { 328 const size_t num_segments = info.segments.size(); 329 for (size_t i = 0; i < num_segments; ++i) { 330 SectionSP section_sp( 331 section_list->FindSectionByName(info.segments[i].name)); 332 if (section_sp) { 333 const addr_t old_section_load_addr = 334 info.segments[i].vmaddr + info.slide; 335 if (m_process->GetTarget().SetSectionUnloaded( 336 section_sp, old_section_load_addr)) 337 changed = true; 338 } else { 339 Host::SystemLog(Host::eSystemLogWarning, 340 "warning: unable to find and unload segment named " 341 "'%s' in '%s' in macosx dynamic loader plug-in.\n", 342 info.segments[i].name.AsCString("<invalid>"), 343 image_object_file->GetFileSpec().GetPath().c_str()); 344 } 345 } 346 } 347 } 348 } 349 return changed; 350 } 351 352 // Given a JSON dictionary (from debugserver, most likely) of binary images 353 // loaded in the inferior process, add the images to the ImageInfo collection. 354 355 bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo( 356 StructuredData::ObjectSP image_details, 357 ImageInfo::collection &image_infos) { 358 StructuredData::ObjectSP images_sp = 359 image_details->GetAsDictionary()->GetValueForKey("images"); 360 if (images_sp.get() == nullptr) 361 return false; 362 363 image_infos.resize(images_sp->GetAsArray()->GetSize()); 364 365 for (size_t i = 0; i < image_infos.size(); i++) { 366 StructuredData::ObjectSP image_sp = 367 images_sp->GetAsArray()->GetItemAtIndex(i); 368 if (image_sp.get() == nullptr || image_sp->GetAsDictionary() == nullptr) 369 return false; 370 StructuredData::Dictionary *image = image_sp->GetAsDictionary(); 371 // clang-format off 372 if (!image->HasKey("load_address") || 373 !image->HasKey("pathname") || 374 !image->HasKey("mod_date") || 375 !image->HasKey("mach_header") || 376 image->GetValueForKey("mach_header")->GetAsDictionary() == nullptr || 377 !image->HasKey("segments") || 378 image->GetValueForKey("segments")->GetAsArray() == nullptr || 379 !image->HasKey("uuid")) { 380 return false; 381 } 382 // clang-format on 383 image_infos[i].address = 384 image->GetValueForKey("load_address")->GetAsInteger()->GetValue(); 385 image_infos[i].mod_date = 386 image->GetValueForKey("mod_date")->GetAsInteger()->GetValue(); 387 image_infos[i].file_spec.SetFile( 388 image->GetValueForKey("pathname")->GetAsString()->GetValue(), 389 FileSpec::Style::native); 390 391 StructuredData::Dictionary *mh = 392 image->GetValueForKey("mach_header")->GetAsDictionary(); 393 image_infos[i].header.magic = 394 mh->GetValueForKey("magic")->GetAsInteger()->GetValue(); 395 image_infos[i].header.cputype = 396 mh->GetValueForKey("cputype")->GetAsInteger()->GetValue(); 397 image_infos[i].header.cpusubtype = 398 mh->GetValueForKey("cpusubtype")->GetAsInteger()->GetValue(); 399 image_infos[i].header.filetype = 400 mh->GetValueForKey("filetype")->GetAsInteger()->GetValue(); 401 402 if (image->HasKey("min_version_os_name")) { 403 std::string os_name = 404 std::string(image->GetValueForKey("min_version_os_name") 405 ->GetAsString() 406 ->GetValue()); 407 if (os_name == "macosx") 408 image_infos[i].os_type = llvm::Triple::MacOSX; 409 else if (os_name == "ios" || os_name == "iphoneos") 410 image_infos[i].os_type = llvm::Triple::IOS; 411 else if (os_name == "tvos") 412 image_infos[i].os_type = llvm::Triple::TvOS; 413 else if (os_name == "watchos") 414 image_infos[i].os_type = llvm::Triple::WatchOS; 415 // NEED_BRIDGEOS_TRIPLE else if (os_name == "bridgeos") 416 // NEED_BRIDGEOS_TRIPLE image_infos[i].os_type = llvm::Triple::BridgeOS; 417 else if (os_name == "maccatalyst") { 418 image_infos[i].os_type = llvm::Triple::IOS; 419 image_infos[i].os_env = llvm::Triple::MacABI; 420 } else if (os_name == "iossimulator") { 421 image_infos[i].os_type = llvm::Triple::IOS; 422 image_infos[i].os_env = llvm::Triple::Simulator; 423 } else if (os_name == "tvossimulator") { 424 image_infos[i].os_type = llvm::Triple::TvOS; 425 image_infos[i].os_env = llvm::Triple::Simulator; 426 } else if (os_name == "watchossimulator") { 427 image_infos[i].os_type = llvm::Triple::WatchOS; 428 image_infos[i].os_env = llvm::Triple::Simulator; 429 } 430 } 431 if (image->HasKey("min_version_os_sdk")) { 432 image_infos[i].min_version_os_sdk = 433 std::string(image->GetValueForKey("min_version_os_sdk") 434 ->GetAsString() 435 ->GetValue()); 436 } 437 438 // Fields that aren't used by DynamicLoaderDarwin so debugserver doesn't 439 // currently send them in the reply. 440 441 if (mh->HasKey("flags")) 442 image_infos[i].header.flags = 443 mh->GetValueForKey("flags")->GetAsInteger()->GetValue(); 444 else 445 image_infos[i].header.flags = 0; 446 447 if (mh->HasKey("ncmds")) 448 image_infos[i].header.ncmds = 449 mh->GetValueForKey("ncmds")->GetAsInteger()->GetValue(); 450 else 451 image_infos[i].header.ncmds = 0; 452 453 if (mh->HasKey("sizeofcmds")) 454 image_infos[i].header.sizeofcmds = 455 mh->GetValueForKey("sizeofcmds")->GetAsInteger()->GetValue(); 456 else 457 image_infos[i].header.sizeofcmds = 0; 458 459 StructuredData::Array *segments = 460 image->GetValueForKey("segments")->GetAsArray(); 461 uint32_t segcount = segments->GetSize(); 462 for (size_t j = 0; j < segcount; j++) { 463 Segment segment; 464 StructuredData::Dictionary *seg = 465 segments->GetItemAtIndex(j)->GetAsDictionary(); 466 segment.name = 467 ConstString(seg->GetValueForKey("name")->GetAsString()->GetValue()); 468 segment.vmaddr = 469 seg->GetValueForKey("vmaddr")->GetAsInteger()->GetValue(); 470 segment.vmsize = 471 seg->GetValueForKey("vmsize")->GetAsInteger()->GetValue(); 472 segment.fileoff = 473 seg->GetValueForKey("fileoff")->GetAsInteger()->GetValue(); 474 segment.filesize = 475 seg->GetValueForKey("filesize")->GetAsInteger()->GetValue(); 476 segment.maxprot = 477 seg->GetValueForKey("maxprot")->GetAsInteger()->GetValue(); 478 479 // Fields that aren't used by DynamicLoaderDarwin so debugserver doesn't 480 // currently send them in the reply. 481 482 if (seg->HasKey("initprot")) 483 segment.initprot = 484 seg->GetValueForKey("initprot")->GetAsInteger()->GetValue(); 485 else 486 segment.initprot = 0; 487 488 if (seg->HasKey("flags")) 489 segment.flags = 490 seg->GetValueForKey("flags")->GetAsInteger()->GetValue(); 491 else 492 segment.flags = 0; 493 494 if (seg->HasKey("nsects")) 495 segment.nsects = 496 seg->GetValueForKey("nsects")->GetAsInteger()->GetValue(); 497 else 498 segment.nsects = 0; 499 500 image_infos[i].segments.push_back(segment); 501 } 502 503 image_infos[i].uuid.SetFromOptionalStringRef( 504 image->GetValueForKey("uuid")->GetAsString()->GetValue()); 505 506 // All sections listed in the dyld image info structure will all either be 507 // fixed up already, or they will all be off by a single slide amount that 508 // is determined by finding the first segment that is at file offset zero 509 // which also has bytes (a file size that is greater than zero) in the 510 // object file. 511 512 // Determine the slide amount (if any) 513 const size_t num_sections = image_infos[i].segments.size(); 514 for (size_t k = 0; k < num_sections; ++k) { 515 // Iterate through the object file sections to find the first section 516 // that starts of file offset zero and that has bytes in the file... 517 if ((image_infos[i].segments[k].fileoff == 0 && 518 image_infos[i].segments[k].filesize > 0) || 519 (image_infos[i].segments[k].name == "__TEXT")) { 520 image_infos[i].slide = 521 image_infos[i].address - image_infos[i].segments[k].vmaddr; 522 // We have found the slide amount, so we can exit this for loop. 523 break; 524 } 525 } 526 } 527 528 return true; 529 } 530 531 void DynamicLoaderDarwin::UpdateSpecialBinariesFromNewImageInfos( 532 ImageInfo::collection &image_infos) { 533 uint32_t exe_idx = UINT32_MAX; 534 uint32_t dyld_idx = UINT32_MAX; 535 Target &target = m_process->GetTarget(); 536 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); 537 ConstString g_dyld_sim_filename("dyld_sim"); 538 539 ArchSpec target_arch = target.GetArchitecture(); 540 const size_t image_infos_size = image_infos.size(); 541 for (size_t i = 0; i < image_infos_size; i++) { 542 if (image_infos[i].header.filetype == llvm::MachO::MH_DYLINKER) { 543 // In a "simulator" process we will have two dyld modules -- 544 // a "dyld" that we want to keep track of, and a "dyld_sim" which 545 // we don't need to keep track of here. dyld_sim will have a non-macosx 546 // OS. 547 if (target_arch.GetTriple().getEnvironment() == llvm::Triple::Simulator && 548 image_infos[i].os_type != llvm::Triple::OSType::MacOSX) { 549 continue; 550 } 551 552 dyld_idx = i; 553 } 554 if (image_infos[i].header.filetype == llvm::MachO::MH_EXECUTE) { 555 exe_idx = i; 556 } 557 } 558 559 // Set the target executable if we haven't found one so far. 560 if (exe_idx != UINT32_MAX && !target.GetExecutableModule()) { 561 const bool can_create = true; 562 ModuleSP exe_module_sp(FindTargetModuleForImageInfo(image_infos[exe_idx], 563 can_create, nullptr)); 564 if (exe_module_sp) { 565 LLDB_LOGF(log, "Found executable module: %s", 566 exe_module_sp->GetFileSpec().GetPath().c_str()); 567 target.GetImages().AppendIfNeeded(exe_module_sp); 568 UpdateImageLoadAddress(exe_module_sp.get(), image_infos[exe_idx]); 569 if (exe_module_sp.get() != target.GetExecutableModulePointer()) { 570 target.SetExecutableModule(exe_module_sp, eLoadDependentsNo); 571 } 572 } 573 } 574 575 if (dyld_idx != UINT32_MAX) { 576 const bool can_create = true; 577 ModuleSP dyld_sp = FindTargetModuleForImageInfo(image_infos[dyld_idx], 578 can_create, nullptr); 579 if (dyld_sp.get()) { 580 LLDB_LOGF(log, "Found dyld module: %s", 581 dyld_sp->GetFileSpec().GetPath().c_str()); 582 target.GetImages().AppendIfNeeded(dyld_sp); 583 UpdateImageLoadAddress(dyld_sp.get(), image_infos[dyld_idx]); 584 SetDYLDModule(dyld_sp); 585 } 586 } 587 } 588 589 void DynamicLoaderDarwin::UpdateDYLDImageInfoFromNewImageInfo( 590 ImageInfo &image_info) { 591 if (image_info.header.filetype == llvm::MachO::MH_DYLINKER) { 592 const bool can_create = true; 593 ModuleSP dyld_sp = 594 FindTargetModuleForImageInfo(image_info, can_create, nullptr); 595 if (dyld_sp.get()) { 596 Target &target = m_process->GetTarget(); 597 target.GetImages().AppendIfNeeded(dyld_sp); 598 UpdateImageLoadAddress(dyld_sp.get(), image_info); 599 SetDYLDModule(dyld_sp); 600 } 601 } 602 } 603 604 void DynamicLoaderDarwin::SetDYLDModule(lldb::ModuleSP &dyld_module_sp) { 605 m_dyld_module_wp = dyld_module_sp; 606 } 607 608 ModuleSP DynamicLoaderDarwin::GetDYLDModule() { 609 ModuleSP dyld_sp(m_dyld_module_wp.lock()); 610 return dyld_sp; 611 } 612 613 bool DynamicLoaderDarwin::AddModulesUsingImageInfos( 614 ImageInfo::collection &image_infos) { 615 std::lock_guard<std::recursive_mutex> guard(m_mutex); 616 // Now add these images to the main list. 617 ModuleList loaded_module_list; 618 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); 619 Target &target = m_process->GetTarget(); 620 ModuleList &target_images = target.GetImages(); 621 622 for (uint32_t idx = 0; idx < image_infos.size(); ++idx) { 623 if (log) { 624 LLDB_LOGF(log, "Adding new image at address=0x%16.16" PRIx64 ".", 625 image_infos[idx].address); 626 image_infos[idx].PutToLog(log); 627 } 628 629 m_dyld_image_infos.push_back(image_infos[idx]); 630 631 ModuleSP image_module_sp( 632 FindTargetModuleForImageInfo(image_infos[idx], true, nullptr)); 633 634 if (image_module_sp) { 635 ObjectFile *objfile = image_module_sp->GetObjectFile(); 636 if (objfile) { 637 SectionList *sections = objfile->GetSectionList(); 638 if (sections) { 639 ConstString commpage_dbstr("__commpage"); 640 Section *commpage_section = 641 sections->FindSectionByName(commpage_dbstr).get(); 642 if (commpage_section) { 643 ModuleSpec module_spec(objfile->GetFileSpec(), 644 image_infos[idx].GetArchitecture()); 645 module_spec.GetObjectName() = commpage_dbstr; 646 ModuleSP commpage_image_module_sp( 647 target_images.FindFirstModule(module_spec)); 648 if (!commpage_image_module_sp) { 649 module_spec.SetObjectOffset(objfile->GetFileOffset() + 650 commpage_section->GetFileOffset()); 651 module_spec.SetObjectSize(objfile->GetByteSize()); 652 commpage_image_module_sp = target.GetOrCreateModule(module_spec, 653 true /* notify */); 654 if (!commpage_image_module_sp || 655 commpage_image_module_sp->GetObjectFile() == nullptr) { 656 commpage_image_module_sp = m_process->ReadModuleFromMemory( 657 image_infos[idx].file_spec, image_infos[idx].address); 658 // Always load a memory image right away in the target in case 659 // we end up trying to read the symbol table from memory... The 660 // __LINKEDIT will need to be mapped so we can figure out where 661 // the symbol table bits are... 662 bool changed = false; 663 UpdateImageLoadAddress(commpage_image_module_sp.get(), 664 image_infos[idx]); 665 target.GetImages().Append(commpage_image_module_sp); 666 if (changed) { 667 image_infos[idx].load_stop_id = m_process->GetStopID(); 668 loaded_module_list.AppendIfNeeded(commpage_image_module_sp); 669 } 670 } 671 } 672 } 673 } 674 } 675 676 // UpdateImageLoadAddress will return true if any segments change load 677 // address. We need to check this so we don't mention that all loaded 678 // shared libraries are newly loaded each time we hit out dyld breakpoint 679 // since dyld will list all shared libraries each time. 680 if (UpdateImageLoadAddress(image_module_sp.get(), image_infos[idx])) { 681 target_images.AppendIfNeeded(image_module_sp); 682 loaded_module_list.AppendIfNeeded(image_module_sp); 683 } 684 685 // To support macCatalyst and legacy iOS simulator, 686 // update the module's platform with the DYLD info. 687 ArchSpec dyld_spec = image_infos[idx].GetArchitecture(); 688 auto &dyld_triple = dyld_spec.GetTriple(); 689 if ((dyld_triple.getEnvironment() == llvm::Triple::MacABI && 690 dyld_triple.getOS() == llvm::Triple::IOS) || 691 (dyld_triple.getEnvironment() == llvm::Triple::Simulator && 692 (dyld_triple.getOS() == llvm::Triple::IOS || 693 dyld_triple.getOS() == llvm::Triple::TvOS || 694 dyld_triple.getOS() == llvm::Triple::WatchOS))) 695 image_module_sp->MergeArchitecture(dyld_spec); 696 } 697 } 698 699 if (loaded_module_list.GetSize() > 0) { 700 if (log) 701 loaded_module_list.LogUUIDAndPaths(log, 702 "DynamicLoaderDarwin::ModulesDidLoad"); 703 m_process->GetTarget().ModulesDidLoad(loaded_module_list); 704 } 705 return true; 706 } 707 708 // On Mac OS X libobjc (the Objective-C runtime) has several critical dispatch 709 // functions written in hand-written assembly, and also have hand-written 710 // unwind information in the eh_frame section. Normally we prefer analyzing 711 // the assembly instructions of a currently executing frame to unwind from that 712 // frame -- but on hand-written functions this profiling can fail. We should 713 // use the eh_frame instructions for these functions all the time. 714 // 715 // As an aside, it would be better if the eh_frame entries had a flag (or were 716 // extensible so they could have an Apple-specific flag) which indicates that 717 // the instructions are asynchronous -- accurate at every instruction, instead 718 // of our normal default assumption that they are not. 719 720 bool DynamicLoaderDarwin::AlwaysRelyOnEHUnwindInfo(SymbolContext &sym_ctx) { 721 ModuleSP module_sp; 722 if (sym_ctx.symbol) { 723 module_sp = sym_ctx.symbol->GetAddressRef().GetModule(); 724 } 725 if (module_sp.get() == nullptr && sym_ctx.function) { 726 module_sp = 727 sym_ctx.function->GetAddressRange().GetBaseAddress().GetModule(); 728 } 729 if (module_sp.get() == nullptr) 730 return false; 731 732 ObjCLanguageRuntime *objc_runtime = ObjCLanguageRuntime::Get(*m_process); 733 return objc_runtime != nullptr && 734 objc_runtime->IsModuleObjCLibrary(module_sp); 735 } 736 737 // Dump a Segment to the file handle provided. 738 void DynamicLoaderDarwin::Segment::PutToLog(Log *log, 739 lldb::addr_t slide) const { 740 if (log) { 741 if (slide == 0) 742 LLDB_LOGF(log, "\t\t%16s [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")", 743 name.AsCString(""), vmaddr + slide, vmaddr + slide + vmsize); 744 else 745 LLDB_LOGF(log, 746 "\t\t%16s [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 747 ") slide = 0x%" PRIx64, 748 name.AsCString(""), vmaddr + slide, vmaddr + slide + vmsize, 749 slide); 750 } 751 } 752 753 lldb_private::ArchSpec DynamicLoaderDarwin::ImageInfo::GetArchitecture() const { 754 // Update the module's platform with the DYLD info. 755 lldb_private::ArchSpec arch_spec(lldb_private::eArchTypeMachO, header.cputype, 756 header.cpusubtype); 757 if (os_env == llvm::Triple::MacABI && os_type == llvm::Triple::IOS) { 758 llvm::Triple triple(llvm::Twine(arch_spec.GetArchitectureName()) + 759 "-apple-ios" + min_version_os_sdk + "-macabi"); 760 ArchSpec maccatalyst_spec(triple); 761 if (arch_spec.IsCompatibleMatch(maccatalyst_spec)) 762 arch_spec.MergeFrom(maccatalyst_spec); 763 } 764 if (os_env == llvm::Triple::Simulator && 765 (os_type == llvm::Triple::IOS || os_type == llvm::Triple::TvOS || 766 os_type == llvm::Triple::WatchOS)) { 767 llvm::Triple triple(llvm::Twine(arch_spec.GetArchitectureName()) + 768 "-apple-" + llvm::Triple::getOSTypeName(os_type) + 769 min_version_os_sdk + "-simulator"); 770 ArchSpec sim_spec(triple); 771 if (arch_spec.IsCompatibleMatch(sim_spec)) 772 arch_spec.MergeFrom(sim_spec); 773 } 774 return arch_spec; 775 } 776 777 const DynamicLoaderDarwin::Segment * 778 DynamicLoaderDarwin::ImageInfo::FindSegment(ConstString name) const { 779 const size_t num_segments = segments.size(); 780 for (size_t i = 0; i < num_segments; ++i) { 781 if (segments[i].name == name) 782 return &segments[i]; 783 } 784 return nullptr; 785 } 786 787 // Dump an image info structure to the file handle provided. 788 void DynamicLoaderDarwin::ImageInfo::PutToLog(Log *log) const { 789 if (!log) 790 return; 791 if (address == LLDB_INVALID_ADDRESS) { 792 LLDB_LOG(log, "modtime={0:x+8} uuid={1} path='{2}' (UNLOADED)", mod_date, 793 uuid.GetAsString(), file_spec.GetPath()); 794 } else { 795 LLDB_LOG(log, "address={0:x+16} modtime={1:x+8} uuid={2} path='{3}'", 796 address, mod_date, uuid.GetAsString(), file_spec.GetPath()); 797 for (uint32_t i = 0; i < segments.size(); ++i) 798 segments[i].PutToLog(log, slide); 799 } 800 } 801 802 void DynamicLoaderDarwin::PrivateInitialize(Process *process) { 803 DEBUG_PRINTF("DynamicLoaderDarwin::%s() process state = %s\n", __FUNCTION__, 804 StateAsCString(m_process->GetState())); 805 Clear(true); 806 m_process = process; 807 m_process->GetTarget().ClearAllLoadedSections(); 808 } 809 810 // Member function that gets called when the process state changes. 811 void DynamicLoaderDarwin::PrivateProcessStateChanged(Process *process, 812 StateType state) { 813 DEBUG_PRINTF("DynamicLoaderDarwin::%s(%s)\n", __FUNCTION__, 814 StateAsCString(state)); 815 switch (state) { 816 case eStateConnected: 817 case eStateAttaching: 818 case eStateLaunching: 819 case eStateInvalid: 820 case eStateUnloaded: 821 case eStateExited: 822 case eStateDetached: 823 Clear(false); 824 break; 825 826 case eStateStopped: 827 // Keep trying find dyld and set our notification breakpoint each time we 828 // stop until we succeed 829 if (!DidSetNotificationBreakpoint() && m_process->IsAlive()) { 830 if (NeedToDoInitialImageFetch()) 831 DoInitialImageFetch(); 832 833 SetNotificationBreakpoint(); 834 } 835 break; 836 837 case eStateRunning: 838 case eStateStepping: 839 case eStateCrashed: 840 case eStateSuspended: 841 break; 842 } 843 } 844 845 ThreadPlanSP 846 DynamicLoaderDarwin::GetStepThroughTrampolinePlan(Thread &thread, 847 bool stop_others) { 848 ThreadPlanSP thread_plan_sp; 849 StackFrame *current_frame = thread.GetStackFrameAtIndex(0).get(); 850 const SymbolContext ¤t_context = 851 current_frame->GetSymbolContext(eSymbolContextSymbol); 852 Symbol *current_symbol = current_context.symbol; 853 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); 854 TargetSP target_sp(thread.CalculateTarget()); 855 856 if (current_symbol != nullptr) { 857 std::vector<Address> addresses; 858 859 if (current_symbol->IsTrampoline()) { 860 ConstString trampoline_name = 861 current_symbol->GetMangled().GetName(Mangled::ePreferMangled); 862 863 if (trampoline_name) { 864 const ModuleList &images = target_sp->GetImages(); 865 866 SymbolContextList code_symbols; 867 images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeCode, 868 code_symbols); 869 size_t num_code_symbols = code_symbols.GetSize(); 870 871 if (num_code_symbols > 0) { 872 for (uint32_t i = 0; i < num_code_symbols; i++) { 873 SymbolContext context; 874 AddressRange addr_range; 875 if (code_symbols.GetContextAtIndex(i, context)) { 876 context.GetAddressRange(eSymbolContextEverything, 0, false, 877 addr_range); 878 addresses.push_back(addr_range.GetBaseAddress()); 879 if (log) { 880 addr_t load_addr = 881 addr_range.GetBaseAddress().GetLoadAddress(target_sp.get()); 882 883 LLDB_LOGF(log, 884 "Found a trampoline target symbol at 0x%" PRIx64 ".", 885 load_addr); 886 } 887 } 888 } 889 } 890 891 SymbolContextList reexported_symbols; 892 images.FindSymbolsWithNameAndType( 893 trampoline_name, eSymbolTypeReExported, reexported_symbols); 894 size_t num_reexported_symbols = reexported_symbols.GetSize(); 895 if (num_reexported_symbols > 0) { 896 for (uint32_t i = 0; i < num_reexported_symbols; i++) { 897 SymbolContext context; 898 if (reexported_symbols.GetContextAtIndex(i, context)) { 899 if (context.symbol) { 900 Symbol *actual_symbol = 901 context.symbol->ResolveReExportedSymbol(*target_sp.get()); 902 if (actual_symbol) { 903 const Address actual_symbol_addr = 904 actual_symbol->GetAddress(); 905 if (actual_symbol_addr.IsValid()) { 906 addresses.push_back(actual_symbol_addr); 907 if (log) { 908 lldb::addr_t load_addr = 909 actual_symbol_addr.GetLoadAddress(target_sp.get()); 910 LLDB_LOGF( 911 log, 912 "Found a re-exported symbol: %s at 0x%" PRIx64 ".", 913 actual_symbol->GetName().GetCString(), load_addr); 914 } 915 } 916 } 917 } 918 } 919 } 920 } 921 922 SymbolContextList indirect_symbols; 923 images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeResolver, 924 indirect_symbols); 925 size_t num_indirect_symbols = indirect_symbols.GetSize(); 926 if (num_indirect_symbols > 0) { 927 for (uint32_t i = 0; i < num_indirect_symbols; i++) { 928 SymbolContext context; 929 AddressRange addr_range; 930 if (indirect_symbols.GetContextAtIndex(i, context)) { 931 context.GetAddressRange(eSymbolContextEverything, 0, false, 932 addr_range); 933 addresses.push_back(addr_range.GetBaseAddress()); 934 if (log) { 935 addr_t load_addr = 936 addr_range.GetBaseAddress().GetLoadAddress(target_sp.get()); 937 938 LLDB_LOGF(log, 939 "Found an indirect target symbol at 0x%" PRIx64 ".", 940 load_addr); 941 } 942 } 943 } 944 } 945 } 946 } else if (current_symbol->GetType() == eSymbolTypeReExported) { 947 // I am not sure we could ever end up stopped AT a re-exported symbol. 948 // But just in case: 949 950 const Symbol *actual_symbol = 951 current_symbol->ResolveReExportedSymbol(*(target_sp.get())); 952 if (actual_symbol) { 953 Address target_addr(actual_symbol->GetAddress()); 954 if (target_addr.IsValid()) { 955 LLDB_LOGF( 956 log, 957 "Found a re-exported symbol: %s pointing to: %s at 0x%" PRIx64 958 ".", 959 current_symbol->GetName().GetCString(), 960 actual_symbol->GetName().GetCString(), 961 target_addr.GetLoadAddress(target_sp.get())); 962 addresses.push_back(target_addr.GetLoadAddress(target_sp.get())); 963 } 964 } 965 } 966 967 if (addresses.size() > 0) { 968 // First check whether any of the addresses point to Indirect symbols, 969 // and if they do, resolve them: 970 std::vector<lldb::addr_t> load_addrs; 971 for (Address address : addresses) { 972 Symbol *symbol = address.CalculateSymbolContextSymbol(); 973 if (symbol && symbol->IsIndirect()) { 974 Status error; 975 Address symbol_address = symbol->GetAddress(); 976 addr_t resolved_addr = thread.GetProcess()->ResolveIndirectFunction( 977 &symbol_address, error); 978 if (error.Success()) { 979 load_addrs.push_back(resolved_addr); 980 LLDB_LOGF(log, 981 "ResolveIndirectFunction found resolved target for " 982 "%s at 0x%" PRIx64 ".", 983 symbol->GetName().GetCString(), resolved_addr); 984 } 985 } else { 986 load_addrs.push_back(address.GetLoadAddress(target_sp.get())); 987 } 988 } 989 thread_plan_sp = std::make_shared<ThreadPlanRunToAddress>( 990 thread, load_addrs, stop_others); 991 } 992 } else { 993 LLDB_LOGF(log, "Could not find symbol for step through."); 994 } 995 996 return thread_plan_sp; 997 } 998 999 void DynamicLoaderDarwin::FindEquivalentSymbols( 1000 lldb_private::Symbol *original_symbol, lldb_private::ModuleList &images, 1001 lldb_private::SymbolContextList &equivalent_symbols) { 1002 ConstString trampoline_name = 1003 original_symbol->GetMangled().GetName(Mangled::ePreferMangled); 1004 if (!trampoline_name) 1005 return; 1006 1007 static const char *resolver_name_regex = "(_gc|_non_gc|\\$[A-Za-z0-9\\$]+)$"; 1008 std::string equivalent_regex_buf("^"); 1009 equivalent_regex_buf.append(trampoline_name.GetCString()); 1010 equivalent_regex_buf.append(resolver_name_regex); 1011 1012 RegularExpression equivalent_name_regex(equivalent_regex_buf); 1013 images.FindSymbolsMatchingRegExAndType(equivalent_name_regex, eSymbolTypeCode, 1014 equivalent_symbols); 1015 1016 } 1017 1018 lldb::ModuleSP DynamicLoaderDarwin::GetPThreadLibraryModule() { 1019 ModuleSP module_sp = m_libpthread_module_wp.lock(); 1020 if (!module_sp) { 1021 SymbolContextList sc_list; 1022 ModuleSpec module_spec; 1023 module_spec.GetFileSpec().GetFilename().SetCString( 1024 "libsystem_pthread.dylib"); 1025 ModuleList module_list; 1026 m_process->GetTarget().GetImages().FindModules(module_spec, module_list); 1027 if (!module_list.IsEmpty()) { 1028 if (module_list.GetSize() == 1) { 1029 module_sp = module_list.GetModuleAtIndex(0); 1030 if (module_sp) 1031 m_libpthread_module_wp = module_sp; 1032 } 1033 } 1034 } 1035 return module_sp; 1036 } 1037 1038 Address DynamicLoaderDarwin::GetPthreadSetSpecificAddress() { 1039 if (!m_pthread_getspecific_addr.IsValid()) { 1040 ModuleSP module_sp = GetPThreadLibraryModule(); 1041 if (module_sp) { 1042 lldb_private::SymbolContextList sc_list; 1043 module_sp->FindSymbolsWithNameAndType(ConstString("pthread_getspecific"), 1044 eSymbolTypeCode, sc_list); 1045 SymbolContext sc; 1046 if (sc_list.GetContextAtIndex(0, sc)) { 1047 if (sc.symbol) 1048 m_pthread_getspecific_addr = sc.symbol->GetAddress(); 1049 } 1050 } 1051 } 1052 return m_pthread_getspecific_addr; 1053 } 1054 1055 lldb::addr_t 1056 DynamicLoaderDarwin::GetThreadLocalData(const lldb::ModuleSP module_sp, 1057 const lldb::ThreadSP thread_sp, 1058 lldb::addr_t tls_file_addr) { 1059 if (!thread_sp || !module_sp) 1060 return LLDB_INVALID_ADDRESS; 1061 1062 std::lock_guard<std::recursive_mutex> guard(m_mutex); 1063 1064 const uint32_t addr_size = m_process->GetAddressByteSize(); 1065 uint8_t buf[sizeof(lldb::addr_t) * 3]; 1066 1067 lldb_private::Address tls_addr; 1068 if (module_sp->ResolveFileAddress(tls_file_addr, tls_addr)) { 1069 Status error; 1070 const size_t tsl_data_size = addr_size * 3; 1071 Target &target = m_process->GetTarget(); 1072 if (target.ReadMemory(tls_addr, buf, tsl_data_size, error, true) == 1073 tsl_data_size) { 1074 const ByteOrder byte_order = m_process->GetByteOrder(); 1075 DataExtractor data(buf, sizeof(buf), byte_order, addr_size); 1076 lldb::offset_t offset = addr_size; // Skip the first pointer 1077 const lldb::addr_t pthread_key = data.GetAddress(&offset); 1078 const lldb::addr_t tls_offset = data.GetAddress(&offset); 1079 if (pthread_key != 0) { 1080 // First check to see if we have already figured out the location of 1081 // TLS data for the pthread_key on a specific thread yet. If we have we 1082 // can re-use it since its location will not change unless the process 1083 // execs. 1084 const tid_t tid = thread_sp->GetID(); 1085 auto tid_pos = m_tid_to_tls_map.find(tid); 1086 if (tid_pos != m_tid_to_tls_map.end()) { 1087 auto tls_pos = tid_pos->second.find(pthread_key); 1088 if (tls_pos != tid_pos->second.end()) { 1089 return tls_pos->second + tls_offset; 1090 } 1091 } 1092 StackFrameSP frame_sp = thread_sp->GetStackFrameAtIndex(0); 1093 if (frame_sp) { 1094 TypeSystemClang *clang_ast_context = 1095 ScratchTypeSystemClang::GetForTarget(target); 1096 1097 if (!clang_ast_context) 1098 return LLDB_INVALID_ADDRESS; 1099 1100 CompilerType clang_void_ptr_type = 1101 clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); 1102 Address pthread_getspecific_addr = GetPthreadSetSpecificAddress(); 1103 if (pthread_getspecific_addr.IsValid()) { 1104 EvaluateExpressionOptions options; 1105 1106 lldb::ThreadPlanSP thread_plan_sp(new ThreadPlanCallFunction( 1107 *thread_sp, pthread_getspecific_addr, clang_void_ptr_type, 1108 llvm::ArrayRef<lldb::addr_t>(pthread_key), options)); 1109 1110 DiagnosticManager execution_errors; 1111 ExecutionContext exe_ctx(thread_sp); 1112 lldb::ExpressionResults results = m_process->RunThreadPlan( 1113 exe_ctx, thread_plan_sp, options, execution_errors); 1114 1115 if (results == lldb::eExpressionCompleted) { 1116 lldb::ValueObjectSP result_valobj_sp = 1117 thread_plan_sp->GetReturnValueObject(); 1118 if (result_valobj_sp) { 1119 const lldb::addr_t pthread_key_data = 1120 result_valobj_sp->GetValueAsUnsigned(0); 1121 if (pthread_key_data) { 1122 m_tid_to_tls_map[tid].insert( 1123 std::make_pair(pthread_key, pthread_key_data)); 1124 return pthread_key_data + tls_offset; 1125 } 1126 } 1127 } 1128 } 1129 } 1130 } 1131 } 1132 } 1133 return LLDB_INVALID_ADDRESS; 1134 } 1135 1136 bool DynamicLoaderDarwin::UseDYLDSPI(Process *process) { 1137 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); 1138 bool use_new_spi_interface = false; 1139 1140 llvm::VersionTuple version = process->GetHostOSVersion(); 1141 if (!version.empty()) { 1142 const llvm::Triple::OSType os_type = 1143 process->GetTarget().GetArchitecture().GetTriple().getOS(); 1144 1145 // macOS 10.12 and newer 1146 if (os_type == llvm::Triple::MacOSX && 1147 version >= llvm::VersionTuple(10, 12)) 1148 use_new_spi_interface = true; 1149 1150 // iOS 10 and newer 1151 if (os_type == llvm::Triple::IOS && version >= llvm::VersionTuple(10)) 1152 use_new_spi_interface = true; 1153 1154 // tvOS 10 and newer 1155 if (os_type == llvm::Triple::TvOS && version >= llvm::VersionTuple(10)) 1156 use_new_spi_interface = true; 1157 1158 // watchOS 3 and newer 1159 if (os_type == llvm::Triple::WatchOS && version >= llvm::VersionTuple(3)) 1160 use_new_spi_interface = true; 1161 1162 // NEED_BRIDGEOS_TRIPLE // Any BridgeOS 1163 // NEED_BRIDGEOS_TRIPLE if (os_type == llvm::Triple::BridgeOS) 1164 // NEED_BRIDGEOS_TRIPLE use_new_spi_interface = true; 1165 } 1166 1167 if (log) { 1168 if (use_new_spi_interface) 1169 LLDB_LOGF( 1170 log, "DynamicLoaderDarwin::UseDYLDSPI: Use new DynamicLoader plugin"); 1171 else 1172 LLDB_LOGF( 1173 log, "DynamicLoaderDarwin::UseDYLDSPI: Use old DynamicLoader plugin"); 1174 } 1175 return use_new_spi_interface; 1176 } 1177