[Lldb-commits] [lldb] r227928 - Make ThreadStateCoordinator to handle properly failed stop/resume operations.

Chaoren Lin chaorenl at google.com
Mon Feb 2 17:51:31 PST 2015


Author: chaoren
Date: Mon Feb  2 19:51:30 2015
New Revision: 227928

URL: http://llvm.org/viewvc/llvm-project?rev=227928&view=rev
Log:
Make ThreadStateCoordinator to handle properly failed stop/resume operations.

Modified:
    lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
    lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.cpp
    lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.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=227928&r1=227927&r2=227928&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Mon Feb  2 19:51:30 2015
@@ -2114,7 +2114,7 @@ NativeProcessLinux::MonitorSIGTRAP(const
                                                        [=](lldb::tid_t tid_to_resume, bool supress_signal)
                                                        {
                                                            reinterpret_cast<NativeThreadLinux*> (new_thread_sp.get ())->SetRunning ();
-                                                           Resume (tid_to_resume, LLDB_INVALID_SIGNAL_NUMBER);
+                                                           return Resume (tid_to_resume, LLDB_INVALID_SIGNAL_NUMBER);
                                                        },
                                                        CoordinatorErrorHandler);
             }
@@ -2136,7 +2136,7 @@ NativeProcessLinux::MonitorSIGTRAP(const
                                                [=](lldb::tid_t tid_to_resume, bool supress_signal)
                                                {
                                                    reinterpret_cast<NativeThreadLinux*> (thread_sp.get ())->SetRunning ();
-                                                   Resume (tid_to_resume, LLDB_INVALID_SIGNAL_NUMBER);
+                                                   return Resume (tid_to_resume, LLDB_INVALID_SIGNAL_NUMBER);
                                                },
                                                CoordinatorErrorHandler);
 
@@ -2240,7 +2240,7 @@ NativeProcessLinux::MonitorSIGTRAP(const
                                                [=](lldb::tid_t tid_to_resume, bool supress_signal)
                                                {
                                                    reinterpret_cast<NativeThreadLinux*> (thread_sp.get ())->SetRunning ();
-                                                   Resume (tid_to_resume, (supress_signal) ? LLDB_INVALID_SIGNAL_NUMBER : signo);
+                                                   return Resume (tid_to_resume, (supress_signal) ? LLDB_INVALID_SIGNAL_NUMBER : signo);
                                                },
                                                CoordinatorErrorHandler);
 
@@ -2349,7 +2349,7 @@ NativeProcessLinux::MonitorSIGTRAP(const
                                                [=](lldb::tid_t tid_to_resume, bool supress_signal)
                                                {
                                                    reinterpret_cast<NativeThreadLinux*> (thread_sp.get ())->SetRunning ();
-                                                   Resume (tid_to_resume, LLDB_INVALID_SIGNAL_NUMBER);
+                                                   return Resume (tid_to_resume, LLDB_INVALID_SIGNAL_NUMBER);
                                                },
                                                CoordinatorErrorHandler);
         break;
@@ -2429,7 +2429,7 @@ NativeProcessLinux::MonitorSignal(const
                                                    [=](lldb::tid_t tid_to_resume, bool supress_signal)
                                                    {
                                                        reinterpret_cast<NativeThreadLinux*> (thread_sp.get ())->SetRunning ();
-                                                       Resume (tid_to_resume, LLDB_INVALID_SIGNAL_NUMBER);
+                                                       return Resume (tid_to_resume, LLDB_INVALID_SIGNAL_NUMBER);
                                                    },
                                                    CoordinatorErrorHandler);
         }
@@ -2528,7 +2528,7 @@ NativeProcessLinux::MonitorSignal(const
                                                    {
                                                        reinterpret_cast<NativeThreadLinux*> (thread_sp.get ())->SetRunning ();
                                                        // Pass this signal number on to the inferior to handle.
-                                                       Resume (tid_to_resume, (supress_signal) ? LLDB_INVALID_SIGNAL_NUMBER : signo);
+                                                       return Resume (tid_to_resume, (supress_signal) ? LLDB_INVALID_SIGNAL_NUMBER : signo);
                                                    },
                                                    CoordinatorErrorHandler);
         }
