48 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
57 const llvm::Triple &triple_ref =
58 process->GetTarget().GetArchitecture().GetTriple();
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::BridgeOS:
66 case llvm::Triple::DriverKit:
67 case llvm::Triple::XROS:
68 create = triple_ref.getVendor() == llvm::Triple::Apple;
112 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
124 std::string dispatch_queue_name;
134 addr_t dispatch_queue_addr =
136 if (
error.Success()) {
140 addr_t pointer_to_label_address =
143 m_process->ReadPointerFromMemory(pointer_to_label_address,
error);
144 if (
error.Success()) {
145 m_process->ReadCStringFromMemory(label_addr, dispatch_queue_name,
155 m_process->ReadMemory(label_addr, &dispatch_queue_name[0],
158 dispatch_queue_name.erase(bytes_read);
162 return dispatch_queue_name;
169 libdispatch_queue_t_address =
171 if (!
error.Success()) {
174 return libdispatch_queue_t_address;
186 uint64_t width =
m_process->ReadUnsignedIntegerFromMemory(
189 if (
error.Success()) {
210 "plo_pthread_tsd_base_address_offset",
229 if (thread_sp && thread_sp->GetFrameWithConcreteFrameIndex(0)) {
231 thread_sp->GetFrameWithConcreteFrameIndex(0)->GetSymbolContext(
232 eSymbolContextSymbol));
254 uint64_t dispatch_queue_addr =
256 if (
error.Success()) {
257 addr_t serialnum_address =
262 if (
error.Success()) {
263 queue_id = serialnum;
275 static ConstString g_dispatch_queue_offsets_symbol_name(
276 "dispatch_queue_offsets");
277 const Symbol *dispatch_queue_offsets_symbol =
nullptr;
283 libSystem_module_spec));
285 dispatch_queue_offsets_symbol = module_sp->FindFirstSymbolWithNameAndType(
290 if (dispatch_queue_offsets_symbol ==
nullptr) {
292 module_sp =
m_process->GetTarget().GetImages().FindFirstModule(
293 libdispatch_module_spec);
295 dispatch_queue_offsets_symbol = module_sp->FindFirstSymbolWithNameAndType(
298 if (dispatch_queue_offsets_symbol)
316 sizeof(memory_buffer),
317 error) ==
sizeof(memory_buffer)) {
331 static ConstString g_libpthread_layout_offsets_symbol_name(
332 "pthread_layout_offsets");
333 const Symbol *libpthread_layout_offsets_symbol =
nullptr;
337 libpthread_module_spec));
339 libpthread_layout_offsets_symbol =
340 module_sp->FindFirstSymbolWithNameAndType(
342 if (libpthread_layout_offsets_symbol) {
363 sizeof(memory_buffer),
364 error) ==
sizeof(memory_buffer)) {
379 static ConstString g_libdispatch_tsd_indexes_symbol_name(
380 "dispatch_tsd_indexes");
381 const Symbol *libdispatch_tsd_indexes_symbol =
nullptr;
385 libpthread_module_spec));
387 libdispatch_tsd_indexes_symbol = module_sp->FindFirstSymbolWithNameAndType(
389 if (libdispatch_tsd_indexes_symbol) {
409 uint16_t dti_version = 2;
414 uint16_t version =
m_process->GetTarget().ReadUnsignedIntegerFromMemory (dti_struct_addr,
false, 2, UINT16_MAX,
error);
415 if (
error.Success() && dti_version != UINT16_MAX)
417 dti_version = version;
426 scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(
eEncodingUint, 16);
427 CompilerType dispatch_tsd_indexes_s = scratch_ts_sp->CreateRecordType(
429 "__lldb_dispatch_tsd_indexes_s",
430 llvm::to_underlying(clang::TagTypeKind::Struct),
435 "dti_version", uint16,
438 "dti_queue_index", uint16,
441 "dti_voucher_index", uint16,
444 "dti_qos_class_index", uint16,
449 dispatch_tsd_indexes_s);
452 struct_reader.
GetField<uint16_t>(
"dti_version");
454 struct_reader.
GetField<uint16_t>(
"dti_queue_index");
456 struct_reader.
GetField<uint16_t>(
"dti_voucher_index");
458 struct_reader.
GetField<uint16_t>(
"dti_qos_class_index");
476 real_thread->GetExtendedBacktraceToken());
479 m_process->GetThreadList().GetExpressionExecutionThread());
497 originating_thread_sp = std::make_shared<HistoryThread>(
499 originating_thread_sp->SetExtendedBacktraceToken(
501 originating_thread_sp->SetQueueName(
511 }
else if (type ==
"Application Specific Backtrace") {
513 real_thread->GetExtendedInfo();
515 if (!thread_extended_sp)
521 if (!thread_extended_info || !thread_extended_info->
GetSize())
524 std::vector<addr_t> app_specific_backtrace_pcs;
526 auto extract_frame_pc =
539 app_specific_backtrace_pcs.push_back(
pc);
544 if (!thread_extended_info->
ForEach(extract_frame_pc))
547 originating_thread_sp = std::make_shared<HistoryThread>(
548 *
m_process, real_thread->GetIndexID(), app_specific_backtrace_pcs,
550 originating_thread_sp->SetQueueName(type.
AsCString());
552 return originating_thread_sp;
561 m_process->GetThreadList().GetExpressionExecutionThread());
578 return_thread_sp = std::make_shared<HistoryThread>(
590 return return_thread_sp;
597 if (type !=
"libdispatch")
598 return extended_thread_sp;
600 extended_thread_sp = std::make_shared<HistoryThread>(
601 *
m_process, queue_item_sp->GetEnqueueingThreadID(),
602 queue_item_sp->GetEnqueueingBacktrace());
603 extended_thread_sp->SetExtendedBacktraceToken(
604 queue_item_sp->GetItemThatEnqueuedThis());
605 extended_thread_sp->SetQueueName(queue_item_sp->GetQueueLabel().c_str());
606 extended_thread_sp->SetQueueID(queue_item_sp->GetEnqueueingQueueID());
610 return extended_thread_sp;
628 static ConstString introspection_dispatch_queue_info_version(
629 "__introspection_dispatch_queue_info_version");
631 m_process->GetTarget().GetImages().FindSymbolsWithNameAndType(
641 static ConstString introspection_dispatch_queue_info_data_offset(
642 "__introspection_dispatch_queue_info_data_offset");
643 m_process->GetTarget().GetImages().FindSymbolsWithNameAndType(
644 introspection_dispatch_queue_info_data_offset,
eSymbolTypeData, sc_list);
653 static ConstString introspection_dispatch_item_info_version(
654 "__introspection_dispatch_item_info_version");
655 m_process->GetTarget().GetImages().FindSymbolsWithNameAndType(
665 static ConstString introspection_dispatch_item_info_data_offset(
666 "__introspection_dispatch_item_info_data_offset");
667 m_process->GetTarget().GetImages().FindSymbolsWithNameAndType(
668 introspection_dispatch_item_info_data_offset,
eSymbolTypeData, sc_list);
682 m_process->ReadUnsignedIntegerFromMemory(queue_info_version_address, 2,
684 if (
error.Success()) {
686 m_process->ReadUnsignedIntegerFromMemory(
687 queue_info_data_offset_address, 2, 0,
error);
688 if (
error.Success()) {
690 m_process->ReadUnsignedIntegerFromMemory(item_info_version_address,
692 if (
error.Success()) {
694 m_process->ReadUnsignedIntegerFromMemory(
695 item_info_data_offset_address, 2, 0,
error);
696 if (!
error.Success()) {
711const std::vector<ConstString> &
727 m_process->GetThreadList().GetExpressionExecutionThread());
734 if (
error.Success()) {
736 if (queue_info_pointer.
count > 0 &&
742 queue_info_pointer.
count, queue_list);
756 if (thread_sp->GetAssociatedWithLibdispatchQueue() !=
eLazyBoolNo) {
758 if (queue_list.
FindQueueByID(thread_sp->GetQueueID()).get() ==
761 thread_sp->GetQueueID(),
762 thread_sp->GetQueueName()));
763 if (thread_sp->ThreadHasQueueInformation()) {
764 queue_sp->SetKind(thread_sp->GetQueueKind());
765 queue_sp->SetLibdispatchQueueAddress(
766 thread_sp->GetQueueLibdispatchQueueAddress());
770 GetQueueKind(thread_sp->GetQueueLibdispatchQueueAddress()));
771 queue_sp->SetLibdispatchQueueAddress(
772 thread_sp->GetQueueLibdispatchQueueAddress());
792 m_process->GetThreadList().GetExpressionExecutionThread());
800 if (
error.Success()) {
801 if (pending_items_pointer.
count > 0 &&
830 uint32_t version = extractor.
GetU32(&offset);
833 uint32_t item_size = extractor.
GetU32(&offset);
834 uint32_t start_of_array_offset = offset;
836 i < pending_items_pointer.
count) {
837 offset = start_of_array_offset + (i * item_size);
840 item.code_address = extractor.
GetAddress(&offset);
848 i < pending_items_pointer.
count) {
862 return pending_item_refs;
887 m_process->GetThreadList().GetExpressionExecutionThread());
919 lldb::addr_t queues_buffer, uint64_t queues_buffer_size, uint64_t count,
925 error) == queues_buffer_size &&
936 uint64_t queues_read = 0;
951 while (queues_read < count && offset < queues_buffer_size) {
952 offset_t start_of_this_item = offset;
954 uint32_t offset_to_next = extractor.
GetU32(&offset);
958 uint64_t serialnum = extractor.
GetU64(&offset);
959 uint32_t running_work_items_count = extractor.
GetU32(&offset);
960 uint32_t pending_work_items_count = extractor.
GetU32(&offset);
963 offset = start_of_this_item +
965 const char *queue_label = extractor.
GetCStr(&offset);
966 if (queue_label ==
nullptr)
969 offset_t start_of_next_item = start_of_this_item + offset_to_next;
970 offset = start_of_next_item;
973 "SystemRuntimeMacOSX::PopulateQueuesUsingLibBTR added "
974 "queue with dispatch_queue_t 0x%" PRIx64
975 ", serial number 0x%" PRIx64
976 ", running items %d, pending items %d, name '%s'",
977 queue, serialnum, running_work_items_count,
978 pending_work_items_count, queue_label);
981 new Queue(
m_process->shared_from_this(), serialnum, queue_label));
982 queue_sp->SetNumRunningWorkItems(running_work_items_count);
983 queue_sp->SetNumPendingWorkItems(pending_work_items_count);
984 queue_sp->SetLibdispatchQueueAddress(queue);
1021 "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()
struct LibdispatchVoucherOffsets m_libdispatch_voucher_offsets
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
lldb::addr_t m_dispatch_voucher_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 class.
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
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.
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.
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.
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.
Address GetFunctionOrSymbolAddress() const
Get the address of the function or symbol represented by this symbol context.
lldb::addr_t GetLoadAddress(Target *target) const
SystemRuntime(Process *process)
Construct with a process.
std::vector< ConstString > m_types
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.
@ Calls
PCs are call addresses.
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
std::vector< ItemRefAndCodeAddress > item_refs_and_code_addresses
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