diff options
author | Jason Molenda <jmolenda@apple.com> | 2013-11-19 05:44:41 +0000 |
---|---|---|
committer | Jason Molenda <jmolenda@apple.com> | 2013-11-19 05:44:41 +0000 |
commit | a6e9130d5243beccb72b68eee7c62b439dd5f32f (patch) | |
tree | 17533c76be47b5d32fb76af0ab3c43f450d993f8 /lldb/source | |
parent | 1f54e805f25c7381e2dbf0d2065f4c1af8ba095a (diff) | |
download | bcm5719-llvm-a6e9130d5243beccb72b68eee7c62b439dd5f32f.tar.gz bcm5719-llvm-a6e9130d5243beccb72b68eee7c62b439dd5f32f.zip |
Add logging for the SB API which creates extended
threads.
Take a stab at fixing the too-soon freeing of the extended
backtrace thread list in Process.
<rdar://problem/15496603>
llvm-svn: 195104
Diffstat (limited to 'lldb/source')
-rw-r--r-- | lldb/source/API/SBThread.cpp | 20 | ||||
-rw-r--r-- | lldb/source/Plugins/Process/Utility/HistoryThread.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Plugins/Process/Utility/HistoryThread.h | 13 | ||||
-rw-r--r-- | lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp | 42 | ||||
-rw-r--r-- | lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h | 6 | ||||
-rw-r--r-- | lldb/source/Target/Process.cpp | 5 |
6 files changed, 73 insertions, 16 deletions
diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp index 93e5646fcac..4170d5b230b 100644 --- a/lldb/source/API/SBThread.cpp +++ b/lldb/source/API/SBThread.cpp @@ -1305,10 +1305,20 @@ SBThread::GetExtendedBacktraceThread (const char *type) if (runtime) { ThreadSP new_thread_sp (runtime->GetExtendedBacktraceThread (real_thread, type_const)); - // Save this in the Process' ExtendedThreadList so a strong pointer retains the - // object. - process->GetExtendedThreadList().AddThread (new_thread_sp); - sb_origin_thread.SetThread (new_thread_sp); + if (new_thread_sp) + { + // Save this in the Process' ExtendedThreadList so a strong pointer retains the + // object. + process->GetExtendedThreadList().AddThread (new_thread_sp); + sb_origin_thread.SetThread (new_thread_sp); + if (log) + { + const char *queue_name = new_thread_sp->GetQueueName(); + if (queue_name == NULL) + queue_name = ""; + log->Printf ("SBThread(%p)::GetExtendedBacktraceThread() => new extended Thread created (%p) with queue_id 0x%" PRIx64 " queue name '%s'", exe_ctx.GetThreadPtr(), new_thread_sp.get(), new_thread_sp->GetQueueID(), queue_name); + } + } } } } @@ -1316,7 +1326,7 @@ SBThread::GetExtendedBacktraceThread (const char *type) else { if (log) - log->Printf ("SBThread(%p)::GetExtendedBacktrace() => error: process is running", exe_ctx.GetThreadPtr()); + log->Printf ("SBThread(%p)::GetExtendedBacktraceThread() => error: process is running", exe_ctx.GetThreadPtr()); } } diff --git a/lldb/source/Plugins/Process/Utility/HistoryThread.cpp b/lldb/source/Plugins/Process/Utility/HistoryThread.cpp index bb8d312fdac..521136295fd 100644 --- a/lldb/source/Plugins/Process/Utility/HistoryThread.cpp +++ b/lldb/source/Plugins/Process/Utility/HistoryThread.cpp @@ -34,7 +34,8 @@ HistoryThread::HistoryThread (lldb_private::Process &process, m_extended_unwind_token (LLDB_INVALID_ADDRESS), m_queue_name (), m_thread_name (), - m_originating_unique_thread_id (tid) + m_originating_unique_thread_id (tid), + m_queue_id (LLDB_INVALID_QUEUE_ID) { m_unwinder_ap.reset (new HistoryUnwind (*this, pcs, stop_id, stop_id_is_valid)); Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); diff --git a/lldb/source/Plugins/Process/Utility/HistoryThread.h b/lldb/source/Plugins/Process/Utility/HistoryThread.h index e6f46e27237..01fdd160870 100644 --- a/lldb/source/Plugins/Process/Utility/HistoryThread.h +++ b/lldb/source/Plugins/Process/Utility/HistoryThread.h @@ -65,6 +65,18 @@ public: m_queue_name = name; } + lldb::queue_id_t + GetQueueID () + { + return m_queue_id; + } + + void + SetQueueID (lldb::queue_id_t queue) + { + m_queue_id = queue; + } + const char * GetThreadName () { @@ -94,6 +106,7 @@ protected: std::string m_queue_name; std::string m_thread_name; lldb::tid_t m_originating_unique_thread_id; + lldb::queue_id_t m_queue_id; }; } // namespace lldb_private diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp index 73f24550fb4..388264a2d95 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp @@ -198,7 +198,15 @@ SystemRuntimeMacOSX::ParseLdiHeaders () m_ldi_header.item_offsets.pthread_id = ldi_extractor.GetU16(&offset); m_ldi_header.item_offsets.enqueueing_thread_dispatch_queue_t = ldi_extractor.GetU16(&offset); m_ldi_header.item_offsets.enqueueing_thread_dispatch_block_ptr = ldi_extractor.GetU16(&offset); - + + if (ldi_header.GetByteSize () > offset) + { + m_ldi_header.item_offsets.queue_id_from_thread_info = ldi_extractor.GetU16(&offset); + } + else + { + m_ldi_header.item_offsets.queue_id_from_thread_info = 0xffff; + } } } } @@ -376,8 +384,28 @@ SystemRuntimeMacOSX::SetNewThreadExtendedBacktraceToken (ThreadSP original_threa } } +void +SystemRuntimeMacOSX::SetNewThreadQueueID (ThreadSP original_thread_sp, ThreadSP new_extended_thread_sp) +{ + queue_id_t queue_id = LLDB_INVALID_QUEUE_ID; + addr_t enqueued_item_ptr = GetThreadCreatorItem (original_thread_sp); + if (enqueued_item_ptr != LLDB_INVALID_ADDRESS && m_ldi_header.item_offsets.queue_id_from_thread_info != 0xffff) + { + Error error; + queue_id = m_process->ReadUnsignedIntegerFromMemory (enqueued_item_ptr + m_ldi_header.item_offsets.queue_id_from_thread_info, 8, LLDB_INVALID_QUEUE_ID, error); + if (!error.Success()) + queue_id = LLDB_INVALID_QUEUE_ID; + } + + if (queue_id != LLDB_INVALID_QUEUE_ID) + { + new_extended_thread_sp->SetQueueID (queue_id); + } +} + + lldb::tid_t -SystemRuntimeMacOSX::GetNewThreadUniquethreadID (ThreadSP original_thread_sp) +SystemRuntimeMacOSX::GetNewThreadUniqueThreadID (ThreadSP original_thread_sp) { tid_t ret = LLDB_INVALID_THREAD_ID; addr_t enqueued_item_ptr = GetThreadCreatorItem (original_thread_sp); @@ -404,14 +432,14 @@ SystemRuntimeMacOSX::GetExtendedBacktraceThread (ThreadSP original_thread_sp, Co if (bt.pcs.size() == 0) return new_extended_thread_sp; - tid_t unique_thread_id = GetNewThreadUniquethreadID (original_thread_sp); + tid_t unique_thread_id = GetNewThreadUniqueThreadID (original_thread_sp); new_extended_thread_sp.reset (new HistoryThread (*m_process, unique_thread_id, bt.pcs, bt.stop_id, bt.stop_id_is_valid)); - SetNewThreadThreadName(original_thread_sp, new_extended_thread_sp); - SetNewThreadQueueName(original_thread_sp, new_extended_thread_sp); - SetNewThreadExtendedBacktraceToken(original_thread_sp, new_extended_thread_sp); - + SetNewThreadThreadName (original_thread_sp, new_extended_thread_sp); + SetNewThreadQueueName (original_thread_sp, new_extended_thread_sp); + SetNewThreadQueueID (original_thread_sp, new_extended_thread_sp); + SetNewThreadExtendedBacktraceToken (original_thread_sp, new_extended_thread_sp); return new_extended_thread_sp; } diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h index 24029d78996..c472bee8572 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h @@ -126,7 +126,7 @@ private: GetThreadCreatorItem (lldb::ThreadSP thread); lldb::tid_t - GetNewThreadUniquethreadID (lldb::ThreadSP original_thread_sp); + GetNewThreadUniqueThreadID (lldb::ThreadSP original_thread_sp); void SetNewThreadThreadName (lldb::ThreadSP original_thread_sp, lldb::ThreadSP new_extended_thread_sp); @@ -137,6 +137,9 @@ private: void SetNewThreadExtendedBacktraceToken (lldb::ThreadSP original_thread_sp, lldb::ThreadSP new_extended_thread_sp); + void + SetNewThreadQueueID (lldb::ThreadSP original_thread_sp, lldb::ThreadSP new_extended_thread_sp); + struct ldi_queue_offsets { uint16_t next; uint16_t prev; @@ -158,6 +161,7 @@ private: uint16_t pthread_id; uint16_t enqueueing_thread_dispatch_queue_t; uint16_t enqueueing_thread_dispatch_block_ptr; + uint16_t queue_id_from_thread_info; }; struct ldi_header { diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 950df69152f..9c2b7f50b32 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -1593,9 +1593,10 @@ Process::UpdateThreadListIfNeeded () m_thread_list_real.Update(real_thread_list); m_thread_list.Update (new_thread_list); m_thread_list.SetStopID (stop_id); + + // Clear any extended threads that we may have accumulated previously + m_extended_thread_list.Clear(); } - // Clear any extended threads that we may have accumulated previously - m_extended_thread_list.Clear(); } } } |