@@ -2603,7 +2603,7 @@ NativeProcessLinux::Resume (const Resume
                                                                {
                                                                    reinterpret_cast<NativeThreadLinux*> (thread_sp.get ())->SetRunning ();
                                                                    // Pass this signal number on to the inferior to handle.
-                                                                   Resume (tid_to_resume, (signo > 0 && !supress_signal) ? signo : LLDB_INVALID_SIGNAL_NUMBER);
+                                                                   return Resume (tid_to_resume, (signo > 0 && !supress_signal) ? signo : LLDB_INVALID_SIGNAL_NUMBER);
                                                                },
                                                                CoordinatorErrorHandler);
                 ++resume_count;
@@ -2618,8 +2618,9 @@ NativeProcessLinux::Resume (const Resume
                                                        [=](lldb::tid_t tid_to_step, bool supress_signal)
                                                        {
                                                            reinterpret_cast<NativeThreadLinux*> (thread_sp.get ())->SetStepping ();
-                                                           auto step_result = SingleStep (tid_to_step,(signo > 0 && !supress_signal) ? signo : LLDB_INVALID_SIGNAL_NUMBER);
-                                                           assert (step_result && "SingleStep() failed");
+                                                           const auto step_result = SingleStep (tid_to_step,(signo > 0 && !supress_signal) ? signo : LLDB_INVALID_SIGNAL_NUMBER);
+                                                           assert (step_result.Success() && "SingleStep() failed");
+                                                           return step_result;
                                                        },
                                                        CoordinatorErrorHandler);
                 stepping = true;
@@ -3872,7 +3873,7 @@ NativeProcessLinux::CallAfterRunningThre
     m_coordinator_up->CallAfterRunningThreadsStop (tid,
                                                    [=](lldb::tid_t request_stop_tid)
                                                    {
-                                                       RequestThreadStop(pid, request_stop_tid);
+                                                       return RequestThreadStop(pid, request_stop_tid);
                                                    },
                                                    call_after_function,
                                                    CoordinatorErrorHandler);
@@ -3892,7 +3893,7 @@ NativeProcessLinux::CallAfterRunningThre
                                                                skip_stop_request_tid != LLDB_INVALID_THREAD_ID ? ThreadStateCoordinator::ThreadIDSet {skip_stop_request_tid} : ThreadStateCoordinator::ThreadIDSet (),
                                                                [=](lldb::tid_t request_stop_tid)
                                                                {
-                                                                   RequestThreadStop(pid, request_stop_tid);
+                                                                   return RequestThreadStop(pid, request_stop_tid);
                                                                },
                                                                call_after_function,
                                                                CoordinatorErrorHandler);

Modified: lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.cpp?rev=227928&r1=227927&r2=227928&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.cpp Mon Feb  2 19:51:30 2015
@@ -73,7 +73,7 @@ class ThreadStateCoordinator::EventCallA
 public:
     EventCallAfterThreadsStop (lldb::tid_t triggering_tid,
                                const ThreadIDSet &wait_for_stop_tids,
-                               const ThreadIDFunction &request_thread_stop_function,
+                               const StopThreadFunction &request_thread_stop_function,
                                const ThreadIDFunction &call_after_function,
                                const ErrorFunction &error_function):
     EventBase (),
@@ -89,7 +89,7 @@ public:
     }
 
     EventCallAfterThreadsStop (lldb::tid_t triggering_tid,
-                               const ThreadIDFunction &request_thread_stop_function,
+                               const StopThreadFunction &request_thread_stop_function,
                                const ThreadIDFunction &call_after_function,
                                const ErrorFunction &error_function) :
     EventBase (),
