pkgsrc-WIP-changes archive

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

lldb-netbsd: Reintroduce NativeProcessNetBSD::SetDefaultPtraceOpts()



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Thu Jan 19 05:12:59 2017 +0100
Changeset:	fa0503e23b5a9b0b89b10e20e06cca8ff6df9608

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

Log Message:
lldb-netbsd: Reintroduce NativeProcessNetBSD::SetDefaultPtraceOpts()

Add SetDefaultPtraceOpts() setting:
 - PTRACE_FORK
 - PTRACE_VFORK_DONE
 - PTRACE_LWP_CREATE
 - PTRACE_LWP_EXIT
with PT_SET_EVENT_MASK.

The PTRACE_VFORK event is currently disabled as unimplemented on NetBSD.

The purpose of this change is to be able to detect the above events in a
tracee in MonitorCallback.

Call SetDefaultPtraceOpts() in function launching inferior process and other.

While there, add more code to support (in future) attaching to a thread.
Currently it's not complete (PID 13555 is running top(1)):

$ lldb -p 13445
(lldb) process attach --pid 13445
error: attach failed: unable to attach
(lldb)

Functional attaching is planned to be added in next milestone.

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

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

diffstat:
 lldb-netbsd/distinfo                               |  4 +-
 ..._Plugins_Process_NetBSD_NativeProcessNetBSD.cpp | 50 +++++++++++++++++++++-
 ...ce_Plugins_Process_NetBSD_NativeProcessNetBSD.h |  6 ++-
 3 files changed, 54 insertions(+), 6 deletions(-)

diffs:
diff --git a/lldb-netbsd/distinfo b/lldb-netbsd/distinfo
index 3f94923..9def0cc 100644
--- a/lldb-netbsd/distinfo
+++ b/lldb-netbsd/distinfo
@@ -28,8 +28,8 @@ 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) = 4b167799f06e78849689db1fd06e2b7021de5f91
-SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h) = 063478b318cd6c891a78b0649ae7a16968020abf
+SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp) = eb44538b6bec27c1c327e70c41bb5b9c99df30ad
+SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h) = d45aa74157f00a0ecb5f0821b07440b6cda99a95
 SHA1 (patch-source_Plugins_Process_NetBSD_NativeThreadNetBSD.cpp) = 7b5525df457a5884e8c5159913a54289feb291ed
 SHA1 (patch-source_Plugins_Process_NetBSD_NativeThreadNetBSD.h) = abc9154b9ccafd515def84869ba236387c4ecaa4
 SHA1 (patch-tools_lldb-mi_MICmnBase.cpp) = 851c82ac61e1241018755fbd7236af00379ac986
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 64a94b7..383ba73 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	2017-01-19 01:40:16.619517153 +0000
 +++ source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
-@@ -0,0 +1,1681 @@
+@@ -0,0 +1,1727 @@
 +//===-- NativeProcessNetBSD.cpp -------------------------------- -*- C++ -*-===//
 +//
 +//                     The LLVM Compiler Infrastructure
@@ -316,7 +316,7 @@ $NetBSD$
 +  // Wait for the child process to trap on its call to execve.
 +  ::pid_t wpid;
 +  int status;
-+  if ((wpid = waitpid( pid, &status, 0)) < 0) {
++  if ((wpid = waitpid(pid, &status, 0)) < 0) {
 +    error.SetErrorToErrno();
 +    if (log)
 +      log->Printf("NativeProcessNetBSD::%s waitpid for inferior failed with %s",
@@ -336,6 +336,8 @@ $NetBSD$
 +    log->Printf("NativeProcessNetBSD::%s inferior started, now in stopped state",
 +                __FUNCTION__);
 +
++  SetDefaultPtraceOpts(pid);
++
 +  // Release the master terminal descriptor and pass it off to the
 +  // NativeProcessNetBSD instance.  Similarly stash the inferior pid.
 +  m_terminal_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor();
@@ -420,13 +422,57 @@ $NetBSD$
 +  if ((status = waitpid(pid, NULL, WALLSIG)) < 0)
 +    return -1;
 +
++  SetDefaultPtraceOpts(pid);
++
 +  m_pid = pid;
++
++  /* Initialize threads */
++  struct ptrace_lwpinfo info = {};
++  error = PtraceWrapper(PT_LWPINFO, pid, &info, sizeof(info));
++  if (error.Fail()) {
++    SetState(StateType::eStateInvalid);
++    return -1;
++  }
++  while (info.pl_lwpid != 0) {
++    NativeThreadNetBSDSP thread_sp = AddThread(info.pl_lwpid);
++    thread_sp->SetStoppedBySignal(SIGSTOP);
++    error = PtraceWrapper(PT_LWPINFO, pid, &info, sizeof(info));
++    if (error.Fail()) {
++      SetState(StateType::eStateInvalid);
++      return -1;
++    }
++  }
++
 +  // Let our process instance know the thread has stopped.
 +  SetState(StateType::eStateStopped);
 +
 +  return pid;
 +}
 +
++Error NativeProcessNetBSD::SetDefaultPtraceOpts(lldb::pid_t pid) {
++  ptrace_event_t event = {};
++
++  // Report forks
++  event.pe_set_event |= PTRACE_FORK;
++
++  // Report vforks
++  // TODO: Currently unsupported in NetBSD
++#if notyet
++  event.pe_set_event |= PTRACE_VFORK;
++#endif
++
++  // Report finished vforks - the parent unblocked after execve(2) or exit(2) of the child
++  event.pe_set_event |= PTRACE_VFORK_DONE;
++
++  // Report LWP (thread) creation
++  event.pe_set_event |= PTRACE_LWP_CREATE;
++
++  // Report LWP (thread) termination
++  event.pe_set_event |= PTRACE_LWP_EXIT;
++
++  return PtraceWrapper(PT_SET_EVENT_MASK, pid, &event, sizeof(struct ptrace_event));
++}
++
 +static ExitType convert_pid_status_to_exit_type(int status) {
 +  if (WIFEXITED(status))
 +    return ExitType::eExitTypeExit;
diff --git a/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h b/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h
index 0e3042d..7449371 100644
--- a/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h
+++ b/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h
@@ -1,8 +1,8 @@
 $NetBSD$
 
---- source/Plugins/Process/NetBSD/NativeProcessNetBSD.h.orig	2016-12-26 05:32:46.173568985 +0000
+--- source/Plugins/Process/NetBSD/NativeProcessNetBSD.h.orig	2017-01-19 01:40:16.637505413 +0000
 +++ source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
-@@ -0,0 +1,180 @@
+@@ -0,0 +1,182 @@
 +//===-- NativeProcessNetBSD.h ---------------------------------- -*- C++ -*-===//
 +//
 +//                     The LLVM Compiler Infrastructure
@@ -142,6 +142,8 @@ $NetBSD$
 +
 +  ::pid_t Attach(lldb::pid_t pid, Error &error);
 +
++  static Error SetDefaultPtraceOpts(const lldb::pid_t);
++
 +  static void *MonitorThread(void *baton);
 +
 +  void MonitorCallback(lldb::pid_t pid, bool exited, int signal, int status);


Home | Main Index | Thread Index | Old Index