pkgsrc-WIP-changes archive

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

lldb-netbsd: Add PtraceWrapper() and stub for MonitorCallback()



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Fri Mar 24 00:28:43 2017 +0100
Changeset:	957bfeaba77a7772edc7a44f180aaeb73da088bb

Modified Files:
	lldb-git/distinfo
Added Files:
	lldb-git/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp
	lldb-git/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h

Log Message:
lldb-netbsd: Add PtraceWrapper() and stub for MonitorCallback()

This is work in progress.

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=957bfeaba77a7772edc7a44f180aaeb73da088bb

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

diffstat:
 lldb-git/distinfo                                  |   2 +
 ..._Plugins_Process_NetBSD_NativeProcessNetBSD.cpp | 177 +++++++++++++++++++++
 ...ce_Plugins_Process_NetBSD_NativeProcessNetBSD.h |  25 +++
 3 files changed, 204 insertions(+)

diffs:
diff --git a/lldb-git/distinfo b/lldb-git/distinfo
index 7931384fd5..abfc3e452a 100644
--- a/lldb-git/distinfo
+++ b/lldb-git/distinfo
@@ -12,3 +12,5 @@ Size (libcxx-3.6.2.src.tar.xz) = 944020 bytes
 SHA1 (llvm-3.6.2.src.tar.xz) = 7a00257eb2bc9431e4c77c3a36b033072c54bc7e
 RMD160 (llvm-3.6.2.src.tar.xz) = 521cbc5fe2925ea3c6e90c7a31f752a04045c972
 Size (llvm-3.6.2.src.tar.xz) = 12802380 bytes
+SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp) = 646d2fc08a0ff62e675aafe06c9647e4c28c2743
+SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h) = ee35eb0b2cde562d36bcd2018496dfbae5379d8b
diff --git a/lldb-git/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp b/lldb-git/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp
new file mode 100644
index 0000000000..1adb6d470e
--- /dev/null
+++ b/lldb-git/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp
@@ -0,0 +1,177 @@
+$NetBSD$
+
+--- source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp.orig	2017-03-21 17:54:57.000000000 +0000
++++ source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
+@@ -11,6 +11,7 @@
+ 
+ // C Includes
+ 
++
+ // C++ Includes
+ 
+ // Other libraries and framework includes
+@@ -20,6 +21,8 @@
+ // System includes - They have to be included after framework includes because
+ // they define some
+ // macros which collide with variable names in other modules
++#include <sys/types.h>
++#include <sys/ptrace.h>
+ 
+ using namespace lldb;
+ using namespace lldb_private;
+@@ -49,3 +52,155 @@ Error NativeProcessProtocol::Attach(
+ 
+ NativeProcessNetBSD::NativeProcessNetBSD()
+     : NativeProcessProtocol(LLDB_INVALID_PROCESS_ID) {}
++
++// Handles all waitpid events from the inferior process.
++void NativeProcessNetBSD::MonitorCallback(lldb::pid_t pid,
++                                         int signal) {
++  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
++
++  ptrace_siginfo_t info;
++  const auto siginfo_err = PtraceWrapper(PT_GET_SIGINFO, pid, &info, sizeof(info));
++    
++  ptrace_state_t state;
++  const auto state_err = PtraceWrapper(PT_GET_PROCESS_STATE, pid, &state, sizeof(state));
++    
++  printf("Signal received signo=%d errno=%d code=%d\n", info.psi_siginfo.si_signo,
++    info.psi_siginfo.si_errno, info.psi_siginfo.si_code); 
++                  
++  // Get details on the signal raised.
++  if (siginfo_err.Success() && state_err.Success()) {
++    switch (info.psi_siginfo.si_signo) {
++    case SIGTRAP:
++      switch (info.psi_siginfo.si_code) {
++      case TRAP_BRKPT:
++        for (const auto &thread_sp : m_threads) {                                                                                     
++          static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedByBreakpoint();
++          FixupBreakpointPCAsNeeded(*static_pointer_cast<NativeThreadNetBSD>(thread_sp));
++        }
++        SetState(StateType::eStateStopped, true);
++        break;
++      case TRAP_TRACE:
++        for (const auto &thread_sp : m_threads) {
++          static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedByTrace();
++        }
++        SetState(StateType::eStateStopped, true);
++        break;
++      case TRAP_EXEC:
++        {
++        // Clear old threads
++        m_threads.clear();
++                                                                                                                                      
++        // Initialize new thread
++        struct ptrace_lwpinfo info = {};
++        Error error = PtraceWrapper(PT_LWPINFO, pid, &info, sizeof(info));
++        if (error.Fail()) {
++          SetState(StateType::eStateInvalid);
++          return;
++        }
++
++        // Reinitialize from scratch threads and register them in process
++        while (info.pl_lwpid != 0) {
++          NativeThreadNetBSDSP thread_sp = AddThread(info.pl_lwpid);
++          thread_sp->SetStoppedByExec();
++          error = PtraceWrapper(PT_LWPINFO, pid, &info, sizeof(info));
++          if (error.Fail()) {
++            SetState(StateType::eStateInvalid);
++            return;                                                                                                                   
++          }
++        }
++
++
++    case SIGSTOP:
++      break;
++    default:
++      // Other signals
++#if 0
++      if (m_signals_to_ignore.find(signo) != m_signals_to_ignore.end()) {
++        ResumeThread(thread, thread.GetState(), signo);                                                                               
++        return;
++      }
++#endif
++
++      for (const auto &thread_sp : m_threads) {
++        static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedBySignal(info.psi_siginfo.si_signo, &info.psi_siginfo);
++      }
++      SetState(StateType::eStateStopped, true);
++    }
++  }
++}
++
++void NativeProcessNetBSD::MonitorExited(lldb::pid_t pid, int signal, int status) {
++  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
++
++  LLDB_LOG(log, "got exit signal({0}) , pid = {1}", signal, pid);
++
++  /* Stop Tracking All Threads attached to Process */
++  m_threads.clear();
++
++  SetExitStatus(convert_pid_status_to_exit_type(status),
++                convert_pid_status_to_return_code(status), nullptr, true);
++
++  // Notify delegate that our process has exited.
++  SetState(StateType::eStateExited, true);
++}
++
++void NativeProcessNetBSD::MonitorSIGSTOP(lldb::pid_t pid) {
++  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
++  ptrace_siginfo_t info;
++
++  const auto siginfo_err = PtraceWrapper(PT_GET_SIGINFO, pid, &info, sizeof(info));
++
++  // Get details on the signal raised.
++  if (siginfo_err.Success()) {
++    // Handle SIGSTOP from LLGS (LLDB GDB Server)
++    if (info.psi_siginfo.si_code == SI_USER && info.psi_siginfo.si_pid == ::getpid()) {
++      /* Stop Tracking All Threads attached to Process */
++      for (const auto &thread_sp : m_threads) {
++        static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedBySignal(SIGSTOP, &info.psi_siginfo);
++      }
++    }
++  }
++}
++
++void NativeProcessNetBSD::MonitorSIGTRAP(lldb::pid_t pid) {
++  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
++  ptrace_siginfo_t info;
++
++  const auto siginfo_err = PtraceWrapper(PT_GET_SIGINFO, pid, &info, sizeof(info));
++
++  // Get details on the signal raised.
++  if (siginfo_err.Success()) {
++    switch (info.psi_siginfo.si_code) {
++    case TRAP_BRKPT:
++      for (const auto &thread_sp : m_threads) {
++        static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedByBreakpoint();                                                                                                       
++        FixupBreakpointPCAsNeeded(*static_pointer_cast<NativeThreadNetBSD>(thread_sp));
++      }
++      SetState(StateType::eStateStopped, true);
++      break;
++  }
++}
++
++Error NativeProcessNetBSD::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
++                                        int data, int *result) {
++  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PTRACE));
++  Error error;
++  int ret;
++
++  errno = 0;
++  ret = ptrace(req, static_cast<::pid_t>(pid), addr, data);
++
++  if (ret == -1)
++    error.SetErrorToErrno();
++
++  if (result)
++    *result = ret;
++
++  LLDB_LOG(log, "ptrace({0}, {1}, {2}, {3}, {4})={6:x}", req, pid, addr,
++           data, ret);
++
++  if (error.Fail())
++    LLDB_LOG(log, "ptrace() failed: {0}", error);
++
++  return error;
++}
diff --git a/lldb-git/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h b/lldb-git/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h
new file mode 100644
index 0000000000..c51e0bcb9a
--- /dev/null
+++ b/lldb-git/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h
@@ -0,0 +1,25 @@
+$NetBSD$
+
+--- source/Plugins/Process/NetBSD/NativeProcessNetBSD.h.orig	2017-03-21 17:54:57.000000000 +0000
++++ source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
+@@ -39,8 +39,20 @@ class NativeProcessNetBSD : public Nativ
+       lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate,
+       MainLoop &mainloop, NativeProcessProtocolSP &process_sp);
+ 
++
++  // ---------------------------------------------------------------------
++  // Interface used by NativeRegisterContext-derived classes.
++  // ---------------------------------------------------------------------
++  static Error PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
++                             int data = 0, int *result = nullptr);
++
+ private:
++  // ---------------------------------------------------------------------
++  // Private Instance Methods
++  // ---------------------------------------------------------------------
+   NativeProcessNetBSD();
++
++  void MonitorCallback(lldb::pid_t pid, bool exited, int signal, int status);
+ };
+ 
+ } // namespace process_netbsd


Home | Main Index | Thread Index | Old Index