[Lldb-commits] [lldb] r164352 - in /lldb/trunk/source/Plugins/Process/MacOSX-Kernel: CommunicationKDP.cpp CommunicationKDP.h ProcessKDP.cpp RegisterContextKDP_arm.cpp RegisterContextKDP_i386.cpp RegisterContextKDP_x86_64.cpp

Greg Clayton gclayton at apple.com
Thu Sep 20 18:55:30 PDT 2012


Author: gclayton
Date: Thu Sep 20 20:55:30 2012
New Revision: 164352

URL: http://llvm.org/viewvc/llvm-project?rev=164352&view=rev
Log:
<rdar://problem/9959501>

KDP -- now with rudimentary process control (continue only) and read + write registers (which means we can see stack frames) for x86_64, i386 and ARM.


Modified:
    lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
    lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h
    lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
    lldb/trunk/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_arm.cpp
    lldb/trunk/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_i386.cpp
    lldb/trunk/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_x86_64.cpp

Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp?rev=164352&r1=164351&r2=164352&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp Thu Sep 20 20:55:30 2012
@@ -256,6 +256,20 @@
         uint8_t reply_command = packet.GetU8(&offset);
         switch (reply_command)
         {
+        case ePacketTypeRequest | KDP_EXCEPTION:
+        case ePacketTypeRequest | KDP_TERMINATION:
+            // We got an exception request, so be sure to send an ACK
+            {
+                PacketStreamType request_ack_packet (Stream::eBinary, m_addr_byte_size, m_byte_order);
+                // Set the reply but and make the ACK packet
+                request_ack_packet.PutHex8 (reply_command | ePacketTypeReply);
+                request_ack_packet.PutHex8 (packet.GetU8(&offset));
+                request_ack_packet.PutHex16 (packet.GetU16(&offset));
+                request_ack_packet.PutHex32 (packet.GetU32(&offset));
+                // Ack to the exception or termination
+                SendRequestPacketNoLock (request_ack_packet);
+            }
+            // Fall through to case below to get packet contents
         case ePacketTypeReply | KDP_CONNECT:
         case ePacketTypeReply | KDP_DISCONNECT:
         case ePacketTypeReply | KDP_HOSTINFO:
@@ -269,8 +283,6 @@
         case ePacketTypeReply | KDP_IMAGEPATH:
         case ePacketTypeReply | KDP_SUSPEND:
         case ePacketTypeReply | KDP_RESUMECPUS:
-        case ePacketTypeReply | KDP_EXCEPTION:
-        case ePacketTypeReply | KDP_TERMINATION:
         case ePacketTypeReply | KDP_BREAKPOINT_SET:
         case ePacketTypeReply | KDP_BREAKPOINT_REMOVE:
         case ePacketTypeReply | KDP_REGIONS:
@@ -1003,7 +1015,7 @@
 uint32_t
 CommunicationKDP::SendRequestReadRegisters (uint32_t cpu,
                                             uint32_t flavor,
-                                            void *dst, 
+                                            void *dst,
                                             uint32_t dst_len,
                                             Error &error)
 {
@@ -1032,7 +1044,7 @@
                 error.Clear();
                 // Return the number of bytes we could have returned regardless if
                 // we copied them or not, just so we know when things don't match up
-                return src_len; 
+                return src_len;
             }
         }
         if (kdp_error)
@@ -1043,6 +1055,34 @@
     return 0;
 }
 
+uint32_t
+CommunicationKDP::SendRequestWriteRegisters (uint32_t cpu,
+                                             uint32_t flavor,
+                                             const void *src,
+                                             uint32_t src_len,
+                                             Error &error)
+{
+    PacketStreamType request_packet (Stream::eBinary, m_addr_byte_size, m_byte_order);
+    const CommandType command = KDP_WRITEREGS;
+    // Size is header + 4 byte cpu and 4 byte flavor
+    const uint32_t command_length = 8 + 4 + 4;
+    const uint32_t request_sequence_id = m_request_sequence_id;
+    MakeRequestPacketHeader (command, request_packet, command_length);
+    request_packet.PutHex32 (cpu);
+    request_packet.PutHex32 (flavor);
+    request_packet.Write(src, src_len);
+    DataExtractor reply_packet;
+    if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet))
+    {
+        uint32_t offset = 8;
+        uint32_t kdp_error = reply_packet.GetU32 (&offset);
+        if (kdp_error == 0)
+            return src_len;
+        error.SetErrorStringWithFormat("failed to read kdp registers for cpu %u flavor %u (error %u)", cpu, flavor, kdp_error);
+    }
+    return 0;
+}
+
 
 bool
 CommunicationKDP::SendRequestResume (uint32_t cpu_mask)

Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h?rev=164352&r1=164351&r2=164352&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h Thu Sep 20 20:55:30 2012
@@ -177,7 +177,14 @@
                               void *dst, 
                               uint32_t dst_size,
                               lldb_private::Error &error);
