pkgsrc-WIP-changes archive

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

lldb-netbsd: Introduce ProcessLauncherPosixFork



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Wed Feb 1 00:22:51 2017 +0100
Changeset:	2006e55d3b0f21db86c878f9f83b93413b290c34

Modified Files:
	lldb-netbsd/distinfo
	lldb-netbsd/patches/patch-include_lldb_Host_netbsd_ProcessLauncherNetBSD.h
	lldb-netbsd/patches/patch-source_Host_CMakeLists.txt
	lldb-netbsd/patches/patch-source_Host_common_Host.cpp
	lldb-netbsd/patches/patch-source_Host_netbsd_ProcessLauncherNetBSD.cpp
	lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp
Added Files:
	lldb-netbsd/patches/patch-include_lldb_Host_linux_ProcessLauncherLinux.h
	lldb-netbsd/patches/patch-include_lldb_Host_posix_ProcessLauncherPosixFork.h
	lldb-netbsd/patches/patch-source_Host_linux_ProcessLauncherLinux.cpp
	lldb-netbsd/patches/patch-source_Host_posix_ProcessLauncherPosixFork.cpp

Log Message:
lldb-netbsd: Introduce ProcessLauncherPosixFork

Solution suggested by Pavel Labath (Google)
 - https://reviews.llvm.org/D29347

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=2006e55d3b0f21db86c878f9f83b93413b290c34

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

diffstat:
 lldb-netbsd/distinfo                               |  14 +-
 ...-include_lldb_Host_linux_ProcessLauncherLinux.h |  30 +++
 ...nclude_lldb_Host_netbsd_ProcessLauncherNetBSD.h |  30 ---
 ...lude_lldb_Host_posix_ProcessLauncherPosixFork.h |  30 +++
 .../patches/patch-source_Host_CMakeLists.txt       |  22 +-
 .../patches/patch-source_Host_common_Host.cpp      |  28 ++-
 ...atch-source_Host_linux_ProcessLauncherLinux.cpp | 231 +++++++++++++++++++
 ...ch-source_Host_netbsd_ProcessLauncherNetBSD.cpp | 175 --------------
 ...-source_Host_posix_ProcessLauncherPosixFork.cpp | 255 +++++++++++++++++++++
 ..._Plugins_Process_NetBSD_NativeProcessNetBSD.cpp |   6 +-
 10 files changed, 589 insertions(+), 232 deletions(-)

diffs:
diff --git a/lldb-netbsd/distinfo b/lldb-netbsd/distinfo
index a91fc1b..2efb94c 100644
--- a/lldb-netbsd/distinfo
+++ b/lldb-netbsd/distinfo
@@ -14,22 +14,26 @@ RMD160 (llvm-3.6.2.src.tar.xz) = 521cbc5fe2925ea3c6e90c7a31f752a04045c972
 Size (llvm-3.6.2.src.tar.xz) = 12802380 bytes
 SHA1 (patch-cmake_LLDBDependencies.cmake) = 2577a759167675d3a89915bebad05c8159798e8a
 SHA1 (patch-include_lldb_Core_Debugger.h) = 20d7995866bfe129ab532e470509d8ff9f4ebdea
+SHA1 (patch-include_lldb_Host_linux_ProcessLauncherLinux.h) = 235ac7771eaff7e7d2aa2cd4957083a99aa7b2ea
 SHA1 (patch-include_lldb_Host_netbsd_HostThreadNetBSD.h) = 79f207cdb9da2ef57d39eeb307ec6d10cf828925
-SHA1 (patch-include_lldb_Host_netbsd_ProcessLauncherNetBSD.h) = c3ee0f4cb0aaf197e4811de8bbd1e7bfbf72f124
+SHA1 (patch-include_lldb_Host_netbsd_ProcessLauncherNetBSD.h) = da39a3ee5e6b4b0d3255bfef95601890afd80709
+SHA1 (patch-include_lldb_Host_posix_ProcessLauncherPosixFork.h) = c2d5a5285874477b35fdc7b048a05c4d92746e06
 SHA1 (patch-source_CMakeLists.txt) = 5dacabc3f39c23bdfd432b5a4895866157b97aa0
 SHA1 (patch-source_Commands_CommandObjectPlatform.cpp) = c578e1b7e787a92b453b343ac8b63583f47585f7
 SHA1 (patch-source_Core_ConstString.cpp) = e79f25d82a90afa3d8a75098d66cab15c13d799f
 SHA1 (patch-source_Core_Debugger.cpp) = 6b284cafa93a30d3ea5d4f88478efb0ada659249
 SHA1 (patch-source_Core_ModuleList.cpp) = ff470cfe29d4702d5be6c5a096d5a8db700547e7
-SHA1 (patch-source_Host_CMakeLists.txt) = 497dcdc995139f6737543a833a8259cc9ff4de24
+SHA1 (patch-source_Host_CMakeLists.txt) = b8f27fd100e3488302a276143e423a7fc58683cb
 SHA1 (patch-source_Host_common_Editline.cpp) = 6bc60cc72e5a6148add175cb276bb445bb3ee0f5
-SHA1 (patch-source_Host_common_Host.cpp) = 18d82f284eaa91ce0fd61c17f7da0a84f5800fa2
+SHA1 (patch-source_Host_common_Host.cpp) = df295302f8e36649adec8203b781ccc9ff014d9a
 SHA1 (patch-source_Host_common_HostInfoBase.cpp) = 402e11c3c8775ba993159cb27c30b2ed9fa82076
 SHA1 (patch-source_Host_common_NativeProcessProtocol.cpp) = 23cc7da280b2123cf0206f3d5660d2647935edbc
 SHA1 (patch-source_Host_linux_HostInfoLinux.cpp) = fb375b959fe0f08c9e888194c58af356edeee441
