31#include "llvm/Support/Error.h"
50 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
59 const llvm::Triple &triple_ref =
60 process->GetTarget().GetArchitecture().GetTriple();
61 switch (triple_ref.getOS()) {
62 case llvm::Triple::Darwin:
63 case llvm::Triple::MacOSX:
64 case llvm::Triple::IOS:
65 case llvm::Triple::TvOS:
66 case llvm::Triple::WatchOS:
67 case llvm::Triple::BridgeOS:
68 case llvm::Triple::DriverKit:
69 case llvm::Triple::XROS:
70 create = triple_ref.getVendor() == llvm::Triple::Apple;
114 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
126 std::string dispatch_queue_name;
135 llvm::Expected<lldb::addr_t> dispatch_queue_addr =
136 m_process->ReadPointerFromMemory(dispatch_qaddr);
137 if (!dispatch_queue_addr) {
138 llvm::consumeError(dispatch_queue_addr.takeError());
139 return dispatch_queue_name;
144 addr_t pointer_to_label_address =
146 llvm::Expected<lldb::addr_t> label_addr =
147 m_process->ReadPointerFromMemory(pointer_to_label_address);
150 m_process->ReadCStringFromMemory(*label_addr, dispatch_queue_name,
153 llvm::consumeError(label_addr.takeError());
163 m_process->ReadMemory(label_addr, &dispatch_queue_name[0],
166 dispatch_queue_name.erase(bytes_read);
169 return dispatch_queue_name;
174 return llvm::expectedToOptional(
175 m_process->ReadPointerFromMemory(dispatch_qaddr))
188 uint64_t width =
m_process->ReadUnsignedIntegerFromMemory(
191 if (
error.Success()) {
212 "plo_pthread_tsd_base_address_offset",
231 if (thread_sp && thread_sp->GetFrameWithConcreteFrameIndex(0)) {
233 thread_sp->GetFrameWithConcreteFrameIndex(0)->GetSymbolContext(
234 eSymbolContextSymbol));
256 llvm::Expected<lldb::addr_t> dispatch_queue_addr =
257 m_process->ReadPointerFromMemory(dispatch_qaddr);
258 if (!dispatch_queue_addr) {
259 llvm::consumeError(dispatch_queue_addr.takeError());
262 addr_t serialnum_address =
267 if (
error.Success()) {
268 queue_id = serialnum;
279 static ConstString g_dispatch_queue_offsets_symbol_name(
280 "dispatch_queue_offsets");
281 const Symbol *dispatch_queue_offsets_symbol =
nullptr;
287 libSystem_module_spec));
289 dispatch_queue_offsets_symbol = module_sp->FindFirstSymbolWithNameAndType(
294 if (dispatch_queue_offsets_symbol ==
nullptr) {
296 module_sp =
m_process->GetTarget().GetImages().FindFirstModule(
297 libdispatch_module_spec);
299 dispatch_queue_offsets_symbol = module_sp->FindFirstSymbolWithNameAndType(
302 if (dispatch_queue_offsets_symbol)
320 sizeof(memory_buffer),
321 error) ==
sizeof(memory_buffer)) {
335 static ConstString g_libpthread_layout_offsets_symbol_name(
336 "pthread_layout_offsets");
337 const Symbol *libpthread_layout_offsets_symbol =
nullptr;
341 libpthread_module_spec));
343 libpthread_layout_offsets_symbol =
344 module_sp->FindFirstSymbolWithNameAndType(
346 if (libpthread_layout_offsets_symbol) {
367 sizeof(memory_buffer),
368 error) ==
sizeof(memory_buffer)) {
383 static ConstString g_libdispatch_tsd_indexes_symbol_name(
384 "dispatch_tsd_indexes");
385 const Symbol *libdispatch_tsd_indexes_symbol =
nullptr;
389 libpthread_module_spec));
391 libdispatch_tsd_indexes_symbol = module_sp->FindFirstSymbolWithNameAndType(
393 if (libdispatch_tsd_indexes_symbol) {
413 uint16_t dti_version = 2;
418 uint16_t version =
m_process->GetTarget().ReadUnsignedIntegerFromMemory (dti_struct_addr,
false, 2, UINT16_MAX,
error);
419 if (
error.Success() && dti_version != UINT16_MAX)
421 dti_version = version;
430 scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(
eEncodingUint, 16);
431 CompilerType dispatch_tsd_indexes_s = scratch_ts_sp->CreateRecordType(
433 llvm::to_underlying(clang::TagTypeKind::Struct),
438 "dti_version", uint16, 0);
440 "dti_queue_index", uint16, 0);
442 "dti_voucher_index", uint16, 0);
444 "dti_qos_class_index", uint16, 0);
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());
478 m_process->GetThreadList().GetExpressionExecutionThread());
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)
518 thread_extended_sp->GetAsArray();
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 = std::make_shared<HistoryThread>(
547 *
m_process, real_thread->GetIndexID(), app_specific_backtrace_pcs,
549 originating_thread_sp->SetQueueName(type.
AsCString(
nullptr));
551 return originating_thread_sp;
560 m_process->GetThreadList().GetExpressionExecutionThread());
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;
632 static ConstString introspection_dispatch_queue_info_version(
633 "__introspection_dispatch_queue_info_version");
635 module_sp->FindSymbolsWithNameAndType(
645 static ConstString introspection_dispatch_queue_info_data_offset(
646 "__introspection_dispatch_queue_info_data_offset");
647 module_sp->FindSymbolsWithNameAndType(
648 introspection_dispatch_queue_info_data_offset,
eSymbolTypeData, sc_list);
657 static ConstString introspection_dispatch_item_info_version(
658 "__introspection_dispatch_item_info_version");
659 module_sp->FindSymbolsWithNameAndType(
669 static ConstString introspection_dispatch_item_info_data_offset(
670 "__introspection_dispatch_item_info_data_offset");
671 module_sp->FindSymbolsWithNameAndType(
672 introspection_dispatch_item_info_data_offset,
eSymbolTypeData, sc_list);
686 m_process->ReadUnsignedIntegerFromMemory(queue_info_version_address, 2,
688 if (
error.Success()) {
690 m_process->ReadUnsignedIntegerFromMemory(
691 queue_info_data_offset_address, 2, 0,
error);
692 if (
error.Success()) {
694 m_process->ReadUnsignedIntegerFromMemory(item_info_version_address,
696 if (
error.Success()) {
698 m_process->ReadUnsignedIntegerFromMemory(
699 item_info_data_offset_address, 2, 0,
error);
700 if (!
error.Success()) {
715const std::vector<ConstString> &
731 m_process->GetThreadList().GetExpressionExecutionThread());
738 if (
error.Success()) {
740 if (queue_info_pointer.
count > 0 &&
746 queue_info_pointer.
count, queue_list);
760 if (thread_sp->GetAssociatedWithLibdispatchQueue() !=
eLazyBoolNo) {
762 if (queue_list.
FindQueueByID(thread_sp->GetQueueID()).get() ==
765 thread_sp->GetQueueID(),
766 thread_sp->GetQueueName()));
767 if (thread_sp->ThreadHasQueueInformation()) {
768 queue_sp->SetKind(thread_sp->GetQueueKind());
769 queue_sp->SetLibdispatchQueueAddress(
770 thread_sp->GetQueueLibdispatchQueueAddress());
774 GetQueueKind(thread_sp->GetQueueLibdispatchQueueAddress()));
775 queue_sp->SetLibdispatchQueueAddress(
776 thread_sp->GetQueueLibdispatchQueueAddress());
796 m_process->GetThreadList().GetExpressionExecutionThread());
804 if (
error.Success()) {
805 if (pending_items_pointer.
count > 0 &&
834 uint32_t version = extractor.
GetU32(&offset);
837 uint32_t item_size = extractor.
GetU32(&offset);
838 uint32_t start_of_array_offset = offset;
840 i < pending_items_pointer.
count) {
841 offset = start_of_array_offset + (i * item_size);
844 item.code_address = extractor.
GetAddress(&offset);
852 i < pending_items_pointer.
count) {
866 return pending_item_refs;
891 m_process->GetThreadList().GetExpressionExecutionThread());
923 lldb::addr_t queues_buffer, uint64_t queues_buffer_size, uint64_t count,
929 error) == queues_buffer_size &&
940 uint64_t queues_read = 0;
955 while (queues_read < count && offset < queues_buffer_size) {
956 offset_t start_of_this_item = offset;
958 uint32_t offset_to_next = extractor.
GetU32(&offset);
962 uint64_t serialnum = extractor.
GetU64(&offset);
963 uint32_t running_work_items_count = extractor.
GetU32(&offset);
964 uint32_t pending_work_items_count = extractor.
GetU32(&offset);
967 offset = start_of_this_item +
969 const char *queue_label = extractor.
GetCStr(&offset);
970 if (queue_label ==
nullptr)
973 offset_t start_of_next_item = start_of_this_item + offset_to_next;
974 offset = start_of_next_item;
977 "SystemRuntimeMacOSX::PopulateQueuesUsingLibBTR added "
978 "queue with dispatch_queue_t 0x%" PRIx64
979 ", serial number 0x%" PRIx64
980 ", running items %d, pending items %d, name '%s'",
981 queue, serialnum, running_work_items_count,
982 pending_work_items_count, queue_label);
985 new Queue(
m_process->shared_from_this(), serialnum, queue_label));
986 queue_sp->SetNumRunningWorkItems(running_work_items_count);
987 queue_sp->SetNumPendingWorkItems(pending_work_items_count);
988 queue_sp->SetLibdispatchQueueAddress(queue);
1025 "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) 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
Finds the first module whose file specification matches module_spec.
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
const ModuleList & GetImages() const
Get accessor for the images for this process.
static bool CompleteTagDeclarationDefinition(const CompilerType &type)
static bool StartTagDeclarationDefinition(const CompilerType &type)
static clang::FieldDecl * AddFieldToRecordType(const CompilerType &type, llvm::StringRef name, const CompilerType &field_type, uint32_t bitfield_bit_size)
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