2010-09-08 04:11:56 +08:00
|
|
|
//===-- Host.cpp ------------------------------------------------*- C++ -*-===//
|
2010-07-03 03:28:44 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-02-18 04:46:30 +08:00
|
|
|
// C includes
|
2010-09-08 04:11:56 +08:00
|
|
|
#include <errno.h>
|
2011-04-08 21:36:44 +08:00
|
|
|
#include <limits.h>
|
2014-03-25 07:10:19 +08:00
|
|
|
#include <stdlib.h>
|
2013-08-23 20:44:05 +08:00
|
|
|
#include <sys/types.h>
|
2014-10-16 01:27:11 +08:00
|
|
|
#ifndef _WIN32
|
2014-01-13 22:55:15 +08:00
|
|
|
#include <unistd.h>
|
2013-08-23 20:44:05 +08:00
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <grp.h>
|
2011-03-24 12:28:38 +08:00
|
|
|
#include <netdb.h>
|
Many improvements to the Platform base class and subclasses. The base Platform
class now implements the Host functionality for a lot of things that make
sense by default so that subclasses can check:
int
PlatformSubclass::Foo ()
{
if (IsHost())
return Platform::Foo (); // Let the platform base class do the host specific stuff
// Platform subclass specific code...
int result = ...
return result;
}
Added new functions to the platform:
virtual const char *Platform::GetUserName (uint32_t uid);
virtual const char *Platform::GetGroupName (uint32_t gid);
The user and group names are cached locally so that remote platforms can avoid
sending packets multiple times to resolve this information.
Added the parent process ID to the ProcessInfo class.
Added a new ProcessInfoMatch class which helps us to match processes up
and changed the Host layer over to using this new class. The new class allows
us to search for processs:
1 - by name (equal to, starts with, ends with, contains, and regex)
2 - by pid
3 - And further check for parent pid == value, uid == value, gid == value,
euid == value, egid == value, arch == value, parent == value.
This is all hookup up to the "platform process list" command which required
adding dumping routines to dump process information. If the Host class
implements the process lookup routines, you can now lists processes on
your local machine:
machine1.foo.com % lldb
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
94727 244 username usergroup username usergroup x86_64-apple-darwin Xcode
92742 92710 username usergroup username usergroup i386-apple-darwin debugserver
This of course also works remotely with the lldb-platform:
machine1.foo.com % lldb-platform --listen 1234
machine2.foo.com % lldb
(lldb) platform create remote-macosx
Platform: remote-macosx
Connected: no
(lldb) platform connect connect://localhost:1444
Platform: remote-macosx
Triple: x86_64-apple-darwin
OS Version: 10.6.7 (10J869)
Kernel: Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386
Hostname: machine1.foo.com
Connected: yes
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99556 244 username usergroup username usergroup x86_64-apple-darwin trustevaluation
99548 65539 username usergroup username usergroup x86_64-apple-darwin lldb
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
The lldb-platform implements everything with the Host:: layer, so this should
"just work" for linux. I will probably be adding more stuff to the Host layer
for launching processes and attaching to processes so that this support should
eventually just work as well.
Modified the target to be able to be created with an architecture that differs
from the main executable. This is needed for iOS debugging since we can have
an "armv6" binary which can run on an "armv7" machine, so we want to be able
to do:
% lldb
(lldb) platform create remote-ios
(lldb) file --arch armv7 a.out
Where "a.out" is an armv6 executable. The platform then can correctly decide
to open all "armv7" images for all dependent shared libraries.
Modified the disassembly to show the current PC value. Example output:
(lldb) disassemble --frame
a.out`main:
0x1eb7: pushl %ebp
0x1eb8: movl %esp, %ebp
0x1eba: pushl %ebx
0x1ebb: subl $20, %esp
0x1ebe: calll 0x1ec3 ; main + 12 at test.c:18
0x1ec3: popl %ebx
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
0x1edb: leal 213(%ebx), %eax
0x1ee1: movl %eax, (%esp)
0x1ee4: calll 0x1f1e ; puts
0x1ee9: calll 0x1f0c ; getchar
0x1eee: movl $20, (%esp)
0x1ef5: calll 0x1e6a ; sleep_loop at test.c:6
0x1efa: movl $12, %eax
0x1eff: addl $20, %esp
0x1f02: popl %ebx
0x1f03: leave
0x1f04: ret
This can be handy when dealing with the new --line options that was recently
added:
(lldb) disassemble --line
a.out`main + 13 at test.c:19
18 {
-> 19 printf("Process: %i\n\n", getpid());
20 puts("Press any key to continue..."); getchar();
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
Modified the ModuleList to have a lookup based solely on a UUID. Since the
UUID is typically the MD5 checksum of a binary image, there is no need
to give the path and architecture when searching for a pre-existing
image in an image list.
Now that we support remote debugging a bit better, our lldb_private::Module
needs to be able to track what the original path for file was as the platform
knows it, as well as where the file is locally. The module has the two
following functions to retrieve both paths:
const FileSpec &Module::GetFileSpec () const;
const FileSpec &Module::GetPlatformFileSpec () const;
llvm-svn: 128563
2011-03-31 02:16:51 +08:00
|
|
|
#include <pwd.h>
|
2013-11-21 10:45:55 +08:00
|
|
|
#include <sys/stat.h>
|
2013-09-05 23:39:09 +08:00
|
|
|
#endif
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
#if defined (__APPLE__)
|
2012-09-19 02:19:49 +08:00
|
|
|
#include <mach/mach_port.h>
|
2013-08-27 13:04:57 +08:00
|
|
|
#include <mach/mach_init.h>
|
|
|
|
#include <mach-o/dyld.h>
|
2013-06-26 02:58:11 +08:00
|
|
|
#endif
|
2011-02-08 08:35:34 +08:00
|
|
|
|
2014-05-03 03:09:40 +08:00
|
|
|
#if defined (__linux__) || defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__) || defined(__NetBSD__)
|
2014-11-08 09:41:49 +08:00
|
|
|
#if !defined(__ANDROID__) && !defined(__ANDROID_NDK__)
|
2013-08-28 04:58:59 +08:00
|
|
|
#include <spawn.h>
|
2014-09-28 00:54:22 +08:00
|
|
|
#endif
|
2011-02-08 01:43:47 +08:00
|
|
|
#include <sys/wait.h>
|
2013-08-02 02:51:08 +08:00
|
|
|
#include <sys/syscall.h>
|
2013-06-26 02:58:11 +08:00
|
|
|
#endif
|
2011-02-08 08:35:34 +08:00
|
|
|
|
2013-06-26 02:58:11 +08:00
|
|
|
#if defined (__FreeBSD__)
|
2011-08-03 04:52:42 +08:00
|
|
|
#include <pthread_np.h>
|
2010-09-08 04:11:56 +08:00
|
|
|
#endif
|
2010-07-03 03:28:44 +08:00
|
|
|
|
2016-03-16 05:11:02 +08:00
|
|
|
// C++ Includes
|
|
|
|
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
2014-07-17 03:03:16 +08:00
|
|
|
|
2014-12-09 05:36:42 +08:00
|
|
|
#include "lldb/Host/FileSystem.h"
|
2013-02-18 04:46:30 +08:00
|
|
|
#include "lldb/Host/Host.h"
|
2014-08-20 01:18:29 +08:00
|
|
|
#include "lldb/Host/HostInfo.h"
|
2013-02-18 04:46:30 +08:00
|
|
|
#include "lldb/Core/ArchSpec.h"
|
|
|
|
#include "lldb/Core/Error.h"
|
|
|
|
#include "lldb/Core/Log.h"
|
|
|
|
#include "lldb/Host/FileSpec.h"
|
2014-10-15 05:55:08 +08:00
|
|
|
#include "lldb/Host/HostProcess.h"
|
|
|
|
#include "lldb/Host/MonitoringProcessLauncher.h"
|
2015-01-16 14:47:43 +08:00
|
|
|
#include "lldb/Host/Predicate.h"
|
2014-10-15 05:55:08 +08:00
|
|
|
#include "lldb/Host/ProcessLauncher.h"
|
2014-09-10 04:54:56 +08:00
|
|
|
#include "lldb/Host/ThreadLauncher.h"
|
2014-08-30 01:35:57 +08:00
|
|
|
#include "lldb/lldb-private-forward.h"
|
2015-01-16 14:47:43 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2014-08-15 00:01:25 +08:00
|
|
|
#include "lldb/Target/FileAction.h"
|
|
|
|
#include "lldb/Target/ProcessLaunchInfo.h"
|
2015-01-16 14:47:43 +08:00
|
|
|
#include "lldb/Target/UnixSignals.h"
|
2013-08-28 04:58:59 +08:00
|
|
|
#include "lldb/Utility/CleanUp.h"
|
2015-01-16 14:47:43 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2013-02-18 04:46:30 +08:00
|
|
|
|
2014-10-15 05:55:08 +08:00
|
|
|
#if defined(_WIN32)
|
|
|
|
#include "lldb/Host/windows/ProcessLauncherWindows.h"
|
2015-02-13 02:13:44 +08:00
|
|
|
#elif defined(__ANDROID__) || defined(__ANDROID_NDK__)
|
|
|
|
#include "lldb/Host/android/ProcessLauncherAndroid.h"
|
2014-10-15 05:55:08 +08:00
|
|
|
#else
|
|
|
|
#include "lldb/Host/posix/ProcessLauncherPosix.h"
|
|
|
|
#endif
|
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
#if defined (__APPLE__)
|
|
|
|
#ifndef _POSIX_SPAWN_DISABLE_ASLR
|
|
|
|
#define _POSIX_SPAWN_DISABLE_ASLR 0x0100
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
int __pthread_chdir(const char *path);
|
|
|
|
int __pthread_fchdir (int fildes);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2013-02-18 04:46:30 +08:00
|
|
|
|
2010-07-03 03:28:44 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#if !defined (__APPLE__) && !defined (_WIN32)
|
2010-09-08 04:11:56 +08:00
|
|
|
struct MonitorInfo
|
|
|
|
{
|
|
|
|
lldb::pid_t pid; // The process ID to monitor
|
|
|
|
Host::MonitorChildProcessCallback callback; // The callback function to call when "pid" exits or signals
|
|
|
|
bool monitor_signals; // If true, call the callback when "pid" gets signaled.
|
|
|
|
};
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
static thread_result_t
|
2010-09-08 04:11:56 +08:00
|
|
|
MonitorChildProcessThreadFunction (void *arg);
|
|
|
|
|
2014-09-10 04:54:56 +08:00
|
|
|
HostThread
|
2016-05-12 00:59:04 +08:00
|
|
|
Host::StartMonitoringChildProcess(const Host::MonitorChildProcessCallback &callback, lldb::pid_t pid,
|
|
|
|
bool monitor_signals)
|
2010-09-08 04:11:56 +08:00
|
|
|
{
|
2011-11-16 13:37:56 +08:00
|
|
|
MonitorInfo * info_ptr = new MonitorInfo();
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2011-11-16 13:37:56 +08:00
|
|
|
info_ptr->pid = pid;
|
|
|
|
info_ptr->callback = callback;
|
|
|
|
info_ptr->monitor_signals = monitor_signals;
|
|
|
|
|
|
|
|
char thread_name[256];
|
2014-09-10 04:54:56 +08:00
|
|
|
::snprintf(thread_name, sizeof(thread_name), "<lldb.host.wait4(pid=%" PRIu64 ")>", pid);
|
|
|
|
return ThreadLauncher::LaunchThread(thread_name, MonitorChildProcessThreadFunction, info_ptr, NULL);
|
2010-09-08 04:11:56 +08:00
|
|
|
}
|
|
|
|
|
2015-03-13 19:16:03 +08:00
|
|
|
#ifndef __linux__
|
2010-07-03 03:28:44 +08:00
|
|
|
//------------------------------------------------------------------
|
2010-09-08 04:11:56 +08:00
|
|
|
// Scoped class that will disable thread canceling when it is
|
|
|
|
// constructed, and exception safely restore the previous value it
|
|
|
|
// when it goes out of scope.
|
2010-07-03 03:28:44 +08:00
|
|
|
//------------------------------------------------------------------
|
2010-09-08 04:11:56 +08:00
|
|
|
class ScopedPThreadCancelDisabler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ScopedPThreadCancelDisabler()
|
|
|
|
{
|
|
|
|
// Disable the ability for this thread to be cancelled
|
|
|
|
int err = ::pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &m_old_state);
|
|
|
|
if (err != 0)
|
|
|
|
m_old_state = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
~ScopedPThreadCancelDisabler()
|
|
|
|
{
|
|
|
|
// Restore the ability for this thread to be cancelled to what it
|
|
|
|
// previously was.
|
|
|
|
if (m_old_state != -1)
|
|
|
|
::pthread_setcancelstate (m_old_state, 0);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
int m_old_state; // Save the old cancelability state.
|
|
|
|
};
|
2015-03-13 19:16:03 +08:00
|
|
|
#endif // __linux__
|
|
|
|
|
|
|
|
#ifdef __linux__
|
2015-08-10 03:04:41 +08:00
|
|
|
#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8))
|
|
|
|
static __thread volatile sig_atomic_t g_usr1_called;
|
|
|
|
#else
|
2015-03-13 19:16:03 +08:00
|
|
|
static thread_local volatile sig_atomic_t g_usr1_called;
|
2015-08-10 03:04:41 +08:00
|
|
|
#endif
|
2015-03-13 19:16:03 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
SigUsr1Handler (int)
|
|
|
|
{
|
|
|
|
g_usr1_called = 1;
|
|
|
|
}
|
|
|
|
#endif // __linux__
|
|
|
|
|
|
|
|
static bool
|
|
|
|
CheckForMonitorCancellation()
|
|
|
|
{
|
|
|
|
#ifdef __linux__
|
|
|
|
if (g_usr1_called)
|
|
|
|
{
|
|
|
|
g_usr1_called = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
::pthread_testcancel ();
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-08 04:11:56 +08:00
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
static thread_result_t
|
2010-09-08 04:11:56 +08:00
|
|
|
MonitorChildProcessThreadFunction (void *arg)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
|
2010-09-08 04:11:56 +08:00
|
|
|
const char *function = __FUNCTION__;
|
|
|
|
if (log)
|
|
|
|
log->Printf ("%s (arg = %p) thread starting...", function, arg);
|
|
|
|
|
|
|
|
MonitorInfo *info = (MonitorInfo *)arg;
|
|
|
|
|
|
|
|
const Host::MonitorChildProcessCallback callback = info->callback;
|
|
|
|
const bool monitor_signals = info->monitor_signals;
|
|
|
|
|
2013-08-28 04:58:59 +08:00
|
|
|
assert (info->pid <= UINT32_MAX);
|
2014-04-02 14:57:45 +08:00
|
|
|
const ::pid_t pid = monitor_signals ? -1 * getpgid(info->pid) : info->pid;
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
delete info;
|
|
|
|
|
|
|
|
int status = -1;
|
2013-07-01 16:21:36 +08:00
|
|
|
#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
|
2013-05-02 04:38:19 +08:00
|
|
|
#define __WALL 0
|
|
|
|
#endif
|
2013-01-09 00:30:18 +08:00
|
|
|
const int options = __WALL;
|
|
|
|
|
2015-03-13 19:16:03 +08:00
|
|
|
#ifdef __linux__
|
|
|
|
// This signal is only used to interrupt the thread from waitpid
|
|
|
|
struct sigaction sigUsr1Action;
|
|
|
|
memset(&sigUsr1Action, 0, sizeof(sigUsr1Action));
|
|
|
|
sigUsr1Action.sa_handler = SigUsr1Handler;
|
|
|
|
::sigaction(SIGUSR1, &sigUsr1Action, nullptr);
|
|
|
|
#endif // __linux__
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
while (1)
|
|
|
|
{
|
2010-10-30 05:48:37 +08:00
|
|
|
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
|
2010-09-08 04:11:56 +08:00
|
|
|
if (log)
|
2015-01-24 06:48:28 +08:00
|
|
|
log->Printf("%s ::waitpid (pid = %" PRIi32 ", &status, options = %i)...", function, pid, options);
|
2010-09-08 04:11:56 +08:00
|
|
|
|
2015-03-13 19:16:03 +08:00
|
|
|
if (CheckForMonitorCancellation ())
|
|
|
|
break;
|
|
|
|
|
2013-01-09 00:30:18 +08:00
|
|
|
// Get signals from all children with same process group of pid
|
2013-08-28 04:58:59 +08:00
|
|
|
const ::pid_t wait_pid = ::waitpid (pid, &status, options);
|
2015-03-13 19:16:03 +08:00
|
|
|
|
|
|
|
if (CheckForMonitorCancellation ())
|
|
|
|
break;
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
if (wait_pid == -1)
|
|
|
|
{
|
|
|
|
if (errno == EINTR)
|
|
|
|
continue;
|
|
|
|
else
|
2013-05-29 07:04:25 +08:00
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf ("%s (arg = %p) thread exiting because waitpid failed (%s)...", __FUNCTION__, arg, strerror(errno));
|
2010-09-08 04:11:56 +08:00
|
|
|
break;
|
2013-05-29 07:04:25 +08:00
|
|
|
}
|
2010-09-08 04:11:56 +08:00
|
|
|
}
|
2013-01-09 00:30:18 +08:00
|
|
|
else if (wait_pid > 0)
|
2010-09-08 04:11:56 +08:00
|
|
|
{
|
|
|
|
bool exited = false;
|
|
|
|
int signal = 0;
|
|
|
|
int exit_status = 0;
|
|
|
|
const char *status_cstr = NULL;
|
|
|
|
if (WIFSTOPPED(status))
|
|
|
|
{
|
|
|
|
signal = WSTOPSIG(status);
|
|
|
|
status_cstr = "STOPPED";
|
|
|
|
}
|
|
|
|
else if (WIFEXITED(status))
|
|
|
|
{
|
|
|
|
exit_status = WEXITSTATUS(status);
|
|
|
|
status_cstr = "EXITED";
|
2013-05-29 07:04:25 +08:00
|
|
|
exited = true;
|
2010-09-08 04:11:56 +08:00
|
|
|
}
|
|
|
|
else if (WIFSIGNALED(status))
|
|
|
|
{
|
|
|
|
signal = WTERMSIG(status);
|
|
|
|
status_cstr = "SIGNALED";
|
2013-09-05 00:06:04 +08:00
|
|
|
if (wait_pid == abs(pid)) {
|
2013-01-09 00:30:18 +08:00
|
|
|
exited = true;
|
|
|
|
exit_status = -1;
|
|
|
|
}
|
2010-09-08 04:11:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-07-20 03:48:13 +08:00
|
|
|
status_cstr = "(\?\?\?)";
|
2010-09-08 04:11:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Scope for pthread_cancel_disabler
|
|
|
|
{
|
2015-03-13 19:16:03 +08:00
|
|
|
#ifndef __linux__
|
2010-09-08 04:11:56 +08:00
|
|
|
ScopedPThreadCancelDisabler pthread_cancel_disabler;
|
2014-09-28 00:54:22 +08:00
|
|
|
#endif
|
2010-09-08 04:11:56 +08:00
|
|
|
|
2010-10-30 05:48:37 +08:00
|
|
|
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
|
2010-09-08 04:11:56 +08:00
|
|
|
if (log)
|
2013-08-28 04:58:59 +08:00
|
|
|
log->Printf ("%s ::waitpid (pid = %" PRIi32 ", &status, options = %i) => pid = %" PRIi32 ", status = 0x%8.8x (%s), signal = %i, exit_state = %i",
|
2010-09-08 04:11:56 +08:00
|
|
|
function,
|
|
|
|
pid,
|
2015-01-24 06:48:28 +08:00
|
|
|
options,
|
|
|
|
wait_pid,
|
2010-09-08 04:11:56 +08:00
|
|
|
status,
|
|
|
|
status_cstr,
|
|
|
|
signal,
|
|
|
|
exit_status);
|
|
|
|
|
|
|
|
if (exited || (signal != 0 && monitor_signals))
|
|
|
|
{
|
2011-11-16 13:37:56 +08:00
|
|
|
bool callback_return = false;
|
|
|
|
if (callback)
|
2016-05-12 00:59:04 +08:00
|
|
|
callback_return = callback(wait_pid, exited, signal, exit_status);
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
// If our process exited, then this thread should exit
|
2013-09-05 00:06:04 +08:00
|
|
|
if (exited && wait_pid == abs(pid))
|
2013-05-29 07:04:25 +08:00
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf ("%s (arg = %p) thread exiting because pid received exit signal...", __FUNCTION__, arg);
|
2010-09-08 04:11:56 +08:00
|
|
|
break;
|
2013-05-29 07:04:25 +08:00
|
|
|
}
|
2010-09-08 04:11:56 +08:00
|
|
|
// If the callback returns true, it means this process should
|
|
|
|
// exit
|
|
|
|
if (callback_return)
|
2013-05-29 07:04:25 +08:00
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf ("%s (arg = %p) thread exiting because callback returned true...", __FUNCTION__, arg);
|
2010-09-08 04:11:56 +08:00
|
|
|
break;
|
2013-05-29 07:04:25 +08:00
|
|
|
}
|
2010-09-08 04:11:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-30 05:48:37 +08:00
|
|
|
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
|
2010-09-08 04:11:56 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf ("%s (arg = %p) thread exiting...", __FUNCTION__, arg);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#endif // #if !defined (__APPLE__) && !defined (_WIN32)
|
|
|
|
|
|
|
|
#if !defined (__APPLE__)
|
2012-01-05 11:57:59 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
Host::SystemLog (SystemLogType type, const char *format, va_list args)
|
|
|
|
{
|
|
|
|
vfprintf (stderr, format, args);
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#endif
|
2011-11-16 13:37:56 +08:00
|
|
|
|
2012-01-05 11:57:59 +08:00
|
|
|
void
|
|
|
|
Host::SystemLog (SystemLogType type, const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start (args, format);
|
|
|
|
SystemLog (type, format, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
lldb::pid_t
|
|
|
|
Host::GetCurrentProcessID()
|
|
|
|
{
|
|
|
|
return ::getpid();
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
lldb::tid_t
|
|
|
|
Host::GetCurrentThreadID()
|
|
|
|
{
|
|
|
|
#if defined (__APPLE__)
|
2013-12-06 17:35:53 +08:00
|
|
|
// Calling "mach_thread_self()" bumps the reference count on the thread
|
2012-09-19 02:19:49 +08:00
|
|
|
// port, so we need to deallocate it. mach_task_self() doesn't bump the ref
|
|
|
|
// count.
|
|
|
|
thread_port_t thread_self = mach_thread_self();
|
|
|
|
mach_port_deallocate(mach_task_self(), thread_self);
|
|
|
|
return thread_self;
|
2011-08-03 04:52:42 +08:00
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
return lldb::tid_t(pthread_getthreadid_np());
|
2014-11-08 09:41:49 +08:00
|
|
|
#elif defined(__ANDROID_NDK__)
|
|
|
|
return lldb::tid_t(gettid());
|
2013-08-02 02:51:08 +08:00
|
|
|
#elif defined(__linux__)
|
|
|
|
return lldb::tid_t(syscall(SYS_gettid));
|
2010-09-08 04:11:56 +08:00
|
|
|
#else
|
|
|
|
return lldb::tid_t(pthread_self());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-04-07 08:00:41 +08:00
|
|
|
lldb::thread_t
|
|
|
|
Host::GetCurrentThread ()
|
|
|
|
{
|
|
|
|
return lldb::thread_t(pthread_self());
|
|
|
|
}
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
const char *
|
|
|
|
Host::GetSignalAsCString (int signo)
|
|
|
|
{
|
|
|
|
switch (signo)
|
|
|
|
{
|
|
|
|
case SIGHUP: return "SIGHUP"; // 1 hangup
|
|
|
|
case SIGINT: return "SIGINT"; // 2 interrupt
|
|
|
|
case SIGQUIT: return "SIGQUIT"; // 3 quit
|
|
|
|
case SIGILL: return "SIGILL"; // 4 illegal instruction (not reset when caught)
|
|
|
|
case SIGTRAP: return "SIGTRAP"; // 5 trace trap (not reset when caught)
|
|
|
|
case SIGABRT: return "SIGABRT"; // 6 abort()
|
2013-12-13 02:12:16 +08:00
|
|
|
#if defined(SIGPOLL)
|
2013-12-13 17:51:39 +08:00
|
|
|
#if !defined(SIGIO) || (SIGPOLL != SIGIO)
|
|
|
|
// Under some GNU/Linux, SIGPOLL and SIGIO are the same. Causing the build to
|
|
|
|
// fail with 'multiple define cases with same value'
|
2010-09-08 04:11:56 +08:00
|
|
|
case SIGPOLL: return "SIGPOLL"; // 7 pollable event ([XSR] generated, not supported)
|
2011-11-05 00:06:40 +08:00
|
|
|
#endif
|
2013-12-13 17:51:39 +08:00
|
|
|
#endif
|
2013-12-13 02:12:16 +08:00
|
|
|
#if defined(SIGEMT)
|
2010-09-08 04:11:56 +08:00
|
|
|
case SIGEMT: return "SIGEMT"; // 7 EMT instruction
|
2011-11-05 00:06:40 +08:00
|
|
|
#endif
|
2010-09-08 04:11:56 +08:00
|
|
|
case SIGFPE: return "SIGFPE"; // 8 floating point exception
|
|
|
|
case SIGKILL: return "SIGKILL"; // 9 kill (cannot be caught or ignored)
|
|
|
|
case SIGBUS: return "SIGBUS"; // 10 bus error
|
|
|
|
case SIGSEGV: return "SIGSEGV"; // 11 segmentation violation
|
|
|
|
case SIGSYS: return "SIGSYS"; // 12 bad argument to system call
|
|
|
|
case SIGPIPE: return "SIGPIPE"; // 13 write on a pipe with no one to read it
|
|
|
|
case SIGALRM: return "SIGALRM"; // 14 alarm clock
|
|
|
|
case SIGTERM: return "SIGTERM"; // 15 software termination signal from kill
|
|
|
|
case SIGURG: return "SIGURG"; // 16 urgent condition on IO channel
|
|
|
|
case SIGSTOP: return "SIGSTOP"; // 17 sendable stop signal not from tty
|
|
|
|
case SIGTSTP: return "SIGTSTP"; // 18 stop signal from tty
|
|
|
|
case SIGCONT: return "SIGCONT"; // 19 continue a stopped process
|
|
|
|
case SIGCHLD: return "SIGCHLD"; // 20 to parent on child stop or exit
|
|
|
|
case SIGTTIN: return "SIGTTIN"; // 21 to readers pgrp upon background tty read
|
|
|
|
case SIGTTOU: return "SIGTTOU"; // 22 like TTIN for output if (tp->t_local<OSTOP)
|
2013-12-13 02:12:16 +08:00
|
|
|
#if defined(SIGIO)
|
2010-09-08 04:11:56 +08:00
|
|
|
case SIGIO: return "SIGIO"; // 23 input/output possible signal
|
|
|
|
#endif
|
|
|
|
case SIGXCPU: return "SIGXCPU"; // 24 exceeded CPU time limit
|
|
|
|
case SIGXFSZ: return "SIGXFSZ"; // 25 exceeded file size limit
|
|
|
|
case SIGVTALRM: return "SIGVTALRM"; // 26 virtual time alarm
|
|
|
|
case SIGPROF: return "SIGPROF"; // 27 profiling time alarm
|
2013-12-13 02:12:16 +08:00
|
|
|
#if defined(SIGWINCH)
|
2010-09-08 04:11:56 +08:00
|
|
|
case SIGWINCH: return "SIGWINCH"; // 28 window size changes
|
2013-12-13 02:12:16 +08:00
|
|
|
#endif
|
|
|
|
#if defined(SIGINFO)
|
2010-09-08 04:11:56 +08:00
|
|
|
case SIGINFO: return "SIGINFO"; // 29 information request
|
|
|
|
#endif
|
|
|
|
case SIGUSR1: return "SIGUSR1"; // 30 user defined signal 1
|
|
|
|
case SIGUSR2: return "SIGUSR2"; // 31 user defined signal 2
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
|
|
|
|
lldb::thread_key_t
|
|
|
|
Host::ThreadLocalStorageCreate(ThreadLocalStorageCleanupCallback callback)
|
|
|
|
{
|
|
|
|
pthread_key_t key;
|
|
|
|
::pthread_key_create (&key, callback);
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
Host::ThreadLocalStorageGet(lldb::thread_key_t key)
|
|
|
|
{
|
|
|
|
return ::pthread_getspecific (key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Host::ThreadLocalStorageSet(lldb::thread_key_t key, void *value)
|
|
|
|
{
|
|
|
|
::pthread_setspecific (key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
#if !defined (__APPLE__) // see Host.mm
|
2012-02-14 07:10:39 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
Host::GetBundleDirectory (const FileSpec &file, FileSpec &bundle)
|
|
|
|
{
|
|
|
|
bundle.Clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-03 03:28:44 +08:00
|
|
|
bool
|
Added a new Host call to find LLDB related paths:
static bool
Host::GetLLDBPath (lldb::PathType path_type, FileSpec &file_spec);
This will fill in "file_spec" with an appropriate path that is appropriate
for the current Host OS. MacOSX will return paths within the LLDB.framework,
and other unixes will return the paths they want. The current PathType
enums are:
typedef enum PathType
{
ePathTypeLLDBShlibDir, // The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists
ePathTypeSupportExecutableDir, // Find LLDB support executable directory (debugserver, etc)
ePathTypeHeaderDir, // Find LLDB header file directory
ePathTypePythonDir // Find Python modules (PYTHONPATH) directory
} PathType;
All places that were finding executables are and python paths are now updated
to use this Host call.
Added another new host call to launch the inferior in a terminal. This ability
will be very host specific and doesn't need to be supported on all systems.
MacOSX currently will create a new .command file and tell Terminal.app to open
the .command file. It also uses the new "darwin-debug" app which is a small
app that uses posix to exec (no fork) and stop at the entry point of the
program. The GDB remote plug-in is almost able launch a process and attach to
it, it currently will spawn the process, but it won't attach to it just yet.
This will let LLDB not have to share the terminal with another process and a
new terminal window will pop up when you launch. This won't get hooked up
until we work out all of the kinks. The new Host function is:
static lldb::pid_t
Host::LaunchInNewTerminal (
const char **argv, // argv[0] is executable
const char **envp,
const ArchSpec *arch_spec,
bool stop_at_entry,
bool disable_aslr);
Cleaned up FileSpec::GetPath to not use strncpy() as it was always zero
filling the entire path buffer.
Fixed an issue with the dynamic checker function where I missed a '$' prefix
that should have been added.
llvm-svn: 116690
2010-10-18 06:03:32 +08:00
|
|
|
Host::ResolveExecutableInBundle (FileSpec &file)
|
2010-07-03 03:28:44 +08:00
|
|
|
{
|
Added a new Host call to find LLDB related paths:
static bool
Host::GetLLDBPath (lldb::PathType path_type, FileSpec &file_spec);
This will fill in "file_spec" with an appropriate path that is appropriate
for the current Host OS. MacOSX will return paths within the LLDB.framework,
and other unixes will return the paths they want. The current PathType
enums are:
typedef enum PathType
{
ePathTypeLLDBShlibDir, // The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists
ePathTypeSupportExecutableDir, // Find LLDB support executable directory (debugserver, etc)
ePathTypeHeaderDir, // Find LLDB header file directory
ePathTypePythonDir // Find Python modules (PYTHONPATH) directory
} PathType;
All places that were finding executables are and python paths are now updated
to use this Host call.
Added another new host call to launch the inferior in a terminal. This ability
will be very host specific and doesn't need to be supported on all systems.
MacOSX currently will create a new .command file and tell Terminal.app to open
the .command file. It also uses the new "darwin-debug" app which is a small
app that uses posix to exec (no fork) and stop at the entry point of the
program. The GDB remote plug-in is almost able launch a process and attach to
it, it currently will spawn the process, but it won't attach to it just yet.
This will let LLDB not have to share the terminal with another process and a
new terminal window will pop up when you launch. This won't get hooked up
until we work out all of the kinks. The new Host function is:
static lldb::pid_t
Host::LaunchInNewTerminal (
const char **argv, // argv[0] is executable
const char **envp,
const ArchSpec *arch_spec,
bool stop_at_entry,
bool disable_aslr);
Cleaned up FileSpec::GetPath to not use strncpy() as it was always zero
filling the entire path buffer.
Fixed an issue with the dynamic checker function where I missed a '$' prefix
that should have been added.
llvm-svn: 116690
2010-10-18 06:03:32 +08:00
|
|
|
return false;
|
2010-07-03 03:28:44 +08:00
|
|
|
}
|
2010-09-08 04:11:56 +08:00
|
|
|
#endif
|
2010-07-03 03:28:44 +08:00
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
|
|
|
FileSpec
|
|
|
|
Host::GetModuleFileSpecForHostAddress (const void *host_addr)
|
|
|
|
{
|
|
|
|
FileSpec module_filespec;
|
2014-11-08 09:41:49 +08:00
|
|
|
#if !defined(__ANDROID__) && !defined(__ANDROID_NDK__)
|
2013-08-23 20:44:05 +08:00
|
|
|
Dl_info info;
|
|
|
|
if (::dladdr (host_addr, &info))
|
|
|
|
{
|
|
|
|
if (info.dli_fname)
|
|
|
|
module_filespec.SetFile(info.dli_fname, true);
|
|
|
|
}
|
2014-09-28 00:54:22 +08:00
|
|
|
#endif
|
2013-08-23 20:44:05 +08:00
|
|
|
return module_filespec;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-06-01 06:00:07 +08:00
|
|
|
#if !defined(__linux__)
|
|
|
|
bool
|
|
|
|
Host::FindProcessThreads (const lldb::pid_t pid, TidMap &tids_to_attach)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-04-14 09:42:46 +08:00
|
|
|
struct ShellInfo
|
|
|
|
{
|
|
|
|
ShellInfo () :
|
|
|
|
process_reaped (false),
|
|
|
|
pid (LLDB_INVALID_PROCESS_ID),
|
|
|
|
signo(-1),
|
|
|
|
status(-1)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb_private::Predicate<bool> process_reaped;
|
|
|
|
lldb::pid_t pid;
|
|
|
|
int signo;
|
|
|
|
int status;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
2016-05-12 00:59:04 +08:00
|
|
|
MonitorShellCommand(std::shared_ptr<ShellInfo> shell_info, lldb::pid_t pid,
|
|
|
|
bool exited, // True if the process did exit
|
|
|
|
int signo, // Zero for no signal
|
|
|
|
int status) // Exit value of process if signal is zero
|
2012-04-14 09:42:46 +08:00
|
|
|
{
|
|
|
|
shell_info->pid = pid;
|
|
|
|
shell_info->signo = signo;
|
|
|
|
shell_info->status = status;
|
|
|
|
// Let the thread running Host::RunShellCommand() know that the process
|
|
|
|
// exited and that ShellInfo has been filled in by broadcasting to it
|
2016-05-12 00:59:04 +08:00
|
|
|
shell_info->process_reaped.SetValue(true, eBroadcastAlways);
|
2012-04-14 09:42:46 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
2015-05-30 03:52:29 +08:00
|
|
|
Host::RunShellCommand(const char *command,
|
|
|
|
const FileSpec &working_dir,
|
|
|
|
int *status_ptr,
|
|
|
|
int *signo_ptr,
|
|
|
|
std::string *command_output_ptr,
|
|
|
|
uint32_t timeout_sec,
|
|
|
|
bool run_in_default_shell)
|
2015-04-17 09:50:11 +08:00
|
|
|
{
|
|
|
|
return RunShellCommand(Args(command), working_dir, status_ptr, signo_ptr, command_output_ptr, timeout_sec, run_in_default_shell);
|
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
2015-05-30 03:52:29 +08:00
|
|
|
Host::RunShellCommand(const Args &args,
|
|
|
|
const FileSpec &working_dir,
|
|
|
|
int *status_ptr,
|
|
|
|
int *signo_ptr,
|
|
|
|
std::string *command_output_ptr,
|
|
|
|
uint32_t timeout_sec,
|
|
|
|
bool run_in_default_shell)
|
2012-04-14 09:42:46 +08:00
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
ProcessLaunchInfo launch_info;
|
2014-12-09 05:36:42 +08:00
|
|
|
launch_info.SetArchitecture(HostInfo::GetArchitecture());
|
2014-10-21 01:46:43 +08:00
|
|
|
if (run_in_default_shell)
|
2012-09-27 11:13:55 +08:00
|
|
|
{
|
|
|
|
// Run the command in a shell
|
2014-10-21 01:46:43 +08:00
|
|
|
launch_info.SetShell(HostInfo::GetDefaultShell());
|
2015-04-17 09:50:11 +08:00
|
|
|
launch_info.GetArguments().AppendArguments(args);
|
2012-09-27 11:13:55 +08:00
|
|
|
const bool localhost = true;
|
|
|
|
const bool will_debug = false;
|
2015-04-17 09:50:11 +08:00
|
|
|
const bool first_arg_is_full_shell_command = false;
|
2012-09-27 11:13:55 +08:00
|
|
|
launch_info.ConvertArgumentsForLaunchingInShell (error,
|
|
|
|
localhost,
|
|
|
|
will_debug,
|
2013-09-10 10:09:47 +08:00
|
|
|
first_arg_is_full_shell_command,
|
|
|
|
0);
|
2012-09-27 11:13:55 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No shell, just run it
|
|
|
|
const bool first_arg_is_executable = true;
|
2012-10-18 06:57:12 +08:00
|
|
|
launch_info.SetArguments(args, first_arg_is_executable);
|
2012-09-27 11:13:55 +08:00
|
|
|
}
|
2012-04-14 09:42:46 +08:00
|
|
|
|
|
|
|
if (working_dir)
|
|
|
|
launch_info.SetWorkingDirectory(working_dir);
|
2014-12-09 05:36:42 +08:00
|
|
|
llvm::SmallString<PATH_MAX> output_file_path;
|
2015-04-17 09:50:11 +08:00
|
|
|
|
2012-04-14 09:42:46 +08:00
|
|
|
if (command_output_ptr)
|
|
|
|
{
|
|
|
|
// Create a temporary file to get the stdout/stderr and redirect the
|
|
|
|
// output of the command into this file. We will later read this file
|
|
|
|
// if all goes well and fill the data into "command_output_ptr"
|
2013-12-05 02:53:50 +08:00
|
|
|
FileSpec tmpdir_file_spec;
|
2014-08-22 01:29:12 +08:00
|
|
|
if (HostInfo::GetLLDBPath(ePathTypeLLDBTempSystemDir, tmpdir_file_spec))
|
2013-12-05 02:53:50 +08:00
|
|
|
{
|
2014-12-09 05:36:42 +08:00
|
|
|
tmpdir_file_spec.AppendPathComponent("lldb-shell-output.%%%%%%");
|
|
|
|
llvm::sys::fs::createUniqueFile(tmpdir_file_spec.GetPath().c_str(), output_file_path);
|
2013-12-05 02:53:50 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-09 05:36:42 +08:00
|
|
|
llvm::sys::fs::createTemporaryFile("lldb-shell-output.%%%%%%", "", output_file_path);
|
2013-12-05 02:53:50 +08:00
|
|
|
}
|
|
|
|
}
|
2015-05-30 03:52:29 +08:00
|
|
|
|
|
|
|
FileSpec output_file_spec{output_file_path.c_str(), false};
|
|
|
|
|
2013-12-05 02:53:50 +08:00
|
|
|
launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false);
|
2015-05-30 03:52:29 +08:00
|
|
|
if (output_file_spec)
|
2013-12-05 02:53:50 +08:00
|
|
|
{
|
2015-05-30 03:52:29 +08:00
|
|
|
launch_info.AppendOpenFileAction(STDOUT_FILENO, output_file_spec, false, true);
|
2012-09-27 11:13:55 +08:00
|
|
|
launch_info.AppendDuplicateFileAction(STDOUT_FILENO, STDERR_FILENO);
|
2012-04-14 09:42:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
launch_info.AppendSuppressFileAction (STDOUT_FILENO, false, true);
|
|
|
|
launch_info.AppendSuppressFileAction (STDERR_FILENO, false, true);
|
|
|
|
}
|
2016-05-12 00:59:04 +08:00
|
|
|
|
|
|
|
std::shared_ptr<ShellInfo> shell_info_sp(new ShellInfo());
|
2012-04-14 09:42:46 +08:00
|
|
|
const bool monitor_signals = false;
|
2016-05-12 00:59:04 +08:00
|
|
|
launch_info.SetMonitorProcessCallback(std::bind(MonitorShellCommand, shell_info_sp, std::placeholders::_1,
|
|
|
|
std::placeholders::_2, std::placeholders::_3,
|
|
|
|
std::placeholders::_4),
|
|
|
|
monitor_signals);
|
|
|
|
|
2012-04-14 09:42:46 +08:00
|
|
|
error = LaunchProcess (launch_info);
|
|
|
|
const lldb::pid_t pid = launch_info.GetProcessID();
|
2015-04-17 09:50:11 +08:00
|
|
|
|
2013-08-27 07:57:52 +08:00
|
|
|
if (error.Success() && pid == LLDB_INVALID_PROCESS_ID)
|
|
|
|
error.SetErrorString("failed to get process ID");
|
2015-04-17 09:50:11 +08:00
|
|
|
|
2013-08-27 07:57:52 +08:00
|
|
|
if (error.Success())
|
2012-04-14 09:42:46 +08:00
|
|
|
{
|
2013-08-28 04:58:59 +08:00
|
|
|
TimeValue *timeout_ptr = nullptr;
|
2012-04-14 09:42:46 +08:00
|
|
|
TimeValue timeout_time(TimeValue::Now());
|
2013-08-28 04:58:59 +08:00
|
|
|
if (timeout_sec > 0) {
|
|
|
|
timeout_time.OffsetWithSeconds(timeout_sec);
|
|
|
|
timeout_ptr = &timeout_time;
|
|
|
|
}
|
2012-04-14 09:42:46 +08:00
|
|
|
bool timed_out = false;
|
2016-05-12 00:59:04 +08:00
|
|
|
shell_info_sp->process_reaped.WaitForValueEqualTo(true, timeout_ptr, &timed_out);
|
2012-04-14 09:42:46 +08:00
|
|
|
if (timed_out)
|
|
|
|
{
|
|
|
|
error.SetErrorString("timed out waiting for shell command to complete");
|
2015-04-17 09:50:11 +08:00
|
|
|
|
2014-07-02 05:22:11 +08:00
|
|
|
// Kill the process since it didn't complete within the timeout specified
|
2013-08-23 20:44:05 +08:00
|
|
|
Kill (pid, SIGKILL);
|
2012-04-14 09:42:46 +08:00
|
|
|
// Wait for the monitor callback to get the message
|
|
|
|
timeout_time = TimeValue::Now();
|
|
|
|
timeout_time.OffsetWithSeconds(1);
|
|
|
|
timed_out = false;
|
2016-05-12 00:59:04 +08:00
|
|
|
shell_info_sp->process_reaped.WaitForValueEqualTo(true, &timeout_time, &timed_out);
|
2012-04-14 09:42:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (status_ptr)
|
2016-05-12 00:59:04 +08:00
|
|
|
*status_ptr = shell_info_sp->status;
|
|
|
|
|
2012-04-14 09:42:46 +08:00
|
|
|
if (signo_ptr)
|
2016-05-12 00:59:04 +08:00
|
|
|
*signo_ptr = shell_info_sp->signo;
|
|
|
|
|
2012-04-14 09:42:46 +08:00
|
|
|
if (command_output_ptr)
|
|
|
|
{
|
|
|
|
command_output_ptr->clear();
|
2015-05-30 03:52:29 +08:00
|
|
|
uint64_t file_size = output_file_spec.GetByteSize();
|
2012-04-14 09:42:46 +08:00
|
|
|
if (file_size > 0)
|
|
|
|
{
|
|
|
|
if (file_size > command_output_ptr->max_size())
|
|
|
|
{
|
|
|
|
error.SetErrorStringWithFormat("shell command output is too large to fit into a std::string");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-30 03:52:29 +08:00
|
|
|
std::vector<char> command_output(file_size);
|
|
|
|
output_file_spec.ReadFileContents(0, command_output.data(), file_size, &error);
|
|
|
|
if (error.Success())
|
|
|
|
command_output_ptr->assign(command_output.data(), file_size);
|
2012-04-14 09:42:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-30 03:52:29 +08:00
|
|
|
|
2014-12-09 05:36:42 +08:00
|
|
|
if (FileSystem::GetFileExists(output_file_spec))
|
2015-05-30 03:52:29 +08:00
|
|
|
FileSystem::Unlink(output_file_spec);
|
2012-04-14 09:42:46 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
// LaunchProcessPosixSpawn for Apple, Linux, FreeBSD and other GLIBC
|
|
|
|
// systems
|
|
|
|
|
2014-05-03 03:09:40 +08:00
|
|
|
#if defined (__APPLE__) || defined (__linux__) || defined (__FreeBSD__) || defined (__GLIBC__) || defined(__NetBSD__)
|
2015-02-13 02:13:44 +08:00
|
|
|
#if !defined(__ANDROID__) && !defined(__ANDROID_NDK__)
|
2014-01-23 08:52:28 +08:00
|
|
|
// this method needs to be visible to macosx/Host.cpp and
|
|
|
|
// common/Host.cpp.
|
|
|
|
|
|
|
|
short
|
2014-10-15 05:55:08 +08:00
|
|
|
Host::GetPosixspawnFlags(const ProcessLaunchInfo &launch_info)
|
2014-01-23 08:52:28 +08:00
|
|
|
{
|
|
|
|
short flags = POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK;
|
|
|
|
|
|
|
|
#if defined (__APPLE__)
|
|
|
|
if (launch_info.GetFlags().Test (eLaunchFlagExec))
|
|
|
|
flags |= POSIX_SPAWN_SETEXEC; // Darwin specific posix_spawn flag
|
|
|
|
|
|
|
|
if (launch_info.GetFlags().Test (eLaunchFlagDebug))
|
|
|
|
flags |= POSIX_SPAWN_START_SUSPENDED; // Darwin specific posix_spawn flag
|
|
|
|
|
|
|
|
if (launch_info.GetFlags().Test (eLaunchFlagDisableASLR))
|
|
|
|
flags |= _POSIX_SPAWN_DISABLE_ASLR; // Darwin specific posix_spawn flag
|
|
|
|
|
|
|
|
if (launch_info.GetLaunchInSeparateProcessGroup())
|
|
|
|
flags |= POSIX_SPAWN_SETPGROUP;
|
|
|
|
|
|
|
|
#ifdef POSIX_SPAWN_CLOEXEC_DEFAULT
|
|
|
|
#if defined (__APPLE__) && (defined (__x86_64__) || defined (__i386__))
|
|
|
|
static LazyBool g_use_close_on_exec_flag = eLazyBoolCalculate;
|
|
|
|
if (g_use_close_on_exec_flag == eLazyBoolCalculate)
|
|
|
|
{
|
|
|
|
g_use_close_on_exec_flag = eLazyBoolNo;
|
|
|
|
|
|
|
|
uint32_t major, minor, update;
|
2014-08-20 01:18:29 +08:00
|
|
|
if (HostInfo::GetOSVersion(major, minor, update))
|
2014-01-23 08:52:28 +08:00
|
|
|
{
|
|
|
|
// Kernel panic if we use the POSIX_SPAWN_CLOEXEC_DEFAULT on 10.7 or earlier
|
|
|
|
if (major > 10 || (major == 10 && minor > 7))
|
|
|
|
{
|
|
|
|
// Only enable for 10.8 and later OS versions
|
|
|
|
g_use_close_on_exec_flag = eLazyBoolYes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static LazyBool g_use_close_on_exec_flag = eLazyBoolYes;
|
|
|
|
#endif
|
|
|
|
// Close all files exception those with file actions if this is supported.
|
|
|
|
if (g_use_close_on_exec_flag == eLazyBoolYes)
|
|
|
|
flags |= POSIX_SPAWN_CLOEXEC_DEFAULT;
|
|
|
|
#endif
|
|
|
|
#endif // #if defined (__APPLE__)
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
2014-10-15 05:55:08 +08:00
|
|
|
Host::LaunchProcessPosixSpawn(const char *exe_path, const ProcessLaunchInfo &launch_info, lldb::pid_t &pid)
|
2013-08-28 04:58:59 +08:00
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_HOST | LIBLLDB_LOG_PROCESS));
|
|
|
|
|
|
|
|
posix_spawnattr_t attr;
|
|
|
|
error.SetError( ::posix_spawnattr_init (&attr), eErrorTypePOSIX);
|
2014-01-23 08:52:28 +08:00
|
|
|
|
|
|
|
if (error.Fail() || log)
|
|
|
|
error.PutToLog(log, "::posix_spawnattr_init ( &attr )");
|
2013-08-28 04:58:59 +08:00
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
|
|
|
|
// Make a quick class that will cleanup the posix spawn attributes in case
|
|
|
|
// we return in the middle of this function.
|
|
|
|
lldb_utility::CleanUp <posix_spawnattr_t *, int> posix_spawnattr_cleanup(&attr, posix_spawnattr_destroy);
|
|
|
|
|
|
|
|
sigset_t no_signals;
|
|
|
|
sigset_t all_signals;
|
|
|
|
sigemptyset (&no_signals);
|
|
|
|
sigfillset (&all_signals);
|
2014-01-23 08:52:28 +08:00
|
|
|
::posix_spawnattr_setsigmask(&attr, &no_signals);
|
2014-01-24 01:07:54 +08:00
|
|
|
#if defined (__linux__) || defined (__FreeBSD__)
|
2013-08-28 04:58:59 +08:00
|
|
|
::posix_spawnattr_setsigdefault(&attr, &no_signals);
|
2014-01-23 08:52:28 +08:00
|
|
|
#else
|
|
|
|
::posix_spawnattr_setsigdefault(&attr, &all_signals);
|
|
|
|
#endif
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
short flags = GetPosixspawnFlags(launch_info);
|
2013-08-28 04:58:59 +08:00
|
|
|
|
|
|
|
error.SetError( ::posix_spawnattr_setflags (&attr, flags), eErrorTypePOSIX);
|
2014-01-23 08:52:28 +08:00
|
|
|
if (error.Fail() || log)
|
|
|
|
error.PutToLog(log, "::posix_spawnattr_setflags ( &attr, flags=0x%8.8x )", flags);
|
2013-08-28 04:58:59 +08:00
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
// posix_spawnattr_setbinpref_np appears to be an Apple extension per:
|
|
|
|
// http://www.unix.com/man-page/OSX/3/posix_spawnattr_setbinpref_np/
|
|
|
|
#if defined (__APPLE__) && !defined (__arm__)
|
2014-02-21 09:25:21 +08:00
|
|
|
|
|
|
|
// Don't set the binpref if a shell was provided. After all, that's only going to affect what version of the shell
|
|
|
|
// is launched, not what fork of the binary is launched. We insert "arch --arch <ARCH> as part of the shell invocation
|
|
|
|
// to do that job on OSX.
|
|
|
|
|
|
|
|
if (launch_info.GetShell() == nullptr)
|
2013-08-28 04:58:59 +08:00
|
|
|
{
|
2014-02-21 09:25:21 +08:00
|
|
|
// We don't need to do this for ARM, and we really shouldn't now that we
|
|
|
|
// have multiple CPU subtypes and no posix_spawnattr call that allows us
|
|
|
|
// to set which CPU subtype to launch...
|
|
|
|
const ArchSpec &arch_spec = launch_info.GetArchitecture();
|
|
|
|
cpu_type_t cpu = arch_spec.GetMachOCPUType();
|
|
|
|
cpu_type_t sub = arch_spec.GetMachOCPUSubType();
|
|
|
|
if (cpu != 0 &&
|
2014-04-02 11:51:35 +08:00
|
|
|
cpu != static_cast<cpu_type_t>(UINT32_MAX) &&
|
|
|
|
cpu != static_cast<cpu_type_t>(LLDB_INVALID_CPUTYPE) &&
|
2014-02-21 09:25:21 +08:00
|
|
|
!(cpu == 0x01000007 && sub == 8)) // If haswell is specified, don't try to set the CPU type or we will fail
|
|
|
|
{
|
|
|
|
size_t ocount = 0;
|
|
|
|
error.SetError( ::posix_spawnattr_setbinpref_np (&attr, 1, &cpu, &ocount), eErrorTypePOSIX);
|
|
|
|
if (error.Fail() || log)
|
|
|
|
error.PutToLog(log, "::posix_spawnattr_setbinpref_np ( &attr, 1, cpu_type = 0x%8.8x, count => %llu )", cpu, (uint64_t)ocount);
|
2014-01-23 08:52:28 +08:00
|
|
|
|
2014-02-21 09:25:21 +08:00
|
|
|
if (error.Fail() || ocount != 1)
|
|
|
|
return error;
|
|
|
|
}
|
2014-01-23 08:52:28 +08:00
|
|
|
}
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
#endif
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
const char *tmp_argv[2];
|
2015-10-19 03:34:38 +08:00
|
|
|
char * const *argv = const_cast<char * const*>(launch_info.GetArguments().GetConstArgumentVector());
|
|
|
|
char * const *envp = const_cast<char * const*>(launch_info.GetEnvironmentEntries().GetConstArgumentVector());
|
2014-01-23 08:52:28 +08:00
|
|
|
if (argv == NULL)
|
|
|
|
{
|
|
|
|
// posix_spawn gets very unhappy if it doesn't have at least the program
|
|
|
|
// name in argv[0]. One of the side affects I have noticed is the environment
|
|
|
|
// variables don't make it into the child process if "argv == NULL"!!!
|
|
|
|
tmp_argv[0] = exe_path;
|
|
|
|
tmp_argv[1] = NULL;
|
2015-10-19 03:34:38 +08:00
|
|
|
argv = const_cast<char * const*>(tmp_argv);
|
2013-08-28 04:58:59 +08:00
|
|
|
}
|
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
#if !defined (__APPLE__)
|
|
|
|
// manage the working directory
|
2013-08-28 04:58:59 +08:00
|
|
|
char current_dir[PATH_MAX];
|
|
|
|
current_dir[0] = '\0';
|
2014-01-23 08:52:28 +08:00
|
|
|
#endif
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2015-05-30 03:52:29 +08:00
|
|
|
FileSpec working_dir{launch_info.GetWorkingDirectory()};
|
2014-01-23 08:52:28 +08:00
|
|
|
if (working_dir)
|
2013-08-28 04:58:59 +08:00
|
|
|
{
|
2014-01-23 08:52:28 +08:00
|
|
|
#if defined (__APPLE__)
|
|
|
|
// Set the working directory on this thread only
|
2015-05-30 03:52:29 +08:00
|
|
|
if (__pthread_chdir(working_dir.GetCString()) < 0) {
|
2014-01-23 08:52:28 +08:00
|
|
|
if (errno == ENOENT) {
|
2015-05-30 03:52:29 +08:00
|
|
|
error.SetErrorStringWithFormat("No such file or directory: %s",
|
|
|
|
working_dir.GetCString());
|
2014-01-23 08:52:28 +08:00
|
|
|
} else if (errno == ENOTDIR) {
|
2015-05-30 03:52:29 +08:00
|
|
|
error.SetErrorStringWithFormat("Path doesn't name a directory: %s",
|
|
|
|
working_dir.GetCString());
|
2014-01-23 08:52:28 +08:00
|
|
|
} else {
|
|
|
|
error.SetErrorStringWithFormat("An unknown error occurred when changing directory for process execution.");
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
#else
|
2013-08-28 04:58:59 +08:00
|
|
|
if (::getcwd(current_dir, sizeof(current_dir)) == NULL)
|
|
|
|
{
|
|
|
|
error.SetError(errno, eErrorTypePOSIX);
|
|
|
|
error.LogIfError(log, "unable to save the current directory");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2015-05-30 03:52:29 +08:00
|
|
|
if (::chdir(working_dir.GetCString()) == -1)
|
2013-08-28 04:58:59 +08:00
|
|
|
{
|
|
|
|
error.SetError(errno, eErrorTypePOSIX);
|
2015-05-30 03:52:29 +08:00
|
|
|
error.LogIfError(log, "unable to change working directory to %s",
|
|
|
|
working_dir.GetCString());
|
2013-08-28 04:58:59 +08:00
|
|
|
return error;
|
|
|
|
}
|
2014-01-23 08:52:28 +08:00
|
|
|
#endif
|
2013-08-28 04:58:59 +08:00
|
|
|
}
|
|
|
|
|
2014-10-15 05:55:08 +08:00
|
|
|
::pid_t result_pid = LLDB_INVALID_PROCESS_ID;
|
2014-01-23 08:52:28 +08:00
|
|
|
const size_t num_file_actions = launch_info.GetNumFileActions ();
|
|
|
|
if (num_file_actions > 0)
|
2013-08-28 04:58:59 +08:00
|
|
|
{
|
2014-01-23 08:52:28 +08:00
|
|
|
posix_spawn_file_actions_t file_actions;
|
|
|
|
error.SetError( ::posix_spawn_file_actions_init (&file_actions), eErrorTypePOSIX);
|
|
|
|
if (error.Fail() || log)
|
|
|
|
error.PutToLog(log, "::posix_spawn_file_actions_init ( &file_actions )");
|
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
|
|
|
|
// Make a quick class that will cleanup the posix spawn attributes in case
|
|
|
|
// we return in the middle of this function.
|
|
|
|
lldb_utility::CleanUp <posix_spawn_file_actions_t *, int> posix_spawn_file_actions_cleanup (&file_actions, posix_spawn_file_actions_destroy);
|
|
|
|
|
|
|
|
for (size_t i=0; i<num_file_actions; ++i)
|
|
|
|
{
|
2014-08-15 00:01:25 +08:00
|
|
|
const FileAction *launch_file_action = launch_info.GetFileActionAtIndex(i);
|
2014-01-23 08:52:28 +08:00
|
|
|
if (launch_file_action)
|
|
|
|
{
|
2014-08-16 06:04:21 +08:00
|
|
|
if (!AddPosixSpawnFileAction(&file_actions, launch_file_action, log, error))
|
2014-01-23 08:52:28 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2014-10-15 05:55:08 +08:00
|
|
|
error.SetError(::posix_spawnp(&result_pid, exe_path, &file_actions, &attr, argv, envp), eErrorTypePOSIX);
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
if (error.Fail() || log)
|
|
|
|
{
|
2014-10-15 05:55:08 +08:00
|
|
|
error.PutToLog(log, "::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )", result_pid,
|
|
|
|
exe_path, static_cast<void *>(&file_actions), static_cast<void *>(&attr), reinterpret_cast<const void *>(argv),
|
|
|
|
reinterpret_cast<const void *>(envp));
|
2014-01-23 08:52:28 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
for (int ii=0; argv[ii]; ++ii)
|
|
|
|
log->Printf("argv[%i] = '%s'", ii, argv[ii]);
|
|
|
|
}
|
|
|
|
}
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-15 05:55:08 +08:00
|
|
|
error.SetError(::posix_spawnp(&result_pid, exe_path, NULL, &attr, argv, envp), eErrorTypePOSIX);
|
2014-01-23 08:52:28 +08:00
|
|
|
|
|
|
|
if (error.Fail() || log)
|
|
|
|
{
|
|
|
|
error.PutToLog(log, "::posix_spawnp ( pid => %i, path = '%s', file_actions = NULL, attr = %p, argv = %p, envp = %p )",
|
2014-10-15 05:55:08 +08:00
|
|
|
result_pid, exe_path, static_cast<void *>(&attr), reinterpret_cast<const void *>(argv),
|
|
|
|
reinterpret_cast<const void *>(envp));
|
2014-01-23 08:52:28 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
for (int ii=0; argv[ii]; ++ii)
|
|
|
|
log->Printf("argv[%i] = '%s'", ii, argv[ii]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-15 05:55:08 +08:00
|
|
|
pid = result_pid;
|
2014-01-23 08:52:28 +08:00
|
|
|
|
|
|
|
if (working_dir)
|
2013-08-28 04:58:59 +08:00
|
|
|
{
|
2014-01-23 08:52:28 +08:00
|
|
|
#if defined (__APPLE__)
|
|
|
|
// No more thread specific current working directory
|
|
|
|
__pthread_fchdir (-1);
|
|
|
|
#else
|
|
|
|
if (::chdir(current_dir) == -1 && error.Success())
|
|
|
|
{
|
|
|
|
error.SetError(errno, eErrorTypePOSIX);
|
|
|
|
error.LogIfError(log, "unable to change current directory back to %s",
|
|
|
|
current_dir);
|
|
|
|
}
|
|
|
|
#endif
|
2013-08-28 04:58:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2014-08-16 06:04:21 +08:00
|
|
|
bool
|
|
|
|
Host::AddPosixSpawnFileAction(void *_file_actions, const FileAction *info, Log *log, Error &error)
|
2014-08-15 00:01:25 +08:00
|
|
|
{
|
|
|
|
if (info == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
posix_spawn_file_actions_t *file_actions = reinterpret_cast<posix_spawn_file_actions_t *>(_file_actions);
|
|
|
|
|
|
|
|
switch (info->GetAction())
|
|
|
|
{
|
2014-08-16 06:04:21 +08:00
|
|
|
case FileAction::eFileActionNone:
|
|
|
|
error.Clear();
|
|
|
|
break;
|
2014-08-15 00:01:25 +08:00
|
|
|
|
2014-08-16 06:04:21 +08:00
|
|
|
case FileAction::eFileActionClose:
|
|
|
|
if (info->GetFD() == -1)
|
|
|
|
error.SetErrorString("invalid fd for posix_spawn_file_actions_addclose(...)");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetError(::posix_spawn_file_actions_addclose(file_actions, info->GetFD()), eErrorTypePOSIX);
|
|
|
|
if (log && (error.Fail() || log))
|
|
|
|
error.PutToLog(log, "posix_spawn_file_actions_addclose (action=%p, fd=%i)",
|
|
|
|
static_cast<void *>(file_actions), info->GetFD());
|
|
|
|
}
|
|
|
|
break;
|
2014-08-15 00:01:25 +08:00
|
|
|
|
2014-08-16 06:04:21 +08:00
|
|
|
case FileAction::eFileActionDuplicate:
|
|
|
|
if (info->GetFD() == -1)
|
|
|
|
error.SetErrorString("invalid fd for posix_spawn_file_actions_adddup2(...)");
|
|
|
|
else if (info->GetActionArgument() == -1)
|
|
|
|
error.SetErrorString("invalid duplicate fd for posix_spawn_file_actions_adddup2(...)");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetError(
|
|
|
|
::posix_spawn_file_actions_adddup2(file_actions, info->GetFD(), info->GetActionArgument()),
|
|
|
|
eErrorTypePOSIX);
|
|
|
|
if (log && (error.Fail() || log))
|
|
|
|
error.PutToLog(log, "posix_spawn_file_actions_adddup2 (action=%p, fd=%i, dup_fd=%i)",
|
|
|
|
static_cast<void *>(file_actions), info->GetFD(), info->GetActionArgument());
|
|
|
|
}
|
|
|
|
break;
|
2014-08-15 00:01:25 +08:00
|
|
|
|
2014-08-16 06:04:21 +08:00
|
|
|
case FileAction::eFileActionOpen:
|
|
|
|
if (info->GetFD() == -1)
|
|
|
|
error.SetErrorString("invalid fd in posix_spawn_file_actions_addopen(...)");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int oflag = info->GetActionArgument();
|
2014-08-15 00:01:25 +08:00
|
|
|
|
2014-08-16 06:04:21 +08:00
|
|
|
mode_t mode = 0;
|
2014-08-15 00:01:25 +08:00
|
|
|
|
2014-08-16 06:04:21 +08:00
|
|
|
if (oflag & O_CREAT)
|
|
|
|
mode = 0640;
|
2014-08-15 00:01:25 +08:00
|
|
|
|
2014-08-16 06:04:21 +08:00
|
|
|
error.SetError(
|
|
|
|
::posix_spawn_file_actions_addopen(file_actions, info->GetFD(), info->GetPath(), oflag, mode),
|
|
|
|
eErrorTypePOSIX);
|
|
|
|
if (error.Fail() || log)
|
|
|
|
error.PutToLog(log,
|
|
|
|
"posix_spawn_file_actions_addopen (action=%p, fd=%i, path='%s', oflag=%i, mode=%i)",
|
|
|
|
static_cast<void *>(file_actions), info->GetFD(), info->GetPath(), oflag, mode);
|
|
|
|
}
|
|
|
|
break;
|
2014-08-15 00:01:25 +08:00
|
|
|
}
|
|
|
|
return error.Success();
|
|
|
|
}
|
2015-02-13 02:13:44 +08:00
|
|
|
#endif // !defined(__ANDROID__) && !defined(__ANDROID_NDK__)
|
|
|
|
#endif // defined (__APPLE__) || defined (__linux__) || defined (__FreeBSD__) || defined (__GLIBC__) || defined(__NetBSD__)
|
2014-01-23 08:52:28 +08:00
|
|
|
|
2014-10-15 05:55:08 +08:00
|
|
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__GLIBC__) || defined(__NetBSD__) || defined(_WIN32)
|
2014-05-03 03:09:40 +08:00
|
|
|
// The functions below implement process launching via posix_spawn() for Linux,
|
|
|
|
// FreeBSD and NetBSD.
|
2013-08-28 04:58:59 +08:00
|
|
|
|
|
|
|
Error
|
|
|
|
Host::LaunchProcess (ProcessLaunchInfo &launch_info)
|
|
|
|
{
|
2014-10-15 05:55:08 +08:00
|
|
|
std::unique_ptr<ProcessLauncher> delegate_launcher;
|
|
|
|
#if defined(_WIN32)
|
|
|
|
delegate_launcher.reset(new ProcessLauncherWindows());
|
2015-02-13 02:13:44 +08:00
|
|
|
#elif defined(__ANDROID__) || defined(__ANDROID_NDK__)
|
|
|
|
delegate_launcher.reset(new ProcessLauncherAndroid());
|
2014-10-15 05:55:08 +08:00
|
|
|
#else
|
|
|
|
delegate_launcher.reset(new ProcessLauncherPosix());
|
|
|
|
#endif
|
|
|
|
MonitoringProcessLauncher launcher(std::move(delegate_launcher));
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2014-10-15 05:55:08 +08:00
|
|
|
Error error;
|
|
|
|
HostProcess process = launcher.LaunchProcess(launch_info, error);
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2014-10-15 05:55:08 +08:00
|
|
|
// TODO(zturner): It would be better if the entire HostProcess were returned instead of writing
|
|
|
|
// it into this structure.
|
|
|
|
launch_info.SetProcessID(process.GetProcessId());
|
2014-01-23 08:52:28 +08:00
|
|
|
|
2013-08-28 04:58:59 +08:00
|
|
|
return error;
|
|
|
|
}
|
2014-05-03 03:09:40 +08:00
|
|
|
#endif // defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#ifndef _WIN32
|
|
|
|
void
|
|
|
|
Host::Kill(lldb::pid_t pid, int signo)
|
|
|
|
{
|
|
|
|
::kill(pid, signo);
|
|
|
|
}
|
2013-02-18 04:46:30 +08:00
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#endif
|
2012-04-14 09:42:46 +08:00
|
|
|
|
2011-08-03 04:52:42 +08:00
|
|
|
#if !defined (__APPLE__)
|
2010-07-03 03:28:44 +08:00
|
|
|
bool
|
2010-12-18 09:54:34 +08:00
|
|
|
Host::OpenFileInExternalEditor (const FileSpec &file_spec, uint32_t line_no)
|
2010-07-03 03:28:44 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
Added a new Host call to find LLDB related paths:
static bool
Host::GetLLDBPath (lldb::PathType path_type, FileSpec &file_spec);
This will fill in "file_spec" with an appropriate path that is appropriate
for the current Host OS. MacOSX will return paths within the LLDB.framework,
and other unixes will return the paths they want. The current PathType
enums are:
typedef enum PathType
{
ePathTypeLLDBShlibDir, // The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists
ePathTypeSupportExecutableDir, // Find LLDB support executable directory (debugserver, etc)
ePathTypeHeaderDir, // Find LLDB header file directory
ePathTypePythonDir // Find Python modules (PYTHONPATH) directory
} PathType;
All places that were finding executables are and python paths are now updated
to use this Host call.
Added another new host call to launch the inferior in a terminal. This ability
will be very host specific and doesn't need to be supported on all systems.
MacOSX currently will create a new .command file and tell Terminal.app to open
the .command file. It also uses the new "darwin-debug" app which is a small
app that uses posix to exec (no fork) and stop at the entry point of the
program. The GDB remote plug-in is almost able launch a process and attach to
it, it currently will spawn the process, but it won't attach to it just yet.
This will let LLDB not have to share the terminal with another process and a
new terminal window will pop up when you launch. This won't get hooked up
until we work out all of the kinks. The new Host function is:
static lldb::pid_t
Host::LaunchInNewTerminal (
const char **argv, // argv[0] is executable
const char **envp,
const ArchSpec *arch_spec,
bool stop_at_entry,
bool disable_aslr);
Cleaned up FileSpec::GetPath to not use strncpy() as it was always zero
filling the entire path buffer.
Fixed an issue with the dynamic checker function where I missed a '$' prefix
that should have been added.
llvm-svn: 116690
2010-10-18 06:03:32 +08:00
|
|
|
|
2010-11-10 12:57:04 +08:00
|
|
|
void
|
|
|
|
Host::SetCrashDescriptionWithFormat (const char *format, ...)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Host::SetCrashDescription (const char *description)
|
|
|
|
{
|
|
|
|
}
|
Added a new Host call to find LLDB related paths:
static bool
Host::GetLLDBPath (lldb::PathType path_type, FileSpec &file_spec);
This will fill in "file_spec" with an appropriate path that is appropriate
for the current Host OS. MacOSX will return paths within the LLDB.framework,
and other unixes will return the paths they want. The current PathType
enums are:
typedef enum PathType
{
ePathTypeLLDBShlibDir, // The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists
ePathTypeSupportExecutableDir, // Find LLDB support executable directory (debugserver, etc)
ePathTypeHeaderDir, // Find LLDB header file directory
ePathTypePythonDir // Find Python modules (PYTHONPATH) directory
} PathType;
All places that were finding executables are and python paths are now updated
to use this Host call.
Added another new host call to launch the inferior in a terminal. This ability
will be very host specific and doesn't need to be supported on all systems.
MacOSX currently will create a new .command file and tell Terminal.app to open
the .command file. It also uses the new "darwin-debug" app which is a small
app that uses posix to exec (no fork) and stop at the entry point of the
program. The GDB remote plug-in is almost able launch a process and attach to
it, it currently will spawn the process, but it won't attach to it just yet.
This will let LLDB not have to share the terminal with another process and a
new terminal window will pop up when you launch. This won't get hooked up
until we work out all of the kinks. The new Host function is:
static lldb::pid_t
Host::LaunchInNewTerminal (
const char **argv, // argv[0] is executable
const char **envp,
const ArchSpec *arch_spec,
bool stop_at_entry,
bool disable_aslr);
Cleaned up FileSpec::GetPath to not use strncpy() as it was always zero
filling the entire path buffer.
Fixed an issue with the dynamic checker function where I missed a '$' prefix
that should have been added.
llvm-svn: 116690
2010-10-18 06:03:32 +08:00
|
|
|
|
2013-11-21 05:07:01 +08:00
|
|
|
#endif
|
2014-08-30 01:35:57 +08:00
|
|
|
|
2015-07-14 09:09:28 +08:00
|
|
|
const UnixSignalsSP &
|
|
|
|
Host::GetUnixSignals()
|
2014-08-30 01:35:57 +08:00
|
|
|
{
|
2015-07-14 09:09:28 +08:00
|
|
|
static const auto s_unix_signals_sp = UnixSignals::Create(HostInfo::GetArchitecture());
|
2014-08-30 01:35:57 +08:00
|
|
|
return s_unix_signals_sp;
|
|
|
|
}
|