@@ -105,7 +105,7 @@ public:
     }
 
     EventCallAfterThreadsStop (lldb::tid_t triggering_tid,
-                               const ThreadIDFunction &request_thread_stop_function,
+                               const StopThreadFunction &request_thread_stop_function,
                                const ThreadIDFunction &call_after_function,
                                const ThreadIDSet &skip_stop_request_tids,
                                const ErrorFunction &error_function) :
@@ -261,10 +261,10 @@ private:
             }
 
             // If the pending stop thread is currently running, we need to send it a stop request.
-            if (find_it->second.m_state == ThreadState::Running)
+            auto& context = find_it->second;
+            if (context.m_state == ThreadState::Running)
             {
-                m_request_thread_stop_function (tid);
-                RequestThreadStop (tid, find_it->second);
+                RequestThreadStop (tid, coordinator, context);
                 sent_tids.insert (tid);
             }
         }
@@ -297,7 +297,7 @@ private:
                 // Request this thread stop if the tid stop request is not explicitly ignored.
                 const bool skip_stop_request = m_skip_stop_request_tids.count (tid) > 0;
                 if (!skip_stop_request)
-                    RequestThreadStop (tid, it->second);
+                    RequestThreadStop (tid, coordinator, it->second);
 
                 // Even if we skipped sending the stop request for other reasons (like stepping),
                 // we still need to wait for that stepping thread to notify completion/stop.
@@ -310,16 +310,24 @@ private:
     }
 
     void
-    RequestThreadStop (lldb::tid_t tid, ThreadContext& context)
+    RequestThreadStop (lldb::tid_t tid, ThreadStateCoordinator &coordinator, ThreadContext& context)
     {
-        m_request_thread_stop_function (tid);
-        context.m_stop_requested = true;
+        const auto error = m_request_thread_stop_function (tid);
+        if (error.Success ())
+        {
+            context.m_stop_requested = true;
+        }
+        else
+        {
+            coordinator.Log ("EventCallAfterThreadsStop::%s failed to request thread stop tid  %" PRIu64 ": %s",
+                             __FUNCTION__, tid, error.AsCString ());
+        }
     }
 
     const lldb::tid_t m_triggering_tid;
     ThreadIDSet m_wait_for_stop_tids;
     const ThreadIDSet m_original_wait_for_stop_tids;
-    ThreadIDFunction m_request_thread_stop_function;
+    StopThreadFunction m_request_thread_stop_function;
     ThreadIDFunction m_call_after_function;
     ErrorFunction m_error_function;
     const bool m_request_stop_on_all_unstopped_threads;
@@ -543,11 +551,18 @@ public:
 
         // Request a resume.  We expect this to be synchronous and the system
         // to reflect it is running after this completes.
-        m_request_thread_resume_function (m_tid, false);
-
-        // Now mark it is running.
-        context.m_state = ThreadState::Running;
-        context.m_request_resume_function = m_request_thread_resume_function;
+        const auto error = m_request_thread_resume_function (m_tid, false);
+        if (error.Success ())
+        {
+            // Now mark it is running.
+            context.m_state = ThreadState::Running;
+            context.m_request_resume_function = m_request_thread_resume_function;
+        }
+        else
+        {
+            coordinator.Log ("EventRequestResume::%s failed to resume thread tid  %" PRIu64 ": %s",
+                             __FUNCTION__, m_tid, error.AsCString ());
+        }
 
         return eventLoopResultContinue;
     }
