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
This commit is contained in:
Jason Molenda 2013-11-19 05:44:41 +00:00
parent 1f54e805f2
commit a6e9130d52
7 changed files with 78 additions and 16 deletions
lldb
include/lldb/Target
source

View File

@ -284,6 +284,11 @@ public:
return LLDB_INVALID_QUEUE_ID;
}
virtual void
SetQueueID (lldb::queue_id_t new_val)
{
}
virtual const char *
GetQueueName ()
{

View File

@ -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());
}
}

View File

@ -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));

View File

@ -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

View File

@ -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;
}

View File

@ -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 {

View File

@ -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();
}
}
}