+SHA1 (patch-source_Host_linux_ProcessLauncherLinux.cpp) = 2f5bf0787feadb5bab39f42a4fbe8a424a2fec88
 SHA1 (patch-source_Host_netbsd_HostThreadNetBSD.cpp) = a1b0fbdad062309a845cfefe4469614fbbe9d20e
-SHA1 (patch-source_Host_netbsd_ProcessLauncherNetBSD.cpp) = 4b161cb0c855d9cb5bef03f6e2c091340e0644f5
+SHA1 (patch-source_Host_netbsd_ProcessLauncherNetBSD.cpp) = da39a3ee5e6b4b0d3255bfef95601890afd80709
 SHA1 (patch-source_Host_netbsd_ThisThread.cpp) = f0d32c81bc1b8fe9aeb86519ea46ba2cb16571c2
+SHA1 (patch-source_Host_posix_ProcessLauncherPosixFork.cpp) = dbd125082787187f946f2bcfa0d9279804985e06
 SHA1 (patch-source_Host_windows_HostInfoWindows.cpp) = 73be6130bfc54bde057c23eee23aecd09c200b8d
 SHA1 (patch-source_Initialization_SystemInitializerCommon.cpp) = 80c850b980fe2902f10e441df7a18f428dd1154a
 SHA1 (patch-source_Plugins_ExpressionParser_Clang_ClangModulesDeclVendor.cpp) = a7f61c10f28fdc3280fdd81b2719f014e854c4fa
@@ -46,7 +50,7 @@ SHA1 (patch-source_Plugins_Process_FreeBSD_ProcessFreeBSD.cpp) = 125cf947d59593d
 SHA1 (patch-source_Plugins_Process_Linux_NativeProcessLinux.cpp) = d260fdfdc464b1bfb1822e9be17c04480b0d2af4
 SHA1 (patch-source_Plugins_Process_MacOSX-Kernel_ProcessKDP.cpp) = 2f4e5859d80f8b0e55554eeb8955bf482cb04b57
 SHA1 (patch-source_Plugins_Process_NetBSD_CMakeLists.txt) = 483584dad2dba01dccd065435a5d75eedf11b3c6
-SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp) = 939638bfe24a0cc377ffd26fab20422cdbb94285
+SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp) = 9c4c93e27b35cc70870545d3ec952188fcb904be
 SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h) = c48bb2dd45682164ab904b8b3f7664b91ac35d5b
 SHA1 (patch-source_Plugins_Process_NetBSD_NativeThreadNetBSD.cpp) = 4369b37e51c367787a12c7f935a8f5daf274841e
 SHA1 (patch-source_Plugins_Process_NetBSD_NativeThreadNetBSD.h) = 22e5c436baea68b38058c8387318d08c7a43c149
diff --git a/lldb-netbsd/patches/patch-include_lldb_Host_linux_ProcessLauncherLinux.h b/lldb-netbsd/patches/patch-include_lldb_Host_linux_ProcessLauncherLinux.h
new file mode 100644
index 0000000..879a708
--- /dev/null
+++ b/lldb-netbsd/patches/patch-include_lldb_Host_linux_ProcessLauncherLinux.h
@@ -0,0 +1,30 @@
+$NetBSD$
+
+--- include/lldb/Host/linux/ProcessLauncherLinux.h.orig	2016-12-17 10:34:14.000000000 +0000
++++ include/lldb/Host/linux/ProcessLauncherLinux.h
+@@ -1,25 +0,0 @@
+-//===-- ProcessLauncherAndroid.h --------------------------------*- C++ -*-===//
+-//
+-//                     The LLVM Compiler Infrastructure
+-//
+-// This file is distributed under the University of Illinois Open Source
+-// License. See LICENSE.TXT for details.
+-//
+-//===----------------------------------------------------------------------===//
+-
+-#ifndef lldb_Host_android_ProcessLauncherAndroid_h_
+-#define lldb_Host_android_ProcessLauncherAndroid_h_
+-
+-#include "lldb/Host/ProcessLauncher.h"
+-
+-namespace lldb_private {
+-
+-class ProcessLauncherLinux : public ProcessLauncher {
+-public:
+-  virtual HostProcess LaunchProcess(const ProcessLaunchInfo &launch_info,
+-                                    Error &error);
+-};
+-
+-} // end of namespace lldb_private
+-
+-#endif
diff --git a/lldb-netbsd/patches/patch-include_lldb_Host_netbsd_ProcessLauncherNetBSD.h b/lldb-netbsd/patches/patch-include_lldb_Host_netbsd_ProcessLauncherNetBSD.h
index f55a46e..e69de29 100644
--- a/lldb-netbsd/patches/patch-include_lldb_Host_netbsd_ProcessLauncherNetBSD.h
+++ b/lldb-netbsd/patches/patch-include_lldb_Host_netbsd_ProcessLauncherNetBSD.h
@@ -1,30 +0,0 @@
-$NetBSD$
-
---- include/lldb/Host/netbsd/ProcessLauncherNetBSD.h.orig	2017-01-31 18:01:27.231199052 +0000
-+++ include/lldb/Host/netbsd/ProcessLauncherNetBSD.h
-@@ -0,0 +1,25 @@
-+//===-- ProcessLauncherNetBSD.h --------------------------------*- C++ -*-===//
-+//
-+//                     The LLVM Compiler Infrastructure
-+//
-+// This file is distributed under the University of Illinois Open Source
-+// License. See LICENSE.TXT for details.
-+//
-+//===----------------------------------------------------------------------===//
-+
-+#ifndef lldb_Host_netbsd_ProcessLauncherNetBSD_h_
-+#define lldb_Host_netbsd_ProcessLauncherNetBSD_h_
-+
-+#include "lldb/Host/ProcessLauncher.h"
-+
-+namespace lldb_private {
-+
-+class ProcessLauncherNetBSD : public ProcessLauncher {
-+public:
-+  virtual HostProcess LaunchProcess(const ProcessLaunchInfo &launch_info,
-+                                    Error &error);
-+};
-+
-+} // end of namespace lldb_private
-+
-+#endif
diff --git a/lldb-netbsd/patches/patch-include_lldb_Host_posix_ProcessLauncherPosixFork.h b/lldb-netbsd/patches/patch-include_lldb_Host_posix_ProcessLauncherPosixFork.h
new file mode 100644
index 0000000..8dd5c6b
--- /dev/null
+++ b/lldb-netbsd/patches/patch-include_lldb_Host_posix_ProcessLauncherPosixFork.h
@@ -0,0 +1,30 @@
+$NetBSD$
+
+--- include/lldb/Host/posix/ProcessLauncherPosixFork.h.orig	2017-01-31 22:15:25.384142043 +0000
++++ include/lldb/Host/posix/ProcessLauncherPosixFork.h
+@@ -0,0 +1,25 @@
++//===-- ProcessLauncherPosixFork.h ------------------------------*- C++ -*-===//
++//
++//                     The LLVM Compiler Infrastructure
++//
++// This file is distributed under the University of Illinois Open Source
++// License. See LICENSE.TXT for details.
++//
++//===----------------------------------------------------------------------===//
++
++#ifndef lldb_Host_posix_ProcessLauncherPosixFork_h_
++#define lldb_Host_posix_ProcessLauncherPosixFork_h_
++
++#include "lldb/Host/ProcessLauncher.h"
++
++namespace lldb_private {
++
++class ProcessLauncherPosixFork : public ProcessLauncher {
++public:
++  virtual HostProcess LaunchProcess(const ProcessLaunchInfo &launch_info,
++                                    Error &error);
++};
++
++} // end of namespace lldb_private
++
++#endif
diff --git a/lldb-netbsd/patches/patch-source_Host_CMakeLists.txt b/lldb-netbsd/patches/patch-source_Host_CMakeLists.txt
index 8c12ff1..2612f83 100644
--- a/lldb-netbsd/patches/patch-source_Host_CMakeLists.txt
+++ b/lldb-netbsd/patches/patch-source_Host_CMakeLists.txt
@@ -2,11 +2,19 @@ $NetBSD$
 
 --- source/Host/CMakeLists.txt.orig	2017-01-31 17:20:57.000000000 +0000
 +++ source/Host/CMakeLists.txt