@@ -633,7 +648,7 @@ ThreadStateCoordinator::SetPendingNotifi
 void
 ThreadStateCoordinator::CallAfterThreadsStop (const lldb::tid_t triggering_tid,
                                               const ThreadIDSet &wait_for_stop_tids,
-                                              const ThreadIDFunction &request_thread_stop_function,
+                                              const StopThreadFunction &request_thread_stop_function,
                                               const ThreadIDFunction &call_after_function,
                                               const ErrorFunction &error_function)
 {
@@ -646,7 +661,7 @@ ThreadStateCoordinator::CallAfterThreads
 
 void
 ThreadStateCoordinator::CallAfterRunningThreadsStop (const lldb::tid_t triggering_tid,
-                                                     const ThreadIDFunction &request_thread_stop_function,
+                                                     const StopThreadFunction &request_thread_stop_function,
                                                      const ThreadIDFunction &call_after_function,
                                                      const ErrorFunction &error_function)
 {
@@ -659,7 +674,7 @@ ThreadStateCoordinator::CallAfterRunning
 void
 ThreadStateCoordinator::CallAfterRunningThreadsStopWithSkipTIDs (lldb::tid_t triggering_tid,
                                                                  const ThreadIDSet &skip_stop_request_tids,
-                                                                 const ThreadIDFunction &request_thread_stop_function,
+                                                                 const StopThreadFunction &request_thread_stop_function,
                                                                  const ThreadIDFunction &call_after_function,
                                                                  const ErrorFunction &error_function)
 {
@@ -708,8 +723,16 @@ ThreadStateCoordinator::ThreadDidStop (l
         // We can end up here if stop was initiated by LLGS but by this time a
         // thread stop has occurred - maybe initiated by another event.
         Log ("Resuming thread %"  PRIu64 " since stop wasn't requested", tid);
-        context.m_request_resume_function (tid, true);
-        context.m_state = ThreadState::Running;
+        const auto error = context.m_request_resume_function (tid, true);
+        if (error.Success ())
+        {
+            context.m_state = ThreadState::Running;
+        }
+        else
+        {
+            Log ("ThreadStateCoordinator::%s failed to resume thread tid  %" PRIu64 ": %s",
+                 __FUNCTION__, tid, error.AsCString ());
+        }
     }
 }
 

Modified: lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.h?rev=227928&r1=227927&r2=227928&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.h (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.h Mon Feb  2 19:51:30 2015
@@ -19,6 +19,8 @@
 
 #include "lldb/lldb-types.h"
 
+#include "lldb/Core/Error.h"
+
 namespace lldb_private
 {
     class ThreadStateCoordinator
@@ -38,7 +40,8 @@ namespace lldb_private
         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<void (lldb::tid_t tid, bool supress_signal)> ResumeThreadFunction;
+        typedef std::function<Error (lldb::tid_t tid)> StopThreadFunction;
+        typedef std::function<Error (lldb::tid_t tid, bool supress_signal)> ResumeThreadFunction;
 
         // Constructors.
         ThreadStateCoordinator (const LogFunction &log_function);
@@ -68,7 +71,7 @@ namespace lldb_private
         void
         CallAfterThreadsStop (lldb::tid_t triggering_tid,
                               const ThreadIDSet &wait_for_stop_tids,
-                              const ThreadIDFunction &request_thread_stop_function,
+                              const StopThreadFunction &request_thread_stop_function,
                               const ThreadIDFunction &call_after_function,
                               const ErrorFunction &error_function);
 
@@ -78,7 +81,7 @@ namespace lldb_private
         // be fired if the triggering tid is unknown at the time of execution.
         void
         CallAfterRunningThreadsStop (lldb::tid_t triggering_tid,
-                                     const ThreadIDFunction &request_thread_stop_function,
+                                     const StopThreadFunction &request_thread_stop_function,
                                      const ThreadIDFunction &call_after_function,
                                      const ErrorFunction &error_function);
 
@@ -91,7 +94,7 @@ namespace lldb_private
         void
         CallAfterRunningThreadsStopWithSkipTIDs (lldb::tid_t triggering_tid,
                                                  const ThreadIDSet &skip_stop_request_tids,
-                                                 const ThreadIDFunction &request_thread_stop_function,
+                                                 const StopThreadFunction &request_thread_stop_function,
                                                  const ThreadIDFunction &call_after_function,
                                                  const ErrorFunction &error_function);
 





More information about the lldb-commits mailing list