2010-06-09 00:52:24 +08:00
|
|
|
//===-- Host.mm -------------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
#include "lldb/Host/Host.h"
|
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
|
|
|
|
2012-01-05 11:57:59 +08:00
|
|
|
#include <asl.h>
|
2010-12-04 08:10:17 +08:00
|
|
|
#include <crt_externs.h>
|
2010-12-03 14:02:24 +08:00
|
|
|
#include <execinfo.h>
|
2011-03-22 05:25:07 +08:00
|
|
|
#include <grp.h>
|
2010-10-20 02:15:50 +08:00
|
|
|
#include <libproc.h>
|
2011-03-22 05:25:07 +08:00
|
|
|
#include <pwd.h>
|
2011-04-12 13:54:46 +08:00
|
|
|
#include <spawn.h>
|
2010-12-03 14:02:24 +08:00
|
|
|
#include <stdio.h>
|
2010-10-20 02:15:50 +08:00
|
|
|
#include <sys/proc.h>
|
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
|
|
|
#include <sys/stat.h>
|
2011-03-22 05:25:07 +08:00
|
|
|
#include <sys/sysctl.h>
|
2010-10-20 02:15:50 +08:00
|
|
|
#include <sys/types.h>
|
2010-12-03 14:02:24 +08:00
|
|
|
#include <unistd.h>
|
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
|
|
|
|
|
|
|
#include "lldb/Core/ArchSpec.h"
|
2010-10-19 11:25:40 +08:00
|
|
|
#include "lldb/Core/Communication.h"
|
|
|
|
#include "lldb/Core/ConnectionFileDescriptor.h"
|
2011-04-01 08:29:43 +08:00
|
|
|
#include "lldb/Core/DataExtractor.h"
|
2010-09-08 04:11:56 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
2011-04-12 13:54:46 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
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
|
|
|
#include "lldb/Core/StreamFile.h"
|
|
|
|
#include "lldb/Core/StreamString.h"
|
2011-04-12 13:54:46 +08:00
|
|
|
#include "lldb/Host/Endian.h"
|
|
|
|
#include "lldb/Host/FileSpec.h"
|
|
|
|
#include "lldb/Target/Platform.h"
|
2011-03-22 05:25:07 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
2011-04-12 13:54:46 +08:00
|
|
|
#include "lldb/Utility/CleanUp.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-07-10 04:39:50 +08:00
|
|
|
#include "cfcpp/CFCBundle.h"
|
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
|
|
|
#include "cfcpp/CFCMutableArray.h"
|
2010-10-01 05:49:03 +08:00
|
|
|
#include "cfcpp/CFCMutableDictionary.h"
|
2010-07-10 04:39:50 +08:00
|
|
|
#include "cfcpp/CFCReleaser.h"
|
|
|
|
#include "cfcpp/CFCString.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-03-22 05:25:07 +08:00
|
|
|
#include "llvm/Support/Host.h"
|
|
|
|
#include "llvm/Support/MachO.h"
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
#include <objc/objc-auto.h>
|
|
|
|
|
2011-11-04 11:34:56 +08:00
|
|
|
#if defined(__arm__)
|
|
|
|
#include <UIKit/UIKit.h>
|
|
|
|
#else
|
2010-10-01 05:49:03 +08:00
|
|
|
#include <ApplicationServices/ApplicationServices.h>
|
2010-09-08 04:11:56 +08:00
|
|
|
#include <Carbon/Carbon.h>
|
2011-11-04 11:34:56 +08:00
|
|
|
#endif
|
2010-09-08 04:11:56 +08:00
|
|
|
#include <Foundation/Foundation.h>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
#ifndef _POSIX_SPAWN_DISABLE_ASLR
|
|
|
|
#define _POSIX_SPAWN_DISABLE_ASLR 0x0100
|
|
|
|
#endif
|
|
|
|
|
2011-11-15 11:53:30 +08:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
int __pthread_chdir(const char *path);
|
|
|
|
int __pthread_fchdir (int fildes);
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2011-11-17 09:23:07 +08:00
|
|
|
static pthread_once_t g_thread_create_once = PTHREAD_ONCE_INIT;
|
|
|
|
static pthread_key_t g_thread_create_key = 0;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
class MacOSXDarwinThread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MacOSXDarwinThread(const char *thread_name) :
|
|
|
|
m_pool (nil)
|
|
|
|
{
|
|
|
|
// Register our thread with the collector if garbage collection is enabled.
|
|
|
|
if (objc_collectingEnabled())
|
|
|
|
{
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5
|
|
|
|
// On Leopard and earlier there is no way objc_registerThreadWithCollector
|
|
|
|
// function, so we do it manually.
|
|
|
|
auto_zone_register_thread(auto_zone());
|
|
|
|
#else
|
2011-01-09 04:28:42 +08:00
|
|
|
// On SnowLeopard and later we just call the thread registration function.
|
2010-06-09 00:52:24 +08:00
|
|
|
objc_registerThreadWithCollector();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Host::SetThreadName (LLDB_INVALID_PROCESS_ID, LLDB_INVALID_THREAD_ID, thread_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
~MacOSXDarwinThread()
|
|
|
|
{
|
|
|
|
if (m_pool)
|
2011-11-17 09:23:07 +08:00
|
|
|
{
|
2010-06-09 00:52:24 +08:00
|
|
|
[m_pool release];
|
2011-11-17 09:23:07 +08:00
|
|
|
m_pool = nil;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PThreadDestructor (void *v)
|
|
|
|
{
|
2011-11-17 09:23:07 +08:00
|
|
|
if (v)
|
|
|
|
delete static_cast<MacOSXDarwinThread*>(v);
|
|
|
|
::pthread_setspecific (g_thread_create_key, NULL);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
NSAutoreleasePool * m_pool;
|
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN (MacOSXDarwinThread);
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitThreadCreated()
|
|
|
|
{
|
|
|
|
::pthread_key_create (&g_thread_create_key, MacOSXDarwinThread::PThreadDestructor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Host::ThreadCreated (const char *thread_name)
|
|
|
|
{
|
|
|
|
::pthread_once (&g_thread_create_once, InitThreadCreated);
|
|
|
|
if (g_thread_create_key)
|
|
|
|
{
|
|
|
|
::pthread_setspecific (g_thread_create_key, new MacOSXDarwinThread(thread_name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-14 07:10:39 +08:00
|
|
|
bool
|
|
|
|
Host::GetBundleDirectory (const FileSpec &file, FileSpec &bundle_directory)
|
|
|
|
{
|
|
|
|
#if defined (__APPLE__)
|
|
|
|
if (file.GetFileType () == FileSpec::eFileTypeDirectory)
|
|
|
|
{
|
|
|
|
char path[PATH_MAX];
|
|
|
|
if (file.GetPath(path, sizeof(path)))
|
|
|
|
{
|
|
|
|
CFCBundle bundle (path);
|
|
|
|
if (bundle.GetPath (path, sizeof(path)))
|
|
|
|
{
|
|
|
|
bundle_directory.SetFile (path, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
bundle_directory.Clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +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-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-08 04:11:56 +08:00
|
|
|
#if defined (__APPLE__)
|
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
|
|
|
if (file.GetFileType () == FileSpec::eFileTypeDirectory)
|
2010-09-08 04:11:56 +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
|
|
|
char path[PATH_MAX];
|
|
|
|
if (file.GetPath(path, sizeof(path)))
|
2010-06-09 00:52:24 +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
|
|
|
CFCBundle bundle (path);
|
|
|
|
CFCReleaser<CFURLRef> url(bundle.CopyExecutableURL ());
|
|
|
|
if (url.get())
|
|
|
|
{
|
|
|
|
if (::CFURLGetFileSystemRepresentation (url.get(), YES, (UInt8*)path, sizeof(path)))
|
|
|
|
{
|
2010-10-21 04:54:39 +08:00
|
|
|
file.SetFile(path, 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
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2010-09-08 04:11:56 +08:00
|
|
|
#endif
|
|
|
|
return false;
|
2010-08-10 07:31:02 +08:00
|
|
|
}
|
2010-08-31 03:44:40 +08:00
|
|
|
|
2010-10-01 05:49:03 +08:00
|
|
|
lldb::pid_t
|
|
|
|
Host::LaunchApplication (const FileSpec &app_file_spec)
|
|
|
|
{
|
2011-11-04 11:34:56 +08:00
|
|
|
#if defined (__arm__)
|
|
|
|
return LLDB_INVALID_PROCESS_ID;
|
|
|
|
#else
|
2010-10-01 05:49:03 +08:00
|
|
|
char app_path[PATH_MAX];
|
|
|
|
app_file_spec.GetPath(app_path, sizeof(app_path));
|
|
|
|
|
|
|
|
LSApplicationParameters app_params;
|
2011-02-05 05:13:05 +08:00
|
|
|
::memset (&app_params, 0, sizeof (app_params));
|
2010-10-01 05:49:03 +08:00
|
|
|
app_params.flags = kLSLaunchDefaults |
|
|
|
|
kLSLaunchDontAddToRecents |
|
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
|
|
|
kLSLaunchNewInstance;
|
|
|
|
|
2010-10-01 05:49:03 +08:00
|
|
|
|
|
|
|
FSRef app_fsref;
|
|
|
|
CFCString app_cfstr (app_path, kCFStringEncodingUTF8);
|
|
|
|
|
2010-11-11 04:16:47 +08:00
|
|
|
OSStatus error = ::FSPathMakeRef ((const UInt8 *)app_path, &app_fsref, NULL);
|
2010-10-01 05:49:03 +08:00
|
|
|
|
|
|
|
// If we found the app, then store away the name so we don't have to re-look it up.
|
|
|
|
if (error != noErr)
|
|
|
|
return LLDB_INVALID_PROCESS_ID;
|
|
|
|
|
|
|
|
app_params.application = &app_fsref;
|
|
|
|
|
|
|
|
ProcessSerialNumber psn;
|
|
|
|
|
|
|
|
error = ::LSOpenApplication (&app_params, &psn);
|
|
|
|
|
|
|
|
if (error != noErr)
|
|
|
|
return LLDB_INVALID_PROCESS_ID;
|
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
|
|
|
|
|
|
|
::pid_t pid = LLDB_INVALID_PROCESS_ID;
|
|
|
|
error = ::GetProcessPID(&psn, &pid);
|
|
|
|
return pid;
|
2011-11-04 11:34:56 +08:00
|
|
|
#endif
|
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-10-20 01:03:58 +08:00
|
|
|
|
|
|
|
|
2010-10-20 02:15:50 +08:00
|
|
|
static void *
|
|
|
|
AcceptPIDFromInferior (void *arg)
|
|
|
|
{
|
|
|
|
const char *connect_url = (const char *)arg;
|
2010-10-20 01:03:58 +08:00
|
|
|
ConnectionFileDescriptor file_conn;
|
2010-10-20 02:15:50 +08:00
|
|
|
Error error;
|
|
|
|
if (file_conn.Connect (connect_url, &error) == eConnectionStatusSuccess)
|
2010-10-20 01:03:58 +08:00
|
|
|
{
|
|
|
|
char pid_str[256];
|
2011-02-05 05:13:05 +08:00
|
|
|
::memset (pid_str, 0, sizeof(pid_str));
|
2010-10-20 01:03:58 +08:00
|
|
|
ConnectionStatus status;
|
2011-06-17 09:22:15 +08:00
|
|
|
const size_t pid_str_len = file_conn.Read (pid_str, sizeof(pid_str), NULL, status, NULL);
|
2010-10-20 01:03:58 +08:00
|
|
|
if (pid_str_len > 0)
|
|
|
|
{
|
2010-10-20 02:15:50 +08:00
|
|
|
int pid = atoi (pid_str);
|
|
|
|
return (void *)(intptr_t)pid;
|
2010-10-20 01:03:58 +08:00
|
|
|
}
|
|
|
|
}
|
2010-10-20 02:15:50 +08:00
|
|
|
return NULL;
|
2010-10-20 01:03:58 +08:00
|
|
|
}
|
|
|
|
|
2010-10-20 02:15:50 +08:00
|
|
|
static bool
|
|
|
|
WaitForProcessToSIGSTOP (const lldb::pid_t pid, const int timeout_in_seconds)
|
|
|
|
{
|
|
|
|
const int time_delta_usecs = 100000;
|
|
|
|
const int num_retries = timeout_in_seconds/time_delta_usecs;
|
|
|
|
for (int i=0; i<num_retries; i++)
|
|
|
|
{
|
|
|
|
struct proc_bsdinfo bsd_info;
|
|
|
|
int error = ::proc_pidinfo (pid, PROC_PIDTBSDINFO,
|
|
|
|
(uint64_t) 0,
|
|
|
|
&bsd_info,
|
|
|
|
PROC_PIDTBSDINFO_SIZE);
|
|
|
|
|
|
|
|
switch (error)
|
|
|
|
{
|
|
|
|
case EINVAL:
|
|
|
|
case ENOTSUP:
|
|
|
|
case ESRCH:
|
|
|
|
case EPERM:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
if (bsd_info.pbi_status == SSTOP)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
::usleep (time_delta_usecs);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-04 11:34:56 +08:00
|
|
|
#if !defined(__arm__)
|
2010-10-20 02:15:50 +08:00
|
|
|
|
|
|
|
static lldb::pid_t
|
|
|
|
LaunchInNewTerminalWithCommandFile
|
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
|
|
|
(
|
|
|
|
const char **argv,
|
|
|
|
const char **envp,
|
Added a new variant of SBTarget::Launch() that deprectates the old one that
takes separate file handles for stdin, stdout, and stder and also allows for
the working directory to be specified.
Added support to "process launch" to a new option: --working-dir=PATH. We
can now set the working directory. If this is not set, it defaults to that
of the process that has LLDB loaded. Added the working directory to the
host LaunchInNewTerminal function to allows the current working directory
to be set in processes that are spawned in their own terminal. Also hooked this
up to the lldb_private::Process and all mac plug-ins. The linux plug-in had its
API changed, but nothing is making use of it yet. Modfied "debugserver" and
"darwin-debug" to also handle the current working directory options and modified
the code in LLDB that spawns these tools to pass the info along.
Fixed ProcessGDBRemote to properly pass along all file handles for stdin, stdout
and stderr.
After clearing the default values for the stdin/out/err file handles for
process to be NULL, we had a crasher in UserSettingsController::UpdateStringVariable
which is now fixed. Also fixed the setting of boolean values to be able to
be set as "true", "yes", "on", "1" for true (case insensitive) and "false", "no",
"off", or "0" for false.
Fixed debugserver to properly handle files for STDIN, STDOUT and STDERR that are not
already opened. Previous to this fix debugserver would only correctly open and dupe
file handles for the slave side of a pseudo terminal. It now correctly handles
getting STDIN for the inferior from a file, and spitting STDOUT and STDERR out to
files. Also made sure the file handles were correctly opened with the NOCTTY flag
for terminals.
llvm-svn: 124060
2011-01-23 13:56:20 +08:00
|
|
|
const char *working_dir,
|
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
|
|
|
const ArchSpec *arch_spec,
|
|
|
|
bool stop_at_entry,
|
|
|
|
bool disable_aslr
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (!argv || !argv[0])
|
|
|
|
return LLDB_INVALID_PROCESS_ID;
|
|
|
|
|
|
|
|
OSStatus error = 0;
|
|
|
|
|
2010-10-21 04:54:39 +08:00
|
|
|
FileSpec program (argv[0], 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-10-19 11:25:40 +08:00
|
|
|
std::string unix_socket_name;
|
|
|
|
|
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
|
|
|
char temp_file_path[PATH_MAX];
|
|
|
|
const char *tmpdir = ::getenv ("TMPDIR");
|
|
|
|
if (tmpdir == NULL)
|
|
|
|
tmpdir = "/tmp/";
|
|
|
|
::snprintf (temp_file_path, sizeof(temp_file_path), "%s%s-XXXXXX", tmpdir, program.GetFilename().AsCString());
|
|
|
|
|
|
|
|
if (::mktemp (temp_file_path) == NULL)
|
|
|
|
return LLDB_INVALID_PROCESS_ID;
|
|
|
|
|
2010-10-19 11:25:40 +08:00
|
|
|
unix_socket_name.assign (temp_file_path);
|
|
|
|
|
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
|
|
|
::strncat (temp_file_path, ".command", sizeof (temp_file_path));
|
|
|
|
|
2011-02-09 09:08:52 +08:00
|
|
|
StreamFile command_file;
|
|
|
|
command_file.GetFile().Open (temp_file_path,
|
|
|
|
File::eOpenOptionWrite | File::eOpenOptionCanCreate,
|
|
|
|
File::ePermissionsDefault);
|
|
|
|
|
|
|
|
if (!command_file.GetFile().IsValid())
|
|
|
|
return LLDB_INVALID_PROCESS_ID;
|
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
|
|
|
|
|
|
|
FileSpec darwin_debug_file_spec;
|
|
|
|
if (!Host::GetLLDBPath (ePathTypeSupportExecutableDir, darwin_debug_file_spec))
|
|
|
|
return LLDB_INVALID_PROCESS_ID;
|
|
|
|
darwin_debug_file_spec.GetFilename().SetCString("darwin-debug");
|
|
|
|
|
|
|
|
if (!darwin_debug_file_spec.Exists())
|
|
|
|
return LLDB_INVALID_PROCESS_ID;
|
|
|
|
|
|
|
|
char launcher_path[PATH_MAX];
|
|
|
|
darwin_debug_file_spec.GetPath(launcher_path, sizeof(launcher_path));
|
|
|
|
command_file.Printf("\"%s\" ", launcher_path);
|
|
|
|
|
2010-10-19 11:25:40 +08:00
|
|
|
command_file.Printf("--unix-socket=%s ", unix_socket_name.c_str());
|
|
|
|
|
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
|
|
|
if (arch_spec && arch_spec->IsValid())
|
|
|
|
{
|
2011-02-23 08:35:02 +08:00
|
|
|
command_file.Printf("--arch=%s ", arch_spec->GetArchitectureName());
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if (disable_aslr)
|
|
|
|
{
|
|
|
|
command_file.PutCString("--disable-aslr ");
|
|
|
|
}
|
|
|
|
|
|
|
|
command_file.PutCString("-- ");
|
|
|
|
|
|
|
|
if (argv)
|
|
|
|
{
|
|
|
|
for (size_t i=0; argv[i] != NULL; ++i)
|
|
|
|
{
|
|
|
|
command_file.Printf("\"%s\" ", argv[i]);
|
|
|
|
}
|
|
|
|
}
|
2010-10-18 09:45:30 +08:00
|
|
|
command_file.PutCString("\necho Process exited with status $?\n");
|
2011-02-09 09:08:52 +08:00
|
|
|
command_file.GetFile().Close();
|
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
|
|
|
if (::chmod (temp_file_path, S_IRWXU | S_IRWXG) != 0)
|
|
|
|
return LLDB_INVALID_PROCESS_ID;
|
|
|
|
|
|
|
|
CFCMutableDictionary cf_env_dict;
|
|
|
|
|
|
|
|
const bool can_create = true;
|
|
|
|
if (envp)
|
|
|
|
{
|
|
|
|
for (size_t i=0; envp[i] != NULL; ++i)
|
|
|
|
{
|
|
|
|
const char *env_entry = envp[i];
|
|
|
|
const char *equal_pos = strchr(env_entry, '=');
|
|
|
|
if (equal_pos)
|
|
|
|
{
|
|
|
|
std::string env_key (env_entry, equal_pos);
|
|
|
|
std::string env_val (equal_pos + 1);
|
|
|
|
CFCString cf_env_key (env_key.c_str(), kCFStringEncodingUTF8);
|
|
|
|
CFCString cf_env_val (env_val.c_str(), kCFStringEncodingUTF8);
|
|
|
|
cf_env_dict.AddValue (cf_env_key.get(), cf_env_val.get(), can_create);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LSApplicationParameters app_params;
|
2011-02-05 05:13:05 +08:00
|
|
|
::memset (&app_params, 0, sizeof (app_params));
|
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
|
|
|
app_params.flags = kLSLaunchDontAddToRecents | kLSLaunchAsync;
|
|
|
|
app_params.argv = NULL;
|
|
|
|
app_params.environment = (CFDictionaryRef)cf_env_dict.get();
|
|
|
|
|
|
|
|
CFCReleaser<CFURLRef> command_file_url (::CFURLCreateFromFileSystemRepresentation (NULL,
|
|
|
|
(const UInt8 *)temp_file_path,
|
2010-10-19 11:25:40 +08:00
|
|
|
strlen(temp_file_path),
|
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
|
|
|
false));
|
|
|
|
|
|
|
|
CFCMutableArray urls;
|
|
|
|
|
|
|
|
// Terminal.app will open the ".command" file we have created
|
|
|
|
// and run our process inside it which will wait at the entry point
|
|
|
|
// for us to attach.
|
|
|
|
urls.AppendValue(command_file_url.get());
|
|
|
|
|
|
|
|
|
2010-10-19 11:25:40 +08:00
|
|
|
lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
|
2010-10-01 05:49:03 +08:00
|
|
|
|
2010-10-19 11:25:40 +08:00
|
|
|
Error lldb_error;
|
|
|
|
// Sleep and wait a bit for debugserver to start to listen...
|
|
|
|
char connect_url[128];
|
|
|
|
::snprintf (connect_url, sizeof(connect_url), "unix-accept://%s", unix_socket_name.c_str());
|
|
|
|
|
2010-10-20 02:15:50 +08:00
|
|
|
// Spawn a new thread to accept incoming connection on the connect_url
|
|
|
|
// so we can grab the pid from the inferior
|
|
|
|
lldb::thread_t accept_thread = Host::ThreadCreate (unix_socket_name.c_str(),
|
|
|
|
AcceptPIDFromInferior,
|
|
|
|
connect_url,
|
|
|
|
&lldb_error);
|
|
|
|
|
2010-10-19 11:25:40 +08:00
|
|
|
ProcessSerialNumber psn;
|
|
|
|
error = LSOpenURLsWithRole(urls.get(), kLSRolesShell, NULL, &app_params, &psn, 1);
|
|
|
|
if (error == noErr)
|
|
|
|
{
|
2010-10-20 02:15:50 +08:00
|
|
|
thread_result_t accept_thread_result = NULL;
|
|
|
|
if (Host::ThreadJoin (accept_thread, &accept_thread_result, &lldb_error))
|
2010-10-19 11:25:40 +08:00
|
|
|
{
|
2010-10-20 02:15:50 +08:00
|
|
|
if (accept_thread_result)
|
2010-10-19 11:25:40 +08:00
|
|
|
{
|
2010-10-20 02:15:50 +08:00
|
|
|
pid = (intptr_t)accept_thread_result;
|
|
|
|
|
|
|
|
// Wait for process to be stopped the the entry point by watching
|
|
|
|
// for the process status to be set to SSTOP which indicates it it
|
|
|
|
// SIGSTOP'ed at the entry point
|
|
|
|
WaitForProcessToSIGSTOP (pid, 5);
|
2010-10-19 11:25:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-20 02:15:50 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Host::ThreadCancel (accept_thread, &lldb_error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pid;
|
|
|
|
}
|
|
|
|
|
2010-10-20 07:16:00 +08:00
|
|
|
const char *applscript_in_new_tty =
|
|
|
|
"tell application \"Terminal\"\n"
|
|
|
|
" do script \"%s\"\n"
|
|
|
|
"end tell\n";
|
|
|
|
|
|
|
|
|
|
|
|
const char *applscript_in_existing_tty = "\
|
|
|
|
set the_shell_script to \"%s\"\n\
|
|
|
|
tell application \"Terminal\"\n\
|
|
|
|
repeat with the_window in (get windows)\n\
|
|
|
|
repeat with the_tab in tabs of the_window\n\
|
|
|
|
set the_tty to tty in the_tab\n\
|
|
|
|
if the_tty contains \"%s\" then\n\
|
|
|
|
if the_tab is not busy then\n\
|
|
|
|
set selected of the_tab to true\n\
|
|
|
|
set frontmost of the_window to true\n\
|
|
|
|
do script the_shell_script in the_tab\n\
|
|
|
|
return\n\
|
|
|
|
end if\n\
|
|
|
|
end if\n\
|
|
|
|
end repeat\n\
|
|
|
|
end repeat\n\
|
|
|
|
do script the_shell_script\n\
|
|
|
|
end tell\n";
|
2010-10-20 02:15:50 +08:00
|
|
|
|
2011-11-08 10:43:13 +08:00
|
|
|
|
|
|
|
static Error
|
|
|
|
LaunchInNewTerminalWithAppleScript (const char *exe_path, ProcessLaunchInfo &launch_info)
|
|
|
|
{
|
|
|
|
Error error;
|
2011-04-12 13:54:46 +08:00
|
|
|
char unix_socket_name[PATH_MAX] = "/tmp/XXXXXX";
|
|
|
|
if (::mktemp (unix_socket_name) == NULL)
|
|
|
|
{
|
|
|
|
error.SetErrorString ("failed to make temporary path for a unix socket");
|
|
|
|
return error;
|
|
|
|
}
|
2010-10-20 02:15:50 +08:00
|
|
|
|
|
|
|
StreamString command;
|
|
|
|
FileSpec darwin_debug_file_spec;
|
|
|
|
if (!Host::GetLLDBPath (ePathTypeSupportExecutableDir, darwin_debug_file_spec))
|
2011-04-12 13:54:46 +08:00
|
|
|
{
|
|
|
|
error.SetErrorString ("can't locate the 'darwin-debug' executable");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2010-10-20 02:15:50 +08:00
|
|
|
darwin_debug_file_spec.GetFilename().SetCString("darwin-debug");
|
|
|
|
|
|
|
|
if (!darwin_debug_file_spec.Exists())
|
2011-04-12 13:54:46 +08:00
|
|
|
{
|
|
|
|
error.SetErrorStringWithFormat ("the 'darwin-debug' executable doesn't exists at %s/%s",
|
|
|
|
darwin_debug_file_spec.GetDirectory().GetCString(),
|
|
|
|
darwin_debug_file_spec.GetFilename().GetCString());
|
|
|
|
return error;
|
|
|
|
}
|
2010-10-20 02:15:50 +08:00
|
|
|
|
|
|
|
char launcher_path[PATH_MAX];
|
|
|
|
darwin_debug_file_spec.GetPath(launcher_path, sizeof(launcher_path));
|
2010-10-20 07:16:00 +08:00
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
const ArchSpec &arch_spec = launch_info.GetArchitecture();
|
|
|
|
if (arch_spec.IsValid())
|
|
|
|
command.Printf("arch -arch %s ", arch_spec.GetArchitectureName());
|
2010-11-08 11:06:10 +08:00
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
command.Printf("'%s' --unix-socket=%s", launcher_path, unix_socket_name);
|
2010-10-20 02:15:50 +08:00
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
if (arch_spec.IsValid())
|
|
|
|
command.Printf(" --arch=%s", arch_spec.GetArchitectureName());
|
2010-10-20 02:15:50 +08:00
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
const char *working_dir = launch_info.GetWorkingDirectory();
|
Added a new variant of SBTarget::Launch() that deprectates the old one that
takes separate file handles for stdin, stdout, and stder and also allows for
the working directory to be specified.
Added support to "process launch" to a new option: --working-dir=PATH. We
can now set the working directory. If this is not set, it defaults to that
of the process that has LLDB loaded. Added the working directory to the
host LaunchInNewTerminal function to allows the current working directory
to be set in processes that are spawned in their own terminal. Also hooked this
up to the lldb_private::Process and all mac plug-ins. The linux plug-in had its
API changed, but nothing is making use of it yet. Modfied "debugserver" and
"darwin-debug" to also handle the current working directory options and modified
the code in LLDB that spawns these tools to pass the info along.
Fixed ProcessGDBRemote to properly pass along all file handles for stdin, stdout
and stderr.
After clearing the default values for the stdin/out/err file handles for
process to be NULL, we had a crasher in UserSettingsController::UpdateStringVariable
which is now fixed. Also fixed the setting of boolean values to be able to
be set as "true", "yes", "on", "1" for true (case insensitive) and "false", "no",
"off", or "0" for false.
Fixed debugserver to properly handle files for STDIN, STDOUT and STDERR that are not
already opened. Previous to this fix debugserver would only correctly open and dupe
file handles for the slave side of a pseudo terminal. It now correctly handles
getting STDIN for the inferior from a file, and spitting STDOUT and STDERR out to
files. Also made sure the file handles were correctly opened with the NOCTTY flag
for terminals.
llvm-svn: 124060
2011-01-23 13:56:20 +08:00
|
|
|
if (working_dir)
|
|
|
|
command.Printf(" --working-dir '%s'", working_dir);
|
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
if (launch_info.GetFlags().Test (eLaunchFlagDisableASLR))
|
2010-10-20 02:15:50 +08:00
|
|
|
command.PutCString(" --disable-aslr");
|
2011-11-08 10:43:13 +08:00
|
|
|
|
2011-11-15 11:53:30 +08:00
|
|
|
command.PutCString(" -- ");
|
|
|
|
|
|
|
|
const char **argv = launch_info.GetArguments().GetConstArgumentVector ();
|
|
|
|
if (argv)
|
2010-10-20 02:15:50 +08:00
|
|
|
{
|
2011-11-15 11:53:30 +08:00
|
|
|
for (size_t i=0; argv[i] != NULL; ++i)
|
2011-11-08 10:43:13 +08:00
|
|
|
{
|
2011-11-15 11:53:30 +08:00
|
|
|
if (i==0)
|
|
|
|
command.Printf(" '%s'", exe_path);
|
|
|
|
else
|
|
|
|
command.Printf(" '%s'", argv[i]);
|
2011-11-08 10:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-15 11:53:30 +08:00
|
|
|
command.Printf(" '%s'", exe_path);
|
2010-10-20 02:15:50 +08:00
|
|
|
}
|
2010-10-20 07:16:00 +08:00
|
|
|
command.PutCString (" ; echo Process exited with status $?");
|
|
|
|
|
|
|
|
StreamString applescript_source;
|
|
|
|
|
2010-11-08 11:06:10 +08:00
|
|
|
const char *tty_command = command.GetString().c_str();
|
2011-04-12 13:54:46 +08:00
|
|
|
// if (tty_name && tty_name[0])
|
|
|
|
// {
|
|
|
|
// applescript_source.Printf (applscript_in_existing_tty,
|
|
|
|
// tty_command,
|
|
|
|
// tty_name);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
2010-10-20 07:16:00 +08:00
|
|
|
applescript_source.Printf (applscript_in_new_tty,
|
2010-11-08 11:06:10 +08:00
|
|
|
tty_command);
|
2011-04-12 13:54:46 +08:00
|
|
|
// }
|
2010-10-20 07:16:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *script_source = applescript_source.GetString().c_str();
|
|
|
|
//puts (script_source);
|
2010-10-20 02:15:50 +08:00
|
|
|
NSAppleScript* applescript = [[NSAppleScript alloc] initWithSource:[NSString stringWithCString:script_source encoding:NSUTF8StringEncoding]];
|
|
|
|
|
|
|
|
lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
|
|
|
|
|
|
|
|
Error lldb_error;
|
|
|
|
// Sleep and wait a bit for debugserver to start to listen...
|
|
|
|
ConnectionFileDescriptor file_conn;
|
|
|
|
char connect_url[128];
|
2011-04-12 13:54:46 +08:00
|
|
|
::snprintf (connect_url, sizeof(connect_url), "unix-accept://%s", unix_socket_name);
|
2010-10-20 02:15:50 +08:00
|
|
|
|
|
|
|
// Spawn a new thread to accept incoming connection on the connect_url
|
2011-04-12 13:54:46 +08:00
|
|
|
// so we can grab the pid from the inferior. We have to do this because we
|
|
|
|
// are sending an AppleScript that will launch a process in Terminal.app,
|
|
|
|
// in a shell and the shell will fork/exec a couple of times before we get
|
|
|
|
// to the process that we wanted to launch. So when our process actually
|
|
|
|
// gets launched, we will handshake with it and get the process ID for it.
|
|
|
|
lldb::thread_t accept_thread = Host::ThreadCreate (unix_socket_name,
|
2010-10-20 02:15:50 +08:00
|
|
|
AcceptPIDFromInferior,
|
|
|
|
connect_url,
|
|
|
|
&lldb_error);
|
|
|
|
|
|
|
|
|
|
|
|
[applescript executeAndReturnError:nil];
|
|
|
|
|
|
|
|
thread_result_t accept_thread_result = NULL;
|
|
|
|
if (Host::ThreadJoin (accept_thread, &accept_thread_result, &lldb_error))
|
|
|
|
{
|
|
|
|
if (accept_thread_result)
|
|
|
|
{
|
|
|
|
pid = (intptr_t)accept_thread_result;
|
|
|
|
|
|
|
|
// Wait for process to be stopped the the entry point by watching
|
|
|
|
// for the process status to be set to SSTOP which indicates it it
|
|
|
|
// SIGSTOP'ed at the entry point
|
|
|
|
WaitForProcessToSIGSTOP (pid, 5);
|
|
|
|
}
|
|
|
|
}
|
2011-04-12 13:54:46 +08:00
|
|
|
::unlink (unix_socket_name);
|
2010-10-20 02:15:50 +08:00
|
|
|
[applescript release];
|
2011-04-12 13:54:46 +08:00
|
|
|
if (pid != LLDB_INVALID_PROCESS_ID)
|
|
|
|
launch_info.SetProcessID (pid);
|
|
|
|
return error;
|
2010-10-01 05:49:03 +08:00
|
|
|
}
|
2010-10-20 02:15:50 +08:00
|
|
|
|
2011-11-04 11:34:56 +08:00
|
|
|
#endif // #if !defined(__arm__)
|
|
|
|
|
2010-10-20 02:15:50 +08:00
|
|
|
|
2010-11-10 12:57:04 +08:00
|
|
|
// On MacOSX CrashReporter will display a string for each shared library if
|
|
|
|
// the shared library has an exported symbol named "__crashreporter_info__".
|
|
|
|
|
|
|
|
static Mutex&
|
|
|
|
GetCrashReporterMutex ()
|
|
|
|
{
|
|
|
|
static Mutex g_mutex;
|
|
|
|
return g_mutex;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
const char *__crashreporter_info__ = NULL;
|
2011-05-20 12:04:17 +08:00
|
|
|
}
|
2010-11-10 12:57:04 +08:00
|
|
|
|
|
|
|
asm(".desc ___crashreporter_info__, 0x10");
|
|
|
|
|
|
|
|
void
|
|
|
|
Host::SetCrashDescriptionWithFormat (const char *format, ...)
|
|
|
|
{
|
|
|
|
static StreamString g_crash_description;
|
|
|
|
Mutex::Locker locker (GetCrashReporterMutex ());
|
|
|
|
|
|
|
|
if (format)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start (args, format);
|
2010-11-11 03:43:40 +08:00
|
|
|
g_crash_description.GetString().clear();
|
2010-11-10 12:57:04 +08:00
|
|
|
g_crash_description.PrintfVarArg(format, args);
|
|
|
|
va_end (args);
|
|
|
|
__crashreporter_info__ = g_crash_description.GetData();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__crashreporter_info__ = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Host::SetCrashDescription (const char *cstr)
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (GetCrashReporterMutex ());
|
2011-11-11 02:31:53 +08:00
|
|
|
static std::string g_crash_description;
|
|
|
|
if (cstr)
|
|
|
|
{
|
|
|
|
g_crash_description.assign (cstr);
|
|
|
|
__crashreporter_info__ = g_crash_description.c_str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__crashreporter_info__ = NULL;
|
|
|
|
}
|
2010-11-10 12:57:04 +08:00
|
|
|
}
|
2010-10-01 05:49:03 +08:00
|
|
|
|
2010-08-31 03:44:40 +08:00
|
|
|
bool
|
2010-10-01 05:49:03 +08:00
|
|
|
Host::OpenFileInExternalEditor (const FileSpec &file_spec, uint32_t line_no)
|
2010-08-31 03:44:40 +08:00
|
|
|
{
|
2011-11-04 11:34:56 +08:00
|
|
|
#if defined(__arm__)
|
|
|
|
return false;
|
|
|
|
#else
|
2010-08-31 03:44:40 +08:00
|
|
|
// We attach this to an 'odoc' event to specify a particular selection
|
|
|
|
typedef struct {
|
2010-08-31 06:00:34 +08:00
|
|
|
int16_t reserved0; // must be zero
|
|
|
|
int16_t fLineNumber;
|
|
|
|
int32_t fSelStart;
|
|
|
|
int32_t fSelEnd;
|
|
|
|
uint32_t reserved1; // must be zero
|
|
|
|
uint32_t reserved2; // must be zero
|
2010-08-31 03:44:40 +08:00
|
|
|
} BabelAESelInfo;
|
|
|
|
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_HOST));
|
2010-08-31 03:44:40 +08:00
|
|
|
char file_path[PATH_MAX];
|
|
|
|
file_spec.GetPath(file_path, PATH_MAX);
|
|
|
|
CFCString file_cfstr (file_path, kCFStringEncodingUTF8);
|
2010-08-31 06:00:34 +08:00
|
|
|
CFCReleaser<CFURLRef> file_URL (::CFURLCreateWithFileSystemPath (NULL,
|
|
|
|
file_cfstr.get(),
|
|
|
|
kCFURLPOSIXPathStyle,
|
|
|
|
false));
|
2010-09-01 02:05:13 +08:00
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Printf("Sending source file: \"%s\" and line: %d to external editor.\n", file_path, line_no);
|
2010-08-31 06:00:34 +08:00
|
|
|
|
2011-12-15 11:14:23 +08:00
|
|
|
long error;
|
2010-08-31 06:00:34 +08:00
|
|
|
BabelAESelInfo file_and_line_info =
|
|
|
|
{
|
2012-02-22 02:37:14 +08:00
|
|
|
0, // reserved0
|
|
|
|
(int16_t)(line_no - 1), // fLineNumber (zero based line number)
|
|
|
|
1, // fSelStart
|
|
|
|
1024, // fSelEnd
|
|
|
|
0, // reserved1
|
|
|
|
0 // reserved2
|
2010-08-31 06:00:34 +08:00
|
|
|
};
|
2010-08-31 03:44:40 +08:00
|
|
|
|
|
|
|
AEKeyDesc file_and_line_desc;
|
|
|
|
|
2010-08-31 06:00:34 +08:00
|
|
|
error = ::AECreateDesc (typeUTF8Text,
|
|
|
|
&file_and_line_info,
|
|
|
|
sizeof (file_and_line_info),
|
|
|
|
&(file_and_line_desc.descContent));
|
2010-08-31 03:44:40 +08:00
|
|
|
|
|
|
|
if (error != noErr)
|
|
|
|
{
|
2010-09-01 02:05:13 +08:00
|
|
|
if (log)
|
2011-12-15 11:14:23 +08:00
|
|
|
log->Printf("Error creating AEDesc: %ld.\n", error);
|
2010-08-31 03:44:40 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
file_and_line_desc.descKey = keyAEPosition;
|
|
|
|
|
2010-09-01 02:56:24 +08:00
|
|
|
static std::string g_app_name;
|
2010-09-01 02:35:14 +08:00
|
|
|
static FSRef g_app_fsref;
|
|
|
|
|
2010-08-31 03:44:40 +08:00
|
|
|
LSApplicationParameters app_params;
|
2011-02-05 05:13:05 +08:00
|
|
|
::memset (&app_params, 0, sizeof (app_params));
|
2010-08-31 06:00:34 +08:00
|
|
|
app_params.flags = kLSLaunchDefaults |
|
|
|
|
kLSLaunchDontAddToRecents |
|
|
|
|
kLSLaunchDontSwitch;
|
2010-09-01 02:35:14 +08:00
|
|
|
|
2010-08-31 07:48:25 +08:00
|
|
|
char *external_editor = ::getenv ("LLDB_EXTERNAL_EDITOR");
|
|
|
|
|
2010-09-01 02:35:14 +08:00
|
|
|
if (external_editor)
|
2010-08-31 07:48:25 +08:00
|
|
|
{
|
2010-09-01 02:05:13 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("Looking for external editor \"%s\".\n", external_editor);
|
|
|
|
|
2010-09-01 02:56:24 +08:00
|
|
|
if (g_app_name.empty() || strcmp (g_app_name.c_str(), external_editor) != 0)
|
2010-08-31 07:48:25 +08:00
|
|
|
{
|
|
|
|
CFCString editor_name (external_editor, kCFStringEncodingUTF8);
|
2010-09-01 02:35:14 +08:00
|
|
|
error = ::LSFindApplicationForInfo (kLSUnknownCreator,
|
|
|
|
NULL,
|
|
|
|
editor_name.get(),
|
|
|
|
&g_app_fsref,
|
|
|
|
NULL);
|
2010-08-31 07:48:25 +08:00
|
|
|
|
|
|
|
// If we found the app, then store away the name so we don't have to re-look it up.
|
2010-09-01 02:35:14 +08:00
|
|
|
if (error != noErr)
|
2010-09-01 02:05:13 +08:00
|
|
|
{
|
|
|
|
if (log)
|
2011-12-15 11:14:23 +08:00
|
|
|
log->Printf("Could not find External Editor application, error: %ld.\n", error);
|
2010-08-31 07:48:25 +08:00
|
|
|
return false;
|
2010-09-01 02:05:13 +08:00
|
|
|
}
|
2010-08-31 07:48:25 +08:00
|
|
|
|
|
|
|
}
|
2010-09-01 02:35:14 +08:00
|
|
|
app_params.application = &g_app_fsref;
|
2010-08-31 07:48:25 +08:00
|
|
|
}
|
|
|
|
|
2010-08-31 03:44:40 +08:00
|
|
|
ProcessSerialNumber psn;
|
|
|
|
CFCReleaser<CFArrayRef> file_array(CFArrayCreate (NULL, (const void **) file_URL.ptr_address(false), 1, NULL));
|
2010-08-31 06:00:34 +08:00
|
|
|
error = ::LSOpenURLsWithRole (file_array.get(),
|
2010-08-31 07:48:25 +08:00
|
|
|
kLSRolesAll,
|
2010-08-31 06:00:34 +08:00
|
|
|
&file_and_line_desc,
|
|
|
|
&app_params,
|
|
|
|
&psn,
|
|
|
|
1);
|
|
|
|
|
2010-08-31 03:44:40 +08:00
|
|
|
AEDisposeDesc (&(file_and_line_desc.descContent));
|
|
|
|
|
|
|
|
if (error != noErr)
|
|
|
|
{
|
2010-09-01 02:05:13 +08:00
|
|
|
if (log)
|
2011-12-15 11:14:23 +08:00
|
|
|
log->Printf("LSOpenURLsWithRole failed, error: %ld.\n", error);
|
2010-09-01 02:05:13 +08:00
|
|
|
|
2010-08-31 03:44:40 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessInfoRec which_process;
|
2011-02-05 05:13:05 +08:00
|
|
|
::memset(&which_process, 0, sizeof(which_process));
|
2010-08-31 03:44:40 +08:00
|
|
|
unsigned char ap_name[PATH_MAX];
|
|
|
|
which_process.processName = ap_name;
|
2010-08-31 06:00:34 +08:00
|
|
|
error = ::GetProcessInformation (&psn, &which_process);
|
2010-08-31 03:44:40 +08:00
|
|
|
|
2010-09-01 02:05:13 +08:00
|
|
|
bool using_xcode;
|
|
|
|
if (error != noErr)
|
|
|
|
{
|
|
|
|
if (log)
|
2011-12-15 11:14:23 +08:00
|
|
|
log->Printf("GetProcessInformation failed, error: %ld.\n", error);
|
2010-09-01 02:05:13 +08:00
|
|
|
using_xcode = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
using_xcode = strncmp((char *) ap_name+1, "Xcode", (int) ap_name[0]) == 0;
|
2010-08-31 03:44:40 +08:00
|
|
|
|
|
|
|
// Xcode doesn't obey the line number in the Open Apple Event. So I have to send
|
|
|
|
// it an AppleScript to focus on the right line.
|
|
|
|
|
|
|
|
if (using_xcode)
|
|
|
|
{
|
|
|
|
static ComponentInstance osa_component = NULL;
|
|
|
|
static const char *as_template = "tell application \"Xcode\"\n"
|
|
|
|
"set doc to the first document whose path is \"%s\"\n"
|
|
|
|
"set the selection to paragraph %d of doc\n"
|
|
|
|
"--- set the selected paragraph range to {%d, %d} of doc\n"
|
|
|
|
"end tell\n";
|
|
|
|
const int chars_for_int = 32;
|
|
|
|
static int as_template_len = strlen (as_template);
|
|
|
|
|
|
|
|
|
|
|
|
char *as_str;
|
|
|
|
AEDesc as_desc;
|
|
|
|
|
|
|
|
if (osa_component == NULL)
|
|
|
|
{
|
2010-08-31 06:00:34 +08:00
|
|
|
osa_component = ::OpenDefaultComponent (kOSAComponentType,
|
|
|
|
kAppleScriptSubtype);
|
2010-08-31 03:44:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (osa_component == NULL)
|
|
|
|
{
|
2010-09-01 02:05:13 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("Could not get default AppleScript component.\n");
|
2010-08-31 03:44:40 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t as_str_size = as_template_len + strlen (file_path) + 3 * chars_for_int + 1;
|
|
|
|
as_str = (char *) malloc (as_str_size);
|
2010-08-31 06:00:34 +08:00
|
|
|
::snprintf (as_str,
|
|
|
|
as_str_size - 1,
|
|
|
|
as_template,
|
|
|
|
file_path,
|
|
|
|
line_no,
|
|
|
|
line_no,
|
|
|
|
line_no);
|
|
|
|
|
|
|
|
error = ::AECreateDesc (typeChar,
|
|
|
|
as_str,
|
|
|
|
strlen (as_str),
|
|
|
|
&as_desc);
|
|
|
|
|
|
|
|
::free (as_str);
|
2010-08-31 03:44:40 +08:00
|
|
|
|
|
|
|
if (error != noErr)
|
2010-09-01 02:05:13 +08:00
|
|
|
{
|
|
|
|
if (log)
|
2011-12-15 11:14:23 +08:00
|
|
|
log->Printf("Failed to create AEDesc for Xcode AppleEvent: %ld.\n", error);
|
2010-08-31 03:44:40 +08:00
|
|
|
return false;
|
2010-09-01 02:05:13 +08:00
|
|
|
}
|
2010-08-31 03:44:40 +08:00
|
|
|
|
|
|
|
OSAID ret_OSAID;
|
2010-08-31 06:00:34 +08:00
|
|
|
error = ::OSACompileExecute (osa_component,
|
|
|
|
&as_desc,
|
|
|
|
kOSANullScript,
|
|
|
|
kOSAModeNeverInteract,
|
|
|
|
&ret_OSAID);
|
|
|
|
|
|
|
|
::OSADispose (osa_component, ret_OSAID);
|
2010-08-31 03:44:40 +08:00
|
|
|
|
2010-08-31 06:00:34 +08:00
|
|
|
::AEDisposeDesc (&as_desc);
|
2010-08-31 03:44:40 +08:00
|
|
|
|
|
|
|
if (error != noErr)
|
2010-09-01 02:05:13 +08:00
|
|
|
{
|
|
|
|
if (log)
|
2011-12-15 11:14:23 +08:00
|
|
|
log->Printf("Sending AppleEvent to Xcode failed, error: %ld.\n", error);
|
2010-08-31 03:44:40 +08:00
|
|
|
return false;
|
2010-09-01 02:05:13 +08:00
|
|
|
}
|
2010-08-31 03:44:40 +08:00
|
|
|
}
|
|
|
|
return true;
|
2011-11-04 11:34:56 +08:00
|
|
|
#endif // #if !defined(__arm__)
|
2010-08-31 03:44:40 +08:00
|
|
|
}
|
2010-12-03 14:02:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Host::Backtrace (Stream &strm, uint32_t max_frames)
|
|
|
|
{
|
|
|
|
char backtrace_path[] = "/tmp/lldb-backtrace-tmp-XXXXXX";
|
|
|
|
int backtrace_fd = ::mkstemp (backtrace_path);
|
|
|
|
if (backtrace_fd != -1)
|
|
|
|
{
|
|
|
|
std::vector<void *> frame_buffer (max_frames, NULL);
|
|
|
|
int count = ::backtrace (&frame_buffer[0], frame_buffer.size());
|
|
|
|
::backtrace_symbols_fd (&frame_buffer[0], count, backtrace_fd);
|
|
|
|
|
|
|
|
const off_t buffer_size = ::lseek(backtrace_fd, 0, SEEK_CUR);
|
|
|
|
|
|
|
|
if (::lseek(backtrace_fd, 0, SEEK_SET) == 0)
|
|
|
|
{
|
|
|
|
char *buffer = (char *)::malloc (buffer_size);
|
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
ssize_t bytes_read = ::read (backtrace_fd, buffer, buffer_size);
|
|
|
|
if (bytes_read > 0)
|
|
|
|
strm.Write(buffer, bytes_read);
|
|
|
|
::free (buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
::close (backtrace_fd);
|
|
|
|
::unlink (backtrace_path);
|
|
|
|
}
|
|
|
|
}
|
2010-12-04 08:10:17 +08:00
|
|
|
|
|
|
|
size_t
|
|
|
|
Host::GetEnvironment (StringList &env)
|
|
|
|
{
|
|
|
|
char **host_env = *_NSGetEnviron();
|
|
|
|
char *env_entry;
|
|
|
|
size_t i;
|
|
|
|
for (i=0; (env_entry = host_env[i]) != NULL; ++i)
|
|
|
|
env.AppendString(env_entry);
|
|
|
|
return i;
|
|
|
|
|
|
|
|
}
|
2011-03-19 09:12:21 +08:00
|
|
|
|
|
|
|
|
2011-03-24 12:28:38 +08:00
|
|
|
bool
|
|
|
|
Host::GetOSBuildString (std::string &s)
|
|
|
|
{
|
|
|
|
int mib[2] = { CTL_KERN, KERN_OSVERSION };
|
|
|
|
char cstr[PATH_MAX];
|
|
|
|
size_t cstr_len = sizeof(cstr);
|
|
|
|
if (::sysctl (mib, 2, cstr, &cstr_len, NULL, 0) == 0)
|
|
|
|
{
|
|
|
|
s.assign (cstr, cstr_len);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
s.clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Host::GetOSKernelDescription (std::string &s)
|
|
|
|
{
|
|
|
|
int mib[2] = { CTL_KERN, KERN_VERSION };
|
|
|
|
char cstr[PATH_MAX];
|
|
|
|
size_t cstr_len = sizeof(cstr);
|
|
|
|
if (::sysctl (mib, 2, cstr, &cstr_len, NULL, 0) == 0)
|
|
|
|
{
|
|
|
|
s.assign (cstr, cstr_len);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
s.clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-19 09:12:21 +08:00
|
|
|
bool
|
|
|
|
Host::GetOSVersion
|
|
|
|
(
|
|
|
|
uint32_t &major,
|
|
|
|
uint32_t &minor,
|
|
|
|
uint32_t &update
|
|
|
|
)
|
|
|
|
{
|
|
|
|
|
2011-11-04 11:34:56 +08:00
|
|
|
#if defined (__arm__)
|
|
|
|
major = UINT32_MAX;
|
|
|
|
minor = UINT32_MAX;
|
|
|
|
update = UINT32_MAX;
|
|
|
|
|
|
|
|
NSString *system_version_nstr = [[UIDevice currentDevice] systemVersion];
|
|
|
|
if (system_version_nstr)
|
|
|
|
{
|
|
|
|
const char *system_version_cstr = system_version_nstr.UTF8String;
|
|
|
|
Args::StringToVersion(system_version_cstr, major, minor, update);
|
|
|
|
}
|
|
|
|
return major != UINT32_MAX;
|
|
|
|
#else
|
2011-03-19 09:12:21 +08:00
|
|
|
SInt32 version;
|
|
|
|
|
|
|
|
OSErr err = ::Gestalt (gestaltSystemVersion, &version);
|
|
|
|
if (err != noErr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (version < 0x1040)
|
|
|
|
{
|
|
|
|
major = ((version & 0xF000) >> 12) * 10 + ((version & 0x0F00) >> 8);
|
|
|
|
minor = (version & 0x00F0) >> 4;
|
|
|
|
update = (version & 0x000F);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (::Gestalt (gestaltSystemVersionMajor, &version) != noErr)
|
|
|
|
return false;
|
|
|
|
major = version;
|
|
|
|
|
|
|
|
if (::Gestalt (gestaltSystemVersionMinor, &version) == noErr)
|
|
|
|
minor = version;
|
|
|
|
else
|
|
|
|
minor = 0;
|
|
|
|
|
|
|
|
if (::Gestalt (gestaltSystemVersionBugFix, &version) == noErr)
|
|
|
|
update = version;
|
|
|
|
else
|
|
|
|
update = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2011-11-04 11:34:56 +08:00
|
|
|
#endif
|
2011-03-19 09:12:21 +08:00
|
|
|
}
|
|
|
|
|
2011-03-22 05:25:07 +08:00
|
|
|
static bool
|
2011-04-12 13:54:46 +08:00
|
|
|
GetMacOSXProcessName (const ProcessInstanceInfoMatch *match_info_ptr,
|
|
|
|
ProcessInstanceInfo &process_info)
|
2011-03-22 05:25:07 +08:00
|
|
|
{
|
|
|
|
if (process_info.ProcessIDIsValid())
|
|
|
|
{
|
|
|
|
char process_name[MAXCOMLEN * 2 + 1];
|
|
|
|
int name_len = ::proc_name(process_info.GetProcessID(), process_name, MAXCOMLEN * 2);
|
|
|
|
if (name_len == 0)
|
|
|
|
return false;
|
|
|
|
|
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
|
|
|
if (match_info_ptr == NULL || NameMatches(process_name,
|
|
|
|
match_info_ptr->GetNameMatchType(),
|
|
|
|
match_info_ptr->GetProcessInfo().GetName()))
|
2011-03-22 05:25:07 +08:00
|
|
|
{
|
2011-11-15 11:53:30 +08:00
|
|
|
process_info.GetExecutableFile().SetFile (process_name, false);
|
2011-03-22 05:25:07 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2011-11-15 11:53:30 +08:00
|
|
|
process_info.GetExecutableFile().Clear();
|
2011-03-22 05:25:07 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
2011-04-12 13:54:46 +08:00
|
|
|
GetMacOSXProcessCPUType (ProcessInstanceInfo &process_info)
|
2011-03-22 05:25:07 +08:00
|
|
|
{
|
|
|
|
if (process_info.ProcessIDIsValid())
|
|
|
|
{
|
|
|
|
// Make a new mib to stay thread safe
|
|
|
|
int mib[CTL_MAXNAME]={0,};
|
|
|
|
size_t mib_len = CTL_MAXNAME;
|
|
|
|
if (::sysctlnametomib("sysctl.proc_cputype", mib, &mib_len))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
mib[mib_len] = process_info.GetProcessID();
|
|
|
|
mib_len++;
|
|
|
|
|
2011-08-12 08:21:20 +08:00
|
|
|
cpu_type_t cpu, sub = 0;
|
2011-03-22 05:25:07 +08:00
|
|
|
size_t cpu_len = sizeof(cpu);
|
|
|
|
if (::sysctl (mib, mib_len, &cpu, &cpu_len, 0, 0) == 0)
|
|
|
|
{
|
|
|
|
switch (cpu)
|
|
|
|
{
|
|
|
|
case llvm::MachO::CPUTypeI386: sub = llvm::MachO::CPUSubType_I386_ALL; break;
|
|
|
|
case llvm::MachO::CPUTypeX86_64: sub = llvm::MachO::CPUSubType_X86_64_ALL; break;
|
|
|
|
default: break;
|
|
|
|
}
|
2011-03-25 05:19:54 +08:00
|
|
|
process_info.GetArchitecture ().SetArchitecture (eArchTypeMachO, cpu, sub);
|
2011-03-22 05:25:07 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
process_info.GetArchitecture().Clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-01 08:29:43 +08:00
|
|
|
static bool
|
2011-04-12 13:54:46 +08:00
|
|
|
GetMacOSXProcessArgs (const ProcessInstanceInfoMatch *match_info_ptr,
|
|
|
|
ProcessInstanceInfo &process_info)
|
2011-04-01 08:29:43 +08:00
|
|
|
{
|
|
|
|
if (process_info.ProcessIDIsValid())
|
|
|
|
{
|
2012-02-22 02:37:14 +08:00
|
|
|
int proc_args_mib[3] = { CTL_KERN, KERN_PROCARGS2, (int)process_info.GetProcessID() };
|
2011-04-01 08:29:43 +08:00
|
|
|
|
|
|
|
char arg_data[8192];
|
|
|
|
size_t arg_data_size = sizeof(arg_data);
|
|
|
|
if (::sysctl (proc_args_mib, 3, arg_data, &arg_data_size , NULL, 0) == 0)
|
|
|
|
{
|
|
|
|
DataExtractor data (arg_data, arg_data_size, lldb::endian::InlHostByteOrder(), sizeof(void *));
|
|
|
|
uint32_t offset = 0;
|
|
|
|
uint32_t start_offset;
|
|
|
|
uint32_t argc = data.GetU32 (&offset);
|
|
|
|
const char *cstr;
|
|
|
|
|
|
|
|
cstr = data.GetCStr (&offset);
|
|
|
|
if (cstr)
|
|
|
|
{
|
|
|
|
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()))
|
|
|
|
{
|
|
|
|
// Skip NULLs
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
const uint8_t *p = data.PeekData(offset, 1);
|
|
|
|
if ((p == NULL) || (*p != '\0'))
|
|
|
|
break;
|
|
|
|
++offset;
|
|
|
|
}
|
|
|
|
// Now extract all arguments
|
2011-04-12 13:54:46 +08:00
|
|
|
Args &proc_args = process_info.GetArguments();
|
2011-04-01 08:29:43 +08:00
|
|
|
for (int i=0; i<argc; ++i)
|
|
|
|
{
|
|
|
|
start_offset = offset;
|
|
|
|
cstr = data.GetCStr(&offset);
|
|
|
|
if (cstr)
|
2011-04-12 13:54:46 +08:00
|
|
|
proc_args.AppendArgument(cstr);
|
2011-04-01 08:29:43 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-22 05:25:07 +08:00
|
|
|
static bool
|
2011-04-12 13:54:46 +08:00
|
|
|
GetMacOSXProcessUserAndGroup (ProcessInstanceInfo &process_info)
|
2011-03-22 05:25:07 +08:00
|
|
|
{
|
|
|
|
if (process_info.ProcessIDIsValid())
|
|
|
|
{
|
|
|
|
int mib[4];
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_PROC;
|
|
|
|
mib[2] = KERN_PROC_PID;
|
|
|
|
mib[3] = process_info.GetProcessID();
|
|
|
|
struct kinfo_proc proc_kinfo;
|
|
|
|
size_t proc_kinfo_size = sizeof(struct kinfo_proc);
|
|
|
|
|
|
|
|
if (::sysctl (mib, 4, &proc_kinfo, &proc_kinfo_size, NULL, 0) == 0)
|
|
|
|
{
|
|
|
|
if (proc_kinfo_size > 0)
|
|
|
|
{
|
|
|
|
process_info.SetParentProcessID (proc_kinfo.kp_eproc.e_ppid);
|
2011-04-12 13:54:46 +08:00
|
|
|
process_info.SetUserID (proc_kinfo.kp_eproc.e_pcred.p_ruid);
|
|
|
|
process_info.SetGroupID (proc_kinfo.kp_eproc.e_pcred.p_rgid);
|
2011-03-22 05:25:07 +08:00
|
|
|
process_info.SetEffectiveUserID (proc_kinfo.kp_eproc.e_ucred.cr_uid);
|
|
|
|
if (proc_kinfo.kp_eproc.e_ucred.cr_ngroups > 0)
|
|
|
|
process_info.SetEffectiveGroupID (proc_kinfo.kp_eproc.e_ucred.cr_groups[0]);
|
|
|
|
else
|
|
|
|
process_info.SetEffectiveGroupID (UINT32_MAX);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
process_info.SetParentProcessID (LLDB_INVALID_PROCESS_ID);
|
2011-04-12 13:54:46 +08:00
|
|
|
process_info.SetUserID (UINT32_MAX);
|
|
|
|
process_info.SetGroupID (UINT32_MAX);
|
2011-03-22 05:25:07 +08:00
|
|
|
process_info.SetEffectiveUserID (UINT32_MAX);
|
|
|
|
process_info.SetEffectiveGroupID (UINT32_MAX);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t
|
2011-04-12 13:54:46 +08:00
|
|
|
Host::FindProcesses (const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos)
|
2011-03-22 05:25:07 +08:00
|
|
|
{
|
2011-04-01 08:29:43 +08:00
|
|
|
std::vector<struct kinfo_proc> kinfos;
|
2011-03-22 05:25:07 +08:00
|
|
|
|
2011-04-01 08:29:43 +08:00
|
|
|
int mib[3] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL };
|
2011-03-22 05:25:07 +08:00
|
|
|
|
2011-04-01 08:29:43 +08:00
|
|
|
size_t pid_data_size = 0;
|
|
|
|
if (::sysctl (mib, 4, NULL, &pid_data_size, NULL, 0) != 0)
|
2011-03-22 05:25:07 +08:00
|
|
|
return 0;
|
|
|
|
|
2011-04-01 08:29:43 +08:00
|
|
|
// Add a few extra in case a few more show up
|
|
|
|
const size_t estimated_pid_count = (pid_data_size / sizeof(struct kinfo_proc)) + 10;
|
|
|
|
|
|
|
|
kinfos.resize (estimated_pid_count);
|
|
|
|
pid_data_size = kinfos.size() * sizeof(struct kinfo_proc);
|
|
|
|
|
|
|
|
if (::sysctl (mib, 4, &kinfos[0], &pid_data_size, NULL, 0) != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const size_t actual_pid_count = (pid_data_size / sizeof(struct kinfo_proc));
|
|
|
|
|
|
|
|
bool all_users = match_info.GetMatchAllUsers();
|
|
|
|
const lldb::pid_t our_pid = getpid();
|
|
|
|
const uid_t our_uid = getuid();
|
|
|
|
for (int i = 0; i < actual_pid_count; i++)
|
2011-03-22 05:25:07 +08:00
|
|
|
{
|
2011-04-01 08:29:43 +08:00
|
|
|
const struct kinfo_proc &kinfo = kinfos[i];
|
2011-03-22 05:25:07 +08:00
|
|
|
|
2011-04-01 08:29:43 +08:00
|
|
|
bool kinfo_user_matches = false;
|
|
|
|
if (all_users)
|
|
|
|
kinfo_user_matches = true;
|
|
|
|
else
|
|
|
|
kinfo_user_matches = kinfo.kp_eproc.e_pcred.p_ruid == our_uid;
|
|
|
|
|
2011-09-13 08:52:59 +08:00
|
|
|
// Special case, if lldb is being run as root we can attach to anything.
|
|
|
|
if (our_uid == 0)
|
|
|
|
kinfo_user_matches = true;
|
|
|
|
|
2011-04-01 08:29:43 +08:00
|
|
|
if (kinfo_user_matches == false || // Make sure the user is acceptable
|
|
|
|
kinfo.kp_proc.p_pid == our_pid || // Skip this process
|
|
|
|
kinfo.kp_proc.p_pid == 0 || // Skip kernel (kernel pid is zero)
|
|
|
|
kinfo.kp_proc.p_stat == SZOMB || // Zombies are bad, they like brains...
|
|
|
|
kinfo.kp_proc.p_flag & P_TRACED || // Being debugged?
|
|
|
|
kinfo.kp_proc.p_flag & P_WEXIT || // Working on exiting?
|
|
|
|
kinfo.kp_proc.p_flag & P_TRANSLATED) // Skip translated ppc (Rosetta)
|
|
|
|
continue;
|
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
ProcessInstanceInfo process_info;
|
2011-04-01 08:29:43 +08:00
|
|
|
process_info.SetProcessID (kinfo.kp_proc.p_pid);
|
|
|
|
process_info.SetParentProcessID (kinfo.kp_eproc.e_ppid);
|
2011-04-12 13:54:46 +08:00
|
|
|
process_info.SetUserID (kinfo.kp_eproc.e_pcred.p_ruid);
|
|
|
|
process_info.SetGroupID (kinfo.kp_eproc.e_pcred.p_rgid);
|
2011-04-01 08:29:43 +08:00
|
|
|
process_info.SetEffectiveUserID (kinfo.kp_eproc.e_ucred.cr_uid);
|
|
|
|
if (kinfo.kp_eproc.e_ucred.cr_ngroups > 0)
|
|
|
|
process_info.SetEffectiveGroupID (kinfo.kp_eproc.e_ucred.cr_groups[0]);
|
|
|
|
else
|
|
|
|
process_info.SetEffectiveGroupID (UINT32_MAX);
|
|
|
|
|
|
|
|
// Make sure our info matches before we go fetch the name and cpu type
|
|
|
|
if (match_info.Matches (process_info))
|
2011-03-22 05:25:07 +08:00
|
|
|
{
|
2011-04-01 08:29:43 +08:00
|
|
|
if (GetMacOSXProcessArgs (&match_info, process_info))
|
|
|
|
{
|
|
|
|
GetMacOSXProcessCPUType (process_info);
|
|
|
|
if (match_info.Matches (process_info))
|
|
|
|
process_infos.Append (process_info);
|
|
|
|
}
|
2011-03-22 05:25:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return process_infos.GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-04-12 13:54:46 +08:00
|
|
|
Host::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
|
2011-03-22 05:25:07 +08:00
|
|
|
{
|
|
|
|
process_info.SetProcessID(pid);
|
2011-04-01 08:29:43 +08:00
|
|
|
if (GetMacOSXProcessArgs (NULL, process_info))
|
2011-03-22 05:25:07 +08:00
|
|
|
{
|
|
|
|
GetMacOSXProcessCPUType (process_info);
|
|
|
|
GetMacOSXProcessUserAndGroup (process_info);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
process_info.Clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
Error
|
|
|
|
Host::LaunchProcess (ProcessLaunchInfo &launch_info)
|
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_HOST | LIBLLDB_LOG_PROCESS));
|
|
|
|
char exe_path[PATH_MAX];
|
|
|
|
PlatformSP host_platform_sp (Platform::GetDefaultPlatform ());
|
|
|
|
|
|
|
|
const ArchSpec &arch_spec = launch_info.GetArchitecture();
|
|
|
|
|
|
|
|
FileSpec exe_spec(launch_info.GetExecutableFile());
|
|
|
|
|
|
|
|
FileSpec::FileType file_type = exe_spec.GetFileType();
|
|
|
|
if (file_type != FileSpec::eFileTypeRegular)
|
|
|
|
{
|
|
|
|
lldb::ModuleSP exe_module_sp;
|
|
|
|
error = host_platform_sp->ResolveExecutable (exe_spec,
|
|
|
|
arch_spec,
|
2012-02-14 07:10:39 +08:00
|
|
|
exe_module_sp,
|
|
|
|
NULL);
|
2011-04-12 13:54:46 +08:00
|
|
|
|
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
|
|
|
|
if (exe_module_sp)
|
|
|
|
exe_spec = exe_module_sp->GetFileSpec();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exe_spec.Exists())
|
|
|
|
{
|
|
|
|
exe_spec.GetPath (exe_path, sizeof(exe_path));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
launch_info.GetExecutableFile().GetPath (exe_path, sizeof(exe_path));
|
|
|
|
error.SetErrorStringWithFormat ("executable doesn't exist: '%s'", exe_path);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY))
|
|
|
|
{
|
|
|
|
#if !defined(__arm__)
|
|
|
|
return LaunchInNewTerminalWithAppleScript (exe_path, launch_info);
|
|
|
|
#else
|
|
|
|
error.SetErrorString ("launching a processs in a new terminal is not supported on iOS devices");
|
|
|
|
return error;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
Error local_err; // Errors that don't affect the spawning.
|
|
|
|
posix_spawnattr_t attr;
|
|
|
|
error.SetError( ::posix_spawnattr_init (&attr), eErrorTypePOSIX);
|
|
|
|
|
|
|
|
if (error.Fail() || log)
|
|
|
|
error.PutToLog(log.get(), "::posix_spawnattr_init ( &attr )");
|
|
|
|
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);
|
|
|
|
|
2011-10-28 09:24:12 +08:00
|
|
|
sigset_t no_signals;
|
|
|
|
sigset_t all_signals;
|
|
|
|
sigemptyset (&no_signals);
|
|
|
|
sigfillset (&all_signals);
|
|
|
|
::posix_spawnattr_setsigmask(&attr, &no_signals);
|
|
|
|
::posix_spawnattr_setsigdefault(&attr, &all_signals);
|
|
|
|
|
|
|
|
short flags = POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK;
|
2011-04-12 13:54:46 +08:00
|
|
|
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
|
|
|
|
|
2011-11-15 11:53:30 +08:00
|
|
|
//#ifdef POSIX_SPAWN_CLOEXEC_DEFAULT
|
|
|
|
// // Close all files exception those with file actions if this is supported.
|
|
|
|
// flags |= POSIX_SPAWN_CLOEXEC_DEFAULT;
|
|
|
|
//#endif
|
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
error.SetError( ::posix_spawnattr_setflags (&attr, flags), eErrorTypePOSIX);
|
|
|
|
if (error.Fail() || log)
|
|
|
|
error.PutToLog(log.get(), "::posix_spawnattr_setflags ( &attr, flags=0x%8.8x )", flags);
|
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
|
|
|
|
#if !defined(__arm__)
|
|
|
|
|
|
|
|
// 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...
|
|
|
|
cpu_type_t cpu = arch_spec.GetMachOCPUType();
|
|
|
|
if (cpu != 0 &&
|
|
|
|
cpu != UINT32_MAX &&
|
|
|
|
cpu != LLDB_INVALID_CPUTYPE)
|
|
|
|
{
|
|
|
|
size_t ocount = 0;
|
|
|
|
error.SetError( ::posix_spawnattr_setbinpref_np (&attr, 1, &cpu, &ocount), eErrorTypePOSIX);
|
|
|
|
if (error.Fail() || log)
|
|
|
|
error.PutToLog(log.get(), "::posix_spawnattr_setbinpref_np ( &attr, 1, cpu_type = 0x%8.8x, count => %zu )", cpu, ocount);
|
|
|
|
|
|
|
|
if (error.Fail() || ocount != 1)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2011-12-02 07:28:38 +08:00
|
|
|
::pid_t pid = LLDB_INVALID_PROCESS_ID;
|
2011-04-12 13:54:46 +08:00
|
|
|
const char *tmp_argv[2];
|
|
|
|
char * const *argv = (char * const*)launch_info.GetArguments().GetConstArgumentVector();
|
|
|
|
char * const *envp = (char * const*)launch_info.GetEnvironmentEntries().GetConstArgumentVector();
|
|
|
|
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;
|
|
|
|
argv = (char * const*)tmp_argv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-15 11:53:30 +08:00
|
|
|
const char *working_dir = launch_info.GetWorkingDirectory();
|
|
|
|
if (working_dir)
|
|
|
|
{
|
|
|
|
// No more thread specific current working directory
|
|
|
|
__pthread_chdir (working_dir);
|
|
|
|
}
|
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
const size_t num_file_actions = launch_info.GetNumFileActions ();
|
|
|
|
if (num_file_actions > 0)
|
|
|
|
{
|
|
|
|
posix_spawn_file_actions_t file_actions;
|
|
|
|
error.SetError( ::posix_spawn_file_actions_init (&file_actions), eErrorTypePOSIX);
|
|
|
|
if (error.Fail() || log)
|
|
|
|
error.PutToLog(log.get(), "::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)
|
|
|
|
{
|
|
|
|
const ProcessLaunchInfo::FileAction *launch_file_action = launch_info.GetFileActionAtIndex(i);
|
|
|
|
if (launch_file_action)
|
|
|
|
{
|
|
|
|
if (!ProcessLaunchInfo::FileAction::AddPosixSpawnFileAction (&file_actions,
|
|
|
|
launch_file_action,
|
|
|
|
log.get(),
|
|
|
|
error))
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
error.SetError (::posix_spawnp (&pid,
|
|
|
|
exe_path,
|
|
|
|
&file_actions,
|
|
|
|
&attr,
|
|
|
|
argv,
|
|
|
|
envp),
|
|
|
|
eErrorTypePOSIX);
|
|
|
|
|
|
|
|
if (error.Fail() || log)
|
|
|
|
error.PutToLog(log.get(), "::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )",
|
|
|
|
pid,
|
|
|
|
exe_path,
|
|
|
|
&file_actions,
|
|
|
|
&attr,
|
|
|
|
argv,
|
|
|
|
envp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetError (::posix_spawnp (&pid,
|
|
|
|
exe_path,
|
|
|
|
NULL,
|
|
|
|
&attr,
|
|
|
|
argv,
|
|
|
|
envp),
|
|
|
|
eErrorTypePOSIX);
|
|
|
|
|
|
|
|
if (error.Fail() || log)
|
|
|
|
error.PutToLog(log.get(), "::posix_spawnp ( pid => %i, path = '%s', file_actions = NULL, attr = %p, argv = %p, envp = %p )",
|
|
|
|
pid,
|
|
|
|
exe_path,
|
|
|
|
&attr,
|
|
|
|
argv,
|
|
|
|
envp);
|
|
|
|
}
|
|
|
|
|
2011-11-15 11:53:30 +08:00
|
|
|
if (working_dir)
|
|
|
|
{
|
|
|
|
// No more thread specific current working directory
|
|
|
|
__pthread_fchdir (-1);
|
|
|
|
}
|
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
if (pid != LLDB_INVALID_PROCESS_ID)
|
|
|
|
{
|
|
|
|
// If all went well, then set the process ID into the launch info
|
2011-11-16 13:37:56 +08:00
|
|
|
launch_info.SetProcessID(pid);
|
|
|
|
|
|
|
|
// Make sure we reap any processes we spawn or we will have zombies.
|
|
|
|
if (!launch_info.MonitorProcess())
|
|
|
|
{
|
|
|
|
const bool monitor_signals = false;
|
|
|
|
StartMonitoringChildProcess (Process::SetProcessExitStatus,
|
|
|
|
NULL,
|
|
|
|
pid,
|
|
|
|
monitor_signals);
|
|
|
|
}
|
2011-04-12 13:54:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Invalid process ID, something didn't go well
|
|
|
|
if (error.Success())
|
|
|
|
error.SetErrorString ("process launch failed for unknown reasons");
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2011-11-16 13:37:56 +08:00
|
|
|
lldb::thread_t
|
|
|
|
Host::StartMonitoringChildProcess (Host::MonitorChildProcessCallback callback,
|
|
|
|
void *callback_baton,
|
|
|
|
lldb::pid_t pid,
|
|
|
|
bool monitor_signals)
|
|
|
|
{
|
|
|
|
lldb::thread_t thread = LLDB_INVALID_HOST_THREAD;
|
|
|
|
unsigned long mask = DISPATCH_PROC_EXIT;
|
|
|
|
if (monitor_signals)
|
|
|
|
mask |= DISPATCH_PROC_SIGNAL;
|
|
|
|
|
2011-11-18 03:41:57 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_HOST | LIBLLDB_LOG_PROCESS));
|
|
|
|
|
2011-11-16 13:37:56 +08:00
|
|
|
|
|
|
|
dispatch_source_t source = ::dispatch_source_create (DISPATCH_SOURCE_TYPE_PROC,
|
|
|
|
pid,
|
|
|
|
mask,
|
|
|
|
::dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT,0));
|
2011-04-12 13:54:46 +08:00
|
|
|
|
2011-11-18 03:41:57 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf ("Host::StartMonitoringChildProcess (callback=%p, baton=%p, pid=%i, monitor_signals=%i) source = %p\n",
|
|
|
|
callback,
|
|
|
|
callback_baton,
|
|
|
|
(int)pid,
|
|
|
|
monitor_signals,
|
|
|
|
source);
|
2011-11-16 13:37:56 +08:00
|
|
|
|
|
|
|
if (source)
|
|
|
|
{
|
|
|
|
::dispatch_source_set_cancel_handler (source, ^{
|
|
|
|
::dispatch_release (source);
|
|
|
|
});
|
|
|
|
::dispatch_source_set_event_handler (source, ^{
|
|
|
|
|
|
|
|
int status= 0;
|
|
|
|
int wait_pid = 0;
|
|
|
|
bool cancel = false;
|
|
|
|
bool exited = false;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
wait_pid = ::waitpid (pid, &status, 0);
|
|
|
|
} while (wait_pid < 0 && errno == EINTR);
|
|
|
|
|
|
|
|
if (wait_pid >= 0)
|
|
|
|
{
|
|
|
|
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";
|
|
|
|
exited = true;
|
|
|
|
}
|
|
|
|
else if (WIFSIGNALED(status))
|
|
|
|
{
|
|
|
|
signal = WTERMSIG(status);
|
|
|
|
status_cstr = "SIGNALED";
|
|
|
|
exited = true;
|
|
|
|
exit_status = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status_cstr = "???";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log)
|
2011-12-02 07:28:38 +08:00
|
|
|
log->Printf ("::waitpid (pid = %llu, &status, 0) => pid = %i, status = 0x%8.8x (%s), signal = %i, exit_status = %i",
|
2011-11-16 13:37:56 +08:00
|
|
|
pid,
|
|
|
|
wait_pid,
|
|
|
|
status,
|
|
|
|
status_cstr,
|
|
|
|
signal,
|
|
|
|
exit_status);
|
|
|
|
|
|
|
|
if (callback)
|
|
|
|
cancel = callback (callback_baton, pid, exited, signal, exit_status);
|
|
|
|
|
|
|
|
if (exited)
|
|
|
|
{
|
|
|
|
::dispatch_source_cancel(source);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
::dispatch_resume (source);
|
|
|
|
}
|
|
|
|
return thread;
|
|
|
|
}
|
2012-01-05 11:57:59 +08:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Log to both stderr and to ASL Logging when running on MacOSX.
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
Host::SystemLog (SystemLogType type, const char *format, va_list args)
|
|
|
|
{
|
|
|
|
if (format && format[0])
|
|
|
|
{
|
|
|
|
static aslmsg g_aslmsg = NULL;
|
|
|
|
if (g_aslmsg == NULL)
|
|
|
|
{
|
|
|
|
g_aslmsg = ::asl_new (ASL_TYPE_MSG);
|
|
|
|
char asl_key_sender[PATH_MAX];
|
|
|
|
snprintf(asl_key_sender, sizeof(asl_key_sender), "com.apple.LLDB.framework");
|
|
|
|
::asl_set (g_aslmsg, ASL_KEY_SENDER, asl_key_sender);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the va_list so we can log this message twice
|
|
|
|
va_list copy_args;
|
|
|
|
va_copy (copy_args, args);
|
|
|
|
// Log to stderr
|
|
|
|
::vfprintf (stderr, format, copy_args);
|
|
|
|
va_end (copy_args);
|
|
|
|
|
|
|
|
int asl_level;
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case eSystemLogError:
|
|
|
|
asl_level = ASL_LEVEL_ERR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eSystemLogWarning:
|
|
|
|
asl_level = ASL_LEVEL_WARNING;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Log to ASL
|
|
|
|
::asl_vlog (NULL, g_aslmsg, asl_level, format, args);
|
|
|
|
}
|
|
|
|
}
|