-@@ -140,6 +140,7 @@ else()
-       netbsd/HostInfoNetBSD.cpp
-       netbsd/HostThreadNetBSD.cpp
-       netbsd/ThisThread.cpp
-+      netbsd/ProcessLauncherNetBSD.cpp
+@@ -86,6 +86,7 @@ else()
+     posix/LockFilePosix.cpp
+     posix/MainLoopPosix.cpp
+     posix/PipePosix.cpp
++    posix/ProcessLauncherPosixFork.cpp
+     )
+ 
+   if (NOT (CMAKE_SYSTEM_NAME MATCHES "Android"))
+@@ -117,7 +118,6 @@ else()
+       linux/HostInfoLinux.cpp
+       linux/HostThreadLinux.cpp
+       linux/LibcGlue.cpp
+-      linux/ProcessLauncherLinux.cpp
+       linux/ThisThread.cpp
        )
-   endif()
- endif()
+     if (CMAKE_SYSTEM_NAME MATCHES "Android")
diff --git a/lldb-netbsd/patches/patch-source_Host_common_Host.cpp b/lldb-netbsd/patches/patch-source_Host_common_Host.cpp
index 2fd3159..8f5ddf5 100644
--- a/lldb-netbsd/patches/patch-source_Host_common_Host.cpp
+++ b/lldb-netbsd/patches/patch-source_Host_common_Host.cpp
@@ -2,16 +2,18 @@ $NetBSD$
 
 --- source/Host/common/Host.cpp.orig	2017-01-31 17:20:57.000000000 +0000
 +++ source/Host/common/Host.cpp
-@@ -73,6 +73,8 @@
+@@ -71,8 +71,8 @@
+ 
+ #if defined(_WIN32)
  #include "lldb/Host/windows/ProcessLauncherWindows.h"
- #elif defined(__linux__)
- #include "lldb/Host/linux/ProcessLauncherLinux.h"
-+#elif defined(__NetBSD__)
-+#include "lldb/Host/netbsd/ProcessLauncherNetBSD.h"
+-#elif defined(__linux__)
+-#include "lldb/Host/linux/ProcessLauncherLinux.h"
++#elif defined(__linux__) || defined(__NetBSD__)
++#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
  #else
  #include "lldb/Host/posix/ProcessLauncherPosix.h"
  #endif
