48 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
57 const llvm::Triple &triple_ref =
59 switch (triple_ref.getOS()) {
60 case llvm::Triple::Darwin:
61 case llvm::Triple::MacOSX:
62 case llvm::Triple::IOS:
63 case llvm::Triple::TvOS:
64 case llvm::Triple::WatchOS:
65 case llvm::Triple::XROS:
66 case llvm::Triple::BridgeOS:
67 create = triple_ref.getVendor() == llvm::Triple::Apple;
84 m_get_queues_handler(process), m_get_pending_items_handler(process),
85 m_get_item_info_handler(process), m_get_thread_item_info_handler(process),
87 m_lib_backtrace_recording_info(),
89 m_libdispatch_offsets(),
92 m_libdispatch_tsd_indexes(),
94 m_libdispatch_voucher_offsets() {
111 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
123 std::string dispatch_queue_name;
133 addr_t dispatch_queue_addr =
135 if (
error.Success()) {
139 addr_t pointer_to_label_address =
143 if (
error.Success()) {
157 dispatch_queue_name.erase(bytes_read);
161 return dispatch_queue_name;
168 libdispatch_queue_t_address =
170 if (!
error.Success()) {
173 return libdispatch_queue_t_address;
188 if (
error.Success()) {
209 "plo_pthread_tsd_base_address_offset",
228 if (thread_sp && thread_sp->GetFrameWithConcreteFrameIndex(0)) {
230 thread_sp->GetFrameWithConcreteFrameIndex(0)->GetSymbolContext(
231 eSymbolContextSymbol));
253 uint64_t dispatch_queue_addr =
255 if (
error.Success()) {
256 addr_t serialnum_address =
261 if (
error.Success()) {
262 queue_id = serialnum;
274 static ConstString g_dispatch_queue_offsets_symbol_name(
275 "dispatch_queue_offsets");
276 const Symbol *dispatch_queue_offsets_symbol =
nullptr;
282 libSystem_module_spec));
284 dispatch_queue_offsets_symbol = module_sp->FindFirstSymbolWithNameAndType(
289 if (dispatch_queue_offsets_symbol ==
nullptr) {
292 libdispatch_module_spec);
294 dispatch_queue_offsets_symbol = module_sp->FindFirstSymbolWithNameAndType(
297 if (dispatch_queue_offsets_symbol)
315 sizeof(memory_buffer),
316 error) ==
sizeof(memory_buffer)) {
330 static ConstString g_libpthread_layout_offsets_symbol_name(
331 "pthread_layout_offsets");
332 const Symbol *libpthread_layout_offsets_symbol =
nullptr;
336 libpthread_module_spec));
338 libpthread_layout_offsets_symbol =
339 module_sp->FindFirstSymbolWithNameAndType(
341 if (libpthread_layout_offsets_symbol) {
362 sizeof(memory_buffer),
363 error) ==
sizeof(memory_buffer)) {
378 static ConstString g_libdispatch_tsd_indexes_symbol_name(
379 "dispatch_tsd_indexes");
380 const Symbol *libdispatch_tsd_indexes_symbol =
nullptr;
384 libpthread_module_spec));
386 libdispatch_tsd_indexes_symbol = module_sp->FindFirstSymbolWithNameAndType(
388 if (libdispatch_tsd_indexes_symbol) {
408 uint16_t dti_version = 2;
414 if (
error.Success() && dti_version != UINT16_MAX)
416 dti_version = version;
425 scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(
eEncodingUint, 16);
426 CompilerType dispatch_tsd_indexes_s = scratch_ts_sp->CreateRecordType(
428 "__lldb_dispatch_tsd_indexes_s",
429 llvm::to_underlying(clang::TagTypeKind::Struct),
434 "dti_version", uint16,
437 "dti_queue_index", uint16,
440 "dti_voucher_index", uint16,
443 "dti_qos_class_index", uint16,
448 dispatch_tsd_indexes_s);
451 struct_reader.
GetField<uint16_t>(
"dti_version");
453 struct_reader.
GetField<uint16_t>(
"dti_queue_index");
455 struct_reader.
GetField<uint16_t>(
"dti_voucher_index");
457 struct_reader.
GetField<uint16_t>(
"dti_qos_class_index");
475 real_thread->GetExtendedBacktraceToken());
496 originating_thread_sp = std::make_shared<HistoryThread>(
498 originating_thread_sp->SetExtendedBacktraceToken(
500 originating_thread_sp->SetQueueName(
510 }
else if (type ==
"Application Specific Backtrace") {
512 real_thread->GetExtendedInfo();
514 if (!thread_extended_sp)
520 if (!thread_extended_info || !thread_extended_info->
GetSize())
523 std::vector<addr_t> app_specific_backtrace_pcs;
525 auto extract_frame_pc =
538 app_specific_backtrace_pcs.push_back(
pc);
543 if (!thread_extended_info->
ForEach(extract_frame_pc))
546 originating_thread_sp =
547 std::make_shared<HistoryThread>(*
m_process, real_thread->GetIndexID(),
548 app_specific_backtrace_pcs,
true);
549 originating_thread_sp->SetQueueName(type.
AsCString());
551 return originating_thread_sp;
577 return_thread_sp = std::make_shared<HistoryThread>(
589 return return_thread_sp;
596 if (type !=
"libdispatch")
597 return extended_thread_sp;
599 extended_thread_sp = std::make_shared<HistoryThread>(
600 *
m_process, queue_item_sp->GetEnqueueingThreadID(),
601 queue_item_sp->GetEnqueueingBacktrace());
602 extended_thread_sp->SetExtendedBacktraceToken(
603 queue_item_sp->GetItemThatEnqueuedThis());
604 extended_thread_sp->SetQueueName(queue_item_sp->GetQueueLabel().c_str());
605 extended_thread_sp->SetQueueID(queue_item_sp->GetEnqueueingQueueID());
609 return extended_thread_sp;
627 static ConstString introspection_dispatch_queue_info_version(
628 "__introspection_dispatch_queue_info_version");
637 queue_info_version_address =
642 static ConstString introspection_dispatch_queue_info_data_offset(
643 "__introspection_dispatch_queue_info_data_offset");
645 introspection_dispatch_queue_info_data_offset,
eSymbolTypeData, sc_list);
651 queue_info_data_offset_address =
656 static ConstString introspection_dispatch_item_info_version(
657 "__introspection_dispatch_item_info_version");
665 item_info_version_address =
670 static ConstString introspection_dispatch_item_info_data_offset(
671 "__introspection_dispatch_item_info_data_offset");
673 introspection_dispatch_item_info_data_offset,
eSymbolTypeData, sc_list);
679 item_info_data_offset_address =
691 if (
error.Success()) {
694 queue_info_data_offset_address, 2, 0,
error);
695 if (
error.Success()) {
699 if (
error.Success()) {
702 item_info_data_offset_address, 2, 0,
error);
703 if (!
error.Success()) {
718const std::vector<ConstString> &
741 if (
error.Success()) {
743 if (queue_info_pointer.
count > 0 &&
749 queue_info_pointer.
count, queue_list);
763 if (thread_sp->GetAssociatedWithLibdispatchQueue() !=
eLazyBoolNo) {
765 if (queue_list.
FindQueueByID(thread_sp->GetQueueID()).get() ==
768 thread_sp->GetQueueID(),
769 thread_sp->GetQueueName()));
770 if (thread_sp->ThreadHasQueueInformation()) {
771 queue_sp->SetKind(thread_sp->GetQueueKind());
772 queue_sp->SetLibdispatchQueueAddress(
773 thread_sp->GetQueueLibdispatchQueueAddress());
777 GetQueueKind(thread_sp->GetQueueLibdispatchQueueAddress()));
778 queue_sp->SetLibdispatchQueueAddress(
779 thread_sp->GetQueueLibdispatchQueueAddress());
807 if (
error.Success()) {
808 if (pending_items_pointer.
count > 0 &&
837 uint32_t version = extractor.
GetU32(&offset);
840 uint32_t item_size = extractor.
GetU32(&offset);
841 uint32_t start_of_array_offset = offset;
843 i < pending_items_pointer.
count) {
844 offset = start_of_array_offset + (i * item_size);
847 item.code_address = extractor.
GetAddress(&offset);
855 i < pending_items_pointer.
count) {
869 return pending_item_refs;
926 lldb::addr_t queues_buffer, uint64_t queues_buffer_size, uint64_t count,
930 Log *log =
GetLog(LLDBLog::SystemRuntime);
932 error) == queues_buffer_size &&
943 uint64_t queues_read = 0;
958 while (queues_read < count && offset < queues_buffer_size) {
959 offset_t start_of_this_item = offset;
961 uint32_t offset_to_next = extractor.
GetU32(&offset);
965 uint64_t serialnum = extractor.
GetU64(&offset);
966 uint32_t running_work_items_count = extractor.
GetU32(&offset);
967 uint32_t pending_work_items_count = extractor.
GetU32(&offset);
970 offset = start_of_this_item +
972 const char *queue_label = extractor.
GetCStr(&offset);
973 if (queue_label ==
nullptr)
976 offset_t start_of_next_item = start_of_this_item + offset_to_next;
977 offset = start_of_next_item;
980 "SystemRuntimeMacOSX::PopulateQueuesUsingLibBTR added "
981 "queue with dispatch_queue_t 0x%" PRIx64
982 ", serial number 0x%" PRIx64
983 ", running items %d, pending items %d, name '%s'",
984 queue, serialnum, running_work_items_count,
985 pending_work_items_count, queue_label);
988 new Queue(
m_process->shared_from_this(), serialnum, queue_label));
989 queue_sp->SetNumRunningWorkItems(running_work_items_count);
990 queue_sp->SetNumPendingWorkItems(pending_work_items_count);
991 queue_sp->SetLibdispatchQueueAddress(queue);
1028 "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.
void RegisterAbortWithPayloadFrameRecognizer(Process *process)
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