llgs: fix Ctrl-C inferior interrupt handling to do the right thing.

* Sends a SIGSTOP to the process.
* Fixes busted SIGSTOP handling.  Now builds a list of non-stopped
  that we wait for the PTRACE group-stop for.  When the final must-stop
  tid gets its group stop, we propagate the process state change.
  Only the signal receiving the notification of the pending SIGSTOP
  is marked with the SIGSTOP signal.  All the rest, if they weren't
  already stopped, are marked as stopped with signal 0.
* Fixes a few broken tests.
* Marks the Linux test I added earlier as expect-pass (no longer XFAIL).

Implements fix for http://llvm.org/bugs/show_bug.cgi?id=20908.

llvm-svn: 217647
diff --git a/lldb/source/Host/common/NativeProcessProtocol.cpp b/lldb/source/Host/common/NativeProcessProtocol.cpp
index b7a7726..e192f19 100644
--- a/lldb/source/Host/common/NativeProcessProtocol.cpp
+++ b/lldb/source/Host/common/NativeProcessProtocol.cpp
@@ -13,6 +13,7 @@
 #include "lldb/Core/ArchSpec.h"
 #include "lldb/Core/Log.h"
 #include "lldb/Core/State.h"
+#include "lldb/Host/Host.h"
 #include "lldb/Target/NativeRegisterContext.h"
 
 #include "NativeThreadProtocol.h"
@@ -44,6 +45,18 @@
 }
 
 lldb_private::Error
+NativeProcessProtocol::Interrupt ()
+{
+    Error error;
+#if !defined (SIGSTOP)
+    error.SetErrorString ("local host does not support signaling");
+    return error;
+#else
+    return Signal (SIGSTOP);
+#endif
+}
+
+lldb_private::Error
 NativeProcessProtocol::GetMemoryRegionInfo (lldb::addr_t load_addr, MemoryRegionInfo &range_info)
 {
     // Default: not implemented.
@@ -110,9 +123,8 @@
 }
 
 NativeThreadProtocolSP
-NativeProcessProtocol::GetThreadByID (lldb::tid_t tid)
+NativeProcessProtocol::GetThreadByIDUnlocked (lldb::tid_t tid)
 {
-    Mutex::Locker locker (m_threads_mutex);
     for (auto thread_sp : m_threads)
     {
         if (thread_sp->GetID() == tid)
@@ -121,6 +133,13 @@
     return NativeThreadProtocolSP ();
 }
 
+NativeThreadProtocolSP
+NativeProcessProtocol::GetThreadByID (lldb::tid_t tid)
+{
+    Mutex::Locker locker (m_threads_mutex);
+    return GetThreadByIDUnlocked (tid);
+}
+
 bool
 NativeProcessProtocol::IsAlive () const
 {
diff --git a/lldb/source/Host/common/NativeProcessProtocol.h b/lldb/source/Host/common/NativeProcessProtocol.h
index 035a264..24a4868 100644
--- a/lldb/source/Host/common/NativeProcessProtocol.h
+++ b/lldb/source/Host/common/NativeProcessProtocol.h
@@ -59,17 +59,25 @@
         //------------------------------------------------------------------
         /// Sends a process a UNIX signal \a signal.
         ///
-        /// Implementer note: the WillSignal ()/DidSignal () calls
-        /// from the Process class are not replicated here since no
-        /// concrete classes implemented any behavior for those and
-        /// put all the work in DoSignal (...).
-        ///
         /// @return
         ///     Returns an error object.
         //------------------------------------------------------------------
         virtual Error
         Signal (int signo) = 0;
 
+        //------------------------------------------------------------------
+        /// Tells a process to interrupt all operations as if by a Ctrl-C.
+        ///
+        /// The default implementation will send a local host's equivalent of
+        /// a SIGSTOP to the process via the NativeProcessProtocol::Signal()
+        /// operation.
+        ///
+        /// @return
+        ///     Returns an error object.
+        //------------------------------------------------------------------
+        virtual Error
+        Interrupt ();
+
         virtual Error
         Kill () = 0;
 
@@ -323,6 +331,9 @@
         void
         NotifyDidExec ();
 
+        NativeThreadProtocolSP
+        GetThreadByIDUnlocked (lldb::tid_t tid);
+
     private:
 
         void