1 //===-- AppleObjCRuntime.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 "AppleObjCRuntime.h" 10 #include "AppleObjCRuntimeV1.h" 11 #include "AppleObjCRuntimeV2.h" 12 #include "AppleObjCTrampolineHandler.h" 13 #include "Plugins/Language/ObjC/NSString.h" 14 #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" 15 #include "Plugins/Process/Utility/HistoryThread.h" 16 #include "lldb/Breakpoint/BreakpointLocation.h" 17 #include "lldb/Core/Module.h" 18 #include "lldb/Core/ModuleList.h" 19 #include "lldb/Core/PluginManager.h" 20 #include "lldb/Core/Section.h" 21 #include "lldb/Core/ValueObject.h" 22 #include "lldb/Core/ValueObjectConstResult.h" 23 #include "lldb/DataFormatters/FormattersHelpers.h" 24 #include "lldb/Expression/DiagnosticManager.h" 25 #include "lldb/Expression/FunctionCaller.h" 26 #include "lldb/Symbol/ObjectFile.h" 27 #include "lldb/Target/ExecutionContext.h" 28 #include "lldb/Target/Process.h" 29 #include "lldb/Target/RegisterContext.h" 30 #include "lldb/Target/StopInfo.h" 31 #include "lldb/Target/Target.h" 32 #include "lldb/Target/Thread.h" 33 #include "lldb/Utility/ConstString.h" 34 #include "lldb/Utility/Log.h" 35 #include "lldb/Utility/Scalar.h" 36 #include "lldb/Utility/Status.h" 37 #include "lldb/Utility/StreamString.h" 38 #include "clang/AST/Type.h" 39 40 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" 41 42 #include <vector> 43 44 using namespace lldb; 45 using namespace lldb_private; 46 47 LLDB_PLUGIN_DEFINE(AppleObjCRuntime) 48 49 char AppleObjCRuntime::ID = 0; 50 51 AppleObjCRuntime::~AppleObjCRuntime() {} 52 53 AppleObjCRuntime::AppleObjCRuntime(Process *process) 54 : ObjCLanguageRuntime(process), m_read_objc_library(false), 55 m_objc_trampoline_handler_up(), m_Foundation_major() { 56 ReadObjCLibraryIfNeeded(process->GetTarget().GetImages()); 57 } 58 59 void AppleObjCRuntime::Initialize() { 60 AppleObjCRuntimeV2::Initialize(); 61 AppleObjCRuntimeV1::Initialize(); 62 } 63 64 void AppleObjCRuntime::Terminate() { 65 AppleObjCRuntimeV2::Terminate(); 66 AppleObjCRuntimeV1::Terminate(); 67 } 68 69 bool AppleObjCRuntime::GetObjectDescription(Stream &str, ValueObject &valobj) { 70 CompilerType compiler_type(valobj.GetCompilerType()); 71 bool is_signed; 72 // ObjC objects can only be pointers (or numbers that actually represents 73 // pointers but haven't been typecast, because reasons..) 74 if (!compiler_type.IsIntegerType(is_signed) && !compiler_type.IsPointerType()) 75 return false; 76 77 // Make the argument list: we pass one arg, the address of our pointer, to 78 // the print function. 79 Value val; 80 81 if (!valobj.ResolveValue(val.GetScalar())) 82 return false; 83 84 // Value Objects may not have a process in their ExecutionContextRef. But we 85 // need to have one in the ref we pass down to eventually call description. 86 // Get it from the target if it isn't present. 87 ExecutionContext exe_ctx; 88 if (valobj.GetProcessSP()) { 89 exe_ctx = ExecutionContext(valobj.GetExecutionContextRef()); 90 } else { 91 exe_ctx.SetContext(valobj.GetTargetSP(), true); 92 if (!exe_ctx.HasProcessScope()) 93 return false; 94 } 95 return GetObjectDescription(str, val, exe_ctx.GetBestExecutionContextScope()); 96 } 97 bool AppleObjCRuntime::GetObjectDescription(Stream &strm, Value &value, 98 ExecutionContextScope *exe_scope) { 99 if (!m_read_objc_library) 100 return false; 101 102 ExecutionContext exe_ctx; 103 exe_scope->CalculateExecutionContext(exe_ctx); 104 Process *process = exe_ctx.GetProcessPtr(); 105 if (!process) 106 return false; 107 108 // We need other parts of the exe_ctx, but the processes have to match. 109 assert(m_process == process); 110 111 // Get the function address for the print function. 112 const Address *function_address = GetPrintForDebuggerAddr(); 113 if (!function_address) 114 return false; 115 116 Target *target = exe_ctx.GetTargetPtr(); 117 CompilerType compiler_type = value.GetCompilerType(); 118 if (compiler_type) { 119 if (!TypeSystemClang::IsObjCObjectPointerType(compiler_type)) { 120 strm.Printf("Value doesn't point to an ObjC object.\n"); 121 return false; 122 } 123 } else { 124 // If it is not a pointer, see if we can make it into a pointer. 125 TypeSystemClang *ast_context = TypeSystemClang::GetScratch(*target); 126 if (!ast_context) 127 return false; 128 129 CompilerType opaque_type = ast_context->GetBasicType(eBasicTypeObjCID); 130 if (!opaque_type) 131 opaque_type = ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); 132 // value.SetContext(Value::eContextTypeClangType, opaque_type_ptr); 133 value.SetCompilerType(opaque_type); 134 } 135 136 ValueList arg_value_list; 137 arg_value_list.PushValue(value); 138 139 // This is the return value: 140 TypeSystemClang *ast_context = TypeSystemClang::GetScratch(*target); 141 if (!ast_context) 142 return false; 143 144 CompilerType return_compiler_type = ast_context->GetCStringType(true); 145 Value ret; 146 // ret.SetContext(Value::eContextTypeClangType, return_compiler_type); 147 ret.SetCompilerType(return_compiler_type); 148 149 if (exe_ctx.GetFramePtr() == nullptr) { 150 Thread *thread = exe_ctx.GetThreadPtr(); 151 if (thread == nullptr) { 152 exe_ctx.SetThreadSP(process->GetThreadList().GetSelectedThread()); 153 thread = exe_ctx.GetThreadPtr(); 154 } 155 if (thread) { 156 exe_ctx.SetFrameSP(thread->GetSelectedFrame()); 157 } 158 } 159 160 // Now we're ready to call the function: 161 162 DiagnosticManager diagnostics; 163 lldb::addr_t wrapper_struct_addr = LLDB_INVALID_ADDRESS; 164 165 if (!m_print_object_caller_up) { 166 Status error; 167 m_print_object_caller_up.reset( 168 exe_scope->CalculateTarget()->GetFunctionCallerForLanguage( 169 eLanguageTypeObjC, return_compiler_type, *function_address, 170 arg_value_list, "objc-object-description", error)); 171 if (error.Fail()) { 172 m_print_object_caller_up.reset(); 173 strm.Printf("Could not get function runner to call print for debugger " 174 "function: %s.", 175 error.AsCString()); 176 return false; 177 } 178 m_print_object_caller_up->InsertFunction(exe_ctx, wrapper_struct_addr, 179 diagnostics); 180 } else { 181 m_print_object_caller_up->WriteFunctionArguments( 182 exe_ctx, wrapper_struct_addr, arg_value_list, diagnostics); 183 } 184 185 EvaluateExpressionOptions options; 186 options.SetUnwindOnError(true); 187 options.SetTryAllThreads(true); 188 options.SetStopOthers(true); 189 options.SetIgnoreBreakpoints(true); 190 options.SetTimeout(process->GetUtilityExpressionTimeout()); 191 options.SetIsForUtilityExpr(true); 192 193 ExpressionResults results = m_print_object_caller_up->ExecuteFunction( 194 exe_ctx, &wrapper_struct_addr, options, diagnostics, ret); 195 if (results != eExpressionCompleted) { 196 strm.Printf("Error evaluating Print Object function: %d.\n", results); 197 return false; 198 } 199 200 addr_t result_ptr = ret.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 201 202 char buf[512]; 203 size_t cstr_len = 0; 204 size_t full_buffer_len = sizeof(buf) - 1; 205 size_t curr_len = full_buffer_len; 206 while (curr_len == full_buffer_len) { 207 Status error; 208 curr_len = process->ReadCStringFromMemory(result_ptr + cstr_len, buf, 209 sizeof(buf), error); 210 strm.Write(buf, curr_len); 211 cstr_len += curr_len; 212 } 213 return cstr_len > 0; 214 } 215 216 lldb::ModuleSP AppleObjCRuntime::GetObjCModule() { 217 ModuleSP module_sp(m_objc_module_wp.lock()); 218 if (module_sp) 219 return module_sp; 220 221 Process *process = GetProcess(); 222 if (process) { 223 const ModuleList &modules = process->GetTarget().GetImages(); 224 for (uint32_t idx = 0; idx < modules.GetSize(); idx++) { 225 module_sp = modules.GetModuleAtIndex(idx); 226 if (AppleObjCRuntime::AppleIsModuleObjCLibrary(module_sp)) { 227 m_objc_module_wp = module_sp; 228 return module_sp; 229 } 230 } 231 } 232 return ModuleSP(); 233 } 234 235 Address *AppleObjCRuntime::GetPrintForDebuggerAddr() { 236 if (!m_PrintForDebugger_addr) { 237 const ModuleList &modules = m_process->GetTarget().GetImages(); 238 239 SymbolContextList contexts; 240 SymbolContext context; 241 242 modules.FindSymbolsWithNameAndType(ConstString("_NSPrintForDebugger"), 243 eSymbolTypeCode, contexts); 244 if (contexts.IsEmpty()) { 245 modules.FindSymbolsWithNameAndType(ConstString("_CFPrintForDebugger"), 246 eSymbolTypeCode, contexts); 247 if (contexts.IsEmpty()) 248 return nullptr; 249 } 250 251 contexts.GetContextAtIndex(0, context); 252 253 m_PrintForDebugger_addr = 254 std::make_unique<Address>(context.symbol->GetAddress()); 255 } 256 257 return m_PrintForDebugger_addr.get(); 258 } 259 260 bool AppleObjCRuntime::CouldHaveDynamicValue(ValueObject &in_value) { 261 return in_value.GetCompilerType().IsPossibleDynamicType( 262 nullptr, 263 false, // do not check C++ 264 true); // check ObjC 265 } 266 267 bool AppleObjCRuntime::GetDynamicTypeAndAddress( 268 ValueObject &in_value, lldb::DynamicValueType use_dynamic, 269 TypeAndOrName &class_type_or_name, Address &address, 270 Value::ValueType &value_type) { 271 return false; 272 } 273 274 TypeAndOrName 275 AppleObjCRuntime::FixUpDynamicType(const TypeAndOrName &type_and_or_name, 276 ValueObject &static_value) { 277 CompilerType static_type(static_value.GetCompilerType()); 278 Flags static_type_flags(static_type.GetTypeInfo()); 279 280 TypeAndOrName ret(type_and_or_name); 281 if (type_and_or_name.HasType()) { 282 // The type will always be the type of the dynamic object. If our parent's 283 // type was a pointer, then our type should be a pointer to the type of the 284 // dynamic object. If a reference, then the original type should be 285 // okay... 286 CompilerType orig_type = type_and_or_name.GetCompilerType(); 287 CompilerType corrected_type = orig_type; 288 if (static_type_flags.AllSet(eTypeIsPointer)) 289 corrected_type = orig_type.GetPointerType(); 290 ret.SetCompilerType(corrected_type); 291 } else { 292 // If we are here we need to adjust our dynamic type name to include the 293 // correct & or * symbol 294 std::string corrected_name(type_and_or_name.GetName().GetCString()); 295 if (static_type_flags.AllSet(eTypeIsPointer)) 296 corrected_name.append(" *"); 297 // the parent type should be a correctly pointer'ed or referenc'ed type 298 ret.SetCompilerType(static_type); 299 ret.SetName(corrected_name.c_str()); 300 } 301 return ret; 302 } 303 304 bool AppleObjCRuntime::AppleIsModuleObjCLibrary(const ModuleSP &module_sp) { 305 if (module_sp) { 306 const FileSpec &module_file_spec = module_sp->GetFileSpec(); 307 static ConstString ObjCName("libobjc.A.dylib"); 308 309 if (module_file_spec) { 310 if (module_file_spec.GetFilename() == ObjCName) 311 return true; 312 } 313 } 314 return false; 315 } 316 317 // we use the version of Foundation to make assumptions about the ObjC runtime 318 // on a target 319 uint32_t AppleObjCRuntime::GetFoundationVersion() { 320 if (!m_Foundation_major.hasValue()) { 321 const ModuleList &modules = m_process->GetTarget().GetImages(); 322 for (uint32_t idx = 0; idx < modules.GetSize(); idx++) { 323 lldb::ModuleSP module_sp = modules.GetModuleAtIndex(idx); 324 if (!module_sp) 325 continue; 326 if (strcmp(module_sp->GetFileSpec().GetFilename().AsCString(""), 327 "Foundation") == 0) { 328 m_Foundation_major = module_sp->GetVersion().getMajor(); 329 return *m_Foundation_major; 330 } 331 } 332 return LLDB_INVALID_MODULE_VERSION; 333 } else 334 return m_Foundation_major.getValue(); 335 } 336 337 void AppleObjCRuntime::GetValuesForGlobalCFBooleans(lldb::addr_t &cf_true, 338 lldb::addr_t &cf_false) { 339 cf_true = cf_false = LLDB_INVALID_ADDRESS; 340 } 341 342 bool AppleObjCRuntime::IsModuleObjCLibrary(const ModuleSP &module_sp) { 343 return AppleIsModuleObjCLibrary(module_sp); 344 } 345 346 bool AppleObjCRuntime::ReadObjCLibrary(const ModuleSP &module_sp) { 347 // Maybe check here and if we have a handler already, and the UUID of this 348 // module is the same as the one in the current module, then we don't have to 349 // reread it? 350 m_objc_trampoline_handler_up = std::make_unique<AppleObjCTrampolineHandler>( 351 m_process->shared_from_this(), module_sp); 352 if (m_objc_trampoline_handler_up != nullptr) { 353 m_read_objc_library = true; 354 return true; 355 } else 356 return false; 357 } 358 359 ThreadPlanSP AppleObjCRuntime::GetStepThroughTrampolinePlan(Thread &thread, 360 bool stop_others) { 361 ThreadPlanSP thread_plan_sp; 362 if (m_objc_trampoline_handler_up) 363 thread_plan_sp = m_objc_trampoline_handler_up->GetStepThroughDispatchPlan( 364 thread, stop_others); 365 return thread_plan_sp; 366 } 367 368 // Static Functions 369 ObjCLanguageRuntime::ObjCRuntimeVersions 370 AppleObjCRuntime::GetObjCVersion(Process *process, ModuleSP &objc_module_sp) { 371 if (!process) 372 return ObjCRuntimeVersions::eObjC_VersionUnknown; 373 374 Target &target = process->GetTarget(); 375 if (target.GetArchitecture().GetTriple().getVendor() != 376 llvm::Triple::VendorType::Apple) 377 return ObjCRuntimeVersions::eObjC_VersionUnknown; 378 379 const ModuleList &target_modules = target.GetImages(); 380 std::lock_guard<std::recursive_mutex> gaurd(target_modules.GetMutex()); 381 382 size_t num_images = target_modules.GetSize(); 383 for (size_t i = 0; i < num_images; i++) { 384 ModuleSP module_sp = target_modules.GetModuleAtIndexUnlocked(i); 385 // One tricky bit here is that we might get called as part of the initial 386 // module loading, but before all the pre-run libraries get winnowed from 387 // the module list. So there might actually be an old and incorrect ObjC 388 // library sitting around in the list, and we don't want to look at that. 389 // That's why we call IsLoadedInTarget. 390 391 if (AppleIsModuleObjCLibrary(module_sp) && 392 module_sp->IsLoadedInTarget(&target)) { 393 objc_module_sp = module_sp; 394 ObjectFile *ofile = module_sp->GetObjectFile(); 395 if (!ofile) 396 return ObjCRuntimeVersions::eObjC_VersionUnknown; 397 398 SectionList *sections = module_sp->GetSectionList(); 399 if (!sections) 400 return ObjCRuntimeVersions::eObjC_VersionUnknown; 401 SectionSP v1_telltale_section_sp = 402 sections->FindSectionByName(ConstString("__OBJC")); 403 if (v1_telltale_section_sp) { 404 return ObjCRuntimeVersions::eAppleObjC_V1; 405 } 406 return ObjCRuntimeVersions::eAppleObjC_V2; 407 } 408 } 409 410 return ObjCRuntimeVersions::eObjC_VersionUnknown; 411 } 412 413 void AppleObjCRuntime::SetExceptionBreakpoints() { 414 const bool catch_bp = false; 415 const bool throw_bp = true; 416 const bool is_internal = true; 417 418 if (!m_objc_exception_bp_sp) { 419 m_objc_exception_bp_sp = LanguageRuntime::CreateExceptionBreakpoint( 420 m_process->GetTarget(), GetLanguageType(), catch_bp, throw_bp, 421 is_internal); 422 if (m_objc_exception_bp_sp) 423 m_objc_exception_bp_sp->SetBreakpointKind("ObjC exception"); 424 } else 425 m_objc_exception_bp_sp->SetEnabled(true); 426 } 427 428 void AppleObjCRuntime::ClearExceptionBreakpoints() { 429 if (!m_process) 430 return; 431 432 if (m_objc_exception_bp_sp.get()) { 433 m_objc_exception_bp_sp->SetEnabled(false); 434 } 435 } 436 437 bool AppleObjCRuntime::ExceptionBreakpointsAreSet() { 438 return m_objc_exception_bp_sp && m_objc_exception_bp_sp->IsEnabled(); 439 } 440 441 bool AppleObjCRuntime::ExceptionBreakpointsExplainStop( 442 lldb::StopInfoSP stop_reason) { 443 if (!m_process) 444 return false; 445 446 if (!stop_reason || stop_reason->GetStopReason() != eStopReasonBreakpoint) 447 return false; 448 449 uint64_t break_site_id = stop_reason->GetValue(); 450 return m_process->GetBreakpointSiteList().BreakpointSiteContainsBreakpoint( 451 break_site_id, m_objc_exception_bp_sp->GetID()); 452 } 453 454 bool AppleObjCRuntime::CalculateHasNewLiteralsAndIndexing() { 455 if (!m_process) 456 return false; 457 458 Target &target(m_process->GetTarget()); 459 460 static ConstString s_method_signature( 461 "-[NSDictionary objectForKeyedSubscript:]"); 462 static ConstString s_arclite_method_signature( 463 "__arclite_objectForKeyedSubscript"); 464 465 SymbolContextList sc_list; 466 467 target.GetImages().FindSymbolsWithNameAndType(s_method_signature, 468 eSymbolTypeCode, sc_list); 469 if (sc_list.IsEmpty()) 470 target.GetImages().FindSymbolsWithNameAndType(s_arclite_method_signature, 471 eSymbolTypeCode, sc_list); 472 return !sc_list.IsEmpty(); 473 } 474 475 lldb::SearchFilterSP AppleObjCRuntime::CreateExceptionSearchFilter() { 476 Target &target = m_process->GetTarget(); 477 478 FileSpecList filter_modules; 479 if (target.GetArchitecture().GetTriple().getVendor() == llvm::Triple::Apple) { 480 filter_modules.Append(std::get<0>(GetExceptionThrowLocation())); 481 } 482 return target.GetSearchFilterForModuleList(&filter_modules); 483 } 484 485 ValueObjectSP AppleObjCRuntime::GetExceptionObjectForThread( 486 ThreadSP thread_sp) { 487 auto *cpp_runtime = m_process->GetLanguageRuntime(eLanguageTypeC_plus_plus); 488 if (!cpp_runtime) return ValueObjectSP(); 489 auto cpp_exception = cpp_runtime->GetExceptionObjectForThread(thread_sp); 490 if (!cpp_exception) return ValueObjectSP(); 491 492 auto descriptor = GetClassDescriptor(*cpp_exception); 493 if (!descriptor || !descriptor->IsValid()) return ValueObjectSP(); 494 495 while (descriptor) { 496 ConstString class_name(descriptor->GetClassName()); 497 if (class_name == "NSException") 498 return cpp_exception; 499 descriptor = descriptor->GetSuperclass(); 500 } 501 502 return ValueObjectSP(); 503 } 504 505 /// Utility method for error handling in GetBacktraceThreadFromException. 506 /// \param msg The message to add to the log. 507 /// \return An invalid ThreadSP to be returned from 508 /// GetBacktraceThreadFromException. 509 LLVM_NODISCARD 510 static ThreadSP FailExceptionParsing(llvm::StringRef msg) { 511 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); 512 LLDB_LOG(log, "Failed getting backtrace from exception: {0}", msg); 513 return ThreadSP(); 514 } 515 516 ThreadSP AppleObjCRuntime::GetBacktraceThreadFromException( 517 lldb::ValueObjectSP exception_sp) { 518 ValueObjectSP reserved_dict = 519 exception_sp->GetChildMemberWithName(ConstString("reserved"), true); 520 if (!reserved_dict) 521 return FailExceptionParsing("Failed to get 'reserved' member."); 522 523 reserved_dict = reserved_dict->GetSyntheticValue(); 524 if (!reserved_dict) 525 return FailExceptionParsing("Failed to get synthetic value."); 526 527 TypeSystemClang *clang_ast_context = 528 TypeSystemClang::GetScratch(*exception_sp->GetTargetSP()); 529 if (!clang_ast_context) 530 return FailExceptionParsing("Failed to get scratch AST."); 531 CompilerType objc_id = 532 clang_ast_context->GetBasicType(lldb::eBasicTypeObjCID); 533 ValueObjectSP return_addresses; 534 535 auto objc_object_from_address = [&exception_sp, &objc_id](uint64_t addr, 536 const char *name) { 537 Value value(addr); 538 value.SetCompilerType(objc_id); 539 auto object = ValueObjectConstResult::Create( 540 exception_sp->GetTargetSP().get(), value, ConstString(name)); 541 object = object->GetDynamicValue(eDynamicDontRunTarget); 542 return object; 543 }; 544 545 for (size_t idx = 0; idx < reserved_dict->GetNumChildren(); idx++) { 546 ValueObjectSP dict_entry = reserved_dict->GetChildAtIndex(idx, true); 547 548 DataExtractor data; 549 data.SetAddressByteSize(dict_entry->GetProcessSP()->GetAddressByteSize()); 550 Status error; 551 dict_entry->GetData(data, error); 552 if (error.Fail()) return ThreadSP(); 553 554 lldb::offset_t data_offset = 0; 555 auto dict_entry_key = data.GetAddress(&data_offset); 556 auto dict_entry_value = data.GetAddress(&data_offset); 557 558 auto key_nsstring = objc_object_from_address(dict_entry_key, "key"); 559 StreamString key_summary; 560 if (lldb_private::formatters::NSStringSummaryProvider( 561 *key_nsstring, key_summary, TypeSummaryOptions()) && 562 !key_summary.Empty()) { 563 if (key_summary.GetString() == "\"callStackReturnAddresses\"") { 564 return_addresses = objc_object_from_address(dict_entry_value, 565 "callStackReturnAddresses"); 566 break; 567 } 568 } 569 } 570 571 if (!return_addresses) 572 return FailExceptionParsing("Failed to get return addresses."); 573 auto frames_value = 574 return_addresses->GetChildMemberWithName(ConstString("_frames"), true); 575 if (!frames_value) 576 return FailExceptionParsing("Failed to get frames_value."); 577 addr_t frames_addr = frames_value->GetValueAsUnsigned(0); 578 auto count_value = 579 return_addresses->GetChildMemberWithName(ConstString("_cnt"), true); 580 if (!count_value) 581 return FailExceptionParsing("Failed to get count_value."); 582 size_t count = count_value->GetValueAsUnsigned(0); 583 auto ignore_value = 584 return_addresses->GetChildMemberWithName(ConstString("_ignore"), true); 585 if (!ignore_value) 586 return FailExceptionParsing("Failed to get ignore_value."); 587 size_t ignore = ignore_value->GetValueAsUnsigned(0); 588 589 size_t ptr_size = m_process->GetAddressByteSize(); 590 std::vector<lldb::addr_t> pcs; 591 for (size_t idx = 0; idx < count; idx++) { 592 Status error; 593 addr_t pc = m_process->ReadPointerFromMemory( 594 frames_addr + (ignore + idx) * ptr_size, error); 595 pcs.push_back(pc); 596 } 597 598 if (pcs.empty()) 599 return FailExceptionParsing("Failed to get PC list."); 600 601 ThreadSP new_thread_sp(new HistoryThread(*m_process, 0, pcs)); 602 m_process->GetExtendedThreadList().AddThread(new_thread_sp); 603 return new_thread_sp; 604 } 605 606 std::tuple<FileSpec, ConstString> 607 AppleObjCRuntime::GetExceptionThrowLocation() { 608 return std::make_tuple( 609 FileSpec("libobjc.A.dylib"), ConstString("objc_exception_throw")); 610 } 611 612 void AppleObjCRuntime::ReadObjCLibraryIfNeeded(const ModuleList &module_list) { 613 if (!HasReadObjCLibrary()) { 614 std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex()); 615 616 size_t num_modules = module_list.GetSize(); 617 for (size_t i = 0; i < num_modules; i++) { 618 auto mod = module_list.GetModuleAtIndex(i); 619 if (IsModuleObjCLibrary(mod)) { 620 ReadObjCLibrary(mod); 621 break; 622 } 623 } 624 } 625 } 626 627 void AppleObjCRuntime::ModulesDidLoad(const ModuleList &module_list) { 628 ReadObjCLibraryIfNeeded(module_list); 629 } 630