diff options
Diffstat (limited to 'lldb/source/Plugins/Process')
6 files changed, 84 insertions, 79 deletions
diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp index 8bb853c0858..ef88dd30586 100644 --- a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp +++ b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp @@ -44,6 +44,8 @@ using namespace lldb; using namespace lldb_private; +static const lldb::tid_t g_kernel_tid = 1; + const char * ProcessKDP::GetPluginNameStatic() { @@ -116,7 +118,8 @@ ProcessKDP::ProcessKDP(Target& target, Listener &listener) : m_async_thread (LLDB_INVALID_HOST_THREAD), m_dyld_plugin_name (), m_kernel_load_addr (LLDB_INVALID_ADDRESS), - m_command_sp() + m_command_sp(), + m_kernel_thread_wp() { m_async_broadcaster.SetEventName (eBroadcastBitAsyncThreadShouldExit, "async thread should exit"); m_async_broadcaster.SetEventName (eBroadcastBitAsyncContinue, "async thread continue"); @@ -377,7 +380,8 @@ ProcessKDP::DoResume () bool resume = false; // With KDP there is only one thread we can tell what to do - ThreadSP kernel_thread_sp (GetKernelThread(m_thread_list, m_thread_list)); + ThreadSP kernel_thread_sp (m_thread_list.FindThreadByProtocolID(g_kernel_tid)); + if (kernel_thread_sp) { const StateType thread_resume_state = kernel_thread_sp->GetTemporaryResumeState(); @@ -449,15 +453,17 @@ ProcessKDP::DoResume () } lldb::ThreadSP -ProcessKDP::GetKernelThread(ThreadList &old_thread_list, ThreadList &new_thread_list) +ProcessKDP::GetKernelThread() { // KDP only tells us about one thread/core. Any other threads will usually // be the ones that are read from memory by the OS plug-ins. - const lldb::tid_t kernel_tid = 1; - ThreadSP thread_sp (old_thread_list.FindThreadByID (kernel_tid, false)); + + ThreadSP thread_sp (m_kernel_thread_wp.lock()); if (!thread_sp) - thread_sp.reset(new ThreadKDP (*this, kernel_tid)); - new_thread_list.AddThread(thread_sp); + { + thread_sp.reset(new ThreadKDP (*this, g_kernel_tid)); + m_kernel_thread_wp = thread_sp; + } return thread_sp; } @@ -474,7 +480,10 @@ ProcessKDP::UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_threa // Even though there is a CPU mask, it doesn't mean we can see each CPU // indivudually, there is really only one. Lets call this thread 1. - GetKernelThread (old_thread_list, new_thread_list); + ThreadSP thread_sp (old_thread_list.FindThreadByProtocolID(g_kernel_tid, false)); + if (!thread_sp) + thread_sp = GetKernelThread (); + new_thread_list.AddThread(thread_sp); return new_thread_list.GetSize(false) > 0; } @@ -798,7 +807,7 @@ ProcessKDP::AsyncThread (void *arg) is_running = true; if (process->m_comm.WaitForPacketWithTimeoutMicroSeconds (exc_reply_packet, 1 * USEC_PER_SEC)) { - ThreadSP thread_sp (process->GetKernelThread(process->GetThreadList(), process->GetThreadList())); + ThreadSP thread_sp (process->GetKernelThread()); if (thread_sp) { lldb::RegisterContextSP reg_ctx_sp (thread_sp->GetRegisterContext()); diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h index 9de262322ae..1dff43f1090 100644 --- a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h +++ b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h @@ -225,12 +225,6 @@ protected: bool ProcessIDIsValid ( ) const; - // static void - // STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len); - - // void - // AppendSTDOUT (const char* s, size_t len); - void Clear ( ); @@ -245,8 +239,7 @@ protected: }; lldb::ThreadSP - GetKernelThread (lldb_private::ThreadList &old_thread_list, - lldb_private::ThreadList &new_thread_list); + GetKernelThread (); //------------------------------------------------------------------ /// Broadcaster event bits definitions. @@ -257,6 +250,7 @@ protected: std::string m_dyld_plugin_name; lldb::addr_t m_kernel_load_addr; lldb::CommandObjectSP m_command_sp; + lldb::ThreadWP m_kernel_thread_wp; bool diff --git a/lldb/source/Plugins/Process/POSIX/POSIXThread.cpp b/lldb/source/Plugins/Process/POSIX/POSIXThread.cpp index 11ed3d18620..8928d372c11 100644 --- a/lldb/source/Plugins/Process/POSIX/POSIXThread.cpp +++ b/lldb/source/Plugins/Process/POSIX/POSIXThread.cpp @@ -140,7 +140,7 @@ POSIXThread::CreateRegisterContextForFrame(lldb_private::StackFrame *frame) lldb::StopInfoSP POSIXThread::GetPrivateStopReason() { - return m_stop_info; + return m_actual_stop_info_sp; } Unwind * @@ -262,19 +262,19 @@ POSIXThread::BreakNotify(const ProcessMessage &message) m_breakpoint = bp_site; - m_stop_info = StopInfo::CreateStopReasonWithBreakpointSiteID(*this, bp_id); + SetStopInfo (StopInfo::CreateStopReasonWithBreakpointSiteID(*this, bp_id)); } void POSIXThread::TraceNotify(const ProcessMessage &message) { - m_stop_info = StopInfo::CreateStopReasonToTrace(*this); + SetStopInfo (StopInfo::CreateStopReasonToTrace(*this)); } void POSIXThread::LimboNotify(const ProcessMessage &message) { - m_stop_info = lldb::StopInfoSP(new POSIXLimboStopInfo(*this)); + SetStopInfo (lldb::StopInfoSP(new POSIXLimboStopInfo(*this))); } void @@ -282,7 +282,7 @@ POSIXThread::SignalNotify(const ProcessMessage &message) { int signo = message.GetSignal(); - m_stop_info = StopInfo::CreateStopReasonWithSignal(*this, signo); + SetStopInfo (StopInfo::CreateStopReasonWithSignal(*this, signo)); SetResumeSignal(signo); } @@ -291,7 +291,7 @@ POSIXThread::SignalDeliveredNotify(const ProcessMessage &message) { int signo = message.GetSignal(); - m_stop_info = StopInfo::CreateStopReasonWithSignal(*this, signo); + SetStopInfo (StopInfo::CreateStopReasonWithSignal(*this, signo)); SetResumeSignal(signo); } @@ -306,15 +306,14 @@ POSIXThread::CrashNotify(const ProcessMessage &message) if (log) log->Printf ("POSIXThread::%s () signo = %i, reason = '%s'", __FUNCTION__, signo, message.PrintCrashReason()); - m_stop_info = lldb::StopInfoSP(new POSIXCrashStopInfo( - *this, signo, message.GetCrashReason())); + SetStopInfo (lldb::StopInfoSP(new POSIXCrashStopInfo(*this, signo, message.GetCrashReason()))); SetResumeSignal(signo); } void POSIXThread::ThreadNotify(const ProcessMessage &message) { - m_stop_info = lldb::StopInfoSP(new POSIXNewThreadStopInfo(*this)); + SetStopInfo (lldb::StopInfoSP(new POSIXNewThreadStopInfo(*this))); } unsigned diff --git a/lldb/source/Plugins/Process/POSIX/POSIXThread.h b/lldb/source/Plugins/Process/POSIX/POSIXThread.h index 094e140b390..3e14652bc25 100644 --- a/lldb/source/Plugins/Process/POSIX/POSIXThread.h +++ b/lldb/source/Plugins/Process/POSIX/POSIXThread.h @@ -84,7 +84,6 @@ private: std::unique_ptr<lldb_private::StackFrame> m_frame_ap; lldb::BreakpointSiteSP m_breakpoint; - lldb::StopInfoSP m_stop_info; ProcessMonitor & GetMonitor(); diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 06e15ab1f40..0302f9312b7 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -1281,14 +1281,14 @@ ProcessGDBRemote::DoResume () void ProcessGDBRemote::ClearThreadIDList () { - Mutex::Locker locker(m_thread_list.GetMutex()); + Mutex::Locker locker(m_thread_list_real.GetMutex()); m_thread_ids.clear(); } bool ProcessGDBRemote::UpdateThreadIDList () { - Mutex::Locker locker(m_thread_list.GetMutex()); + Mutex::Locker locker(m_thread_list_real.GetMutex()); bool sequence_mutex_unavailable = false; m_gdb_comm.GetCurrentThreadIDs (m_thread_ids, sequence_mutex_unavailable); if (sequence_mutex_unavailable) @@ -1323,12 +1323,6 @@ ProcessGDBRemote::UpdateThreadList (ThreadList &old_thread_list, ThreadList &new { tid_t tid = m_thread_ids[i]; ThreadSP thread_sp (old_thread_list_copy.RemoveThreadByProtocolID(tid, false)); - if (thread_sp) - { - ThreadSP backing_thread_sp (thread_sp->GetBackingThread()); - if (backing_thread_sp && backing_thread_sp->GetProtocolID() == tid) - thread_sp = backing_thread_sp; - } if (!thread_sp) thread_sp.reset (new ThreadGDBRemote (*this, tid)); new_thread_list.AddThread(thread_sp); @@ -1385,7 +1379,6 @@ ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet) std::vector<addr_t> exc_data; addr_t thread_dispatch_qaddr = LLDB_INVALID_ADDRESS; ThreadSP thread_sp; - ThreadSP backing_thread_sp; ThreadGDBRemote *gdb_thread = NULL; while (stop_packet.GetNameColonValue(name, value)) @@ -1404,31 +1397,24 @@ ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet) { // thread in big endian hex lldb::tid_t tid = Args::StringToUInt64 (value.c_str(), LLDB_INVALID_THREAD_ID, 16); - // m_thread_list does have its own mutex, but we need to - // hold onto the mutex between the call to m_thread_list.FindThreadByID(...) - // and the m_thread_list.AddThread(...) so it doesn't change on us - Mutex::Locker locker (m_thread_list.GetMutex ()); - thread_sp = m_thread_list.FindThreadByProtocolID(tid, false); + // m_thread_list_real does have its own mutex, but we need to + // hold onto the mutex between the call to m_thread_list_real.FindThreadByID(...) + // and the m_thread_list_real.AddThread(...) so it doesn't change on us + Mutex::Locker locker (m_thread_list_real.GetMutex ()); + thread_sp = m_thread_list_real.FindThreadByProtocolID(tid, false); - if (thread_sp) - { - backing_thread_sp = thread_sp->GetBackingThread(); - if (backing_thread_sp) - gdb_thread = static_cast<ThreadGDBRemote *> (backing_thread_sp.get()); - else - gdb_thread = static_cast<ThreadGDBRemote *> (thread_sp.get()); - } - else + if (!thread_sp) { // Create the thread if we need to thread_sp.reset (new ThreadGDBRemote (*this, tid)); - gdb_thread = static_cast<ThreadGDBRemote *> (thread_sp.get()); - m_thread_list.AddThread(thread_sp); + m_thread_list_real.AddThread(thread_sp); } + gdb_thread = static_cast<ThreadGDBRemote *> (thread_sp.get()); + } else if (name.compare("threads") == 0) { - Mutex::Locker locker(m_thread_list.GetMutex()); + Mutex::Locker locker(m_thread_list_real.GetMutex()); m_thread_ids.clear(); // A comma separated list of all threads in the current // process that includes the thread for this stop reply @@ -1508,6 +1494,9 @@ ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet) if (thread_sp) { + // Clear the stop info just in case we don't set it to anything + thread_sp->SetStopInfo (StopInfoSP()); + gdb_thread->SetThreadDispatchQAddr (thread_dispatch_qaddr); gdb_thread->SetName (thread_name.empty() ? NULL : thread_name.c_str()); if (exc_type != 0) @@ -1610,11 +1599,6 @@ ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet) if (!handled) thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithSignal (*thread_sp, signo)); } - else - { - StopInfoSP invalid_stop_info_sp; - thread_sp->SetStopInfo (invalid_stop_info_sp); - } if (!description.empty()) { @@ -1647,7 +1631,7 @@ ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet) void ProcessGDBRemote::RefreshStateAfterStop () { - Mutex::Locker locker(m_thread_list.GetMutex()); + Mutex::Locker locker(m_thread_list_real.GetMutex()); m_thread_ids.clear(); // Set the thread stop info. It might have a "threads" key whose value is // a list of all thread IDs in the current process, so m_thread_ids might @@ -1662,7 +1646,7 @@ ProcessGDBRemote::RefreshStateAfterStop () // Let all threads recover from stopping and do any clean up based // on the previous thread state (if any). - m_thread_list.RefreshStateAfterStop(); + m_thread_list_real.RefreshStateAfterStop(); } @@ -2330,6 +2314,7 @@ void ProcessGDBRemote::Clear() { m_flags = 0; + m_thread_list_real.Clear(); m_thread_list.Clear(); } diff --git a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp index 321fe8d819a..40b367c3993 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp @@ -204,27 +204,46 @@ ThreadGDBRemote::GetPrivateStopReason () if (process_sp) { 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 (m_thread_stop_reason_stop_id == process_stop_id) + { + // Our stop info is up to date even if it is empty... + return m_actual_stop_info_sp; + } + + if (m_actual_stop_info_sp && m_actual_stop_info_sp->IsValid()) + { + // The stop info is up to date, reset it so everything updates + SetStopInfo (m_actual_stop_info_sp); + } + else { if (IsStillAtLastBreakpointHit()) - return m_actual_stop_info_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 = static_cast<ProcessGDBRemote *>(process_sp.get()); - if (gdb_process->GetGDBRemote().GetThreadStopInfo(GetProtocolID(), stop_packet)) - gdb_process->SetThreadStopInfo (stop_packet); + { + SetStopInfo(m_actual_stop_info_sp); + } + else + { + // 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_actual_stop_info_sp.reset(); + + StringExtractorGDBRemote stop_packet; + ProcessGDBRemote *gdb_process = static_cast<ProcessGDBRemote *>(process_sp.get()); + if (gdb_process->GetGDBRemote().GetThreadStopInfo(GetProtocolID(), stop_packet)) + { + gdb_process->SetThreadStopInfo (stop_packet); + } + else + { + SetStopInfo (StopInfoSP()); + } + } } } return m_actual_stop_info_sp; |