[Lldb-commits] [lldb] r202311 - A better long term fix for stopping the process when it is running by writing to the pipe that was used for cancel.
Greg Clayton
gclayton at apple.com
Wed Feb 26 14:47:33 PST 2014
Author: gclayton
Date: Wed Feb 26 16:47:33 2014
New Revision: 202311
URL: http://llvm.org/viewvc/llvm-project?rev=202311&view=rev
Log:
A better long term fix for stopping the process when it is running by writing to the pipe that was used for cancel.
We now write a 'q' to indicate to exit the IOHandlerProcessSTDIO::Run(), and a 'i' to interrupt the process. This should make this code safer to use in a signal handler function.
Modified:
lldb/trunk/source/Target/Process.cpp
Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=202311&r1=202310&r2=202311&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Wed Feb 26 16:47:33 2014
@@ -4793,7 +4793,16 @@ public:
// Consume the interrupt byte
n = 1;
m_pipe_read.Read (&ch, n);
- SetIsDone(true);
+ switch (ch)
+ {
+ case 'q':
+ SetIsDone(true);
+ break;
+ case 'i':
+ if (StateIsRunningState(m_process->GetState()))
+ m_process->Halt();
+ break;
+ }
}
}
}
@@ -4829,15 +4838,28 @@ public:
Cancel ()
{
size_t n = 1;
- char ch = 'q';
+ char ch = 'q'; // Send 'q' for quit
m_pipe_write.Write (&ch, n);
}
virtual void
Interrupt ()
{
+#ifdef _MSC_VER
+ // Windows doesn't support pipes, so we will send an async interrupt
+ // event to stop the process
if (StateIsRunningState(m_process->GetState()))
m_process->SendAsyncInterrupt();
+#else
+ // Do only things that are safe to do in an interrupt context (like in
+ // a SIGINT handler), like write 1 byte to a file descriptor. This will
+ // interrupt the IOHandlerProcessSTDIO::Run() and we can look at the byte
+ // that was written to the pipe and then call m_process->Halt() from a
+ // much safer location in code.
+ size_t n = 1;
+ char ch = 'i'; // Send 'i' for interrupt
+ m_pipe_write.Write (&ch, n);
+#endif
}
virtual void
More information about the lldb-commits
mailing list