47 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
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);
118 std::string dispatch_queue_name;
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->GetFrameWithConcreteFrameIndex(0)) {
225 thread_sp->GetFrameWithConcreteFrameIndex(0)->GetSymbolContext(
226 eSymbolContextSymbol));
248 uint64_t dispatch_queue_addr =
250 if (
error.Success()) {
251 addr_t serialnum_address =
256 if (
error.Success()) {
257 queue_id = serialnum;
269 static ConstString g_dispatch_queue_offsets_symbol_name(
270 "dispatch_queue_offsets");
271 const Symbol *dispatch_queue_offsets_symbol =
nullptr;
277 libSystem_module_spec));
279 dispatch_queue_offsets_symbol = module_sp->FindFirstSymbolWithNameAndType(
284 if (dispatch_queue_offsets_symbol ==
nullptr) {
287 libdispatch_module_spec);
289 dispatch_queue_offsets_symbol = module_sp->FindFirstSymbolWithNameAndType(
292 if (dispatch_queue_offsets_symbol)
310 sizeof(memory_buffer),
311 error) ==
sizeof(memory_buffer)) {
325 static ConstString g_libpthread_layout_offsets_symbol_name(
326 "pthread_layout_offsets");
327 const Symbol *libpthread_layout_offsets_symbol =
nullptr;
331 libpthread_module_spec));
333 libpthread_layout_offsets_symbol =
334 module_sp->FindFirstSymbolWithNameAndType(
336 if (libpthread_layout_offsets_symbol) {
357 sizeof(memory_buffer),
358 error) ==
sizeof(memory_buffer)) {
373 static ConstString g_libdispatch_tsd_indexes_symbol_name(
374 "dispatch_tsd_indexes");
375 const Symbol *libdispatch_tsd_indexes_symbol =
nullptr;
379 libpthread_module_spec));
381 libdispatch_tsd_indexes_symbol = module_sp->FindFirstSymbolWithNameAndType(
383 if (libdispatch_tsd_indexes_symbol) {
403 uint16_t dti_version = 2;
409 if (
error.Success() && dti_version != UINT16_MAX)
411 dti_version = version;
420 scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(
eEncodingUint, 16);
421 CompilerType dispatch_tsd_indexes_s = scratch_ts_sp->CreateRecordType(
423 "__lldb_dispatch_tsd_indexes_s",
424 llvm::to_underlying(clang::TagTypeKind::Struct),
429 "dti_version", uint16,
432 "dti_queue_index", uint16,
435 "dti_voucher_index", uint16,
438 "dti_qos_class_index", uint16,
443 dispatch_tsd_indexes_s);
446 struct_reader.
GetField<uint16_t>(
"dti_version");
448 struct_reader.
GetField<uint16_t>(
"dti_queue_index");
450 struct_reader.
GetField<uint16_t>(
"dti_voucher_index");
452 struct_reader.
GetField<uint16_t>(
"dti_qos_class_index");
470 real_thread->GetExtendedBacktraceToken());
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;
572 return_thread_sp = std::make_shared<HistoryThread>(
584 return return_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()) {
713const std::vector<ConstString> &
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());
802 if (
error.Success()) {
803 if (pending_items_pointer.
count > 0 &&
832 uint32_t version = extractor.
GetU32(&offset);
835 uint32_t item_size = extractor.
GetU32(&offset);
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;
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;
956 uint32_t offset_to_next = extractor.
GetU32(&offset);
960 uint64_t serialnum = extractor.
GetU64(&offset);
961 uint32_t running_work_items_count = extractor.
GetU32(&offset);
962 uint32_t pending_work_items_count = extractor.
GetU32(&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);
1023 "System runtime plugin for Mac OS X native libraries.",
CreateInstance);
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
#define LLDB_PLUGIN_DEFINE(PluginName)
void ReadLibpthreadOffsets()
lldb::addr_t m_dispatch_tsd_indexes_addr
lldb::ThreadSP GetExtendedBacktraceThread(lldb::ThreadSP thread, lldb_private::ConstString type) override
Return a Thread which shows the origin of this thread's creation.
PendingItemsForQueue GetPendingItemRefsForQueue(lldb::addr_t queue)
lldb::queue_id_t GetQueueIDFromThreadQAddress(lldb::addr_t dispatch_qaddr) override
Get the QueueID for the libdispatch queue given the thread's dispatch_qaddr.
~SystemRuntimeMacOSX() override
lldb_private::AppleGetPendingItemsHandler m_get_pending_items_handler
lldb_private::AppleGetQueuesHandler m_get_queues_handler
struct LibdispatchTSDIndexes m_libdispatch_tsd_indexes
lldb::addr_t m_page_to_free
void ReadLibdispatchTSDIndexesAddress()
void ReadLibdispatchTSDIndexes()
libBacktraceRecording_info m_lib_backtrace_recording_info
lldb_private::AppleGetItemInfoHandler m_get_item_info_handler
lldb::addr_t m_dispatch_queue_offsets_addr
std::string GetQueueNameFromThreadQAddress(lldb::addr_t dispatch_qaddr) override
Get the queue name for a thread given a thread's dispatch_qaddr.
void PopulateQueuesUsingLibBTR(lldb::addr_t queues_buffer, uint64_t queues_buffer_size, uint64_t count, lldb_private::QueueList &queue_list)
void Detach() override
Called before detaching from a process.
void ReadLibdispatchOffsetsAddress()
struct LibdispatchOffsets m_libdispatch_offsets
std::recursive_mutex m_mutex
void PopulatePendingItemsForQueue(lldb_private::Queue *queue) override
Get the pending work items for a libdispatch Queue.
const std::vector< lldb_private::ConstString > & GetExtendedBacktraceTypes() override
Return a list of thread origin extended backtraces that may be available.
lldb_private::AppleGetThreadItemInfoHandler m_get_thread_item_info_handler
lldb::addr_t GetLibdispatchQueueAddressFromThreadQAddress(lldb::addr_t dispatch_qaddr) override
Get the libdispatch_queue_t address for the queue given the thread's dispatch_qaddr.
void ReadLibdispatchOffsets()
bool BacktraceRecordingHeadersInitialized()
lldb::QueueKind GetQueueKind(lldb::addr_t dispatch_queue_addr) override
Retrieve the Queue kind for the queue at a thread's dispatch_qaddr.
ItemInfo ExtractItemInfoFromBuffer(lldb_private::DataExtractor &extractor)
lldb::addr_t m_libpthread_layout_offsets_addr
bool SafeToCallFunctionsOnThisThread(lldb::ThreadSP thread_sp) override
Determine whether it is safe to run an expression on a given thread.
void CompleteQueueItem(lldb_private::QueueItem *queue_item, lldb::addr_t item_ref) override
Complete the fields in a QueueItem.
uint64_t m_page_to_free_size
static lldb_private::SystemRuntime * CreateInstance(lldb_private::Process *process)
void AddThreadExtendedInfoPacketHints(lldb_private::StructuredData::ObjectSP dict) override
Add key-value pairs to the StructuredData dictionary object with information debugserver may need whe...
lldb::ThreadSP GetExtendedBacktraceFromItemRef(lldb::addr_t item_ref)
struct LibpthreadOffsets m_libpthread_offsets
lldb::ThreadSP GetExtendedBacktraceForQueueItem(lldb::QueueItemSP queue_item_sp, lldb_private::ConstString type) override
Get the extended backtrace thread for a QueueItem.
void Clear(bool clear_process)
lldb::user_id_t m_break_id
void ReadLibpthreadOffsetsAddress()
void PopulateQueueList(lldb_private::QueueList &queue_list) override
Populate the Process' QueueList with libdispatch / GCD queues that exist.
SystemRuntimeMacOSX(lldb_private::Process *process)
static llvm::StringRef GetPluginNameStatic()
A section + offset based address range class.
Address & GetBaseAddress()
Get accessor for the base address of the range.
A section + offset based address class.
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
GetItemInfoReturnInfo GetItemInfo(Thread &thread, lldb::addr_t item, lldb::addr_t page_to_free, uint64_t page_to_free_size, lldb_private::Status &error)
Get the information about a work item by calling __introspection_dispatch_queue_item_get_info.
GetPendingItemsReturnInfo GetPendingItems(Thread &thread, lldb::addr_t queue, lldb::addr_t page_to_free, uint64_t page_to_free_size, lldb_private::Status &error)
Get the list of pending items for a given queue via a call to __introspection_dispatch_queue_get_pend...
GetQueuesReturnInfo GetCurrentQueues(Thread &thread, lldb::addr_t page_to_free, uint64_t page_to_free_size, lldb_private::Status &error)
Get the list of queues that exist (with any active or pending items) via a call to introspection_get_...
GetThreadItemInfoReturnInfo GetThreadItemInfo(Thread &thread, lldb::tid_t thread_id, lldb::addr_t page_to_free, uint64_t page_to_free_size, lldb_private::Status &error)
Get the information about a work item by calling __introspection_dispatch_thread_get_item_info.
llvm::Triple & GetTriple()
Architecture triple accessor.
Generic representation of a type in a programming language.
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
A subclass of DataBuffer that stores a data buffer on the heap.
lldb::offset_t GetByteSize() const override
Get the number of bytes in the data buffer.
lldb::ModuleSP FindFirstModule(const ModuleSpec &module_spec) const
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list) const
A class that describes an executable image and its associated object and symbol files.
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
A plug-in interface definition class for object file parsers.
virtual ArchSpec GetArchitecture()=0
Get the ArchSpec for this object file.
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
RetType GetField(llvm::StringRef name, RetType fail_value=RetType())
A plug-in interface definition class for debugging a process.
ThreadList & GetThreadList()
size_t ReadCStringFromMemory(lldb::addr_t vm_addr, char *cstr, size_t cstr_max_len, Status &error)
Read a NULL terminated C string from memory.
virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
lldb::ByteOrder GetByteOrder() const
ThreadList::ThreadIterable Threads()
uint64_t ReadUnsignedIntegerFromMemory(lldb::addr_t load_addr, size_t byte_size, uint64_t fail_value, Status &error)
Reads an unsigned integer of the specified byte size from process memory.
Status ClearBreakpointSiteByID(lldb::user_id_t break_id)
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
virtual bool IsAlive()
Check if a process is still alive.
uint32_t GetAddressByteSize() const
Target & GetTarget()
Get the target object pointer for this module.
void SetThreadLabel(std::string thread_name)
void SetTargetQueueLabel(std::string queue_name)
void SetEnqueueingBacktrace(std::vector< lldb::addr_t > backtrace)
void SetStopID(uint32_t stop_id)
void SetEnqueueingThreadID(lldb::tid_t tid)
void SetQueueLabel(std::string queue_name)
void SetItemThatEnqueuedThis(lldb::addr_t address_of_item)
void SetEnqueueingQueueID(lldb::queue_id_t qid)
lldb::QueueSP FindQueueByID(lldb::queue_id_t qid)
Find a queue in the QueueList by QueueID.
void AddQueue(lldb::QueueSP queue)
Add a Queue to the QueueList.
void PushPendingQueueItem(lldb::QueueItemSP item)
lldb::addr_t GetLibdispatchQueueAddress() const
Get the dispatch_queue_t structure address for this Queue.
static lldb::TypeSystemClangSP GetForTarget(Target &target, std::optional< IsolatedASTKind > ast_kind=DefaultAST, bool create_on_demand=true)
Returns the scratch TypeSystemClang for the given target.
bool ForEach(std::function< bool(Object *object)> const &foreach_callback) const
bool GetValueForKeyAsInteger(llvm::StringRef key, IntType &result) const
void AddIntegerItem(llvm::StringRef key, T value)
Dictionary * GetAsDictionary()
std::shared_ptr< Object > ObjectSP
Defines a list of symbol context objects.
bool GetContextAtIndex(size_t idx, SymbolContext &sc) const
Get accessor for a symbol context at index idx.
void Clear()
Clear the object's state.
Defines a symbol context baton that can be handed other debug core functions.
ConstString GetFunctionName(Mangled::NamePreference preference=Mangled::ePreferDemangled) const
Find a name of the innermost function for the symbol context.
bool GetAddressRange(uint32_t scope, uint32_t range_idx, bool use_inline_block_range, AddressRange &range) const
Get the address range contained within a symbol context.
lldb::addr_t GetLoadAddress(Target *target) const
A plug-in interface definition class for system runtimes.
std::vector< ConstString > m_types
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, uint32_t stop_id=SectionLoadHistory::eStopIDNow)
const ModuleList & GetImages() const
Get accessor for the images for this process.
uint64_t ReadUnsignedIntegerFromMemory(const Address &addr, size_t integer_byte_size, uint64_t fail_value, Status &error, bool force_live_memory=false)
lldb::ThreadSP GetExpressionExecutionThread()
static clang::FieldDecl * AddFieldToRecordType(const CompilerType &type, llvm::StringRef name, const CompilerType &field_type, lldb::AccessType access, uint32_t bitfield_bit_size)
static bool CompleteTagDeclarationDefinition(const CompilerType &type)
static bool StartTagDeclarationDefinition(const CompilerType &type)
uint8_t * GetBytes()
Get a pointer to the data.
#define LLDB_INVALID_QUEUE_ID
#define LLDB_INVALID_BREAK_ID
#define LLDB_BREAK_ID_IS_VALID(bid)
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::shared_ptr< lldb_private::Queue > QueueSP
std::shared_ptr< lldb_private::Thread > ThreadSP
@ eLanguageTypeC
Non-standardized C, such as K&R.
@ eEncodingUint
unsigned integer
std::shared_ptr< lldb_private::TypeSystemClang > TypeSystemClangSP
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::QueueItem > QueueItemSP
std::string target_queue_label
std::vector< lldb::addr_t > enqueuing_callstack
uint64_t target_queue_serialnum
uint64_t enqueuing_queue_serialnum
std::string enqueuing_queue_label
lldb::addr_t item_that_enqueued_this
std::string enqueuing_thread_label
lldb::addr_t function_or_block
uint32_t enqueuing_callstack_frame_count
uint64_t enqueuing_thread_id
lldb::addr_t code_address
uint16_t dqo_serialnum_size
uint64_t dti_voucher_index
uint64_t dti_qos_class_index
uint16_t plo_pthread_tsd_entry_size
uint16_t plo_pthread_tsd_base_address_offset
uint16_t plo_pthread_tsd_base_offset
std::vector< ItemRefAndCodeAddress > item_refs_and_code_addresses
uint16_t queue_info_version
uint16_t queue_info_data_offset
uint16_t item_info_data_offset
uint16_t item_info_version
lldb::addr_t item_buffer_ptr
lldb::addr_t item_buffer_size
lldb::addr_t items_buffer_size
lldb::addr_t items_buffer_ptr
lldb::addr_t queues_buffer_ptr
lldb::addr_t queues_buffer_size
lldb::addr_t item_buffer_size
lldb::addr_t item_buffer_ptr