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/MacOSX-Kernel | |
parent | 3508a0054301ef24b8d8619351788698bcd97620 (diff) | |
download | bcm5719-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/MacOSX-Kernel')
5 files changed, 104 insertions, 74 deletions
diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp index ab872f8e7d7..3b45691d2e0 100644 --- a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp +++ b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp @@ -312,7 +312,7 @@ ProcessKDP::UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_threa lldb::tid_t tid = cpu_mask_bit; ThreadSP thread_sp (old_thread_list.FindThreadByID (tid, false)); if (!thread_sp) - thread_sp.reset(new ThreadKDP (*this, tid)); + thread_sp.reset(new ThreadKDP (shared_from_this(), tid)); new_thread_list.AddThread(thread_sp); } return new_thread_list.GetSize(false); diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_arm.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_arm.cpp index fdd22b2f3b3..296fbbac7e9 100644 --- a/lldb/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_arm.cpp +++ b/lldb/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_arm.cpp @@ -33,11 +33,15 @@ RegisterContextKDP_arm::~RegisterContextKDP_arm() int RegisterContextKDP_arm::DoReadGPR (lldb::tid_t tid, int flavor, GPR &gpr) { - Error error; - if (m_kdp_thread.GetKDPProcess().GetCommunication().SendRequestReadRegisters (tid, GPRRegSet, &gpr, sizeof(gpr), error)) + ProcessSP process_sp (CalculateProcess()); + if (process_sp) { - if (error.Success()) - return 0; + Error error; + if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestReadRegisters (tid, GPRRegSet, &gpr, sizeof(gpr), error)) + { + if (error.Success()) + return 0; + } } return -1; } @@ -45,11 +49,15 @@ RegisterContextKDP_arm::DoReadGPR (lldb::tid_t tid, int flavor, GPR &gpr) int RegisterContextKDP_arm::DoReadFPU (lldb::tid_t tid, int flavor, FPU &fpu) { - Error error; - if (m_kdp_thread.GetKDPProcess().GetCommunication().SendRequestReadRegisters (tid, FPURegSet, &fpu, sizeof(fpu), error)) + ProcessSP process_sp (CalculateProcess()); + if (process_sp) { - if (error.Success()) - return 0; + Error error; + if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestReadRegisters (tid, FPURegSet, &fpu, sizeof(fpu), error)) + { + if (error.Success()) + return 0; + } } return -1; } @@ -57,11 +65,15 @@ RegisterContextKDP_arm::DoReadFPU (lldb::tid_t tid, int flavor, FPU &fpu) int RegisterContextKDP_arm::DoReadEXC (lldb::tid_t tid, int flavor, EXC &exc) { - Error error; - if (m_kdp_thread.GetKDPProcess().GetCommunication().SendRequestReadRegisters (tid, EXCRegSet, &exc, sizeof(exc), error)) + ProcessSP process_sp (CalculateProcess()); + if (process_sp) { - if (error.Success()) - return 0; + Error error; + if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestReadRegisters (tid, EXCRegSet, &exc, sizeof(exc), error)) + { + if (error.Success()) + return 0; + } } return -1; } @@ -69,11 +81,15 @@ RegisterContextKDP_arm::DoReadEXC (lldb::tid_t tid, int flavor, EXC &exc) int RegisterContextKDP_arm::DoReadDBG (lldb::tid_t tid, int flavor, DBG &dbg) { - Error error; - if (m_kdp_thread.GetKDPProcess().GetCommunication().SendRequestReadRegisters (tid, DBGRegSet, &dbg, sizeof(dbg), error)) + ProcessSP process_sp (CalculateProcess()); + if (process_sp) { - if (error.Success()) - return 0; + Error error; + if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestReadRegisters (tid, DBGRegSet, &dbg, sizeof(dbg), error)) + { + if (error.Success()) + return 0; + } } return -1; } diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_i386.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_i386.cpp index 503ce75181c..504ea07ba4f 100644 --- a/lldb/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_i386.cpp +++ b/lldb/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_i386.cpp @@ -33,11 +33,15 @@ RegisterContextKDP_i386::~RegisterContextKDP_i386() int RegisterContextKDP_i386::DoReadGPR (lldb::tid_t tid, int flavor, GPR &gpr) { - Error error; - if (m_kdp_thread.GetKDPProcess().GetCommunication().SendRequestReadRegisters (tid, GPRRegSet, &gpr, sizeof(gpr), error)) + ProcessSP process_sp (CalculateProcess()); + if (process_sp) { - if (error.Success()) - return 0; + Error error; + if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestReadRegisters (tid, GPRRegSet, &gpr, sizeof(gpr), error)) + { + if (error.Success()) + return 0; + } } return -1; } @@ -45,11 +49,15 @@ RegisterContextKDP_i386::DoReadGPR (lldb::tid_t tid, int flavor, GPR &gpr) int RegisterContextKDP_i386::DoReadFPU (lldb::tid_t tid, int flavor, FPU &fpu) { - Error error; - if (m_kdp_thread.GetKDPProcess().GetCommunication().SendRequestReadRegisters (tid, FPURegSet, &fpu, sizeof(fpu), error)) + ProcessSP process_sp (CalculateProcess()); + if (process_sp) { - if (error.Success()) - return 0; + Error error; + if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestReadRegisters (tid, FPURegSet, &fpu, sizeof(fpu), error)) + { + if (error.Success()) + return 0; + } } return -1; } @@ -57,11 +65,15 @@ RegisterContextKDP_i386::DoReadFPU (lldb::tid_t tid, int flavor, FPU &fpu) int RegisterContextKDP_i386::DoReadEXC (lldb::tid_t tid, int flavor, EXC &exc) { - Error error; - if (m_kdp_thread.GetKDPProcess().GetCommunication().SendRequestReadRegisters (tid, EXCRegSet, &exc, sizeof(exc), error)) + ProcessSP process_sp (CalculateProcess()); + if (process_sp) { - if (error.Success()) - return 0; + Error error; + if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestReadRegisters (tid, EXCRegSet, &exc, sizeof(exc), error)) + { + if (error.Success()) + return 0; + } } return -1; } @@ -69,19 +81,19 @@ RegisterContextKDP_i386::DoReadEXC (lldb::tid_t tid, int flavor, EXC &exc) int RegisterContextKDP_i386::DoWriteGPR (lldb::tid_t tid, int flavor, const GPR &gpr) { - return ::thread_set_state(tid, flavor, (thread_state_t)&gpr, GPRWordCount); + return -1; } int RegisterContextKDP_i386::DoWriteFPU (lldb::tid_t tid, int flavor, const FPU &fpu) { - return ::thread_set_state(tid, flavor, (thread_state_t)&fpu, FPUWordCount); + return -1; } int RegisterContextKDP_i386::DoWriteEXC (lldb::tid_t tid, int flavor, const EXC &exc) { - return ::thread_set_state(tid, flavor, (thread_state_t)&exc, EXCWordCount); + return -1; } diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp index 6fb947087e5..9f68d104942 100644 --- a/lldb/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp +++ b/lldb/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp @@ -36,18 +36,18 @@ using namespace lldb_private; // Thread Registers //---------------------------------------------------------------------- -ThreadKDP::ThreadKDP (ProcessKDP &process, lldb::tid_t tid) : - Thread(process, tid), +ThreadKDP::ThreadKDP (const lldb::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) { - ProcessKDPLog::LogIf(KDP_LOG_THREAD, "%p: ThreadKDP::ThreadKDP (pid = %i, tid = 0x%4.4x)", this, m_process.GetID(), GetID()); + ProcessKDPLog::LogIf(KDP_LOG_THREAD, "%p: ThreadKDP::ThreadKDP (tid = 0x%4.4x)", this, GetID()); } ThreadKDP::~ThreadKDP () { - ProcessKDPLog::LogIf(KDP_LOG_THREAD, "%p: ThreadKDP::~ThreadKDP (pid = %i, tid = 0x%4.4x)", this, m_process.GetID(), GetID()); + ProcessKDPLog::LogIf(KDP_LOG_THREAD, "%p: ThreadKDP::~ThreadKDP (tid = 0x%4.4x)", this, GetID()); DestroyThread(); } @@ -157,20 +157,24 @@ ThreadKDP::CreateRegisterContextForFrame (StackFrame *frame) if (concrete_frame_idx == 0) { - switch (GetKDPProcess().GetCommunication().GetCPUType()) + ProcessSP process_sp (CalculateProcess()); + if (process_sp) { - case llvm::MachO::CPUTypeARM: - reg_ctx_sp.reset (new RegisterContextKDP_arm (*this, concrete_frame_idx)); - break; - case llvm::MachO::CPUTypeI386: - reg_ctx_sp.reset (new RegisterContextKDP_i386 (*this, concrete_frame_idx)); - break; - case llvm::MachO::CPUTypeX86_64: - reg_ctx_sp.reset (new RegisterContextKDP_x86_64 (*this, concrete_frame_idx)); - break; - default: - assert (!"Add CPU type support in KDP"); - break; + switch (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().GetCPUType()) + { + case llvm::MachO::CPUTypeARM: + reg_ctx_sp.reset (new RegisterContextKDP_arm (*this, concrete_frame_idx)); + break; + case llvm::MachO::CPUTypeI386: + reg_ctx_sp.reset (new RegisterContextKDP_i386 (*this, concrete_frame_idx)); + break; + case llvm::MachO::CPUTypeX86_64: + reg_ctx_sp.reset (new RegisterContextKDP_x86_64 (*this, concrete_frame_idx)); + break; + default: + assert (!"Add CPU type support in KDP"); + break; + } } } else if (m_unwinder_ap.get()) @@ -181,26 +185,30 @@ ThreadKDP::CreateRegisterContextForFrame (StackFrame *frame) lldb::StopInfoSP ThreadKDP::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) { - // TODO: can we query the initial state of the thread here? - // For now I am just going to pretend that a SIGSTOP happened. - - SetStopInfo(StopInfo::CreateStopReasonWithSignal (*this, SIGSTOP)); - - // If GetKDPProcess().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 KDP 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(); + 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())) + { + // TODO: can we query the initial state of the thread here? + // For now I am just going to pretend that a SIGSTOP happened. + + SetStopInfo(StopInfo::CreateStopReasonWithSignal (*this, SIGSTOP)); + + // If GetKDPProcess().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 KDP 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(); + } } return m_actual_stop_info_sp; } diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.h b/lldb/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.h index a37fa91ee2b..1bf688de20a 100644 --- a/lldb/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.h +++ b/lldb/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.h @@ -20,7 +20,7 @@ class ProcessKDP; class ThreadKDP : public lldb_private::Thread { public: - ThreadKDP (ProcessKDP &process, + ThreadKDP (const lldb::ProcessSP &process_sp, lldb::tid_t tid); virtual @@ -47,12 +47,6 @@ public: virtual void ClearStackFrames (); - ProcessKDP & - GetKDPProcess () - { - return (ProcessKDP &)m_process; - } - void Dump (lldb_private::Log *log, uint32_t index); |