47 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
51 create = (object_file->
GetStrata() == ObjectFile::eStrataUser);
56 const llvm::Triple &triple_ref =
58 switch (triple_ref.getOS()) {
59 case llvm::Triple::Darwin:
60 case llvm::Triple::MacOSX:
61 case llvm::Triple::IOS:
62 case llvm::Triple::TvOS:
63 case llvm::Triple::WatchOS:
65 create = triple_ref.getVendor() == llvm::Triple::Apple;
82 m_get_queues_handler(process), m_get_pending_items_handler(process),
83 m_get_item_info_handler(process), m_get_thread_item_info_handler(process),
85 m_lib_backtrace_recording_info(),
87 m_libdispatch_offsets(),
90 m_libdispatch_tsd_indexes(),
92 m_libdispatch_voucher_offsets() {}
106 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
128 addr_t dispatch_queue_addr =
130 if (
error.Success()) {
134 addr_t pointer_to_label_address =
138 if (
error.Success()) {
152 dispatch_queue_name.erase(bytes_read);
156 return dispatch_queue_name;
163 libdispatch_queue_t_address =
165 if (!
error.Success()) {
168 return libdispatch_queue_t_address;
183 if (
error.Success()) {
204 "plo_pthread_tsd_base_address_offset",
223 if (thread_sp && thread_sp->GetStackFrameCount() > 0 &&
224 thread_sp->GetFrameWithConcreteFrameIndex(0)) {
226 thread_sp->GetFrameWithConcreteFrameIndex(0)->GetSymbolContext(
227 eSymbolContextSymbol));
249 uint64_t dispatch_queue_addr =
251 if (
error.Success()) {
252 addr_t serialnum_address =
257 if (
error.Success()) {
258 queue_id = serialnum;
270 static ConstString g_dispatch_queue_offsets_symbol_name(
271 "dispatch_queue_offsets");
272 const Symbol *dispatch_queue_offsets_symbol =
nullptr;
278 libSystem_module_spec));
280 dispatch_queue_offsets_symbol = module_sp->FindFirstSymbolWithNameAndType(
285 if (dispatch_queue_offsets_symbol ==
nullptr) {
288 libdispatch_module_spec);
290 dispatch_queue_offsets_symbol = module_sp->FindFirstSymbolWithNameAndType(
293 if (dispatch_queue_offsets_symbol)
311 sizeof(memory_buffer),
312 error) ==
sizeof(memory_buffer)) {
326 static ConstString g_libpthread_layout_offsets_symbol_name(
327 "pthread_layout_offsets");
328 const Symbol *libpthread_layout_offsets_symbol =
nullptr;
332 libpthread_module_spec));
334 libpthread_layout_offsets_symbol =
335 module_sp->FindFirstSymbolWithNameAndType(
337 if (libpthread_layout_offsets_symbol) {
358 sizeof(memory_buffer),
359 error) ==
sizeof(memory_buffer)) {
374 static ConstString g_libdispatch_tsd_indexes_symbol_name(
375 "dispatch_tsd_indexes");
376 const Symbol *libdispatch_tsd_indexes_symbol =
nullptr;
380 libpthread_module_spec));
382 libdispatch_tsd_indexes_symbol = module_sp->FindFirstSymbolWithNameAndType(
384 if (libdispatch_tsd_indexes_symbol) {
410 if (
error.Success() && dti_version != UINT16_MAX)
412 dti_version = version;
417 TypeSystemClangSP scratch_ts_sp =
421 scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(
eEncodingUint, 16);
422 CompilerType dispatch_tsd_indexes_s = scratch_ts_sp->CreateRecordType(
424 "__lldb_dispatch_tsd_indexes_s", clang::TTK_Struct,
427 TypeSystemClang::StartTagDeclarationDefinition(dispatch_tsd_indexes_s);
428 TypeSystemClang::AddFieldToRecordType(dispatch_tsd_indexes_s,
429 "dti_version", uint16,
431 TypeSystemClang::AddFieldToRecordType(dispatch_tsd_indexes_s,
432 "dti_queue_index", uint16,
434 TypeSystemClang::AddFieldToRecordType(dispatch_tsd_indexes_s,
435 "dti_voucher_index", uint16,
437 TypeSystemClang::AddFieldToRecordType(dispatch_tsd_indexes_s,
438 "dti_qos_class_index", uint16,
440 TypeSystemClang::CompleteTagDeclarationDefinition(dispatch_tsd_indexes_s);
443 dispatch_tsd_indexes_s);
459 ThreadSP originating_thread_sp;
470 real_thread->GetExtendedBacktraceToken());
472 ThreadSP cur_thread_sp(
491 originating_thread_sp = std::make_shared<HistoryThread>(
493 originating_thread_sp->SetExtendedBacktraceToken(
495 originating_thread_sp->SetQueueName(
505 }
else if (type ==
"Application Specific Backtrace") {
507 real_thread->GetExtendedInfo();
509 if (!thread_extended_sp)
515 if (!thread_extended_info || !thread_extended_info->
GetSize())
518 std::vector<addr_t> app_specific_backtrace_pcs;
520 auto extract_frame_pc =
533 app_specific_backtrace_pcs.push_back(
pc);
538 if (!thread_extended_info->
ForEach(extract_frame_pc))
541 originating_thread_sp =
542 std::make_shared<HistoryThread>(*
m_process, real_thread->GetIndexID(),
543 app_specific_backtrace_pcs,
true);
544 originating_thread_sp->SetQueueName(type.
AsCString());
546 return originating_thread_sp;
551 ThreadSP return_thread_sp;
554 ThreadSP cur_thread_sp(
572 return_thread_sp = std::make_shared<HistoryThread>(
584 return return_thread_sp;
590 ThreadSP extended_thread_sp;
591 if (type !=
"libdispatch")
592 return extended_thread_sp;
594 extended_thread_sp = std::make_shared<HistoryThread>(
595 *
m_process, queue_item_sp->GetEnqueueingThreadID(),
596 queue_item_sp->GetEnqueueingBacktrace());
597 extended_thread_sp->SetExtendedBacktraceToken(
598 queue_item_sp->GetItemThatEnqueuedThis());
599 extended_thread_sp->SetQueueName(queue_item_sp->GetQueueLabel().c_str());
600 extended_thread_sp->SetQueueID(queue_item_sp->GetEnqueueingQueueID());
604 return extended_thread_sp;
622 static ConstString introspection_dispatch_queue_info_version(
623 "__introspection_dispatch_queue_info_version");
632 queue_info_version_address =
637 static ConstString introspection_dispatch_queue_info_data_offset(
638 "__introspection_dispatch_queue_info_data_offset");
640 introspection_dispatch_queue_info_data_offset,
eSymbolTypeData, sc_list);
646 queue_info_data_offset_address =
651 static ConstString introspection_dispatch_item_info_version(
652 "__introspection_dispatch_item_info_version");
660 item_info_version_address =
665 static ConstString introspection_dispatch_item_info_data_offset(
666 "__introspection_dispatch_item_info_data_offset");
668 introspection_dispatch_item_info_data_offset,
eSymbolTypeData, sc_list);
674 item_info_data_offset_address =
686 if (
error.Success()) {
689 queue_info_data_offset_address, 2, 0,
error);
690 if (
error.Success()) {
694 if (
error.Success()) {
697 item_info_data_offset_address, 2, 0,
error);
698 if (!
error.Success()) {
713 const std::vector<ConstString> &
728 ThreadSP cur_thread_sp(
736 if (
error.Success()) {
738 if (queue_info_pointer.
count > 0 &&
744 queue_info_pointer.
count, queue_list);
758 if (thread_sp->GetAssociatedWithLibdispatchQueue() !=
eLazyBoolNo) {
760 if (queue_list.
FindQueueByID(thread_sp->GetQueueID()).get() ==
763 thread_sp->GetQueueID(),
764 thread_sp->GetQueueName()));
765 if (thread_sp->ThreadHasQueueInformation()) {
766 queue_sp->SetKind(thread_sp->GetQueueKind());
767 queue_sp->SetLibdispatchQueueAddress(
768 thread_sp->GetQueueLibdispatchQueueAddress());
772 GetQueueKind(thread_sp->GetQueueLibdispatchQueueAddress()));
773 queue_sp->SetLibdispatchQueueAddress(
774 thread_sp->GetQueueLibdispatchQueueAddress());
793 ThreadSP cur_thread_sp(
802 if (
error.Success()) {
803 if (pending_items_pointer.
count > 0 &&
836 uint32_t start_of_array_offset = offset;
838 i < pending_items_pointer.
count) {
839 offset = start_of_array_offset + (i * item_size);
842 item.code_address = extractor.
GetAddress(&offset);
850 i < pending_items_pointer.
count) {
864 return pending_item_refs;
876 QueueItemSP queue_item_sp(
new QueueItem(queue->shared_from_this(),
888 ThreadSP cur_thread_sp(
921 lldb::addr_t queues_buffer, uint64_t queues_buffer_size, uint64_t count,
925 Log *log =
GetLog(LLDBLog::SystemRuntime);
927 error) == queues_buffer_size &&
938 uint64_t queues_read = 0;
953 while (queues_read < count && offset < queues_buffer_size) {
954 offset_t start_of_this_item = offset;
960 uint64_t serialnum = extractor.
GetU64(&offset);
965 offset = start_of_this_item +
967 const char *queue_label = extractor.
GetCStr(&offset);
968 if (queue_label ==
nullptr)
971 offset_t start_of_next_item = start_of_this_item + offset_to_next;
972 offset = start_of_next_item;
975 "SystemRuntimeMacOSX::PopulateQueuesUsingLibBTR added "
976 "queue with dispatch_queue_t 0x%" PRIx64
977 ", serial number 0x%" PRIx64
978 ", running items %d, pending items %d, name '%s'",
979 queue, serialnum, running_work_items_count,
980 pending_work_items_count, queue_label);
983 new Queue(
m_process->shared_from_this(), serialnum, queue_label));
984 queue_sp->SetNumRunningWorkItems(running_work_items_count);
985 queue_sp->SetNumPendingWorkItems(pending_work_items_count);
986 queue_sp->SetLibdispatchQueueAddress(queue);
1021 PluginManager::RegisterPlugin(
1023 "System runtime plugin for Mac OS X native libraries.",
CreateInstance);