Add a "force_kill" arg to Process::Destroy(). This is needed after
authorJason Molenda <jmolenda@apple.com>
Fri, 17 Apr 2015 05:01:58 +0000 (05:01 +0000)
committerJason Molenda <jmolenda@apple.com>
Fri, 17 Apr 2015 05:01:58 +0000 (05:01 +0000)
the changes in r233255/r233258.  Normally if lldb attaches to
a running process, when we call Process::Destroy, we want to detach
from the process.  If lldb launched the process itself, ::Destroy
should kill it.

However, if we attach to a process and the driver calls SBProcess::Kill()
(which calls Destroy), we need to kill it even if we didn't launch it
originally.

The force_kill param allows for the SBProcess::Kill method to force the
behavior of Destroy.

<rdar://problem/20424439>

llvm-svn: 235158

lldb/include/lldb/Target/Process.h
lldb/source/API/SBProcess.cpp
lldb/source/Commands/CommandObjectProcess.cpp
lldb/source/Core/IOHandler.cpp
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/source/Target/Process.cpp
lldb/source/Target/Target.cpp

index e8cf910..5e47409 100644 (file)
@@ -1343,11 +1343,19 @@ public:
     /// This function is not meant to be overridden by Process
     /// subclasses.
     ///
+    /// @param[in] force_kill
+    ///     Whether lldb should force a kill (instead of a detach) from
+    ///     the inferior process.  Normally if lldb launched a binary and
+    ///     Destory is called, lldb kills it.  If lldb attached to a 
+    ///     running process and Destory is called, lldb detaches.  If 
+    ///     this behavior needs to be over-ridden, this is the bool that
+    ///     can be used.
+    ///
     /// @return
     ///     Returns an error object.
     //------------------------------------------------------------------
     Error
-    Destroy();
+    Destroy(bool force_kill);
 
     //------------------------------------------------------------------
     /// Sends a process a UNIX signal \a signal.
index d979db7..aad3f85 100644 (file)
@@ -768,7 +768,7 @@ SBProcess::Destroy ()
     if (process_sp)
     {
         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
-        sb_error.SetError(process_sp->Destroy());
+        sb_error.SetError(process_sp->Destroy(false));
     }
     else
         sb_error.SetErrorString ("SBProcess is invalid");
@@ -821,7 +821,7 @@ SBProcess::Kill ()
     if (process_sp)
     {
         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
-        sb_error.SetError (process_sp->Destroy());
+        sb_error.SetError (process_sp->Destroy(true));
     }
     else
         sb_error.SetErrorString ("SBProcess is invalid");
index 487a979..c9d9210 100644 (file)
@@ -93,7 +93,7 @@ protected:
                     }
                     else
                     {
-                        Error destroy_error (process->Destroy());
+                        Error destroy_error (process->Destroy(false));
                         if (destroy_error.Success())
                         {
                             result.SetStatus (eReturnStatusSuccessFinishResult);
@@ -1466,7 +1466,7 @@ protected:
 
         if (command.GetArgumentCount() == 0)
         {
-            Error error (process->Destroy());
+            Error error (process->Destroy(false));
             if (error.Success())
             {
                 result.SetStatus (eReturnStatusSuccessFinishResult);
index 0f9d8a8..81afae5 100644 (file)
@@ -4433,7 +4433,7 @@ public:
                     {
                         Process *process = exe_ctx.GetProcessPtr();
                         if (process && process->IsAlive())
-                            process->Destroy();
+                            process->Destroy(false);
                     }
                 }
                 return MenuActionResult::Handled;
@@ -5392,7 +5392,7 @@ public:
                 {
                     ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
                     if (exe_ctx.HasProcessScope())
-                        exe_ctx.GetProcessRef().Destroy();
+                        exe_ctx.GetProcessRef().Destroy(false);
                 }
                 return eKeyHandled;
 
index dc61ec8..da3a650 100644 (file)
@@ -2166,7 +2166,7 @@ ProcessGDBRemote::DoDestroy ()
                         }
                     }
                     Resume ();
-                    return Destroy();
+                    return Destroy(false);
                 }
             }
         }
index 606c2c0..caa6756 100644 (file)
@@ -836,7 +836,7 @@ Process::Finalize()
         case eStateStepping:
         case eStateCrashed:
         case eStateSuspended:
-            Destroy();
+            Destroy(false);
             break;
             
         case eStateInvalid:
@@ -3160,7 +3160,7 @@ Process::Launch (ProcessLaunchInfo &launch_info)
                         // catch the initial stop.
                         error.SetErrorString ("failed to catch stop after launch");
                         SetExitStatus (0, "failed to catch stop after launch");
-                        Destroy();
+                        Destroy(false);
                     }
                     else if (state == eStateStopped || state == eStateCrashed)
                     {
@@ -3787,7 +3787,7 @@ Process::Halt (bool clear_thread_plans)
                 RestorePrivateProcessEvents();
                 restored_process_events = true;
                 SetExitStatus(SIGKILL, "Cancelled async attach.");
-                Destroy ();
+                Destroy (false);
             }
             else
             {
@@ -3961,12 +3961,15 @@ Process::Detach (bool keep_stopped)
 }
 
 Error
-Process::Destroy ()
+Process::Destroy (bool force_kill)
 {
     
     // Tell ourselves we are in the process of destroying the process, so that we don't do any unnecessary work
     // that might hinder the destruction.  Remember to set this back to false when we are done.  That way if the attempt
     // failed and the process stays around for some reason it won't be in a confused state.
+
+    if (force_kill)
+        m_should_detach = false;
     
     if (GetShouldDetach())
     {
index 193d62d..400cf47 100644 (file)
@@ -189,7 +189,7 @@ Target::DeleteCurrentProcess ()
     {
         m_section_load_history.Clear();
         if (m_process_sp->IsAlive())
-            m_process_sp->Destroy();
+            m_process_sp->Destroy(false);
         
         m_process_sp->Finalize();
 
@@ -2753,7 +2753,7 @@ Target::Attach (ProcessAttachInfo &attach_info, Stream *stream)
                 error.SetErrorStringWithFormat ("attach failed: %s", exit_desc);
             else
                 error.SetErrorString ("attach failed: process did not stop (no such process or permission problem?)");
-            process_sp->Destroy ();
+            process_sp->Destroy (false);
         }
     }
     return error;