pkgsrc-WIP-changes archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
lldb-netbsd: Fix env parsing
Module Name: pkgsrc-wip
Committed By: Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By: kamil
Date: Thu Apr 6 20:50:00 2017 +0200
Changeset: 2211656ef70c89a8821b0f503c8bd6be08da16ea
Modified Files:
lldb-netbsd/distinfo
Added Files:
lldb-netbsd/patches/patch-source_Host_netbsd_Host.cpp
Log Message:
lldb-netbsd: Fix env parsing
curses applications now works
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=2211656ef70c89a8821b0f503c8bd6be08da16ea
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
diffstat:
lldb-netbsd/distinfo | 1 +
.../patches/patch-source_Host_netbsd_Host.cpp | 264 +++++++++++++++++++++
2 files changed, 265 insertions(+)
diffs:
diff --git a/lldb-netbsd/distinfo b/lldb-netbsd/distinfo
index 7931384fd5..96384599fb 100644
--- a/lldb-netbsd/distinfo
+++ b/lldb-netbsd/distinfo
@@ -12,3 +12,4 @@ 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_Host_netbsd_Host.cpp) = 0ee74330bfb76889e2e8e9780e9d5e808dc996b0
diff --git a/lldb-netbsd/patches/patch-source_Host_netbsd_Host.cpp b/lldb-netbsd/patches/patch-source_Host_netbsd_Host.cpp
new file mode 100644
index 0000000000..d23bd05aa5
--- /dev/null
+++ b/lldb-netbsd/patches/patch-source_Host_netbsd_Host.cpp
@@ -0,0 +1,264 @@
+$NetBSD$
+
+--- source/Host/netbsd/Host.cpp.orig 2017-04-06 18:49:15.976960208 +0000
++++ source/Host/netbsd/Host.cpp
+@@ -0,0 +1,259 @@
++//===-- source/Host/netbsd/Host.cpp -----------------------------*- C++ -*-===//
++//
++// The LLVM Compiler Infrastructure
++//
++// This file is distributed under the University of Illinois Open Source
++// License. See LICENSE.TXT for details.
++//
++//===----------------------------------------------------------------------===//
++
++// C Includes
++#include <dlfcn.h>
++#include <execinfo.h>
++#include <stdio.h>
++#include <sys/proc.h>
++#include <sys/sysctl.h>
++#include <sys/types.h>
++
++#include <limits.h>
++
++#include <elf.h>
++#include <kvm.h>
++#include <sys/exec.h>
++#include <sys/ptrace.h>
++
++// C++ Includes
++// Other libraries and framework includes
++// Project includes
++#include "lldb/Core/Module.h"
++#include "lldb/Core/StreamFile.h"
++#include "lldb/Host/Host.h"
++#include "lldb/Host/HostInfo.h"
++#include "lldb/Target/Platform.h"
++#include "lldb/Target/Process.h"
++#include "lldb/Utility/DataExtractor.h"
++#include "lldb/Utility/Endian.h"
++#include "lldb/Utility/Error.h"
++#include "lldb/Utility/Log.h"
++#include "lldb/Utility/StreamString.h"
++
++#include "lldb/Utility/CleanUp.h"
++#include "lldb/Utility/DataBufferHeap.h"
++#include "lldb/Utility/DataExtractor.h"
++#include "lldb/Utility/NameMatches.h"
++
++#include "llvm/Support/Host.h"
++
++extern "C" {
++extern char **environ;
++}
++
++using namespace lldb;
++using namespace lldb_private;
++
++size_t Host::GetEnvironment(StringList &env) {
++ char **host_env = environ;
++ char *env_entry;
++ size_t i;
++ for (i = 0; (env_entry = host_env[i]) != NULL; ++i)
++ env.AppendString(env_entry);
++ return i;
++}
++
++static bool GetNetBSDProcessArgs(const ProcessInstanceInfoMatch *match_info_ptr,
++ ProcessInstanceInfo &process_info) {
++ if (!process_info.ProcessIDIsValid())
++ return false;
++
++ int pid = process_info.GetProcessID();
++
++ int mib[4] = {CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_ARGV};
++
++ char arg_data[8192];
++ size_t arg_data_size = sizeof(arg_data);
++ if (::sysctl(mib, 4, arg_data, &arg_data_size, NULL, 0) != 0)
++ return false;
++
++ DataExtractor data(arg_data, arg_data_size, endian::InlHostByteOrder(),
++ sizeof(void *));
++ lldb::offset_t offset = 0;
++ const char *cstr;
++
++ cstr = data.GetCStr(&offset);
++ if (!cstr)
++ return false;
++
++ process_info.GetExecutableFile().SetFile(cstr, false);
++
++ if (!(match_info_ptr == NULL ||
++ NameMatches(process_info.GetExecutableFile().GetFilename().GetCString(),
++ match_info_ptr->GetNameMatchType(),
++ match_info_ptr->GetProcessInfo().GetName())))
++ return false;
++
++ Args &proc_args = process_info.GetArguments();
++ while (1) {
++ const uint8_t *p = data.PeekData(offset, 1);
++ while ((p != NULL) && (*p == '\0') && offset < arg_data_size) {
++ ++offset;
++ p = data.PeekData(offset, 1);
++ }
++ if (p == NULL || offset >= arg_data_size)
++ break;
++
++ cstr = data.GetCStr(&offset);
++ if (!cstr)
++ break;
++
++ proc_args.AppendArgument(llvm::StringRef(cstr));
++ }
++
++ return true;
++}
++
++static bool GetNetBSDProcessCPUType(ProcessInstanceInfo &process_info) {
++ if (process_info.ProcessIDIsValid()) {
++ process_info.GetArchitecture() =
++ HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
++ return true;
++ }
++ process_info.GetArchitecture().Clear();
++ return false;
++}
++
++static bool GetNetBSDProcessUserAndGroup(ProcessInstanceInfo &process_info) {
++ ::kvm_t *kdp;
++ char errbuf[_POSIX2_LINE_MAX]; /* XXX: error string unused */
++
++ struct ::kinfo_proc2 *proc_kinfo;
++ const int pid = process_info.GetProcessID();
++ int nproc;
++
++ if (!process_info.ProcessIDIsValid())
++ goto error;
++
++ if ((kdp = ::kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL)
++ goto error;
++
++ if ((proc_kinfo = ::kvm_getproc2(kdp, KERN_PROC_PID, pid,
++ sizeof(struct ::kinfo_proc2), &nproc)) ==
++ NULL) {
++ ::kvm_close(kdp);
++ goto error;
++ }
++
++ if (nproc < 1) {
++ ::kvm_close(kdp); /* XXX: we don't check for error here */
++ goto error;
++ }
++
++ process_info.SetParentProcessID(proc_kinfo->p_ppid);
++ process_info.SetUserID(proc_kinfo->p_ruid);
++ process_info.SetGroupID(proc_kinfo->p_rgid);
++ process_info.SetEffectiveUserID(proc_kinfo->p_uid);
++ process_info.SetEffectiveGroupID(proc_kinfo->p_gid);
++
++ ::kvm_close(kdp); /* XXX: we don't check for error here */
++
++ return true;
++
++error:
++ process_info.SetParentProcessID(LLDB_INVALID_PROCESS_ID);
++ process_info.SetUserID(UINT32_MAX);
++ process_info.SetGroupID(UINT32_MAX);
++ process_info.SetEffectiveUserID(UINT32_MAX);
++ process_info.SetEffectiveGroupID(UINT32_MAX);
++ return false;
++}
++
++uint32_t Host::FindProcesses(const ProcessInstanceInfoMatch &match_info,
++ ProcessInstanceInfoList &process_infos) {
++ const ::pid_t our_pid = ::getpid();
++ const ::uid_t our_uid = ::getuid();
++
++ const bool all_users =
++ match_info.GetMatchAllUsers() ||
++ // Special case, if lldb is being run as root we can attach to anything
++ (our_uid == 0);
++
++ kvm_t *kdp;
++ char errbuf[_POSIX2_LINE_MAX]; /* XXX: error string unused */
++ if ((kdp = ::kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL)
++ return 0;
++
++ struct ::kinfo_proc2 *proc_kinfo;
++ int nproc;
++ if ((proc_kinfo = ::kvm_getproc2(kdp, KERN_PROC_ALL, 0,
++ sizeof(struct ::kinfo_proc2), &nproc)) ==
++ NULL) {
++ ::kvm_close(kdp);
++ return 0;
++ }
++
++ for (int i = 0; i < nproc; i++) {
++ if (proc_kinfo[i].p_pid < 1)
++ continue; /* not valid */
++ /* Make sure the user is acceptable */
++ if (!all_users && proc_kinfo[i].p_ruid != our_uid)
++ continue;
++
++ if (proc_kinfo[i].p_pid == our_pid || // Skip this process
++ proc_kinfo[i].p_pid == 0 || // Skip kernel (kernel pid is 0)
++ proc_kinfo[i].p_stat == LSZOMB || // Zombies are bad
++ proc_kinfo[i].p_flag & P_TRACED || // Being debugged?
++ proc_kinfo[i].p_flag & P_WEXIT) // Working on exiting
++ continue;
++
++ // Every thread is a process in NetBSD, but all the threads of a single
++ // process have the same pid. Do not store the process info in the
++ // result list if a process with given identifier is already registered
++ // there.
++ if (proc_kinfo[i].p_nlwps > 1) {
++ bool already_registered = false;
++ for (size_t pi = 0; pi < process_infos.GetSize(); pi++) {
++ if (process_infos.GetProcessIDAtIndex(pi) == proc_kinfo[i].p_pid) {
++ already_registered = true;
++ break;
++ }
++ }
++
++ if (already_registered)
++ continue;
++ }
++ ProcessInstanceInfo process_info;
++ process_info.SetProcessID(proc_kinfo[i].p_pid);
++ process_info.SetParentProcessID(proc_kinfo[i].p_ppid);
++ process_info.SetUserID(proc_kinfo[i].p_ruid);
++ process_info.SetGroupID(proc_kinfo[i].p_rgid);
++ process_info.SetEffectiveUserID(proc_kinfo[i].p_uid);
++ process_info.SetEffectiveGroupID(proc_kinfo[i].p_gid);
++ // Make sure our info matches before we go fetch the name and cpu type
++ if (match_info.Matches(process_info) &&
++ GetNetBSDProcessArgs(&match_info, process_info)) {
++ GetNetBSDProcessCPUType(process_info);
++ if (match_info.Matches(process_info))
++ process_infos.Append(process_info);
++ }
++ }
++
++ kvm_close(kdp); /* XXX: we don't check for error here */
++
++ return process_infos.GetSize();
++}
++
++bool Host::GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info) {
++ process_info.SetProcessID(pid);
++
++ if (GetNetBSDProcessArgs(NULL, process_info)) {
++ GetNetBSDProcessCPUType(process_info);
++ GetNetBSDProcessUserAndGroup(process_info);
++ return true;
++ }
++
++ process_info.Clear();
++ return false;
++}
++
++Error Host::ShellExpandArguments(ProcessLaunchInfo &launch_info) {
++ return Error("unimplemented");
++}
Home |
Main Index |
Thread Index |
Old Index