pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lldb-netbsd: Kill SetDefaultPtraceOpts(), adapt ReadMemory() for NetBSD



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Sat Dec 17 19:36:09 2016 +0100
Changeset:	0a0ed070694008a8045c54e4c7b5e3889ba18b95

Modified Files:
	lldb-netbsd/distinfo
	lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp

Log Message:
lldb-netbsd: Kill SetDefaultPtraceOpts(), adapt ReadMemory() for NetBSD

SetDefaultPtraceOpts() is currently Linux-specific

There is no ProcessVmReadvSupported() on NetBSD, ptrace(2) offers PT_IO
for the same purpose to copy data in larger chunks.

Adjust that ptrace(2) returns int on NetBSD, not long like on Linux.

Sponsored by <The NetBSD Foundation>

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=0a0ed070694008a8045c54e4c7b5e3889ba18b95

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 lldb-netbsd/distinfo                               |  2 +-
 ..._Plugins_Process_NetBSD_NativeProcessNetBSD.cpp | 94 ++++------------------
 2 files changed, 17 insertions(+), 79 deletions(-)

diffs:
diff --git a/lldb-netbsd/distinfo b/lldb-netbsd/distinfo
index 5b22684..7d1c854 100644
--- a/lldb-netbsd/distinfo
+++ b/lldb-netbsd/distinfo
@@ -18,7 +18,7 @@ SHA1 (patch-include_lldb_Host_netbsd_Ptrace.h) = 3ef61ded004c2acb81e132dc0e46d0a
 SHA1 (patch-source_CMakeLists.txt) = 5dacabc3f39c23bdfd432b5a4895866157b97aa0
 SHA1 (patch-source_Plugins_Process_CMakeLists.txt) = c0168f81da56d9896eb414e6b8bb7262de04ac33
 SHA1 (patch-source_Plugins_Process_NetBSD_CMakeLists.txt) = 8c1d8274523f6ef4bce90caa6c981160ef930cb9
-SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp) = 071f81ea0d1b1a07f7aba75867c4a27f43d2a357
+SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp) = 976522b07559dcf085a6793cef40ab8b3b031e2f
 SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h) = 3177f7a17f3ab1fa8c155f2bcab6cbf2033644e9
 SHA1 (patch-source_Plugins_Process_NetBSD_NativeRegisterContextNetBSD.cpp) = cf569f95362538af5a2709aab9ff61770744a78d
 SHA1 (patch-source_Plugins_Process_NetBSD_NativeRegisterContextNetBSD.h) = 558e8514b2a8f0595c0e375f308c53d8a9a6e9f1
diff --git a/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp b/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp
index a0dd50c..f0940e2 100644
--- a/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp
+++ b/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp
@@ -2,7 +2,7 @@ $NetBSD$
 
 --- source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp.orig	2016-12-17 13:23:23.782610208 +0000
 +++ source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
-@@ -0,0 +1,2747 @@
+@@ -0,0 +1,2685 @@
 +//===-- NativeProcessNetBSD.cpp -------------------------------- -*- C++ -*-===//
 +//
 +//                     The LLVM Compiler Infrastructure
@@ -526,25 +526,6 @@ $NetBSD$
 +  return pid;
 +}
 +
