Could we have a test for this?<br><div class="gmail_quote">On Thu, Apr 16, 2015 at 10:05 PM Jason Molenda <<a href="mailto:jmolenda@apple.com">jmolenda@apple.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: jmolenda<br>
Date: Fri Apr 17 00:01:58 2015<br>
New Revision: 235158<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=235158&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=235158&view=rev</a><br>
Log:<br>
Add a "force_kill" arg to Process::Destroy(). This is needed after<br>
the changes in r233255/r233258. Normally if lldb attaches to<br>
a running process, when we call Process::Destroy, we want to detach<br>
from the process. If lldb launched the process itself, ::Destroy<br>
should kill it.<br>
<br>
However, if we attach to a process and the driver calls SBProcess::Kill()<br>
(which calls Destroy), we need to kill it even if we didn't launch it<br>
originally.<br>
<br>
The force_kill param allows for the SBProcess::Kill method to force the<br>
behavior of Destroy.<br>
<br>
<rdar://problem/20424439><br>
<br>
<br>
Modified:<br>
lldb/trunk/include/lldb/Target/Process.h<br>
lldb/trunk/source/API/SBProcess.cpp<br>
lldb/trunk/source/Commands/CommandObjectProcess.cpp<br>
lldb/trunk/source/Core/IOHandler.cpp<br>
lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp<br>
lldb/trunk/source/Target/Process.cpp<br>
lldb/trunk/source/Target/Target.cpp<br>
<br>
Modified: lldb/trunk/include/lldb/Target/Process.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=235158&r1=235157&r2=235158&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=235158&r1=235157&r2=235158&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/Target/Process.h (original)<br>
+++ lldb/trunk/include/lldb/Target/Process.h Fri Apr 17 00:01:58 2015<br>
@@ -1343,11 +1343,19 @@ public:<br>
/// This function is not meant to be overridden by Process<br>
/// subclasses.<br>
///<br>
+ /// @param[in] force_kill<br>
+ /// Whether lldb should force a kill (instead of a detach) from<br>
+ /// the inferior process. Normally if lldb launched a binary and<br>
+ /// Destory is called, lldb kills it. If lldb attached to a<br>
+ /// running process and Destory is called, lldb detaches. If<br>
+ /// this behavior needs to be over-ridden, this is the bool that<br>
+ /// can be used.<br>
+ ///<br>
/// @return<br>
/// Returns an error object.<br>
//------------------------------------------------------------------<br>
Error<br>
- Destroy();<br>
+ Destroy(bool force_kill);<br>
<br>
//------------------------------------------------------------------<br>
/// Sends a process a UNIX signal \a signal.<br>
<br>
Modified: lldb/trunk/source/API/SBProcess.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBProcess.cpp?rev=235158&r1=235157&r2=235158&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBProcess.cpp?rev=235158&r1=235157&r2=235158&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/API/SBProcess.cpp (original)<br>
+++ lldb/trunk/source/API/SBProcess.cpp Fri Apr 17 00:01:58 2015<br>
@@ -768,7 +768,7 @@ SBProcess::Destroy ()<br>
if (process_sp)<br>
{<br>
Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());<br>
- sb_error.SetError(process_sp->Destroy());<br>
+ sb_error.SetError(process_sp->Destroy(false));<br>
}<br>
else<br>
sb_error.SetErrorString ("SBProcess is invalid");<br>
@@ -821,7 +821,7 @@ SBProcess::Kill ()<br>
if (process_sp)<br>
{<br>
Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());<br>
- sb_error.SetError (process_sp->Destroy());<br>
+ sb_error.SetError (process_sp->Destroy(true));<br>
}<br>
else<br>
sb_error.SetErrorString ("SBProcess is invalid");<br>
<br>
Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=235158&r1=235157&r2=235158&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=235158&r1=235157&r2=235158&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)<br>
+++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Fri Apr 17 00:01:58 2015<br>
@@ -93,7 +93,7 @@ protected:<br>
}<br>
else<br>
{<br>
- Error destroy_error (process->Destroy());<br>
+ Error destroy_error (process->Destroy(false));<br>
if (destroy_error.Success())<br>
{<br>
result.SetStatus (eReturnStatusSuccessFinishResult);<br>
@@ -1466,7 +1466,7 @@ protected:<br>
<br>
if (command.GetArgumentCount() == 0)<br>
{<br>
- Error error (process->Destroy());<br>
+ Error error (process->Destroy(false));<br>
if (error.Success())<br>
{<br>
result.SetStatus (eReturnStatusSuccessFinishResult);<br>
<br>
Modified: lldb/trunk/source/Core/IOHandler.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/IOHandler.cpp?rev=235158&r1=235157&r2=235158&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/IOHandler.cpp?rev=235158&r1=235157&r2=235158&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Core/IOHandler.cpp (original)<br>
+++ lldb/trunk/source/Core/IOHandler.cpp Fri Apr 17 00:01:58 2015<br>
@@ -4433,7 +4433,7 @@ public:<br>
{<br>
Process *process = exe_ctx.GetProcessPtr();<br>
if (process && process->IsAlive())<br>
- process->Destroy();<br>
+ process->Destroy(false);<br>
}<br>
}<br>
return MenuActionResult::Handled;<br>
@@ -5392,7 +5392,7 @@ public:<br>
{<br>
ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();<br>
if (exe_ctx.HasProcessScope())<br>
- exe_ctx.GetProcessRef().Destroy();<br>
+ exe_ctx.GetProcessRef().Destroy(false);<br>
}<br>
return eKeyHandled;<br>
<br>
<br>
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=235158&r1=235157&r2=235158&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=235158&r1=235157&r2=235158&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)<br>
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Fri Apr 17 00:01:58 2015<br>
@@ -2166,7 +2166,7 @@ ProcessGDBRemote::DoDestroy ()<br>
}<br>
}<br>
Resume ();<br>
- return Destroy();<br>
+ return Destroy(false);<br>
}<br>
}<br>
}<br>
<br>
Modified: lldb/trunk/source/Target/Process.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=235158&r1=235157&r2=235158&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=235158&r1=235157&r2=235158&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Target/Process.cpp (original)<br>
+++ lldb/trunk/source/Target/Process.cpp Fri Apr 17 00:01:58 2015<br>
@@ -836,7 +836,7 @@ Process::Finalize()<br>
case eStateStepping:<br>
case eStateCrashed:<br>
case eStateSuspended:<br>
- Destroy();<br>
+ Destroy(false);<br>
break;<br>
<br>
case eStateInvalid:<br>
@@ -3160,7 +3160,7 @@ Process::Launch (ProcessLaunchInfo &laun<br>
// catch the initial stop.<br>
error.SetErrorString ("failed to catch stop after launch");<br>
SetExitStatus (0, "failed to catch stop after launch");<br>
- Destroy();<br>
+ Destroy(false);<br>
}<br>
else if (state == eStateStopped || state == eStateCrashed)<br>
{<br>
@@ -3787,7 +3787,7 @@ Process::Halt (bool clear_thread_plans)<br>
RestorePrivateProcessEvents();<br>
restored_process_events = true;<br>
SetExitStatus(SIGKILL, "Cancelled async attach.");<br>
- Destroy ();<br>
+ Destroy (false);<br>
}<br>
else<br>
{<br>
@@ -3961,12 +3961,15 @@ Process::Detach (bool keep_stopped)<br>
}<br>
<br>
Error<br>
-Process::Destroy ()<br>
+Process::Destroy (bool force_kill)<br>
{<br>
<br>
// Tell ourselves we are in the process of destroying the process, so that we don't do any unnecessary work<br>
// that might hinder the destruction. Remember to set this back to false when we are done. That way if the attempt<br>
// failed and the process stays around for some reason it won't be in a confused state.<br>
+<br>
+ if (force_kill)<br>
+ m_should_detach = false;<br>
<br>
if (GetShouldDetach())<br>
{<br>
<br>
Modified: lldb/trunk/source/Target/Target.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=235158&r1=235157&r2=235158&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=235158&r1=235157&r2=235158&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Target/Target.cpp (original)<br>
+++ lldb/trunk/source/Target/Target.cpp Fri Apr 17 00:01:58 2015<br>
@@ -189,7 +189,7 @@ Target::DeleteCurrentProcess ()<br>
{<br>
m_section_load_history.Clear();<br>
if (m_process_sp->IsAlive())<br>
- m_process_sp->Destroy();<br>
+ m_process_sp->Destroy(false);<br>
<br>
m_process_sp->Finalize();<br>
<br>
@@ -2753,7 +2753,7 @@ Target::Attach (ProcessAttachInfo &attac<br>
error.SetErrorStringWithFormat ("attach failed: %s", exit_desc);<br>
else<br>
error.SetErrorString ("attach failed: process did not stop (no such process or permission problem?)");<br>
- process_sp->Destroy ();<br>
+ process_sp->Destroy (false);<br>
}<br>
}<br>
return error;<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@cs.uiuc.edu" target="_blank">lldb-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits</a><br>
</blockquote></div>