pkgsrc-WIP-changes archive

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

lldb-git: Include ProcessLauncherNetBSD



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Tue Jan 31 22:04:06 2017 +0100
Changeset:	b2800872cb0917f2580c20a97a30391d3149dbed

Modified Files:
	lldb-git/distinfo
Added Files:
	lldb-git/patches/patch-include_lldb_Host_netbsd_ProcessLauncherNetBSD.h
	lldb-git/patches/patch-source_Host_CMakeLists.txt
	lldb-git/patches/patch-source_Host_common_Host.cpp
	lldb-git/patches/patch-source_Host_netbsd_ProcessLauncherNetBSD.cpp

Log Message:
lldb-git: Include ProcessLauncherNetBSD

Patch sent upstream.

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

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

diffstat:
 lldb-git/distinfo                                  |   4 +
 ...nclude_lldb_Host_netbsd_ProcessLauncherNetBSD.h |  30 ++++
 lldb-git/patches/patch-source_Host_CMakeLists.txt  |  12 ++
 lldb-git/patches/patch-source_Host_common_Host.cpp |  22 +++
 ...ch-source_Host_netbsd_ProcessLauncherNetBSD.cpp | 175 +++++++++++++++++++++
 5 files changed, 243 insertions(+)

diffs:
diff --git a/lldb-git/distinfo b/lldb-git/distinfo
index 9fa704a..afa609b 100644
--- a/lldb-git/distinfo
+++ b/lldb-git/distinfo
@@ -13,13 +13,17 @@ 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-include_lldb_Core_Debugger.h) = 6b1f7e7c3d24a5f5c63e5c99374289e48612c0fd
+SHA1 (patch-include_lldb_Host_netbsd_ProcessLauncherNetBSD.h) = 88bca9a4d9d0c72e0e062c2ce57e087a3cf5dd50
 SHA1 (patch-source_Commands_CommandObjectPlatform.cpp) = b1a96f4e6e9a9f896d0b77b8c067584d85ec6835
 SHA1 (patch-source_Core_ConstString.cpp) = e9ba124104c8fdfb9a64d51a53a1a4702746ef06
 SHA1 (patch-source_Core_Debugger.cpp) = 9f445f15298b553fdd78221f1c4cdacf66b857f9
 SHA1 (patch-source_Core_ModuleList.cpp) = 1dc5f5d9309646f5ca0119bbbd30e8d9c3146c4d
+SHA1 (patch-source_Host_CMakeLists.txt) = 576fc14b58053d1083161bb9311c58163ddc69b8
 SHA1 (patch-source_Host_common_Editline.cpp) = f0d179ac0f29325ba852578ebfa98c53cc6c02a8
+SHA1 (patch-source_Host_common_Host.cpp) = f7571aa056e913e2246ac7a15c428848f79bb795
 SHA1 (patch-source_Host_common_HostInfoBase.cpp) = 425b35aa4444cf204c46cc60e0be589faec4fb37
 SHA1 (patch-source_Host_linux_HostInfoLinux.cpp) = 98b21e116762d41cb211bd36036f2631bbe7923e
+SHA1 (patch-source_Host_netbsd_ProcessLauncherNetBSD.cpp) = 68c84744d12e51116340ea32e4c9599de9d7938b
 SHA1 (patch-source_Host_windows_HostInfoWindows.cpp) = 81480be68f9892b749766f646dd93be4d31b786f
 SHA1 (patch-source_Plugins_ExpressionParser_Clang_ClangModulesDeclVendor.cpp) = 06c35238d7821929feb6678b14efe913d3d707fe
 SHA1 (patch-source_Plugins_Language_CPlusPlus_CPlusPlusLanguage.cpp) = 16ff918313d4ee9eb96054a5fc0084cbfc11d691
diff --git a/lldb-git/patches/patch-include_lldb_Host_netbsd_ProcessLauncherNetBSD.h b/lldb-git/patches/patch-include_lldb_Host_netbsd_ProcessLauncherNetBSD.h
new file mode 100644
index 0000000..9fd9381
--- /dev/null
+++ b/lldb-git/patches/patch-include_lldb_Host_netbsd_ProcessLauncherNetBSD.h
@@ -0,0 +1,30 @@
+$NetBSD$
+
+--- include/lldb/Host/netbsd/ProcessLauncherNetBSD.h.orig	2017-01-31 21:05:08.736680888 +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-git/patches/patch-source_Host_CMakeLists.txt b/lldb-git/patches/patch-source_Host_CMakeLists.txt
new file mode 100644
index 0000000..9917d29
--- /dev/null
+++ b/lldb-git/patches/patch-source_Host_CMakeLists.txt
@@ -0,0 +1,12 @@
+$NetBSD$
+
+--- source/Host/CMakeLists.txt.orig	2017-01-31 21:04:43.225937908 +0000
++++ source/Host/CMakeLists.txt
+@@ -146,6 +146,7 @@ else()
+       netbsd/HostInfoNetBSD.cpp
+       netbsd/HostThreadNetBSD.cpp
+       netbsd/ThisThread.cpp
++      netbsd/ProcessLauncherNetBSD.cpp
+       )
+   endif()
+ endif()
diff --git a/lldb-git/patches/patch-source_Host_common_Host.cpp b/lldb-git/patches/patch-source_Host_common_Host.cpp
new file mode 100644
index 0000000..b578a41
--- /dev/null
+++ b/lldb-git/patches/patch-source_Host_common_Host.cpp
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- source/Host/common/Host.cpp.orig	2017-01-31 20:59:30.000000000 +0000
++++ source/Host/common/Host.cpp
+@@ -73,6 +73,8 @@
+ #include "lldb/Host/windows/ProcessLauncherWindows.h"
+ #elif defined(__linux__)
+ #include "lldb/Host/linux/ProcessLauncherLinux.h"
++#elif defined(__NetBSD__)
++#include "lldb/Host/netbsd/ProcessLauncherNetBSD.h"
+ #else
+ #include "lldb/Host/posix/ProcessLauncherPosix.h"
+ #endif
+@@ -977,6 +979,8 @@ Error Host::LaunchProcess(ProcessLaunchI
+   delegate_launcher.reset(new ProcessLauncherWindows());
+ #elif defined(__linux__)
+   delegate_launcher.reset(new ProcessLauncherLinux());
++#elif defined(__NetBSD__)
++  delegate_launcher.reset(new ProcessLauncherNetBSD());
+ #else
+   delegate_launcher.reset(new ProcessLauncherPosix());
+ #endif
diff --git a/lldb-git/patches/patch-source_Host_netbsd_ProcessLauncherNetBSD.cpp b/lldb-git/patches/patch-source_Host_netbsd_ProcessLauncherNetBSD.cpp
new file mode 100644
index 0000000..bfb9e2b
--- /dev/null
+++ b/lldb-git/patches/patch-source_Host_netbsd_ProcessLauncherNetBSD.cpp
@@ -0,0 +1,175 @@
+$NetBSD$
+
+--- source/Host/netbsd/ProcessLauncherNetBSD.cpp.orig	2017-01-31 21:05:08.808267808 +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();
++}


Home | Main Index | Thread Index | Old Index