[Lldb-commits] [lldb] r236595 - [NativeProcessLinux] Remove the post-stop lambda

Pavel Labath labath at google.com
Wed May 6 05:22:38 PDT 2015


Author: labath
Date: Wed May  6 07:22:37 2015
New Revision: 236595

URL: http://llvm.org/viewvc/llvm-project?rev=236595&view=rev
Log:
[NativeProcessLinux] Remove the post-stop lambda

Summary:
The lambda was always calling SetState(eStateStopped) with small variations, so I have inlined
the code. Given that we don't have the TSC anymore, I believe we don't need to be so generic.

The only major change here is the way we choose a stop reason thread when we're interrupting a
program on client request. Previously, we were setting a null stop reason for all threads and
then fixing up the reason for one victim thread in the lambda. Now, I make sure the stop reason
is set for the victim thread correctly in the first place.

I also take the opportunity to rename CallAfter* functions into something more appropriate.

Test Plan: All tests continue to pass.

Reviewers: chaoren, vharron

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D9321

Modified:
    lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
    lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp?rev=236595&r1=236594&r2=236595&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Wed May  6 07:22:37 2015
@@ -2460,11 +2460,7 @@ NativeProcessLinux::MonitorSIGTRAP(const
         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 @@ NativeProcessLinux::MonitorTrace(lldb::p
     // 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 @@ NativeProcessLinux::MonitorBreakpoint(ll
 
 
     // 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 @@ NativeProcessLinux::MonitorWatchpoint(ll
     std::static_pointer_cast<NativeThreadLinux>(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 @@ NativeProcessLinux::MonitorSignal(const
             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 @@ NativeProcessLinux::MonitorSignal(const
     }
 
     // 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 @@ NativeProcessLinux::Resume (const Resume
     // 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<NativeThreadLinux> (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 @@ NativeProcessLinux::Interrupt ()
                      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<NativeThreadLinux> (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 @@ NativeProcessLinux::NotifyThreadStop (ll
 }
 
 void
-NativeProcessLinux::CallAfterRunningThreadsStop (lldb::tid_t tid,
-                                                 const std::function<void (lldb::tid_t tid)> &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<void (lldb::tid_t tid)> &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 @@ NativeProcessLinux::DoResume(
 //===----------------------------------------------------------------------===//
 
 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<std::mutex> lock(m_event_mutex);
@@ -4456,9 +4406,8 @@ NativeProcessLinux::CallAfterThreadsStop
                 __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 @@ NativeProcessLinux::CallAfterThreadsStop
 }
 
 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<std::mutex> lock(m_event_mutex);
@@ -4480,10 +4428,9 @@ NativeProcessLinux::CallAfterRunningThre
                 __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 @@ NativeProcessLinux::CallAfterRunningThre
 }
 
 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<std::mutex> lock(m_event_mutex);
@@ -4507,10 +4453,9 @@ NativeProcessLinux::CallAfterRunningThre
                 __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 @@ NativeProcessLinux::SignalIfRequirements
 {
     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 @@ NativeProcessLinux::ThreadDidStop (lldb:
 }
 
 void
-NativeProcessLinux::DoCallAfterThreadsStop(PendingNotificationUP &&notification_up)
+NativeProcessLinux::DoStopThreads(PendingNotificationUP &&notification_up)
 {
     // Validate we know about the deferred trigger thread.
     if (!IsKnownThread (notification_up->triggering_tid))
@@ -4697,12 +4643,7 @@ NativeProcessLinux::DoCallAfterThreadsSt
             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

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h?rev=236595&r1=236594&r2=236595&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h Wed May  6 07:22:37 2015
@@ -359,13 +359,11 @@ namespace process_linux {
         NotifyThreadStop (lldb::tid_t tid);
 
         void
-        CallAfterRunningThreadsStop (lldb::tid_t tid,
-                                     const std::function<void (lldb::tid_t tid)> &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<void (lldb::tid_t tid)> &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 @@ namespace process_linux {
         typedef std::unordered_set<lldb::tid_t> ThreadIDSet;
 
         // Callback/block definitions.
-        typedef std::function<void (lldb::tid_t tid)> ThreadIDFunction;
         typedef std::function<void (const char *format, va_list args)> LogFunction;
         typedef std::function<void (const std::string &error_message)> ErrorFunction;
         typedef std::function<Error (lldb::tid_t tid)> StopThreadFunction;
@@ -403,39 +400,31 @@ namespace process_linux {
                            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 @@ namespace process_linux {
             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 @@ namespace process_linux {
 
             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 @@ namespace process_linux {
 
             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 @@ namespace process_linux {
             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 @@ namespace process_linux {
                 ErrorFunction error_function, bool error_when_already_running);
 
         void
-        DoCallAfterThreadsStop(PendingNotificationUP &&notification_up);
+        DoStopThreads(PendingNotificationUP &&notification_up);
 
         void
         ThreadWasCreated (lldb::tid_t tid, bool is_stopped, const ErrorFunction &error_function);





More information about the lldb-commits mailing list