Enable more Linux aarch64 PTRACE support for local and remote debugging.

See http://reviews.llvm.org/D4803 for more details.

Change by Paul Osmialowski.

llvm-svn: 216185
diff --git a/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp b/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp
index 42a0aa5..048a517 100644
--- a/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp
+++ b/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp
@@ -17,12 +17,18 @@
 #include <unistd.h>
 #include <sys/personality.h>
 #include <sys/ptrace.h>
+#include <sys/uio.h>
 #include <sys/socket.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
 #include <sys/user.h>
 #include <sys/wait.h>
 
+#if defined (__arm64__) || defined (__aarch64__)
+// NT_PRSTATUS and NT_FPREGSET definition
+#include <elf.h>
+#endif
+
 // C++ Includes
 // Other libraries and framework includes
 #include "lldb/Core/Debugger.h"
@@ -124,15 +130,13 @@
                 verbose_log->Printf("PTRACE_POKEUSER %s", buf.GetData());
                 break;
             }
-#ifdef PT_SETREGS
+#if !defined (__arm64__) && !defined (__aarch64__)
         case PTRACE_SETREGS:
             {
                 DisplayBytes(buf, data, data_size);
                 verbose_log->Printf("PTRACE_SETREGS %s", buf.GetData());
                 break;
             }
-#endif
-#ifdef PT_SETFPREGS
         case PTRACE_SETFPREGS:
             {
                 DisplayBytes(buf, data, data_size);
@@ -570,13 +574,21 @@
 void
 ReadGPROperation::Execute(ProcessMonitor *monitor)
 {
-#ifdef PT_GETREGS
-    if (PTRACE(PTRACE_GETREGS, m_tid, NULL, m_buf, m_buf_size) < 0)
+#if defined (__arm64__) || defined (__aarch64__)
+    int regset = NT_PRSTATUS;
+    struct iovec ioVec;
+
+    ioVec.iov_base = m_buf;
+    ioVec.iov_len = m_buf_size;
+    if (PTRACE(PTRACE_GETREGSET, m_tid, &regset, &ioVec, m_buf_size) < 0)
         m_result = false;
     else
         m_result = true;
 #else
-    m_result = false;
+    if (PTRACE(PTRACE_GETREGS, m_tid, NULL, m_buf, m_buf_size) < 0)
+        m_result = false;
+    else
+        m_result = true;
 #endif
 }
 
@@ -602,13 +614,21 @@
 void
 ReadFPROperation::Execute(ProcessMonitor *monitor)
 {
-#ifdef PT_GETFPREGS
-    if (PTRACE(PTRACE_GETFPREGS, m_tid, NULL, m_buf, m_buf_size) < 0)
+#if defined (__arm64__) || defined (__aarch64__)
+    int regset = NT_FPREGSET;
+    struct iovec ioVec;
+
+    ioVec.iov_base = m_buf;
+    ioVec.iov_len = m_buf_size;
+    if (PTRACE(PTRACE_GETREGSET, m_tid, &regset, &ioVec, m_buf_size) < 0)
         m_result = false;
     else
         m_result = true;
 #else
-    m_result = false;
+    if (PTRACE(PTRACE_GETFPREGS, m_tid, NULL, m_buf, m_buf_size) < 0)
+        m_result = false;
+    else
+        m_result = true;
 #endif
 }
 
@@ -663,13 +683,21 @@
 void
 WriteGPROperation::Execute(ProcessMonitor *monitor)
 {
-#ifdef PT_SETREGS
-    if (PTRACE(PTRACE_SETREGS, m_tid, NULL, m_buf, m_buf_size) < 0)
+#if defined (__arm64__) || defined (__aarch64__)
+    int regset = NT_PRSTATUS;
+    struct iovec ioVec;
+
+    ioVec.iov_base = m_buf;
+    ioVec.iov_len = m_buf_size;
+    if (PTRACE(PTRACE_SETREGSET, m_tid, &regset, &ioVec, m_buf_size) < 0)
         m_result = false;
     else
         m_result = true;
 #else
-    m_result = false;
+    if (PTRACE(PTRACE_SETREGS, m_tid, NULL, m_buf, m_buf_size) < 0)
+        m_result = false;
+    else
+        m_result = true;
 #endif
 }
 
@@ -695,13 +723,21 @@
 void
 WriteFPROperation::Execute(ProcessMonitor *monitor)
 {
-#ifdef PT_SETFPREGS
-    if (PTRACE(PTRACE_SETFPREGS, m_tid, NULL, m_buf, m_buf_size) < 0)
+#if defined (__arm64__) || defined (__aarch64__)
+    int regset = NT_FPREGSET;
+    struct iovec ioVec;
+
+    ioVec.iov_base = m_buf;
+    ioVec.iov_len = m_buf_size;
+    if (PTRACE(PTRACE_SETREGSET, m_tid, &regset, &ioVec, m_buf_size) < 0)
         m_result = false;
     else
         m_result = true;
 #else
-    m_result = false;
+    if (PTRACE(PTRACE_SETFPREGS, m_tid, NULL, m_buf, m_buf_size) < 0)
+        m_result = false;
+    else
+        m_result = true;
 #endif
 }