pkgsrc-WIP-changes archive

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

lldb-netbsd: Add support for PT_GET_SIGINFO and PT_GET_PROCESS_STATE



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Fri Jan 6 06:50:10 2017 +0100
Changeset:	d07620af079c638afe6d5f5cb4e1ad08799feb63

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

Log Message:
lldb-netbsd: Add support for PT_GET_SIGINFO and PT_GET_PROCESS_STATE

Add initial code to distinguish events from tracee:
 - breakpoint
 - single step (and temporarily also hardware wachpoint on x86)
 - fork(2)
 - SIGSTOP from LLGS (LLDB GDB Server)

TODO:
 - vfork(2)
 - vfork(2) finished (parent resumed)
 - LWP created
 - LWP terminated
 - clone(2)/__clone(2)
 - execve(2)
 - posix_spawn(2)

Currently there is no support for fork(2) and vfork(2) events on Linux.

LWP creation/termination is required to keep track of the threads and manage
hardware assisted traps (watchpoints, breakpoints, ...).

clone(2)/__clone(2) might be handled by existing fork(2) and vfork(2) code.

execve(2) looks trivial as I plan to add special si_code TRAP_EXEC for it soon.

posix_spawn(2) isn't researched.

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=d07620af079c638afe6d5f5cb4e1ad08799feb63

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 | 48 +++++++++++++++++++++-
 2 files changed, 47 insertions(+), 3 deletions(-)

diffs:
diff --git a/lldb-netbsd/distinfo b/lldb-netbsd/distinfo
index aef4585..dbf9eff 100644
--- a/lldb-netbsd/distinfo
+++ b/lldb-netbsd/distinfo
@@ -28,7 +28,7 @@ SHA1 (patch-source_Plugins_Platform_NetBSD_PlatformNetBSD.cpp) = 129e853c1f93f06
 SHA1 (patch-source_Plugins_Platform_NetBSD_PlatformNetBSD.h) = 4327a21e79378b8f35adb07614adb41c37bbaf61
 SHA1 (patch-source_Plugins_Process_CMakeLists.txt) = c0168f81da56d9896eb414e6b8bb7262de04ac33
 SHA1 (patch-source_Plugins_Process_NetBSD_CMakeLists.txt) = df17afdf71c29d945c887e318718904793cd48ad
-SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp) = 69619e6a98078c13c87969a06b2ea488e51fd531
+SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp) = 32b86cdfc4fedb98db488d1063002186214b6bfb
 SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h) = 063478b318cd6c891a78b0649ae7a16968020abf
 SHA1 (patch-source_Plugins_Process_NetBSD_NativeThreadNetBSD.cpp) = a90056d84664722cf7ed21a8b929b2a9adb00564
 SHA1 (patch-source_Plugins_Process_NetBSD_NativeThreadNetBSD.h) = 68c7f7976e48275b6554a03da0e55c8bf59ead47
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 85dca20..0a1907a 100644
--- a/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp
+++ b/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp
@@ -1,8 +1,8 @@
 $NetBSD$
 
---- source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp.orig	2016-12-26 05:32:46.166552242 +0000
+--- source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp.orig	2017-01-05 14:32:45.880405612 +0000
 +++ source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
-@@ -0,0 +1,1593 @@
+@@ -0,0 +1,1637 @@
 +//===-- NativeProcessNetBSD.cpp -------------------------------- -*- C++ -*-===//
 +//
 +//                     The LLVM Compiler Infrastructure
@@ -476,6 +476,50 @@ $NetBSD$
 +    // Notify delegate that our process has exited.
 +    SetState(StateType::eStateExited, true);
 +  }
++
++  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:
++      // breakpoint
++      if ((info.psi_siginfo.si_code & TRAP_BRKPT) != 0)
++          printf("Breakpoint reported\n");
++      // single step (and temporarily also hardware watchpoint on x86)
++      else if ((info.psi_siginfo.si_code & TRAP_TRACE) != 0)
++          printf("Single step reported\n");
++      // fork(2)
++      else if ((state.pe_report_event & PTRACE_FORK) != 0)
++          printf("Fork reported\n");
++      // TODO: vfork(2)
++      // TODO: vfork(2) finished (parent resumed)
++      // TODO: LWP created
++      // TODO: LWP terminated
++      // ????: clone(2)/__clone(2) -- seems to be split between fork(2) and vfork(2)
++      // ????: posix_spawn(2)
++      // TODO: execve(2)
++      // Unknown
++      else
++        printf("Unknown event for SIGTRAP\n");
++      break;
++    case SIGSTOP:
++      // 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);
++        }
++      }
++    }
++  }
 +}
 +
 +namespace {


Home | Main Index | Thread Index | Old Index