summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2012-02-21 00:09:25 +0000
committerGreg Clayton <gclayton@apple.com>2012-02-21 00:09:25 +0000
commit1ac04c308832f7a9b2e07e360f07c82f7cb2a02c (patch)
treebb908a56f1d08a946f4f25aa7b4b762066e1ec57 /lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
parent3508a0054301ef24b8d8619351788698bcd97620 (diff)
downloadbcm5719-llvm-1ac04c308832f7a9b2e07e360f07c82f7cb2a02c.tar.gz
bcm5719-llvm-1ac04c308832f7a9b2e07e360f07c82f7cb2a02c.zip
Thread hardening part 3. Now lldb_private::Thread objects have std::weak_ptr
objects for the backlink to the lldb_private::Process. The issues we were running into before was someone was holding onto a shared pointer to a lldb_private::Thread for too long, and the lldb_private::Process parent object would get destroyed and the lldb_private::Thread had a "Process &m_process" member which would just treat whatever memory that used to be a Process as a valid Process. This was mostly happening for lldb_private::StackFrame objects that had a member like "Thread &m_thread". So this completes the internal strong/weak changes. Documented the ExecutionContext and ExecutionContextRef classes so that our LLDB developers can understand when and where to use ExecutionContext and ExecutionContextRef objects. llvm-svn: 151009
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp')
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp128
1 files changed, 80 insertions, 48 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
index 49385916ad6..55cb222ce47 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
@@ -32,18 +32,25 @@ using namespace lldb_private;
// Thread Registers
//----------------------------------------------------------------------
-ThreadGDBRemote::ThreadGDBRemote (ProcessGDBRemote &process, lldb::tid_t tid) :
- Thread(process, tid),
+ThreadGDBRemote::ThreadGDBRemote (const ProcessSP &process_sp, lldb::tid_t tid) :
+ Thread(process_sp, tid),
m_thread_name (),
m_dispatch_queue_name (),
m_thread_dispatch_qaddr (LLDB_INVALID_ADDRESS)
{
- ProcessGDBRemoteLog::LogIf(GDBR_LOG_THREAD, "%p: ThreadGDBRemote::ThreadGDBRemote (pid = %i, tid = 0x%4.4x)", this, m_process.GetID(), GetID());
+ ProcessGDBRemoteLog::LogIf(GDBR_LOG_THREAD, "%p: ThreadGDBRemote::ThreadGDBRemote (pid = %i, tid = 0x%4.4x)",
+ this,
+ process_sp ? process_sp->GetID() : LLDB_INVALID_PROCESS_ID,
+ GetID());
}
ThreadGDBRemote::~ThreadGDBRemote ()
{
- ProcessGDBRemoteLog::LogIf(GDBR_LOG_THREAD, "%p: ThreadGDBRemote::~ThreadGDBRemote (pid = %i, tid = 0x%4.4x)", this, m_process.GetID(), GetID());
+ ProcessSP process_sp(GetProcess());
+ ProcessGDBRemoteLog::LogIf(GDBR_LOG_THREAD, "%p: ThreadGDBRemote::~ThreadGDBRemote (pid = %i, tid = 0x%4.4x)",
+ this,
+ process_sp ? process_sp->GetID() : LLDB_INVALID_PROCESS_ID,
+ GetID());
DestroyThread();
}
@@ -60,8 +67,16 @@ const char *
ThreadGDBRemote::GetQueueName ()
{
// Always re-fetch the dispatch queue name since it can change
+
if (m_thread_dispatch_qaddr != 0 || m_thread_dispatch_qaddr != LLDB_INVALID_ADDRESS)
- return GetGDBProcess().GetDispatchQueueNameForThread (m_thread_dispatch_qaddr, m_dispatch_queue_name);
+ {
+ ProcessSP process_sp (GetProcess());
+ if (process_sp)
+ {
+ ProcessGDBRemote *gdb_process = static_cast<ProcessGDBRemote *>(process_sp.get());
+ return gdb_process->GetDispatchQueueNameForThread (m_thread_dispatch_qaddr, m_dispatch_queue_name);
+ }
+ }
return NULL;
}
@@ -79,32 +94,37 @@ ThreadGDBRemote::WillResume (StateType resume_state)
if (log)
log->Printf ("Resuming thread: %4.4llx with state: %s.", GetID(), StateAsCString(resume_state));
- ProcessGDBRemote &process = GetGDBProcess();
- switch (resume_state)
+ ProcessSP process_sp (GetProcess());
+ if (process_sp)
{
- case eStateSuspended:
- case eStateStopped:
- // Don't append anything for threads that should stay stopped.
- break;
-
- case eStateRunning:
- if (m_process.GetUnixSignals().SignalIsValid (signo))
- process.m_continue_C_tids.push_back(std::make_pair(GetID(), signo));
- else
- process.m_continue_c_tids.push_back(GetID());
- break;
-
- case eStateStepping:
- if (m_process.GetUnixSignals().SignalIsValid (signo))
- process.m_continue_S_tids.push_back(std::make_pair(GetID(), signo));
- else
- process.m_continue_s_tids.push_back(GetID());
- break;
-
- default:
- break;
+ ProcessGDBRemote *gdb_process = static_cast<ProcessGDBRemote *>(process_sp.get());
+ switch (resume_state)
+ {
+ case eStateSuspended:
+ case eStateStopped:
+ // Don't append anything for threads that should stay stopped.
+ break;
+
+ case eStateRunning:
+ if (gdb_process->GetUnixSignals().SignalIsValid (signo))
+ gdb_process->m_continue_C_tids.push_back(std::make_pair(GetID(), signo));
+ else
+ gdb_process->m_continue_c_tids.push_back(GetID());
+ break;
+
+ case eStateStepping:
+ if (gdb_process->GetUnixSignals().SignalIsValid (signo))
+ gdb_process->m_continue_S_tids.push_back(std::make_pair(GetID(), signo));
+ else
+ gdb_process->m_continue_s_tids.push_back(GetID());
+ break;
+
+ default:
+ break;
+ }
+ return true;
}
- return true;
+ return false;
}
void
@@ -167,8 +187,16 @@ ThreadGDBRemote::CreateRegisterContextForFrame (StackFrame *frame)
if (frame)
concrete_frame_idx = frame->GetConcreteFrameIndex ();
+
if (concrete_frame_idx == 0)
- reg_ctx_sp.reset (new GDBRemoteRegisterContext (*this, concrete_frame_idx, GetGDBProcess().m_register_info, read_all_registers_at_once));
+ {
+ ProcessSP process_sp (GetProcess());
+ if (process_sp)
+ {
+ ProcessGDBRemote *gdb_process = static_cast<ProcessGDBRemote *>(process_sp.get());
+ reg_ctx_sp.reset (new GDBRemoteRegisterContext (*this, concrete_frame_idx, gdb_process->m_register_info, read_all_registers_at_once));
+ }
+ }
else if (m_unwinder_ap.get())
reg_ctx_sp = m_unwinder_ap->CreateRegisterContextForFrame (frame);
return reg_ctx_sp;
@@ -185,25 +213,29 @@ ThreadGDBRemote::PrivateSetRegisterValue (uint32_t reg, StringExtractor &respons
lldb::StopInfoSP
ThreadGDBRemote::GetPrivateStopReason ()
{
- const uint32_t process_stop_id = GetProcess().GetStopID();
- if (m_thread_stop_reason_stop_id != process_stop_id ||
- (m_actual_stop_info_sp && !m_actual_stop_info_sp->IsValid()))
+ ProcessSP process_sp (GetProcess());
+ if (process_sp)
{
- // If GetGDBProcess().SetThreadStopInfo() doesn't find a stop reason
- // for this thread, then m_actual_stop_info_sp will not ever contain
- // a valid stop reason and the "m_actual_stop_info_sp->IsValid() == false"
- // check will never be able to tell us if we have the correct stop info
- // for this thread and we will continually send qThreadStopInfo packets
- // down to the remote GDB server, so we need to keep our own notion
- // of the stop ID that m_actual_stop_info_sp is valid for (even if it
- // contains nothing). We use m_thread_stop_reason_stop_id for this below.
- m_thread_stop_reason_stop_id = process_stop_id;
- m_actual_stop_info_sp.reset();
-
- StringExtractorGDBRemote stop_packet;
- ProcessGDBRemote &gdb_process = GetGDBProcess();
- if (gdb_process.GetGDBRemote().GetThreadStopInfo(GetID(), stop_packet))
- gdb_process.SetThreadStopInfo (stop_packet);
+ const uint32_t process_stop_id = process_sp->GetStopID();
+ if (m_thread_stop_reason_stop_id != process_stop_id ||
+ (m_actual_stop_info_sp && !m_actual_stop_info_sp->IsValid()))
+ {
+ // If GetGDBProcess().SetThreadStopInfo() doesn't find a stop reason
+ // for this thread, then m_actual_stop_info_sp will not ever contain
+ // a valid stop reason and the "m_actual_stop_info_sp->IsValid() == false"
+ // check will never be able to tell us if we have the correct stop info
+ // for this thread and we will continually send qThreadStopInfo packets
+ // down to the remote GDB server, so we need to keep our own notion
+ // of the stop ID that m_actual_stop_info_sp is valid for (even if it
+ // contains nothing). We use m_thread_stop_reason_stop_id for this below.
+ m_thread_stop_reason_stop_id = process_stop_id;
+ m_actual_stop_info_sp.reset();
+
+ StringExtractorGDBRemote stop_packet;
+ ProcessGDBRemote *gdb_process = static_cast<ProcessGDBRemote *>(process_sp.get());
+ if (gdb_process->GetGDBRemote().GetThreadStopInfo(GetID(), stop_packet))
+ gdb_process->SetThreadStopInfo (stop_packet);
+ }
}
return m_actual_stop_info_sp;
}
OpenPOWER on IntegriCloud