From e424a9b5ca05763480068f93afecca3ee9c4fe75 Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Sat, 10 Nov 2012 06:54:30 +0000 Subject: [PATCH] Add support for libdispatch version 4 structure layout for finding GCD queue names of threads to ProcessGDBRemote::GetDispatchQueueNameForThread() May need tweaking once this version is rolled out but visual inspection looks fine. llvm-svn: 167667 --- .../Process/gdb-remote/ProcessGDBRemote.cpp | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 3bae50f60810..30c17c9e98a7 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -2946,8 +2946,8 @@ ProcessGDBRemote::GetDispatchQueueNameForThread struct dispatch_queue_offsets_s { uint16_t dqo_version; - uint16_t dqo_label; - uint16_t dqo_label_size; + uint16_t dqo_label; // in version 1-3, offset to string; in version 4+, offset to a pointer to a string + uint16_t dqo_label_size; // in version 1-3, length of string; in version 4+, size of a (void*) in this process } dispatch_queue_offsets; @@ -2961,11 +2961,28 @@ ProcessGDBRemote::GetDispatchQueueNameForThread { data_offset = 0; lldb::addr_t queue_addr = data.GetAddress(&data_offset); - lldb::addr_t label_addr = queue_addr + dispatch_queue_offsets.dqo_label; - dispatch_queue_name.resize(dispatch_queue_offsets.dqo_label_size, '\0'); - size_t bytes_read = ReadMemory (label_addr, &dispatch_queue_name[0], dispatch_queue_offsets.dqo_label_size, error); - if (bytes_read < dispatch_queue_offsets.dqo_label_size) - dispatch_queue_name.erase (bytes_read); + if (dispatch_queue_offsets.dqo_version >= 4) + { + // libdispatch versions 4+, pointer to dispatch name is in the + // queue structure. + lldb::addr_t pointer_to_label_address = queue_addr + dispatch_queue_offsets.dqo_label; + if (ReadMemory (pointer_to_label_address, &memory_buffer, data.GetAddressByteSize(), error) == data.GetAddressByteSize()) + { + data_offset = 0; + lldb::addr_t label_addr = data.GetAddress(&data_offset); + ReadCStringFromMemory (label_addr, dispatch_queue_name, error); + } + } + else + { + // libdispatch versions 1-3, dispatch name is a fixed width char array + // in the queue structure. + lldb::addr_t label_addr = queue_addr + dispatch_queue_offsets.dqo_label; + dispatch_queue_name.resize(dispatch_queue_offsets.dqo_label_size, '\0'); + size_t bytes_read = ReadMemory (label_addr, &dispatch_queue_name[0], dispatch_queue_offsets.dqo_label_size, error); + if (bytes_read < dispatch_queue_offsets.dqo_label_size) + dispatch_queue_name.erase (bytes_read); + } } } }