[Lldb-commits] [lldb] r163591 - in /lldb/trunk: include/lldb/Target/Process.h source/Target/Process.cpp tools/debugserver/source/RNBRemote.cpp

Greg Clayton gclayton at apple.com
Mon Sep 10 19:33:37 PDT 2012


Author: gclayton
Date: Mon Sep 10 21:33:37 2012
New Revision: 163591

URL: http://llvm.org/viewvc/llvm-project?rev=163591&view=rev
Log:
<rdar://problem/11935492>

Fixed an issue where if we call "Process::Destroy()" and the process is running, if we try to stop it and get "exited" back as the stop reason, we will still deliver the exited event.


Modified:
    lldb/trunk/include/lldb/Target/Process.h
    lldb/trunk/source/Target/Process.cpp
    lldb/trunk/tools/debugserver/source/RNBRemote.cpp

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=163591&r1=163590&r2=163591&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Mon Sep 10 21:33:37 2012
@@ -3033,7 +3033,7 @@
     GetNextEvent (lldb::EventSP &event_sp);
 
     lldb::StateType
-    WaitForProcessToStop (const TimeValue *timeout);
+    WaitForProcessToStop (const TimeValue *timeout, lldb::EventSP *event_sp_ptr = NULL);
 
     lldb::StateType
     WaitForStateChangedEvents (const TimeValue *timeout, lldb::EventSP &event_sp);

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=163591&r1=163590&r2=163591&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Mon Sep 10 21:33:37 2012
@@ -1078,12 +1078,13 @@
 
 
 StateType
-Process::WaitForProcessToStop (const TimeValue *timeout)
+Process::WaitForProcessToStop (const TimeValue *timeout, lldb::EventSP *event_sp_ptr)
 {
     // We can't just wait for a "stopped" event, because the stopped event may have restarted the target.
     // We have to actually check each event, and in the case of a stopped event check the restarted flag
     // on the event.
-    EventSP event_sp;
+    if (event_sp_ptr)
+        event_sp_ptr->reset();
     StateType state = GetState();
     // If we are exited or detached, we won't ever get back to any
     // other valid state...
@@ -1092,7 +1093,11 @@
 
     while (state != eStateInvalid)
     {
+        EventSP event_sp;
         state = WaitForStateChangedEvents (timeout, event_sp);
+        if (event_sp_ptr && event_sp)
+            *event_sp_ptr = event_sp;
+
         switch (state)
         {
         case eStateCrashed:
@@ -3108,6 +3113,7 @@
     Error error (WillDestroy());
     if (error.Success())
     {
+        EventSP exit_event_sp;
         if (m_public_state.GetValue() == eStateRunning)
         {
             LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
@@ -3117,10 +3123,12 @@
             if (error.Success())
             {
                 // Consume the halt event.
-                EventSP stop_event;
                 TimeValue timeout (TimeValue::Now());
                 timeout.OffsetWithSeconds(1);
-                StateType state = WaitForProcessToStop (&timeout);
+                StateType state = WaitForProcessToStop (&timeout, &exit_event_sp);
+                if (state != eStateExited)
+                    exit_event_sp.reset(); // It is ok to consume any non-exit stop events
+        
                 if (state != eStateStopped)
                 {
                     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
@@ -3131,16 +3139,18 @@
                     StateType private_state = m_private_state.GetValue();
                     if (private_state != eStateStopped && private_state != eStateExited)
                     {
+                        // If we exited when we were waiting for a process to stop, then
+                        // forward the event here so we don't lose the event
                         return error;
                     }
                 }
             }
             else
             {
-                    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
-                    if (log)
-                        log->Printf("Process::Destroy() Halt got error: %s", error.AsCString());
-                    return error;
+                LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
+                if (log)
+                    log->Printf("Process::Destroy() Halt got error: %s", error.AsCString());
+                return error;
             }
         }
 
@@ -3166,7 +3176,16 @@
             m_target.GetDebugger().PopInputReader (m_process_input_reader);
         if (m_process_input_reader)
             m_process_input_reader.reset();
-            
+        
+        // If we exited when we were waiting for a process to stop, then
+        // forward the event here so we don't lose the event
+        if (exit_event_sp)
+        {
+            // Directly broadcast our exited event because we shut down our
+            // private state thread above
+            BroadcastEvent(exit_event_sp);
+        }
+
         // If we have been interrupted (to kill us) in the middle of running, we may not end up propagating
         // the last events through the event system, in which case we might strand the write lock.  Unlock
         // it here so when we do to tear down the process we don't get an error destroying the lock.

Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.cpp?rev=163591&r1=163590&r2=163591&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/RNBRemote.cpp (original)
+++ lldb/trunk/tools/debugserver/source/RNBRemote.cpp Mon Sep 10 21:33:37 2012
@@ -3525,10 +3525,17 @@
 rnb_err_t
 RNBRemote::HandlePacket_stop_process (const char *p)
 {
+//#define TEST_EXIT_ON_INTERRUPT // This should only be uncommented to test exiting on interrupt
+#if defined(TEST_EXIT_ON_INTERRUPT)
+    rnb_err_t err = HandlePacket_k (p);
+    m_comm.Disconnect(true);
+    return err;
+#else
     DNBProcessSignal (m_ctx.ProcessID(), SIGSTOP);
     //DNBProcessSignal (m_ctx.ProcessID(), SIGINT);
     // Do not send any response packet! Wait for the stop reply packet to naturally happen
     return rnb_success;
+#endif
 }
 
 /* 's'





More information about the lldb-commits mailing list