diff options
author | Greg Clayton <gclayton@apple.com> | 2012-02-21 00:09:25 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2012-02-21 00:09:25 +0000 |
commit | 1ac04c308832f7a9b2e07e360f07c82f7cb2a02c (patch) | |
tree | bb908a56f1d08a946f4f25aa7b4b762066e1ec57 /lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp | |
parent | 3508a0054301ef24b8d8619351788698bcd97620 (diff) | |
download | llvm-1ac04c308832f7a9b2e07e360f07c82f7cb2a02c.zip llvm-1ac04c308832f7a9b2e07e360f07c82f7cb2a02c.tar.gz llvm-1ac04c308832f7a9b2e07e360f07c82f7cb2a02c.tar.bz2 |
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/GDBRemoteRegisterContext.cpp')
-rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp | 63 |
1 files changed, 43 insertions, 20 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp index 07b17b4..0648845 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp @@ -17,6 +17,7 @@ #include "lldb/Core/RegisterValue.h" #include "lldb/Core/Scalar.h" #include "lldb/Core/StreamString.h" +#include "lldb/Target/ExecutionContext.h" // Project includes #include "Utility/StringExtractorGDBRemote.h" #include "ProcessGDBRemote.h" @@ -61,18 +62,6 @@ GDBRemoteRegisterContext::~GDBRemoteRegisterContext() { } -ProcessGDBRemote & -GDBRemoteRegisterContext::GetGDBProcess() -{ - return static_cast<ProcessGDBRemote &>(m_thread.GetProcess()); -} - -ThreadGDBRemote & -GDBRemoteRegisterContext::GetGDBThread() -{ - return static_cast<ThreadGDBRemote &>(m_thread); -} - void GDBRemoteRegisterContext::InvalidateAllRegisters () { @@ -158,7 +147,14 @@ GDBRemoteRegisterContext::PrivateSetRegisterValue (uint32_t reg, StringExtractor bool GDBRemoteRegisterContext::ReadRegisterBytes (const RegisterInfo *reg_info, DataExtractor &data) { - GDBRemoteCommunicationClient &gdb_comm (GetGDBProcess().GetGDBRemote()); + ExecutionContext exe_ctx (CalculateThread()); + + Process *process = exe_ctx.GetProcessPtr(); + Thread *thread = exe_ctx.GetThreadPtr(); + if (process == NULL || thread == NULL) + return false; + + GDBRemoteCommunicationClient &gdb_comm (((ProcessGDBRemote *)process)->GetGDBRemote()); InvalidateIfNeeded(false); @@ -170,7 +166,8 @@ GDBRemoteRegisterContext::ReadRegisterBytes (const RegisterInfo *reg_info, DataE if (gdb_comm.GetSequenceMutex (locker)) { const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported(); - if (thread_suffix_supported || GetGDBProcess().GetGDBRemote().SetCurrentThread(m_thread.GetID())) + ProcessSP process_sp (m_thread.GetProcess()); + if (thread_suffix_supported || static_cast<ProcessGDBRemote *>(process_sp.get())->GetGDBRemote().SetCurrentThread(m_thread.GetID())) { char packet[64]; StringExtractorGDBRemote response; @@ -238,7 +235,14 @@ GDBRemoteRegisterContext::WriteRegister (const RegisterInfo *reg_info, bool GDBRemoteRegisterContext::WriteRegisterBytes (const lldb_private::RegisterInfo *reg_info, DataExtractor &data, uint32_t data_offset) { - GDBRemoteCommunicationClient &gdb_comm (GetGDBProcess().GetGDBRemote()); + ExecutionContext exe_ctx (CalculateThread()); + + Process *process = exe_ctx.GetProcessPtr(); + Thread *thread = exe_ctx.GetThreadPtr(); + if (process == NULL || thread == NULL) + return false; + + GDBRemoteCommunicationClient &gdb_comm (((ProcessGDBRemote *)process)->GetGDBRemote()); // FIXME: This check isn't right because IsRunning checks the Public state, but this // is work you need to do - for instance in ShouldStop & friends - before the public // state has been changed. @@ -264,7 +268,8 @@ GDBRemoteRegisterContext::WriteRegisterBytes (const lldb_private::RegisterInfo * if (gdb_comm.GetSequenceMutex (locker)) { const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported(); - if (thread_suffix_supported || GetGDBProcess().GetGDBRemote().SetCurrentThread(m_thread.GetID())) + ProcessSP process_sp (m_thread.GetProcess()); + if (thread_suffix_supported || static_cast<ProcessGDBRemote *>(process_sp.get())->GetGDBRemote().SetCurrentThread(m_thread.GetID())) { uint32_t offset, end_offset; StreamString packet; @@ -334,7 +339,15 @@ GDBRemoteRegisterContext::WriteRegisterBytes (const lldb_private::RegisterInfo * bool GDBRemoteRegisterContext::ReadAllRegisterValues (lldb::DataBufferSP &data_sp) { - GDBRemoteCommunicationClient &gdb_comm (GetGDBProcess().GetGDBRemote()); + ExecutionContext exe_ctx (CalculateThread()); + + Process *process = exe_ctx.GetProcessPtr(); + Thread *thread = exe_ctx.GetThreadPtr(); + if (process == NULL || thread == NULL) + return false; + + GDBRemoteCommunicationClient &gdb_comm (((ProcessGDBRemote *)process)->GetGDBRemote()); + StringExtractorGDBRemote response; Mutex::Locker locker; @@ -342,7 +355,8 @@ GDBRemoteRegisterContext::ReadAllRegisterValues (lldb::DataBufferSP &data_sp) { char packet[32]; const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported(); - if (thread_suffix_supported || GetGDBProcess().GetGDBRemote().SetCurrentThread(m_thread.GetID())) + ProcessSP process_sp (m_thread.GetProcess()); + if (thread_suffix_supported || static_cast<ProcessGDBRemote *>(process_sp.get())->GetGDBRemote().SetCurrentThread(m_thread.GetID())) { int packet_len = 0; if (thread_suffix_supported) @@ -382,13 +396,22 @@ GDBRemoteRegisterContext::WriteAllRegisterValues (const lldb::DataBufferSP &data if (!data_sp || data_sp->GetBytes() == NULL || data_sp->GetByteSize() == 0) return false; - GDBRemoteCommunicationClient &gdb_comm (GetGDBProcess().GetGDBRemote()); + ExecutionContext exe_ctx (CalculateThread()); + + Process *process = exe_ctx.GetProcessPtr(); + Thread *thread = exe_ctx.GetThreadPtr(); + if (process == NULL || thread == NULL) + return false; + + GDBRemoteCommunicationClient &gdb_comm (((ProcessGDBRemote *)process)->GetGDBRemote()); + StringExtractorGDBRemote response; Mutex::Locker locker; if (gdb_comm.GetSequenceMutex (locker)) { const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported(); - if (thread_suffix_supported || GetGDBProcess().GetGDBRemote().SetCurrentThread(m_thread.GetID())) + ProcessSP process_sp (m_thread.GetProcess()); + if (thread_suffix_supported || static_cast<ProcessGDBRemote *>(process_sp.get())->GetGDBRemote().SetCurrentThread(m_thread.GetID())) { // The data_sp contains the entire G response packet including the // G, and if the thread suffix is supported, it has the thread suffix |