[Lldb-commits] [lldb] r223901 - Add D request handler to GDBRemoteCommunicationServer in order to support detach from inferior.

Oleksiy Vyalov ovyalov at google.com
Tue Dec 9 17:27:28 PST 2014


Author: ovyalov
Date: Tue Dec  9 19:27:28 2014
New Revision: 223901

URL: http://llvm.org/viewvc/llvm-project?rev=223901&view=rev
Log:
Add D request handler to GDBRemoteCommunicationServer in order to support detach from inferior.

Modified:
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp?rev=223901&r1=223900&r2=223901&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp Tue Dec  9 19:27:28 2014
@@ -430,6 +430,10 @@ GDBRemoteCommunicationServer::GetPacketA
             packet_result = Handle_vAttach (packet);
             break;
 
+        case StringExtractorGDBRemote::eServerPacketType_D:
+            packet_result = Handle_D (packet);
+            break;
+
         case StringExtractorGDBRemote::eServerPacketType_qThreadStopInfo:
             packet_result = Handle_qThreadStopInfo (packet);
             break;
@@ -4190,8 +4194,73 @@ GDBRemoteCommunicationServer::Handle_vAt
 
     // Notify we attached by sending a stop packet.
     return SendStopReasonForState (m_debugged_process_sp->GetState (), true);
+}
 
-    return PacketResult::Success;
+GDBRemoteCommunicationServer::PacketResult
+GDBRemoteCommunicationServer::Handle_D (StringExtractorGDBRemote &packet)
+{
+    Log *log (GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS));
+
+    // We don't support if we're not llgs.
+    if (!IsGdbServer())
+        return SendUnimplementedResponse ("only supported for lldb-gdbserver");
+
+    // Scope for mutex locker.
+    Mutex::Locker locker (m_spawned_pids_mutex);
+
+    // Fail if we don't have a current process.
+    if (!m_debugged_process_sp || (m_debugged_process_sp->GetID () == LLDB_INVALID_PROCESS_ID))
+    {
+        if (log)
+            log->Printf ("GDBRemoteCommunicationServer::%s failed, no process available", __FUNCTION__);
+        return SendErrorResponse (0x15);
+    }
+
+    if (m_spawned_pids.find(m_debugged_process_sp->GetID ()) == m_spawned_pids.end())
+    {
+        if (log)
+            log->Printf ("GDBRemoteCommunicationServer::%s failed to find PID %" PRIu64 " in spawned pids list",
+                         __FUNCTION__, m_debugged_process_sp->GetID ());
+        return SendErrorResponse (0x1);
+    }
+
+    lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
+
+    // Consume the ';' after D.
+    packet.SetFilePos (1);
+    if (packet.GetBytesLeft ())
+    {
+        if (packet.GetChar () != ';')
+            return SendIllFormedResponse (packet, "D missing expected ';'");
+
+        // Grab the PID from which we will detach (assume hex encoding).
+        pid = packet.GetU32 (LLDB_INVALID_PROCESS_ID, 16);
+        if (pid == LLDB_INVALID_PROCESS_ID)
+            return SendIllFormedResponse (packet, "D failed to parse the process id");
+    }
+
+    if (pid != LLDB_INVALID_PROCESS_ID &&
+        m_debugged_process_sp->GetID () != pid)
+    {
+        return SendIllFormedResponse (packet, "Invalid pid");
+    }
+
+    if (m_stdio_communication.IsConnected ())
+    {
+        m_stdio_communication.StopReadThread ();
+    }
+
+    const Error error = m_debugged_process_sp->Detach ();
+    if (error.Fail ())
+    {
+        if (log)
+            log->Printf ("GDBRemoteCommunicationServer::%s failed to detach from pid %" PRIu64 ": %s\n",
+                         __FUNCTION__, m_debugged_process_sp->GetID (), error.AsCString ());
+        return SendErrorResponse (0x01);
+    }
+
+    m_spawned_pids.erase (m_debugged_process_sp->GetID ());
+    return SendOKResponse ();
 }
 
 GDBRemoteCommunicationServer::PacketResult

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h?rev=223901&r1=223900&r2=223901&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h Tue Dec  9 19:27:28 2014
@@ -460,6 +460,9 @@ protected:
     Handle_vAttach (StringExtractorGDBRemote &packet);
 
     PacketResult
+    Handle_D (StringExtractorGDBRemote &packet);
+
+    PacketResult
     Handle_qThreadStopInfo (StringExtractorGDBRemote &packet);
 
     void





More information about the lldb-commits mailing list