Index: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h =================================================================== --- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h +++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h @@ -359,13 +359,11 @@ NotifyThreadStop (lldb::tid_t tid); void - CallAfterRunningThreadsStop (lldb::tid_t tid, - const std::function &call_after_function); + StopRunningThreads (lldb::tid_t triggering_tid); void - CallAfterRunningThreadsStopWithSkipTID (lldb::tid_t deferred_signal_tid, - lldb::tid_t skip_stop_request_tid, - const std::function &call_after_function); + StopRunningThreadsWithSkipTID (lldb::tid_t deferred_signal_tid, + lldb::tid_t skip_stop_request_tid); Error Detach(lldb::tid_t tid); @@ -379,7 +377,6 @@ typedef std::unordered_set ThreadIDSet; // Callback/block definitions. - typedef std::function ThreadIDFunction; typedef std::function LogFunction; typedef std::function ErrorFunction; typedef std::function StopThreadFunction; @@ -403,39 +400,31 @@ const ErrorFunction &error_function); - // This method is the main purpose of the class: triggering a deferred - // action after a given set of threads stop. The triggering_tid is the - // thread id passed to the call_after_function. The error_function will - // be fired if either the triggering tid or any of the wait_for_stop_tids - // are unknown at the time the method is processed. + // Notify the delegate after a given set of threads stops. The triggering_tid will be set + // as the current thread. The error_function will be fired if either the triggering tid + // or any of the wait_for_stop_tids are unknown. void - CallAfterThreadsStop (lldb::tid_t triggering_tid, + StopThreads(lldb::tid_t triggering_tid, const ThreadIDSet &wait_for_stop_tids, const StopThreadFunction &request_thread_stop_function, - const ThreadIDFunction &call_after_function, const ErrorFunction &error_function); - // This method is the main purpose of the class: triggering a deferred - // action after all non-stopped threads stop. The triggering_tid is the - // thread id passed to the call_after_function. The error_function will - // be fired if the triggering tid is unknown at the time of execution. + // Notify the delegate after all non-stopped threads stop. The triggering_tid will be set + // as the current thread. The error_function will be fired if the triggering tid + // is unknown. void - CallAfterRunningThreadsStop (lldb::tid_t triggering_tid, + StopRunningThreads(lldb::tid_t triggering_tid, const StopThreadFunction &request_thread_stop_function, - const ThreadIDFunction &call_after_function, const ErrorFunction &error_function); - // This method is the main purpose of the class: triggering a deferred - // action after all non-stopped threads stop. The triggering_tid is the - // thread id passed to the call_after_function. The error_function will - // be fired if the triggering tid is unknown at the time of execution. - // This variant will send stop requests to all non-stopped threads except - // for any contained in skip_stop_request_tids. + // Notify the delegate after all non-stopped threads stop. The triggering_tid will be set + // as the current thread. The error_function will be fired if either the triggering tid + // or any of the wait_for_stop_tids are unknown. This variant will send stop requests to + // all non-stopped threads except for any contained in skip_stop_request_tids. void - CallAfterRunningThreadsStopWithSkipTIDs (lldb::tid_t triggering_tid, + StopRunningThreadsWithSkipTID(lldb::tid_t triggering_tid, const ThreadIDSet &skip_stop_request_tids, const StopThreadFunction &request_thread_stop_function, - const ThreadIDFunction &call_after_function, const ErrorFunction &error_function); // Notify the thread stopped. Will trigger error at time of execution if we @@ -493,13 +482,11 @@ PendingNotification (lldb::tid_t triggering_tid, const ThreadIDSet &wait_for_stop_tids, const StopThreadFunction &request_thread_stop_function, - const ThreadIDFunction &call_after_function, const ErrorFunction &error_function): triggering_tid (triggering_tid), wait_for_stop_tids (wait_for_stop_tids), original_wait_for_stop_tids (wait_for_stop_tids), request_thread_stop_function (request_thread_stop_function), - call_after_function (call_after_function), error_function (error_function), request_stop_on_all_unstopped_threads (false), skip_stop_request_tids () @@ -508,13 +495,11 @@ PendingNotification (lldb::tid_t triggering_tid, const StopThreadFunction &request_thread_stop_function, - const ThreadIDFunction &call_after_function, const ErrorFunction &error_function) : triggering_tid (triggering_tid), wait_for_stop_tids (), original_wait_for_stop_tids (), request_thread_stop_function (request_thread_stop_function), - call_after_function (call_after_function), error_function (error_function), request_stop_on_all_unstopped_threads (true), skip_stop_request_tids () @@ -523,14 +508,12 @@ PendingNotification (lldb::tid_t triggering_tid, const StopThreadFunction &request_thread_stop_function, - const ThreadIDFunction &call_after_function, const ThreadIDSet &skip_stop_request_tids, const ErrorFunction &error_function) : triggering_tid (triggering_tid), wait_for_stop_tids (), original_wait_for_stop_tids (), request_thread_stop_function (request_thread_stop_function), - call_after_function (call_after_function), error_function (error_function), request_stop_on_all_unstopped_threads (true), skip_stop_request_tids (skip_stop_request_tids) @@ -541,7 +524,6 @@ ThreadIDSet wait_for_stop_tids; const ThreadIDSet original_wait_for_stop_tids; StopThreadFunction request_thread_stop_function; - ThreadIDFunction call_after_function; ErrorFunction error_function; const bool request_stop_on_all_unstopped_threads; ThreadIDSet skip_stop_request_tids; @@ -570,7 +552,7 @@ ErrorFunction error_function, bool error_when_already_running); void - DoCallAfterThreadsStop(PendingNotificationUP &¬ification_up); + DoStopThreads(PendingNotificationUP &¬ification_up); void ThreadWasCreated (lldb::tid_t tid, bool is_stopped, const ErrorFunction &error_function); Index: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp =================================================================== --- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -2460,11 +2460,7 @@ assert (main_thread_sp && "exec called during ptraced process but no main thread metadata tracked"); // Let the process know we're stopped. - CallAfterRunningThreadsStop (pid, - [=] (lldb::tid_t signaling_tid) - { - SetState (StateType::eStateStopped, true); - }); + StopRunningThreads (pid); break; } @@ -2584,11 +2580,7 @@ // once all running threads have checked in as stopped. SetCurrentThreadID(pid); // Tell the process we have a stop (from software breakpoint). - CallAfterRunningThreadsStop(pid, - [=](lldb::tid_t signaling_tid) - { - SetState(StateType::eStateStopped, true); - }); + StopRunningThreads(pid); } void @@ -2633,13 +2625,7 @@ // We need to tell all other running threads before we notify the delegate about this stop. - CallAfterRunningThreadsStop(pid, - [=](lldb::tid_t deferred_notification_tid) - { - SetCurrentThreadID(deferred_notification_tid); - // Tell the process we have a stop (from software breakpoint). - SetState(StateType::eStateStopped, true); - }); + StopRunningThreads(pid); } void @@ -2660,13 +2646,7 @@ std::static_pointer_cast(thread_sp)->SetStoppedByWatchpoint(wp_index); // We need to tell all other running threads before we notify the delegate about this stop. - CallAfterRunningThreadsStop(pid, - [=](lldb::tid_t deferred_notification_tid) - { - SetCurrentThreadID(deferred_notification_tid); - // Tell the process we have a stop (from watchpoint). - SetState(StateType::eStateStopped, true); - }); + StopRunningThreads(pid); } void @@ -2759,10 +2739,18 @@ const StateType thread_state = linux_thread_sp->GetState (); if (!StateIsStoppedState (thread_state, false)) { - // An inferior thread just stopped, but was not the primary cause of the process stop. - // Instead, something else (like a breakpoint or step) caused the stop. Mark the - // stop signal as 0 to let lldb know this isn't the important stop. - linux_thread_sp->SetStoppedBySignal (0); + // An inferior thread has stopped because of a SIGSTOP we have sent it. + // Generally, these are not important stops and we don't want to report them as + // they are just used to stop other threads when one thread (the one with the + // *real* stop reason) hits a breakpoint (watchpoint, etc...). However, in the + // case of an asynchronous Interrupt(), this *is* the real stop reason, so we + // leave the signal intact if this is the thread that was chosen as the + // triggering thread. + if (m_pending_notification_up && m_pending_notification_up->triggering_tid == pid) + linux_thread_sp->SetStoppedBySignal(SIGSTOP); + else + linux_thread_sp->SetStoppedBySignal(0); + SetCurrentThreadID (thread_sp->GetID ()); NotifyThreadStop (thread_sp->GetID (), true, CoordinatorErrorHandler); } @@ -2840,12 +2828,7 @@ } // Send a stop to the debugger after we get all other threads to stop. - CallAfterRunningThreadsStop (pid, - [=] (lldb::tid_t signaling_tid) - { - SetCurrentThreadID (signaling_tid); - SetState (StateType::eStateStopped, true); - }); + StopRunningThreads (pid); } namespace { @@ -3154,21 +3137,7 @@ // after all other running threads have stopped. // If there is a stepping thread involved we'll be eventually stopped by SIGTRAP trace signal. if (deferred_signal_tid != LLDB_INVALID_THREAD_ID && !stepping) - { - CallAfterRunningThreadsStopWithSkipTID (deferred_signal_tid, - deferred_signal_skip_tid, - [=](lldb::tid_t deferred_notification_tid) - { - // Set the signal thread to the current thread. - SetCurrentThreadID (deferred_notification_tid); - - // Set the thread state as stopped by the deferred signo. - std::static_pointer_cast (deferred_signal_thread_sp)->SetStoppedBySignal (deferred_signo); - - // Tell the process delegate that the process is in a stopped state. - SetState (StateType::eStateStopped, true); - }); - } + StopRunningThreadsWithSkipTID(deferred_signal_tid, deferred_signal_skip_tid); return Error(); } @@ -3272,18 +3241,7 @@ running_thread_sp ? "running" : "stopped", deferred_signal_thread_sp->GetID ()); - CallAfterRunningThreadsStop (deferred_signal_thread_sp->GetID (), - [=](lldb::tid_t deferred_notification_tid) - { - // Set the signal thread to the current thread. - SetCurrentThreadID (deferred_notification_tid); - - // Set the thread state as stopped by the deferred signo. - std::static_pointer_cast (deferred_signal_thread_sp)->SetStoppedBySignal (SIGSTOP); - - // Tell the process delegate that the process is in a stopped state. - SetState (StateType::eStateStopped, true); - }); + StopRunningThreads(deferred_signal_thread_sp->GetID()); return Error(); } @@ -4260,37 +4218,30 @@ } void -NativeProcessLinux::CallAfterRunningThreadsStop (lldb::tid_t tid, - const std::function &call_after_function) +NativeProcessLinux::StopRunningThreads(lldb::tid_t trigerring_tid) { Log *const log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD)); if (log) - log->Printf("NativeProcessLinux::%s tid %" PRIu64, __FUNCTION__, tid); + log->Printf("NativeProcessLinux::%s tid %" PRIu64, __FUNCTION__, trigerring_tid); const lldb::pid_t pid = GetID (); - CallAfterRunningThreadsStop (tid, - [=](lldb::tid_t request_stop_tid) - { - return RequestThreadStop(pid, request_stop_tid); - }, - call_after_function, - CoordinatorErrorHandler); + StopRunningThreads(trigerring_tid, + [=](lldb::tid_t request_stop_tid) { return RequestThreadStop(pid, request_stop_tid); }, + CoordinatorErrorHandler); } void -NativeProcessLinux::CallAfterRunningThreadsStopWithSkipTID (lldb::tid_t deferred_signal_tid, - lldb::tid_t skip_stop_request_tid, - const std::function &call_after_function) +NativeProcessLinux::StopRunningThreadsWithSkipTID(lldb::tid_t deferred_signal_tid, + lldb::tid_t skip_stop_request_tid) { Log *const log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD)); if (log) log->Printf("NativeProcessLinux::%s deferred_signal_tid %" PRIu64 ", skip_stop_request_tid %" PRIu64, __FUNCTION__, deferred_signal_tid, skip_stop_request_tid); const lldb::pid_t pid = GetID (); - CallAfterRunningThreadsStopWithSkipTIDs (deferred_signal_tid, + StopRunningThreadsWithSkipTID(deferred_signal_tid, skip_stop_request_tid != LLDB_INVALID_THREAD_ID ? NativeProcessLinux::ThreadIDSet {skip_stop_request_tid} : NativeProcessLinux::ThreadIDSet (), [=](lldb::tid_t request_stop_tid) { return RequestThreadStop(pid, request_stop_tid); }, - call_after_function, CoordinatorErrorHandler); } @@ -4442,10 +4393,9 @@ //===----------------------------------------------------------------------===// void -NativeProcessLinux::CallAfterThreadsStop (const lldb::tid_t triggering_tid, +NativeProcessLinux::StopThreads(const lldb::tid_t triggering_tid, const ThreadIDSet &wait_for_stop_tids, const StopThreadFunction &request_thread_stop_function, - const ThreadIDFunction &call_after_function, const ErrorFunction &error_function) { std::lock_guard lock(m_event_mutex); @@ -4456,9 +4406,8 @@ __FUNCTION__, triggering_tid, wait_for_stop_tids.size()); } - DoCallAfterThreadsStop(PendingNotificationUP(new PendingNotification( - triggering_tid, wait_for_stop_tids, request_thread_stop_function, - call_after_function, error_function))); + DoStopThreads(PendingNotificationUP(new PendingNotification( + triggering_tid, wait_for_stop_tids, request_thread_stop_function, error_function))); if (m_log_event_processing) { @@ -4467,9 +4416,8 @@ } void -NativeProcessLinux::CallAfterRunningThreadsStop (const lldb::tid_t triggering_tid, +NativeProcessLinux::StopRunningThreads(const lldb::tid_t triggering_tid, const StopThreadFunction &request_thread_stop_function, - const ThreadIDFunction &call_after_function, const ErrorFunction &error_function) { std::lock_guard lock(m_event_mutex); @@ -4480,10 +4428,9 @@ __FUNCTION__, triggering_tid); } - DoCallAfterThreadsStop(PendingNotificationUP(new PendingNotification( + DoStopThreads(PendingNotificationUP(new PendingNotification( triggering_tid, request_thread_stop_function, - call_after_function, error_function))); if (m_log_event_processing) @@ -4493,10 +4440,9 @@ } void -NativeProcessLinux::CallAfterRunningThreadsStopWithSkipTIDs (lldb::tid_t triggering_tid, +NativeProcessLinux::StopRunningThreadsWithSkipTID(lldb::tid_t triggering_tid, const ThreadIDSet &skip_stop_request_tids, const StopThreadFunction &request_thread_stop_function, - const ThreadIDFunction &call_after_function, const ErrorFunction &error_function) { std::lock_guard lock(m_event_mutex); @@ -4507,10 +4453,9 @@ __FUNCTION__, triggering_tid, skip_stop_request_tids.size()); } - DoCallAfterThreadsStop(PendingNotificationUP(new PendingNotification( + DoStopThreads(PendingNotificationUP(new PendingNotification( triggering_tid, request_thread_stop_function, - call_after_function, skip_stop_request_tids, error_function))); @@ -4525,7 +4470,8 @@ { if (m_pending_notification_up && m_pending_notification_up->wait_for_stop_tids.empty ()) { - m_pending_notification_up->call_after_function(m_pending_notification_up->triggering_tid); + SetCurrentThreadID(m_pending_notification_up->triggering_tid); + SetState(StateType::eStateStopped, true); m_pending_notification_up.reset(); } } @@ -4664,7 +4610,7 @@ } void -NativeProcessLinux::DoCallAfterThreadsStop(PendingNotificationUP &¬ification_up) +NativeProcessLinux::DoStopThreads(PendingNotificationUP &¬ification_up) { // Validate we know about the deferred trigger thread. if (!IsKnownThread (notification_up->triggering_tid)) @@ -4697,12 +4643,7 @@ return; } - if (m_pending_notification_up->wait_for_stop_tids.empty ()) - { - // We're not waiting for any threads. Fire off the deferred signal delivery event. - m_pending_notification_up->call_after_function(m_pending_notification_up->triggering_tid); - m_pending_notification_up.reset(); - } + SignalIfRequirementsSatisfied(); } void