[Lldb-commits] [lldb] r132587 - in /lldb/trunk/source/Plugins/Process/Linux: ProcessMonitor.cpp ProcessMonitor.h RegisterContextLinux_x86_64.cpp RegisterContextLinux_x86_64.h

Peter Collingbourne peter at pcc.me.uk
Fri Jun 3 13:41:02 PDT 2011


Author: pcc
Date: Fri Jun  3 15:41:02 2011
New Revision: 132587

URL: http://llvm.org/viewvc/llvm-project?rev=132587&view=rev
Log:
Implement RegisterContextLinux_x86_64::{Read,Write}AllRegisterValues

Modified:
    lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp
    lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h
    lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp
    lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.h

Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp?rev=132587&r1=132586&r2=132587&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp Fri Jun  3 15:41:02 2011
@@ -334,6 +334,58 @@
 }
 
 //------------------------------------------------------------------------------
+/// @class WriteGPROperation
+/// @brief Implements ProcessMonitor::WriteGPR.
+class WriteGPROperation : public Operation
+{
+public:
+    WriteGPROperation(void *buf, bool &result)
+        : m_buf(buf), m_result(result)
+        { }
+
+    void Execute(ProcessMonitor *monitor);
+
+private:
+    void *m_buf;
+    bool &m_result;
+};
+
+void
+WriteGPROperation::Execute(ProcessMonitor *monitor)
+{
+    if (ptrace(PTRACE_SETREGS, monitor->GetPID(), NULL, m_buf) < 0)
+        m_result = false;
+    else
+        m_result = true;
+}
+
+//------------------------------------------------------------------------------
+/// @class WriteFPROperation
+/// @brief Implements ProcessMonitor::WriteFPR.
+class WriteFPROperation : public Operation
+{
+public:
+    WriteFPROperation(void *buf, bool &result)
+        : m_buf(buf), m_result(result)
+        { }
+
+    void Execute(ProcessMonitor *monitor);
+
+private:
+    void *m_buf;
+    bool &m_result;
+};
+
+void
+WriteFPROperation::Execute(ProcessMonitor *monitor)
+{
+    if (ptrace(PTRACE_SETFPREGS, monitor->GetPID(), NULL, m_buf) < 0)
+        m_result = false;
+    else
+        m_result = true;
+}
+
+//------------------------------------------------------------------------------
 /// @class ResumeOperation
 /// @brief Implements ProcessMonitor::Resume.
 class ResumeOperation : public Operation
@@ -1134,6 +1186,24 @@
 }
 
 bool
+ProcessMonitor::WriteGPR(void *buf)
+{
+    bool result;
+    WriteGPROperation op(buf, result);
+    DoOperation(&op);
+    return result;
+}
+
+bool
+ProcessMonitor::WriteFPR(void *buf)
+{
+    bool result;
+    WriteFPROperation op(buf, result);
+    DoOperation(&op);
+    return result;
+}
+
+bool
 ProcessMonitor::Resume(lldb::tid_t tid, uint32_t signo)
 {
     bool result;

Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h?rev=132587&r1=132586&r2=132587&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h Fri Jun  3 15:41:02 2011
@@ -117,6 +117,14 @@
     bool
     ReadFPR(void *buf);
 
+    /// Writes all general purpose registers into the specified buffer.
+    bool
+    WriteGPR(void *buf);
+
+    /// Writes all floating point registers into the specified buffer.
+    bool
+    WriteFPR(void *buf);
+
     /// Writes a siginfo_t structure corresponding to the given thread ID to the
     /// memory region pointed to by @p siginfo.
     bool

Modified: lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp?rev=132587&r1=132586&r2=132587&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp Fri Jun  3 15:41:02 2011
@@ -11,6 +11,7 @@
 #include <errno.h>
 #include <stdint.h>
 
+#include "lldb/Core/DataBufferHeap.h"
 #include "lldb/Core/DataExtractor.h"
 #include "lldb/Core/Scalar.h"
 #include "lldb/Target/Thread.h"
@@ -324,6 +325,8 @@
       { gcc_dwarf_fpu_##reg##i, gcc_dwarf_fpu_##reg##i,            \
         LLDB_INVALID_REGNUM, gdb_fpu_##reg##i, fpu_##reg##i } }
 
+#define REG_CONTEXT_SIZE (sizeof(RegisterContextLinux_x86_64::GPR) + sizeof(RegisterContextLinux_x86_64::FPU))
+
 static RegisterInfo
 g_register_infos[k_num_registers] =
 {
@@ -487,6 +490,16 @@
 bool
 RegisterContextLinux_x86_64::ReadAllRegisterValues(DataBufferSP &data_sp)
 {
+    data_sp.reset (new DataBufferHeap (REG_CONTEXT_SIZE, 0));
+    if (data_sp && ReadGPR () && ReadFPR ())
+    {
+        uint8_t *dst = data_sp->GetBytes();
+        ::memcpy (dst, &user.regs, sizeof(user.regs));
+        dst += sizeof(user.regs);
+
+        ::memcpy (dst, &user.i387, sizeof(user.i387));
+        return true;
+    }
     return false;
 }
 
@@ -500,8 +513,17 @@
 }
 
 bool
-RegisterContextLinux_x86_64::WriteAllRegisterValues(const DataBufferSP &data)
+RegisterContextLinux_x86_64::WriteAllRegisterValues(const DataBufferSP &data_sp)
 {
+    if (data_sp && data_sp->GetByteSize() == REG_CONTEXT_SIZE)
+    {
+        const uint8_t *src = data_sp->GetBytes();
+        ::memcpy (&user.regs, src, sizeof(user.regs));
+        src += sizeof(user.regs);
+
+        ::memcpy (&user.i387, src, sizeof(user.i387));
+        return WriteGPR() & WriteFPR();
+    }
     return false;
 }
 
@@ -699,3 +721,17 @@
     ProcessMonitor &monitor = GetMonitor();
     return monitor.ReadFPR(&user.i387);
 }
+
+bool
+RegisterContextLinux_x86_64::WriteGPR()
+{
+     ProcessMonitor &monitor = GetMonitor();
+     return monitor.WriteGPR(&user.regs);
+}
+
+bool
+RegisterContextLinux_x86_64::WriteFPR()
+{
+    ProcessMonitor &monitor = GetMonitor();
+    return monitor.WriteFPR(&user.i387);
+}

Modified: lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.h?rev=132587&r1=132586&r2=132587&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.h (original)
+++ lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.h Fri Jun  3 15:41:02 2011
@@ -151,6 +151,9 @@
 
     bool ReadGPR();
     bool ReadFPR();
+
+    bool WriteGPR();
+    bool WriteFPR();
 };
 
 #endif // #ifndef liblldb_RegisterContextLinux_x86_64_H_





More information about the lldb-commits mailing list