-@@ -623,7 +625,7 @@ Error Host::RunShellCommand(const Args &
+@@ -623,7 +623,7 @@ Error Host::RunShellCommand(const Args &
    return error;
  }
  
@@ -20,7 +22,7 @@ $NetBSD$
  // systems
  
  #if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__) ||        \
-@@ -700,7 +702,7 @@ Error Host::LaunchProcessPosixSpawn(cons
+@@ -700,7 +700,7 @@ Error Host::LaunchProcessPosixSpawn(cons
    sigemptyset(&no_signals);
    sigfillset(&all_signals);
    ::posix_spawnattr_setsigmask(&attr, &no_signals);
@@ -29,12 +31,14 @@ $NetBSD$
    ::posix_spawnattr_setsigdefault(&attr, &no_signals);
  #else
    ::posix_spawnattr_setsigdefault(&attr, &all_signals);
-@@ -977,6 +979,8 @@ Error Host::LaunchProcess(ProcessLaunchI
+@@ -975,8 +975,8 @@ Error Host::LaunchProcess(ProcessLaunchI
+   std::unique_ptr<ProcessLauncher> delegate_launcher;
+ #if defined(_WIN32)
    delegate_launcher.reset(new ProcessLauncherWindows());
- #elif defined(__linux__)
-   delegate_launcher.reset(new ProcessLauncherLinux());
-+#elif defined(__NetBSD__)
-+  delegate_launcher.reset(new ProcessLauncherNetBSD());
+-#elif defined(__linux__)
+-  delegate_launcher.reset(new ProcessLauncherLinux());
++#elif defined(__linux__) || defined(__NetBSD__)
++  delegate_launcher.reset(new ProcessLauncherPosixFork());
  #else
    delegate_launcher.reset(new ProcessLauncherPosix());
  #endif
diff --git a/lldb-netbsd/patches/patch-source_Host_linux_ProcessLauncherLinux.cpp b/lldb-netbsd/patches/patch-source_Host_linux_ProcessLauncherLinux.cpp
new file mode 100644
index 0000000..f16d5c1
--- /dev/null
+++ b/lldb-netbsd/patches/patch-source_Host_linux_ProcessLauncherLinux.cpp
@@ -0,0 +1,231 @@
+$NetBSD$
+
+--- source/Host/linux/ProcessLauncherLinux.cpp.orig	2017-01-31 17:20:57.000000000 +0000
++++ source/Host/linux/ProcessLauncherLinux.cpp
+@@ -1,225 +1 @@
+-//===-- ProcessLauncherLinux.cpp --------------------------------*- C++ -*-===//
+-//
+-//                     The LLVM Compiler Infrastructure
+-//
+-// This file is distributed under the University of Illinois Open Source
+-// License. See LICENSE.TXT for details.
+-//
+-//===----------------------------------------------------------------------===//
+-
+-#include "lldb/Host/linux/ProcessLauncherLinux.h"
+-#include "lldb/Core/Log.h"
+-#include "lldb/Host/FileSpec.h"
+-#include "lldb/Host/Host.h"
+-#include "lldb/Host/HostProcess.h"
+-#include "lldb/Host/Pipe.h"
+-#include "lldb/Target/ProcessLaunchInfo.h"
+-
+-#include <limits.h>
+-#include <sys/ptrace.h>
+-#include <sys/wait.h>
+-
+-#include <sstream>
+-
+-#ifdef __ANDROID__
+-#include <android/api-level.h>
+-#endif
+-
+-#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
+-#include <linux/personality.h>
+-#else
+-#include <sys/personality.h>
+-#endif
+-
+-using namespace lldb;
+-using namespace lldb_private;
+-
+-static void FixupEnvironment(Args &env) {
+-#ifdef __ANDROID__
+-  // If there is no PATH variable specified inside the environment then set the
+-  // path to /system/bin. It is required because the default path used by
+-  // execve() is wrong on android.
+-  static const char *path = "PATH=";
+-  for (auto &entry : env.entries()) {
+-    if (entry.ref.startswith(path))
+-      return;
+-  }
+-  env.AppendArgument(llvm::StringRef("PATH=/system/bin"));
+-#endif
+-}
+-
+-static void LLVM_ATTRIBUTE_NORETURN ExitWithError(int error_fd,
+-                                                  const char *operation) {
+-  std::ostringstream os;
+-  os << operation << " failed: " << strerror(errno);
+-  write(error_fd, os.str().data(), os.str().size());
+-  close(error_fd);
+-  _exit(1);
+-}
+-
+-static void DupDescriptor(int error_fd, const FileSpec &file_spec, int fd,
+-                          int flags) {
+-  int target_fd = ::open(file_spec.GetCString(), flags, 0666);
+-
+-  if (target_fd == -1)
+-    ExitWithError(error_fd, "DupDescriptor-open");
+-
+-  if (target_fd == fd)
+-    return;
+-
+-  if (::dup2(target_fd, fd) == -1)
+-    ExitWithError(error_fd, "DupDescriptor-dup2");
+-
+-  ::close(target_fd);
+-  return;
+-}
+-
+-static void LLVM_ATTRIBUTE_NORETURN ChildFunc(int error_fd,
+-                                              const ProcessLaunchInfo &info) {
+-  // First, make sure we disable all logging. If we are logging to stdout, our
+-  // logs can be
+-  // mistaken for inferior output.
+-  Log::DisableAllLogChannels(nullptr);
+-
+-  // Do not inherit setgid powers.
+-  if (setgid(getgid()) != 0)
+-    ExitWithError(error_fd, "setgid");
+-
+-  if (info.GetFlags().Test(eLaunchFlagLaunchInSeparateProcessGroup)) {
+-    if (setpgid(0, 0) != 0)
+-      ExitWithError(error_fd, "setpgid");
+-  }
+-
+-  for (size_t i = 0; i < info.GetNumFileActions(); ++i) {
+-    const FileAction &action = *info.GetFileActionAtIndex(i);
+-    switch (action.GetAction()) {
+-    case FileAction::eFileActionClose:
+-      if (close(action.GetFD()) != 0)
+-        ExitWithError(error_fd, "close");
+-      break;
+-    case FileAction::eFileActionDuplicate:
+-      if (dup2(action.GetFD(), action.GetActionArgument()) == -1)
+-        ExitWithError(error_fd, "dup2");
+-      break;
+-    case FileAction::eFileActionOpen:
+-      DupDescriptor(error_fd, action.GetFileSpec(), action.GetFD(),
+-                    action.GetActionArgument());
+-      break;
+-    case FileAction::eFileActionNone:
+-      break;
+-    }
+-  }
+-
+-  const char **argv = info.GetArguments().GetConstArgumentVector();
+-
+-  // Change working directory
+-  if (info.GetWorkingDirectory() &&
+-      0 != ::chdir(info.GetWorkingDirectory().GetCString()))
+-    ExitWithError(error_fd, "chdir");
+-
+-  // Disable ASLR if requested.
+-  if (info.GetFlags().Test(lldb::eLaunchFlagDisableASLR)) {
+-    const unsigned long personality_get_current = 0xffffffff;
+-    int value = personality(personality_get_current);
+-    if (value == -1)
+-      ExitWithError(error_fd, "personality get");
+-
+-    value = personality(ADDR_NO_RANDOMIZE | value);
+-    if (value == -1)
+-      ExitWithError(error_fd, "personality set");
+-  }
+-
+-  Args env = info.GetEnvironmentEntries();
+-  FixupEnvironment(env);
+-  const char **envp = env.GetConstArgumentVector();
+-
+-  // Clear the signal mask to prevent the child from being affected by
+-  // any masking done by the parent.
+-  sigset_t set;
+-  if (sigemptyset(&set) != 0 ||
+-      pthread_sigmask(SIG_SETMASK, &set, nullptr) != 0)
+-    ExitWithError(error_fd, "pthread_sigmask");
+-
+-  if (info.GetFlags().Test(eLaunchFlagDebug)) {
+-    // HACK:
+-    // Close everything besides stdin, stdout, and stderr that has no file
+-    // action to avoid leaking. Only do this when debugging, as elsewhere we
+-    // actually rely on
+-    // passing open descriptors to child processes.
+-    for (int fd = 3; fd < sysconf(_SC_OPEN_MAX); ++fd)
+-      if (!info.GetFileActionForFD(fd) && fd != error_fd)
+-        close(fd);
+-
+-    // Start tracing this child that is about to exec.
+-    if (ptrace(PTRACE_TRACEME, 0, nullptr, nullptr) == -1)
+-      ExitWithError(error_fd, "ptrace");
+-  }
+-
+-  // Execute.  We should never return...
+-  execve(argv[0], const_cast<char *const *>(argv),
+-         const_cast<char *const *>(envp));
+-
+-  if (errno == ETXTBSY) {
+-    // On android M and earlier we can get this error because the adb deamon can
+-    // hold a write
+-    // handle on the executable even after it has finished uploading it. This
+-    // state lasts
+-    // only a short time and happens only when there are many concurrent adb
+-    // commands being
+-    // issued, such as when running the test suite. (The file remains open when
+-    // someone does
+-    // an "adb shell" command in the fork() child before it has had a chance to
+-    // exec.) Since
+-    // this state should clear up quickly, wait a while and then give it one
+-    // more go.
+-    usleep(50000);
+-    execve(argv[0], const_cast<char *const *>(argv),
+-           const_cast<char *const *>(envp));
+-  }
+-
+-  // ...unless exec fails.  In which case we definitely need to end the child
+-  // here.
+-  ExitWithError(error_fd, "execve");
+-}
+-
+-HostProcess
+-ProcessLauncherLinux::LaunchProcess(const ProcessLaunchInfo &launch_info,
+-                                    Error &error) {
+-  char exe_path[PATH_MAX];
+-  launch_info.GetExecutableFile().GetPath(exe_path, sizeof(exe_path));
+-
+-  // A pipe used by the child process to report errors.
+-  PipePosix pipe;
+-  const bool child_processes_inherit = false;
+-  error = pipe.CreateNew(child_processes_inherit);
+-  if (error.Fail())
+-    return HostProcess();
+-
+-  ::pid_t pid = ::fork();
+-  if (pid == -1) {
+-    // Fork failed
+-    error.SetErrorStringWithFormat("Fork failed with error message: %s",
+-                                   strerror(errno));
+-    return HostProcess(LLDB_INVALID_PROCESS_ID);
+-  }
+-  if (pid == 0) {
+-    // child process
+-    pipe.CloseReadFileDescriptor();
+-    ChildFunc(pipe.ReleaseWriteFileDescriptor(), launch_info);
+-  }
+-
+-  // parent process
+-
+-  pipe.CloseWriteFileDescriptor();
+-  char buf[1000];
+-  int r = read(pipe.GetReadFileDescriptor(), buf, sizeof buf);
+-
+-  if (r == 0)
+-    return HostProcess(pid); // No error. We're done.
+-
+-  error.SetErrorString(buf);
+-
+-  waitpid(pid, nullptr, 0);
+-
+-  return HostProcess();
+-}
++k
diff --git a/lldb-netbsd/patches/patch-source_Host_netbsd_ProcessLauncherNetBSD.cpp b/lldb-netbsd/patches/patch-source_Host_netbsd_ProcessLauncherNetBSD.cpp
index 4389042..e69de29 100644
--- a/lldb-netbsd/patches/patch-source_Host_netbsd_ProcessLauncherNetBSD.cpp
+++ b/lldb-netbsd/patches/patch-source_Host_netbsd_ProcessLauncherNetBSD.cpp
@@ -1,175 +0,0 @@
-$NetBSD$
-
---- source/Host/netbsd/ProcessLauncherNetBSD.cpp.orig	2017-01-31 18:01:27.339780598 +0000
-+++ source/Host/netbsd/ProcessLauncherNetBSD.cpp
-@@ -0,0 +1,170 @@
-+//===-- ProcessLauncherNetBSD.cpp --------------------------------*- C++ -*-===//
-+//
-+//                     The LLVM Compiler Infrastructure
-+//
-+// This file is distributed under the University of Illinois Open Source
-+// License. See LICENSE.TXT for details.
-+//
-+//===----------------------------------------------------------------------===//
-+
-+#include "lldb/Host/netbsd/ProcessLauncherNetBSD.h"
-+#include "lldb/Core/Log.h"
-+#include "lldb/Host/FileSpec.h"
-+#include "lldb/Host/Host.h"
-+#include "lldb/Host/HostProcess.h"
-+#include "lldb/Host/Pipe.h"
-+#include "lldb/Target/ProcessLaunchInfo.h"
-+
-+#include <limits.h>
-+#include <sys/ptrace.h>
-+#include <sys/wait.h>
-+
-+#include <sstream>
-+
-+using namespace lldb;
-+using namespace lldb_private;
-+
-+static void LLVM_ATTRIBUTE_NORETURN ExitWithError(int error_fd,
-+                                                  const char *operation) {
-+  std::ostringstream os;
-+  os << operation << " failed: " << strerror(errno);
-+  write(error_fd, os.str().data(), os.str().size());
-+  close(error_fd);
-+  _exit(1);
-+}
-+
-+static void DupDescriptor(int error_fd, const FileSpec &file_spec, int fd,
-+                          int flags) {
-+  int target_fd = ::open(file_spec.GetCString(), flags, 0666);
-+
-+  if (target_fd == -1)
-+    ExitWithError(error_fd, "DupDescriptor-open");
-+
-+  if (target_fd == fd)
-+    return;
-+
-+  if (::dup2(target_fd, fd) == -1)
-+    ExitWithError(error_fd, "DupDescriptor-dup2");
-+
-+  ::close(target_fd);
-+  return;
-+}
-+
-+static void LLVM_ATTRIBUTE_NORETURN ChildFunc(int error_fd,
-+                                              const ProcessLaunchInfo &info) {
-+  // First, make sure we disable all logging. If we are logging to stdout, our
-+  // logs can be
-+  // mistaken for inferior output.
-+  Log::DisableAllLogChannels(nullptr);
-+
-+  // Do not inherit setgid powers.
-+  if (setgid(getgid()) != 0)
-+    ExitWithError(error_fd, "setgid");
-+
-+  if (info.GetFlags().Test(eLaunchFlagLaunchInSeparateProcessGroup)) {
-+    if (setpgid(0, 0) != 0)
-+      ExitWithError(error_fd, "setpgid");
-+  }
-+
-+  for (size_t i = 0; i < info.GetNumFileActions(); ++i) {
-+    const FileAction &action = *info.GetFileActionAtIndex(i);
-+    switch (action.GetAction()) {
-+    case FileAction::eFileActionClose:
-+      if (close(action.GetFD()) != 0)
-+        ExitWithError(error_fd, "close");
-+      break;
-+    case FileAction::eFileActionDuplicate:
-+      if (dup2(action.GetFD(), action.GetActionArgument()) == -1)
-+        ExitWithError(error_fd, "dup2");
-+      break;
-+    case FileAction::eFileActionOpen:
-+      DupDescriptor(error_fd, action.GetFileSpec(), action.GetFD(),
-+                    action.GetActionArgument());
-+      break;
-+    case FileAction::eFileActionNone:
-+      break;
-+    }
-+  }
-+
-+  const char **argv = info.GetArguments().GetConstArgumentVector();
-+
-+  // Change working directory
-+  if (info.GetWorkingDirectory() &&
-+      0 != ::chdir(info.GetWorkingDirectory().GetCString()))
-+    ExitWithError(error_fd, "chdir");
-+
-+  Args env = info.GetEnvironmentEntries();
-+  const char **envp = env.GetConstArgumentVector();
-+
-+  // Clear the signal mask to prevent the child from being affected by
-+  // any masking done by the parent.
-+  sigset_t set;
-+  if (sigemptyset(&set) != 0 ||
-+      sigprocmask(SIG_SETMASK, &set, nullptr) != 0)
-+    ExitWithError(error_fd, "pthread_sigmask");
-+
-+  if (info.GetFlags().Test(eLaunchFlagDebug)) {
-+    // HACK:
-+    // Close everything besides stdin, stdout, and stderr that has no file
-+    // action to avoid leaking. Only do this when debugging, as elsewhere we
-+    // actually rely on
-+    // passing open descriptors to child processes.
-+    for (int fd = 3; fd < sysconf(_SC_OPEN_MAX); ++fd)
-+      if (!info.GetFileActionForFD(fd) && fd != error_fd)
-+        close(fd);
-+
-+    // Start tracing this child that is about to exec.
-+    if (ptrace(PT_TRACE_ME, 0, nullptr, 0) == -1)
-+      ExitWithError(error_fd, "ptrace");
-+  }
-+
-+  // Execute.  We should never return...
-+  execve(argv[0], const_cast<char *const *>(argv),
-+         const_cast<char *const *>(envp));
-+
-+  // ...unless exec fails.  In which case we definitely need to end the child
-+  // here.
-+  ExitWithError(error_fd, "execve");
-+}
-+
-+HostProcess
-+ProcessLauncherNetBSD::LaunchProcess(const ProcessLaunchInfo &launch_info,
-+                                    Error &error) {
-+  char exe_path[PATH_MAX];
-+  launch_info.GetExecutableFile().GetPath(exe_path, sizeof(exe_path));
-+
-+  // A pipe used by the child process to report errors.
-+  PipePosix pipe;
-+  const bool child_processes_inherit = false;
-+  error = pipe.CreateNew(child_processes_inherit);
-+  if (error.Fail())
-+    return HostProcess();
-+
-+  ::pid_t pid = ::fork();
-+  if (pid == -1) {
-+    // Fork failed
-+    error.SetErrorStringWithFormat("Fork failed with error message: %s",
-+                                   strerror(errno));
-+    return HostProcess(LLDB_INVALID_PROCESS_ID);
-+  }
-+  if (pid == 0) {
-+    // child process
-+    pipe.CloseReadFileDescriptor();
-+    ChildFunc(pipe.ReleaseWriteFileDescriptor(), launch_info);
-+  }
-+
-+  // parent process
-+
-+  pipe.CloseWriteFileDescriptor();
-+  char buf[1000];
-+  int r = read(pipe.GetReadFileDescriptor(), buf, sizeof buf);
-+
-+  if (r == 0)
-+    return HostProcess(pid); // No error. We're done.
-+
-+  error.SetErrorString(buf);
-+
-+  waitpid(pid, nullptr, 0);
-+
-+  return HostProcess();
-+}
diff --git a/lldb-netbsd/patches/patch-source_Host_posix_ProcessLauncherPosixFork.cpp b/lldb-netbsd/patches/patch-source_Host_posix_ProcessLauncherPosixFork.cpp
new file mode 100644
index 0000000..91c59ec
--- /dev/null
+++ b/lldb-netbsd/patches/patch-source_Host_posix_ProcessLauncherPosixFork.cpp
@@ -0,0 +1,255 @@
+$NetBSD$
+
+--- source/Host/posix/ProcessLauncherPosixFork.cpp.orig	2017-01-31 22:19:11.628280905 +0000
++++ source/Host/posix/ProcessLauncherPosixFork.cpp
+@@ -0,0 +1,250 @@
++//===-- ProcessLauncherLinux.cpp --------------------------------*- C++ -*-===//
++//
++//                     The LLVM Compiler Infrastructure
++//
++// This file is distributed under the University of Illinois Open Source
++// License. See LICENSE.TXT for details.
++//
++//===----------------------------------------------------------------------===//
++
++#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
++#include "lldb/Core/Log.h"
++#include "lldb/Host/FileSpec.h"
++#include "lldb/Host/Host.h"
++#include "lldb/Host/HostProcess.h"
++#include "lldb/Host/Pipe.h"
++#include "lldb/Target/ProcessLaunchInfo.h"
++
++#include <limits.h>
++#include <sys/ptrace.h>
++#include <sys/wait.h>
++
++#include <sstream>
++
++#ifdef __ANDROID__
++#include <android/api-level.h>
++#endif
++
++#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
++#include <linux/personality.h>
++#elif defined(__linux__)
++#include <sys/personality.h>
++#endif
++
++using namespace lldb;
++using namespace lldb_private;
++
++static void FixupEnvironment(Args &env) {
++#ifdef __ANDROID__
++  // If there is no PATH variable specified inside the environment then set the
++  // path to /system/bin. It is required because the default path used by
++  // execve() is wrong on android.
++  static const char *path = "PATH=";
++  for (auto &entry : env.entries()) {
++    if (entry.ref.startswith(path))
++      return;
++  }
++  env.AppendArgument(llvm::StringRef("PATH=/system/bin"));
++#endif
++}
++
++static void LLVM_ATTRIBUTE_NORETURN ExitWithError(int error_fd,
++                                                  const char *operation) {
++  std::ostringstream os;
++  os << operation << " failed: " << strerror(errno);
++  write(error_fd, os.str().data(), os.str().size());
++  close(error_fd);
++  _exit(1);
++}
++
++static void DisableASLRIfRequested(int error_fd, const ProcessLaunchInfo &info) {
++#if defined(__linux__)
++  if (info.GetFlags().Test(lldb::eLaunchFlagDisableASLR)) {
++    const unsigned long personality_get_current = 0xffffffff;
++    int value = personality(personality_get_current);
++    if (value == -1)
++      ExitWithError(error_fd, "personality get");
++
++    value = personality(ADDR_NO_RANDOMIZE | value);
++    if (value == -1)
++      ExitWithError(error_fd, "personality set");
++  }
++#endif
++}
++
++static int PtraceMe() {
++#if defined(__linux__)
++  return ptrace(PTRACE_TRACEME, 0, nullptr, nullptr);
++#elif defined(__NetBSD__)
++  return ptrace(PT_TRACE_ME, 0, nullptr, 0);
++#else
++#error portme
++#endif
++}
++
++static int SignalSetMask(const sigset_t *set) {
++#if defined(__linux__)
++  return pthread_sigmask(SIG_SETMASK, set, nullptr);
++#elif defined(__NetBSD__)
++  return sigprocmask(SIG_SETMASK, set, nullptr);
++#else
++#error portme
++#endif
++}
++
++static void DupDescriptor(int error_fd, const FileSpec &file_spec, int fd,
++                          int flags) {
++  int target_fd = ::open(file_spec.GetCString(), flags, 0666);
++
++  if (target_fd == -1)
++    ExitWithError(error_fd, "DupDescriptor-open");
++
++  if (target_fd == fd)
++    return;
++
++  if (::dup2(target_fd, fd) == -1)
++    ExitWithError(error_fd, "DupDescriptor-dup2");
++
++  ::close(target_fd);
++  return;
++}
++
++static void LLVM_ATTRIBUTE_NORETURN ChildFunc(int error_fd,
++                                              const ProcessLaunchInfo &info) {
++  // First, make sure we disable all logging. If we are logging to stdout, our
++  // logs can be
++  // mistaken for inferior output.
++  Log::DisableAllLogChannels(nullptr);
++
++  // Do not inherit setgid powers.
++  if (setgid(getgid()) != 0)
++    ExitWithError(error_fd, "setgid");
++
++  if (info.GetFlags().Test(eLaunchFlagLaunchInSeparateProcessGroup)) {
++    if (setpgid(0, 0) != 0)
++      ExitWithError(error_fd, "setpgid");
++  }
++
++  for (size_t i = 0; i < info.GetNumFileActions(); ++i) {
++    const FileAction &action = *info.GetFileActionAtIndex(i);
++    switch (action.GetAction()) {
++    case FileAction::eFileActionClose:
++      if (close(action.GetFD()) != 0)
++        ExitWithError(error_fd, "close");
++      break;
++    case FileAction::eFileActionDuplicate:
++      if (dup2(action.GetFD(), action.GetActionArgument()) == -1)
++        ExitWithError(error_fd, "dup2");
++      break;
++    case FileAction::eFileActionOpen:
++      DupDescriptor(error_fd, action.GetFileSpec(), action.GetFD(),
++                    action.GetActionArgument());
++      break;
++    case FileAction::eFileActionNone:
++      break;
++    }
++  }
++
++  const char **argv = info.GetArguments().GetConstArgumentVector();
++
++  // Change working directory
++  if (info.GetWorkingDirectory() &&
++      0 != ::chdir(info.GetWorkingDirectory().GetCString()))
++    ExitWithError(error_fd, "chdir");
++
++  DisableASLRIfRequested(error_fd, info);
++  Args env = info.GetEnvironmentEntries();
++  FixupEnvironment(env);
++  const char **envp = env.GetConstArgumentVector();
++
++  // Clear the signal mask to prevent the child from being affected by
++  // any masking done by the parent.
++  sigset_t set;
++  if (sigemptyset(&set) != 0 || SignalSetMask(&set) != 0)
++    ExitWithError(error_fd, "pthread_sigmask");
++
++  if (info.GetFlags().Test(eLaunchFlagDebug)) {
++    // HACK:
++    // Close everything besides stdin, stdout, and stderr that has no file
++    // action to avoid leaking. Only do this when debugging, as elsewhere we
++    // actually rely on
++    // passing open descriptors to child processes.
++    for (int fd = 3; fd < sysconf(_SC_OPEN_MAX); ++fd)
++      if (!info.GetFileActionForFD(fd) && fd != error_fd)
++        close(fd);
++
++    // Start tracing this child that is about to exec.
++    if (PtraceMe() == -1)
++      ExitWithError(error_fd, "ptrace");
++  }
++
++  // Execute.  We should never return...
++  execve(argv[0], const_cast<char *const *>(argv),
++         const_cast<char *const *>(envp));
++
++#if defined(__linux__)
++  if (errno == ETXTBSY) {
++    // On android M and earlier we can get this error because the adb deamon can
++    // hold a write
++    // handle on the executable even after it has finished uploading it. This
++    // state lasts
++    // only a short time and happens only when there are many concurrent adb
++    // commands being
++    // issued, such as when running the test suite. (The file remains open when
++    // someone does
++    // an "adb shell" command in the fork() child before it has had a chance to
++    // exec.) Since
++    // this state should clear up quickly, wait a while and then give it one
++    // more go.
++    usleep(50000);
++    execve(argv[0], const_cast<char *const *>(argv),
++           const_cast<char *const *>(envp));
++  }
++#endif
++
++  // ...unless exec fails.  In which case we definitely need to end the child
++  // here.
++  ExitWithError(error_fd, "execve");
++}
++
++HostProcess
++ProcessLauncherPosixFork::LaunchProcess(const ProcessLaunchInfo &launch_info,
++                                        Error &error) {
++  char exe_path[PATH_MAX];
++  launch_info.GetExecutableFile().GetPath(exe_path, sizeof(exe_path));
++
++  // A pipe used by the child process to report errors.
++  PipePosix pipe;
++  const bool child_processes_inherit = false;
++  error = pipe.CreateNew(child_processes_inherit);
++  if (error.Fail())
++    return HostProcess();
++
++  ::pid_t pid = ::fork();
++  if (pid == -1) {
++    // Fork failed
++    error.SetErrorStringWithFormat("Fork failed with error message: %s",
++                                   strerror(errno));
++    return HostProcess(LLDB_INVALID_PROCESS_ID);
++  }
++  if (pid == 0) {
++    // child process
++    pipe.CloseReadFileDescriptor();
++    ChildFunc(pipe.ReleaseWriteFileDescriptor(), launch_info);
++  }
++
++  // parent process
++
++  pipe.CloseWriteFileDescriptor();
++  char buf[1000];
++  int r = read(pipe.GetReadFileDescriptor(), buf, sizeof buf);
++
++  if (r == 0)
++    return HostProcess(pid); // No error. We're done.
++
++  error.SetErrorString(buf);
++
++  waitpid(pid, nullptr, 0);
++
++  return HostProcess();
++}
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 8e124a2..ded8739 100644
--- a/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp
+++ b/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp
@@ -1,6 +1,6 @@
 $NetBSD$
 
---- source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp.orig	2017-01-31 18:01:27.497302816 +0000
+--- source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp.orig	2017-01-31 18:03:04.646466474 +0000
 +++ source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
 @@ -0,0 +1,1387 @@
 +//===-- NativeProcessNetBSD.cpp -------------------------------- -*- C++ -*-===//
@@ -39,7 +39,7 @@ $NetBSD$
 +#include "lldb/Host/ThreadLauncher.h"
 +#include "lldb/Host/common/NativeBreakpoint.h"
 +#include "lldb/Host/common/NativeRegisterContext.h"
-+#include "lldb/Host/netbsd/ProcessLauncherNetBSD.h"
++#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
 +#include "lldb/Symbol/ObjectFile.h"
 +#include "lldb/Target/Process.h"
 +#include "lldb/Target/ProcessLaunchInfo.h"
@@ -307,7 +307,7 @@ $NetBSD$
 +  MaybeLogLaunchInfo(launch_info);
 +
 +  ::pid_t pid =
-+      ProcessLauncherNetBSD().LaunchProcess(launch_info, error).GetProcessId();
++      ProcessLauncherPosixFork().LaunchProcess(launch_info, error).GetProcessId();
 +  if (error.Fail())
 +    return error;
 +


Home | Main Index | Thread Index | Old Index