-+Error NativeProcessNetBSD::SetDefaultPtraceOpts(lldb::pid_t pid) {
-+  long ptrace_opts = 0;
-+
-+  // Have the child raise an event on exit.  This is used to keep the child in
-+  // limbo until it is destroyed.
-+  ptrace_opts |= PTRACE_O_TRACEEXIT;
-+
-+  // Have the tracer trace threads which spawn in the inferior process.
-+  // TODO: if we want to support tracing the inferiors' child, add the
-+  // appropriate ptrace flags here (PTRACE_O_TRACEFORK, PTRACE_O_TRACEVFORK)
-+  ptrace_opts |= PTRACE_O_TRACECLONE;
-+
-+  // Have the tracer notify us before execve returns
-+  // (needed to disable legacy SIGTRAP generation)
-+  ptrace_opts |= PTRACE_O_TRACEEXEC;
-+
-+  return PtraceWrapper(PTRACE_SETOPTIONS, pid, nullptr, (void *)ptrace_opts);
-+}
-+
 +static ExitType convert_pid_status_to_exit_type(int status) {
 +  if (WIFEXITED(status))
 +    return ExitType::eExitTypeExit;
@@ -2135,39 +2116,8 @@ $NetBSD$
 +
 +Error NativeProcessNetBSD::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
 +                                     size_t &bytes_read) {
-+  if (ProcessVmReadvSupported()) {
-+    // The process_vm_readv path is about 50 times faster than ptrace api. We
-+    // want to use
-+    // this syscall if it is supported.
-+
-+    const ::pid_t pid = GetID();
-+
-+    struct iovec local_iov, remote_iov;
-+    local_iov.iov_base = buf;
-+    local_iov.iov_len = size;
-+    remote_iov.iov_base = reinterpret_cast<void *>(addr);
-+    remote_iov.iov_len = size;
-+
-+    bytes_read = process_vm_readv(pid, &local_iov, 1, &remote_iov, 1, 0);
-+    const bool success = bytes_read == size;
-+
-+    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
-+    if (log)
-+      log->Printf("NativeProcessNetBSD::%s using process_vm_readv to read %zd "
-+                  "bytes from inferior address 0x%" PRIx64 ": %s",
-+                  __FUNCTION__, size, addr,
-+                  success ? "Success" : strerror(errno));
-+
-+    if (success)
-+      return Error();
-+    // else
-+    //     the call failed for some reason, let's retry the read using ptrace
-+    //     api.
-+  }
-+
 +  unsigned char *dst = static_cast<unsigned char *>(buf);
-+  size_t remainder;
-+  long data;
++  struct ptrace_io_desc io;
 +
 +  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_ALL));
 +  if (log)
@@ -2177,36 +2127,24 @@ $NetBSD$
 +    log->Printf("NativeProcessNetBSD::%s(%p, %p, %zd, _)", __FUNCTION__,
 +                (void *)addr, buf, size);
 +
-+  for (bytes_read = 0; bytes_read < size; bytes_read += remainder) {
++  bytes_read = 0;
++  io.piod_op = PIOD_READ_D;
++
++  do {
++    io.piod_offs = (void *)(addr + bytes_read);
++    io.piod_offs = dst + bytes_read;
++    io.piod_len = buf;
++
 +    Error error = NativeProcessNetBSD::PtraceWrapper(
-+        PTRACE_PEEKDATA, GetID(), (void *)addr, nullptr, 0, &data);
++        PT_IO, GetID(), &io);
 +    if (error.Fail()) {
 +      if (log)
 +        ProcessPOSIXLog::DecNestLevel();
 +      return error;
 +    }
 +
-+    remainder = size - bytes_read;
-+    remainder = remainder > k_ptrace_word_size ? k_ptrace_word_size : remainder;
-+
-+    // Copy the data into our buffer
-+    memcpy(dst, &data, remainder);
-+
-+    if (log && ProcessPOSIXLog::AtTopNestLevel() &&
-+        (log->GetMask().Test(POSIX_LOG_MEMORY_DATA_LONG) ||
-+         (log->GetMask().Test(POSIX_LOG_MEMORY_DATA_SHORT) &&
-+          size <= POSIX_LOG_MEMORY_SHORT_BYTES))) {
-+      uintptr_t print_dst = 0;
-+      // Format bytes from data by moving into print_dst for log output
-+      for (unsigned i = 0; i < remainder; ++i)
-+        print_dst |= (((data >> i * 8) & 0xFF) << i * 8);
-+      log->Printf("NativeProcessNetBSD::%s() [0x%" PRIx64 "]:0x%" PRIx64
-+                  " (0x%" PRIx64 ")",
-+                  __FUNCTION__, addr, uint64_t(print_dst), uint64_t(data));
-+    }
-+    addr += k_ptrace_word_size;
-+    dst += k_ptrace_word_size;
-+  }
++    bytes_read = io.piod_len;
++  } while(bytes_read < size);
 +
 +  if (log)
 +    ProcessPOSIXLog::DecNestLevel();
@@ -2706,9 +2644,9 @@ $NetBSD$
 +// Note that ptrace sets errno on error because -1 can be a valid result (i.e.
 +// for PT_READ*)
 +Error NativeProcessNetBSD::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
-+                                        int data, long *result) {
++                                        int data, int *result) {
 +  Error error;
-+  long int ret;
++  int ret;
 +
 +  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PTRACE));
 +
@@ -2724,7 +2662,7 @@ $NetBSD$
 +    *result = ret;
 +
 +  if (log)
-+    log->Printf("ptrace(%d, %d, %p, %d, %zu)=%lX", req, pid, addr,
++    log->Printf("ptrace(%d, %d, %p, %d, %d)=%lX", req, pid, addr,
 +                data, ret);
 +
 +  if (log && error.GetError() != 0) {


Home | Main Index | Thread Index | Old Index