Fix a place in GDBRemoteCommunicationClient::SendContinuePacketAndWaitForReply where we weren't taking
m_interrupt_sent into account.  Also don't reset m_interrupt_sent in SendInterrupt but do so in SendPacketAndWaitForResponse
when we know we've handled the interrupt.
Fix a code path through ProcessGDBRemote::DoDestroy where we were tearing down the debug session but
not setting the exit status.


git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@158043 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 6b5bb9a..caf3461 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -1646,6 +1646,10 @@
     bool discard_thread_plans = true; 
     bool catch_stop_event = true;
     EventSP event_sp;
+    
+    // FIXME: InterruptIfRunning should be done in the Process base class, or better still make Halt do what is
+    // needed.  This shouldn't be a feature of a particular plugin.
+    
     return InterruptIfRunning (discard_thread_plans, catch_stop_event, event_sp);
 }
 
@@ -1688,6 +1692,9 @@
         log->Printf ("ProcessGDBRemote::DoDestroy()");
 
     // Interrupt if our inferior is running...
+    int exit_status = SIGABRT;
+    std::string exit_string;
+
     if (m_gdb_comm.IsConnected())
     {
         if (m_public_state.GetValue() != eStateAttaching)
@@ -1703,16 +1710,39 @@
                 {
                     SetLastStopPacket (response);
                     ClearThreadIDList ();
-                    SetExitStatus(response.GetHexU8(), NULL);
+                    exit_status = response.GetHexU8();
+                }
+                else
+                {
+                    if (log)
+                        log->Printf ("ProcessGDBRemote::DoDestroy - got unexpected response to k packet: %s", response.GetStringRef().c_str());
+                    exit_string.assign("got unexpected response to k packet: ");
+                    exit_string.append(response.GetStringRef());
                 }
             }
             else
             {
-                SetExitStatus(SIGABRT, NULL);
-                //error.SetErrorString("kill packet failed");
+                if (log)
+                    log->Printf ("ProcessGDBRemote::DoDestroy - failed to send k packet");
+                exit_string.assign("failed to send the k packet");
             }
         }
+        else
+        {
+            if (log)
+                log->Printf ("ProcessGDBRemote::DoDestroy - failed to send k packet");
+            exit_string.assign ("killing while attaching.");
+        }
     }
+    else
+    {
+        // If we missed setting the exit status on the way out, do it here.
+        // NB set exit status can be called multiple times, the first one sets the status.
+        exit_string.assign("destroying when not connected to debugserver");
+    }
+
+    SetExitStatus(exit_status, exit_string.c_str());
+
     StopAsyncThread ();
     KillDebugserverProcess ();
     return error;