-    
+
+    uint32_t
+    SendRequestWriteRegisters (uint32_t cpu,
+                               uint32_t flavor,
+                               const void *src,
+                               uint32_t src_size,
+                               lldb_private::Error &error);
+
     const char *
     GetKernelVersion ();
     

Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp?rev=164352&r1=164351&r2=164352&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp Thu Sep 20 20:55:30 2012
@@ -307,7 +307,16 @@
 ProcessKDP::DoResume ()
 {
     Error error;
-    if (!m_comm.SendRequestResume ())
+    if (m_comm.SendRequestResume ())
+    {
+        SetPrivateState(eStateRunning);
+        DataExtractor exc_reply_packet;
+        if (m_comm.WaitForPacketWithTimeoutMicroSeconds (exc_reply_packet, 60 * USEC_PER_SEC))
+        {
+            SetPrivateState(eStateStopped);
+        }
+    }
+    else
         error.SetErrorString ("KDP resume failed");
     return error;
 }

Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_arm.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_arm.cpp?rev=164352&r1=164351&r2=164352&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_arm.cpp (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_arm.cpp Thu Sep 20 20:55:30 2012
@@ -97,24 +97,64 @@
 int
 RegisterContextKDP_arm::DoWriteGPR (lldb::tid_t tid, int flavor, const GPR &gpr)
 {
+    ProcessSP process_sp (CalculateProcess());
+    if (process_sp)
+    {
+        Error error;
+        if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestWriteRegisters (tid, GPRRegSet, &gpr, sizeof(gpr), error))
+        {
+            if (error.Success())
+                return 0;
+        }
+    }
     return -1;
 }
 
 int
 RegisterContextKDP_arm::DoWriteFPU (lldb::tid_t tid, int flavor, const FPU &fpu)
 {
+    ProcessSP process_sp (CalculateProcess());
+    if (process_sp)
+    {
+        Error error;
+        if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestWriteRegisters (tid, FPURegSet, &fpu, sizeof(fpu), error))
+        {
+            if (error.Success())
+                return 0;
+        }
+    }
     return -1;
 }
 
 int
 RegisterContextKDP_arm::DoWriteEXC (lldb::tid_t tid, int flavor, const EXC &exc)
 {
+    ProcessSP process_sp (CalculateProcess());
+    if (process_sp)
+    {
+        Error error;
+        if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestWriteRegisters (tid, EXCRegSet, &exc, sizeof(exc), error))
+        {
+            if (error.Success())
+                return 0;
+        }
+    }
     return -1;
 }
 
 int
 RegisterContextKDP_arm::DoWriteDBG (lldb::tid_t tid, int flavor, const DBG &dbg)
 {
+    ProcessSP process_sp (CalculateProcess());
+    if (process_sp)
+    {
+        Error error;
+        if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestWriteRegisters (tid, DBGRegSet, &dbg, sizeof(dbg), error))
+        {
+            if (error.Success())
+                return 0;
+        }
+    }
     return -1;
 }
 

Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_i386.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_i386.cpp?rev=164352&r1=164351&r2=164352&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_i386.cpp (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_i386.cpp Thu Sep 20 20:55:30 2012
@@ -81,18 +81,48 @@
 int
 RegisterContextKDP_i386::DoWriteGPR (lldb::tid_t tid, int flavor, const GPR &gpr)
 {
+    ProcessSP process_sp (CalculateProcess());
+    if (process_sp)
+    {
+        Error error;
+        if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestWriteRegisters (tid, GPRRegSet, &gpr, sizeof(gpr), error))
+        {
+            if (error.Success())
+                return 0;
+        }
+    }
     return -1;
 }
 
 int
 RegisterContextKDP_i386::DoWriteFPU (lldb::tid_t tid, int flavor, const FPU &fpu)
 {
+    ProcessSP process_sp (CalculateProcess());
+    if (process_sp)
+    {
+        Error error;
+        if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestWriteRegisters (tid, FPURegSet, &fpu, sizeof(fpu), error))
+        {
+            if (error.Success())
+                return 0;
+        }
+    }
     return -1;
 }
 
 int
 RegisterContextKDP_i386::DoWriteEXC (lldb::tid_t tid, int flavor, const EXC &exc)
 {
+    ProcessSP process_sp (CalculateProcess());
+    if (process_sp)
+    {
+        Error error;
+        if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestWriteRegisters (tid, EXCRegSet, &exc, sizeof(exc), error))
+        {
+            if (error.Success())
+                return 0;
+        }
+    }
     return -1;
 }
 

Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_x86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_x86_64.cpp?rev=164352&r1=164351&r2=164352&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_x86_64.cpp (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/RegisterContextKDP_x86_64.cpp Thu Sep 20 20:55:30 2012
@@ -33,35 +33,95 @@
 int
 RegisterContextKDP_x86_64::DoReadGPR (lldb::tid_t tid, int flavor, GPR &gpr)
 {
+    ProcessSP process_sp (CalculateProcess());
+    if (process_sp)
+    {
+        Error error;
+        if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestReadRegisters (tid, GPRRegSet, &gpr, sizeof(gpr), error))
+        {
+            if (error.Success())
+                return 0;
+        }
+    }
     return -1;
 }
 
 int
 RegisterContextKDP_x86_64::DoReadFPU (lldb::tid_t tid, int flavor, FPU &fpu)
 {
+    ProcessSP process_sp (CalculateProcess());
+    if (process_sp)
+    {
+        Error error;
+        if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestReadRegisters (tid, FPURegSet, &fpu, sizeof(fpu), error))
+        {
+            if (error.Success())
+                return 0;
+        }
+    }
     return -1;
 }
 
 int
 RegisterContextKDP_x86_64::DoReadEXC (lldb::tid_t tid, int flavor, EXC &exc)
 {
+    ProcessSP process_sp (CalculateProcess());
+    if (process_sp)
+    {
+        Error error;
+        if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestReadRegisters (tid, EXCRegSet, &exc, sizeof(exc), error))
+        {
+            if (error.Success())
+                return 0;
+        }
+    }
     return -1;
 }
 
 int
 RegisterContextKDP_x86_64::DoWriteGPR (lldb::tid_t tid, int flavor, const GPR &gpr)
 {
+    ProcessSP process_sp (CalculateProcess());
+    if (process_sp)
+    {
+        Error error;
+        if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestWriteRegisters (tid, GPRRegSet, &gpr, sizeof(gpr), error))
+        {
+            if (error.Success())
+                return 0;
+        }
+    }
     return -1;
 }
 
 int
 RegisterContextKDP_x86_64::DoWriteFPU (lldb::tid_t tid, int flavor, const FPU &fpu)
 {
+    ProcessSP process_sp (CalculateProcess());
+    if (process_sp)
+    {
+        Error error;
+        if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestWriteRegisters (tid, FPURegSet, &fpu, sizeof(fpu), error))
+        {
+            if (error.Success())
+                return 0;
+        }
+    }
     return -1;
 }
 
 int
 RegisterContextKDP_x86_64::DoWriteEXC (lldb::tid_t tid, int flavor, const EXC &exc)
 {
+    ProcessSP process_sp (CalculateProcess());
+    if (process_sp)
+    {
+        Error error;
+        if (static_cast<ProcessKDP *>(process_sp.get())->GetCommunication().SendRequestWriteRegisters (tid, EXCRegSet, &exc, sizeof(exc), error))
+        {
+            if (error.Success())
+                return 0;
+        }
+    }
     return -1;
 }





More information about the lldb-commits mailing list