Greg Clayton 160c9d81e0 <rdar://problem/13700260>
<rdar://problem/13723772>

Modified the lldb_private::Thread to work much better with the OperatingSystem plug-ins. Operating system plug-ins can now return have a "core" key/value pair in each thread dictionary for the OperatingSystemPython plug-ins which allows the core threads to be contained with memory threads. It also allows these memory threads to be stepped, resumed, and controlled just as if they were the actual backing threads themselves.

A few things are introduced:
- lldb_private::Thread now has a GetProtocolID() method which returns the thread protocol ID for a given thread. The protocol ID (Thread::GetProtocolID()) is usually the same as the thread id (Thread::GetID()), but it can differ when a memory thread has its own id, but is backed by an actual API thread.
- Cleaned up the Thread::WillResume() code to do the mandatory parts in Thread::ShouldResume(), and let the thread subclasses override the Thread::WillResume() which is now just a notification.
- Cleaned up ClearStackFrames() implementations so that fewer thread subclasses needed to override them
- Changed the POSIXThread class a bit since it overrode Thread::WillResume(). It is doing the wrong thing by calling "Thread::SetResumeState()" on its own, this shouldn't be done by thread subclasses, but the current code might rely on it so I left it in with a TODO comment with an explanation.

llvm-svn: 180886
2013-05-01 21:54:04 +00:00

153 lines
4.0 KiB
C++

//===-- ThreadMemory.h -----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_ThreadMemory_h_
#define liblldb_ThreadMemory_h_
#include "lldb/Target/Thread.h"
class ThreadMemory :
public lldb_private::Thread
{
public:
ThreadMemory (lldb_private::Process &process,
lldb::tid_t tid,
const lldb::ValueObjectSP &thread_info_valobj_sp);
ThreadMemory (lldb_private::Process &process,
lldb::tid_t tid,
const char *name,
const char *queue,
lldb::addr_t register_data_addr);
virtual
~ThreadMemory();
//------------------------------------------------------------------
// lldb_private::Thread methods
//------------------------------------------------------------------
virtual lldb::RegisterContextSP
GetRegisterContext ();
virtual lldb::RegisterContextSP
CreateRegisterContextForFrame (lldb_private::StackFrame *frame);
virtual lldb::StopInfoSP
GetPrivateStopReason ();
virtual const char *
GetInfo ()
{
if (m_backing_thread_sp)
m_backing_thread_sp->GetInfo();
return NULL;
}
virtual const char *
GetName ()
{
if (!m_name.empty())
return m_name.c_str();
if (m_backing_thread_sp)
m_backing_thread_sp->GetName();
return NULL;
}
virtual const char *
GetQueueName ()
{
if (!m_queue.empty())
return m_queue.c_str();
if (m_backing_thread_sp)
m_backing_thread_sp->GetQueueName();
return NULL;
}
virtual void
WillResume (lldb::StateType resume_state);
virtual void
DidResume ()
{
if (m_backing_thread_sp)
m_backing_thread_sp->DidResume();
}
virtual lldb::user_id_t
GetProtocolID () const
{
if (m_backing_thread_sp)
return m_backing_thread_sp->GetProtocolID();
return Thread::GetProtocolID();
}
virtual void
RefreshStateAfterStop();
lldb::ValueObjectSP &
GetValueObject ()
{
return m_thread_info_valobj_sp;
}
virtual void
ClearStackFrames ();
virtual void
ClearBackingThread ()
{
m_backing_thread_sp.reset();
}
virtual bool
SetBackingThread (const lldb::ThreadSP &thread_sp)
{
//printf ("Thread 0x%llx is being backed by thread 0x%llx\n", GetID(), thread_sp->GetID());
m_backing_thread_sp = thread_sp;
return (bool)thread_sp;
}
virtual lldb::ThreadSP
GetBackingThread () const
{
return m_backing_thread_sp;
}
protected:
virtual bool
IsOperatingSystemPluginThread () const
{
return true;
}
//------------------------------------------------------------------
// For ThreadMemory and subclasses
//------------------------------------------------------------------
// If this memory thread is actually represented by a thread from the
// lldb_private::Process subclass, then fill in the thread here and
// all APIs will be routed through this thread object. If m_backing_thread_sp
// is empty, then this thread is simply in memory with no representation
// through the process plug-in.
lldb::ThreadSP m_backing_thread_sp;
lldb::ValueObjectSP m_thread_info_valobj_sp;
std::string m_name;
std::string m_queue;
lldb::addr_t m_register_data_addr;
private:
//------------------------------------------------------------------
// For ThreadMemory only
//------------------------------------------------------------------
DISALLOW_COPY_AND_ASSIGN (ThreadMemory);
};
#endif // liblldb_ThreadMemory_h_