[Lldb-commits] [lldb] r235158 - Add a "force_kill" arg to Process::Destroy(). This is needed after

Zachary Turner zturner at google.com
Thu Apr 16 23:32:40 PDT 2015


Could we have a test for this?
On Thu, Apr 16, 2015 at 10:05 PM Jason Molenda <jmolenda at apple.com> wrote:

> Author: jmolenda
> Date: Fri Apr 17 00:01:58 2015
> New Revision: 235158
>
> URL: http://llvm.org/viewvc/llvm-project?rev=235158&view=rev
> Log:
> Add a "force_kill" arg to Process::Destroy().  This is needed after
> 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>
>
>
> Modified:
>     lldb/trunk/include/lldb/Target/Process.h
>     lldb/trunk/source/API/SBProcess.cpp
>     lldb/trunk/source/Commands/CommandObjectProcess.cpp
>     lldb/trunk/source/Core/IOHandler.cpp
>     lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
>     lldb/trunk/source/Target/Process.cpp
>     lldb/trunk/source/Target/Target.cpp
>
> Modified: lldb/trunk/include/lldb/Target/Process.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=235158&r1=235157&r2=235158&view=diff
>
> ==============================================================================
> --- lldb/trunk/include/lldb/Target/Process.h (original)
> +++ lldb/trunk/include/lldb/Target/Process.h Fri Apr 17 00:01:58 2015
> @@ -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.
>
> Modified: lldb/trunk/source/API/SBProcess.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBProcess.cpp?rev=235158&r1=235157&r2=235158&view=diff
>
> ==============================================================================
> --- lldb/trunk/source/API/SBProcess.cpp (original)
> +++ lldb/trunk/source/API/SBProcess.cpp Fri Apr 17 00:01:58 2015
> @@ -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");
>
> Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=235158&r1=235157&r2=235158&view=diff
>
> ==============================================================================
> --- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)
> +++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Fri Apr 17
> 00:01:58 2015
> @@ -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);
>
> Modified: lldb/trunk/source/Core/IOHandler.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/IOHandler.cpp?rev=235158&r1=235157&r2=235158&view=diff
>
> ==============================================================================
> --- lldb/trunk/source/Core/IOHandler.cpp (original)
> +++ lldb/trunk/source/Core/IOHandler.cpp Fri Apr 17 00:01:58 2015
> @@ -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;
>
>
> Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=235158&r1=235157&r2=235158&view=diff
>
> ==============================================================================
> --- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
> (original)
> +++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Fri
> Apr 17 00:01:58 2015
> @@ -2166,7 +2166,7 @@ ProcessGDBRemote::DoDestroy ()
>                          }
>                      }
>                      Resume ();
> -                    return Destroy();
> +                    return Destroy(false);
>                  }
>              }
>          }
>
> Modified: lldb/trunk/source/Target/Process.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=235158&r1=235157&r2=235158&view=diff
>
> ==============================================================================
> --- lldb/trunk/source/Target/Process.cpp (original)
> +++ lldb/trunk/source/Target/Process.cpp Fri Apr 17 00:01:58 2015
> @@ -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 &laun
>                          // 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())
>      {
>
> Modified: lldb/trunk/source/Target/Target.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=235158&r1=235157&r2=235158&view=diff
>
> ==============================================================================
> --- lldb/trunk/source/Target/Target.cpp (original)
> +++ lldb/trunk/source/Target/Target.cpp Fri Apr 17 00:01:58 2015
> @@ -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 &attac
>                  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;
>
>
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150417/ca1b00d6/attachment.html>


More information about the lldb-commits mailing list