2010-09-08 04:11:56 +08:00
|
|
|
//===-- Host.cpp ------------------------------------------------*- C++ -*-===//
|
2010-07-03 03:28:44 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-05 08:20:57 +08:00
|
|
|
#include "lldb/lldb-python.h"
|
|
|
|
|
2013-02-18 04:46:30 +08:00
|
|
|
// C includes
|
2010-09-08 04:11:56 +08:00
|
|
|
#include <errno.h>
|
2011-04-08 21:36:44 +08:00
|
|
|
#include <limits.h>
|
2014-03-25 07:10:19 +08:00
|
|
|
#include <stdlib.h>
|
2013-08-23 20:44:05 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "lldb/Host/windows/windows.h"
|
|
|
|
#include <winsock2.h>
|
2014-03-11 06:31:39 +08:00
|
|
|
#include <ws2tcpip.h>
|
2013-08-23 20:44:05 +08:00
|
|
|
#else
|
2014-01-13 22:55:15 +08:00
|
|
|
#include <unistd.h>
|
2013-08-23 20:44:05 +08:00
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <grp.h>
|
2011-03-24 12:28:38 +08:00
|
|
|
#include <netdb.h>
|
Many improvements to the Platform base class and subclasses. The base Platform
class now implements the Host functionality for a lot of things that make
sense by default so that subclasses can check:
int
PlatformSubclass::Foo ()
{
if (IsHost())
return Platform::Foo (); // Let the platform base class do the host specific stuff
// Platform subclass specific code...
int result = ...
return result;
}
Added new functions to the platform:
virtual const char *Platform::GetUserName (uint32_t uid);
virtual const char *Platform::GetGroupName (uint32_t gid);
The user and group names are cached locally so that remote platforms can avoid
sending packets multiple times to resolve this information.
Added the parent process ID to the ProcessInfo class.
Added a new ProcessInfoMatch class which helps us to match processes up
and changed the Host layer over to using this new class. The new class allows
us to search for processs:
1 - by name (equal to, starts with, ends with, contains, and regex)
2 - by pid
3 - And further check for parent pid == value, uid == value, gid == value,
euid == value, egid == value, arch == value, parent == value.
This is all hookup up to the "platform process list" command which required
adding dumping routines to dump process information. If the Host class
implements the process lookup routines, you can now lists processes on
your local machine:
machine1.foo.com % lldb
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
94727 244 username usergroup username usergroup x86_64-apple-darwin Xcode
92742 92710 username usergroup username usergroup i386-apple-darwin debugserver
This of course also works remotely with the lldb-platform:
machine1.foo.com % lldb-platform --listen 1234
machine2.foo.com % lldb
(lldb) platform create remote-macosx
Platform: remote-macosx
Connected: no
(lldb) platform connect connect://localhost:1444
Platform: remote-macosx
Triple: x86_64-apple-darwin
OS Version: 10.6.7 (10J869)
Kernel: Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386
Hostname: machine1.foo.com
Connected: yes
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99556 244 username usergroup username usergroup x86_64-apple-darwin trustevaluation
99548 65539 username usergroup username usergroup x86_64-apple-darwin lldb
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
The lldb-platform implements everything with the Host:: layer, so this should
"just work" for linux. I will probably be adding more stuff to the Host layer
for launching processes and attaching to processes so that this support should
eventually just work as well.
Modified the target to be able to be created with an architecture that differs
from the main executable. This is needed for iOS debugging since we can have
an "armv6" binary which can run on an "armv7" machine, so we want to be able
to do:
% lldb
(lldb) platform create remote-ios
(lldb) file --arch armv7 a.out
Where "a.out" is an armv6 executable. The platform then can correctly decide
to open all "armv7" images for all dependent shared libraries.
Modified the disassembly to show the current PC value. Example output:
(lldb) disassemble --frame
a.out`main:
0x1eb7: pushl %ebp
0x1eb8: movl %esp, %ebp
0x1eba: pushl %ebx
0x1ebb: subl $20, %esp
0x1ebe: calll 0x1ec3 ; main + 12 at test.c:18
0x1ec3: popl %ebx
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
0x1edb: leal 213(%ebx), %eax
0x1ee1: movl %eax, (%esp)
0x1ee4: calll 0x1f1e ; puts
0x1ee9: calll 0x1f0c ; getchar
0x1eee: movl $20, (%esp)
0x1ef5: calll 0x1e6a ; sleep_loop at test.c:6
0x1efa: movl $12, %eax
0x1eff: addl $20, %esp
0x1f02: popl %ebx
0x1f03: leave
0x1f04: ret
This can be handy when dealing with the new --line options that was recently
added:
(lldb) disassemble --line
a.out`main + 13 at test.c:19
18 {
-> 19 printf("Process: %i\n\n", getpid());
20 puts("Press any key to continue..."); getchar();
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
Modified the ModuleList to have a lookup based solely on a UUID. Since the
UUID is typically the MD5 checksum of a binary image, there is no need
to give the path and architecture when searching for a pre-existing
image in an image list.
Now that we support remote debugging a bit better, our lldb_private::Module
needs to be able to track what the original path for file was as the platform
knows it, as well as where the file is locally. The module has the two
following functions to retrieve both paths:
const FileSpec &Module::GetFileSpec () const;
const FileSpec &Module::GetPlatformFileSpec () const;
llvm-svn: 128563
2011-03-31 02:16:51 +08:00
|
|
|
#include <pwd.h>
|
2013-11-21 10:45:55 +08:00
|
|
|
#include <sys/stat.h>
|
2013-09-05 23:39:09 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined (__GNU__) && !defined (_WIN32)
|
|
|
|
// Does not exist under GNU/HURD or Windows
|
2013-06-28 20:35:08 +08:00
|
|
|
#include <sys/sysctl.h>
|
2013-08-23 20:44:05 +08:00
|
|
|
#endif
|
2010-09-08 04:11:56 +08:00
|
|
|
|
|
|
|
#if defined (__APPLE__)
|
2012-09-19 02:19:49 +08:00
|
|
|
#include <mach/mach_port.h>
|
2013-08-27 13:04:57 +08:00
|
|
|
#include <mach/mach_init.h>
|
|
|
|
#include <mach-o/dyld.h>
|
2013-11-22 08:51:36 +08:00
|
|
|
#include <AvailabilityMacros.h>
|
2013-06-26 02:58:11 +08:00
|
|
|
#endif
|
2011-02-08 08:35:34 +08:00
|
|
|
|
2014-05-03 03:09:40 +08:00
|
|
|
#if defined (__linux__) || defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__) || defined(__NetBSD__)
|
2013-08-28 04:58:59 +08:00
|
|
|
#include <spawn.h>
|
2011-02-08 01:43:47 +08:00
|
|
|
#include <sys/wait.h>
|
2013-08-02 02:51:08 +08:00
|
|
|
#include <sys/syscall.h>
|
2013-06-26 02:58:11 +08:00
|
|
|
#endif
|
2011-02-08 08:35:34 +08:00
|
|
|
|
2013-06-26 02:58:11 +08:00
|
|
|
#if defined (__FreeBSD__)
|
2011-08-03 04:52:42 +08:00
|
|
|
#include <pthread_np.h>
|
2010-09-08 04:11:56 +08:00
|
|
|
#endif
|
2010-07-03 03:28:44 +08:00
|
|
|
|
2013-02-18 04:46:30 +08:00
|
|
|
#include "lldb/Host/Host.h"
|
|
|
|
#include "lldb/Core/ArchSpec.h"
|
|
|
|
#include "lldb/Core/ConstString.h"
|
|
|
|
#include "lldb/Core/Debugger.h"
|
|
|
|
#include "lldb/Core/Error.h"
|
|
|
|
#include "lldb/Core/Log.h"
|
2013-08-28 04:58:59 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
2013-02-18 04:46:30 +08:00
|
|
|
#include "lldb/Core/StreamString.h"
|
|
|
|
#include "lldb/Core/ThreadSafeSTLMap.h"
|
|
|
|
#include "lldb/Host/Config.h"
|
|
|
|
#include "lldb/Host/Endian.h"
|
|
|
|
#include "lldb/Host/FileSpec.h"
|
|
|
|
#include "lldb/Host/Mutex.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/TargetList.h"
|
2013-08-28 04:58:59 +08:00
|
|
|
#include "lldb/Utility/CleanUp.h"
|
2013-02-18 04:46:30 +08:00
|
|
|
|
2014-06-27 13:17:41 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2013-08-07 05:40:08 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2013-02-18 04:46:30 +08:00
|
|
|
#include "llvm/Support/Host.h"
|
2013-08-07 05:40:08 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2013-02-18 04:46:30 +08:00
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
#if defined (__APPLE__)
|
|
|
|
#ifndef _POSIX_SPAWN_DISABLE_ASLR
|
|
|
|
#define _POSIX_SPAWN_DISABLE_ASLR 0x0100
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
int __pthread_chdir(const char *path);
|
|
|
|
int __pthread_fchdir (int fildes);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2013-02-18 04:46:30 +08:00
|
|
|
|
2010-07-03 03:28:44 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2011-11-16 13:37:56 +08:00
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#if !defined (__APPLE__) && !defined (_WIN32)
|
2010-09-08 04:11:56 +08:00
|
|
|
struct MonitorInfo
|
|
|
|
{
|
|
|
|
lldb::pid_t pid; // The process ID to monitor
|
|
|
|
Host::MonitorChildProcessCallback callback; // The callback function to call when "pid" exits or signals
|
|
|
|
void *callback_baton; // The callback baton for the callback function
|
|
|
|
bool monitor_signals; // If true, call the callback when "pid" gets signaled.
|
|
|
|
};
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
static thread_result_t
|
2010-09-08 04:11:56 +08:00
|
|
|
MonitorChildProcessThreadFunction (void *arg);
|
|
|
|
|
|
|
|
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;
|
2011-11-16 13:37:56 +08:00
|
|
|
MonitorInfo * info_ptr = new MonitorInfo();
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2011-11-16 13:37:56 +08:00
|
|
|
info_ptr->pid = pid;
|
|
|
|
info_ptr->callback = callback;
|
|
|
|
info_ptr->callback_baton = callback_baton;
|
|
|
|
info_ptr->monitor_signals = monitor_signals;
|
|
|
|
|
|
|
|
char thread_name[256];
|
2012-11-30 05:49:15 +08:00
|
|
|
::snprintf (thread_name, sizeof(thread_name), "<lldb.host.wait4(pid=%" PRIu64 ")>", pid);
|
2011-11-16 13:37:56 +08:00
|
|
|
thread = ThreadCreate (thread_name,
|
|
|
|
MonitorChildProcessThreadFunction,
|
|
|
|
info_ptr,
|
|
|
|
NULL);
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
return thread;
|
|
|
|
}
|
|
|
|
|
2010-07-03 03:28:44 +08:00
|
|
|
//------------------------------------------------------------------
|
2010-09-08 04:11:56 +08:00
|
|
|
// Scoped class that will disable thread canceling when it is
|
|
|
|
// constructed, and exception safely restore the previous value it
|
|
|
|
// when it goes out of scope.
|
2010-07-03 03:28:44 +08:00
|
|
|
//------------------------------------------------------------------
|
2010-09-08 04:11:56 +08:00
|
|
|
class ScopedPThreadCancelDisabler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ScopedPThreadCancelDisabler()
|
|
|
|
{
|
|
|
|
// Disable the ability for this thread to be cancelled
|
|
|
|
int err = ::pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &m_old_state);
|
|
|
|
if (err != 0)
|
|
|
|
m_old_state = -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
~ScopedPThreadCancelDisabler()
|
|
|
|
{
|
|
|
|
// Restore the ability for this thread to be cancelled to what it
|
|
|
|
// previously was.
|
|
|
|
if (m_old_state != -1)
|
|
|
|
::pthread_setcancelstate (m_old_state, 0);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
int m_old_state; // Save the old cancelability state.
|
|
|
|
};
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
static thread_result_t
|
2010-09-08 04:11:56 +08:00
|
|
|
MonitorChildProcessThreadFunction (void *arg)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
|
2010-09-08 04:11:56 +08:00
|
|
|
const char *function = __FUNCTION__;
|
|
|
|
if (log)
|
|
|
|
log->Printf ("%s (arg = %p) thread starting...", function, arg);
|
|
|
|
|
|
|
|
MonitorInfo *info = (MonitorInfo *)arg;
|
|
|
|
|
|
|
|
const Host::MonitorChildProcessCallback callback = info->callback;
|
|
|
|
void * const callback_baton = info->callback_baton;
|
|
|
|
const bool monitor_signals = info->monitor_signals;
|
|
|
|
|
2013-08-28 04:58:59 +08:00
|
|
|
assert (info->pid <= UINT32_MAX);
|
2014-04-02 14:57:45 +08:00
|
|
|
const ::pid_t pid = monitor_signals ? -1 * getpgid(info->pid) : info->pid;
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
delete info;
|
|
|
|
|
|
|
|
int status = -1;
|
2013-07-01 16:21:36 +08:00
|
|
|
#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
|
2013-05-02 04:38:19 +08:00
|
|
|
#define __WALL 0
|
|
|
|
#endif
|
2013-01-09 00:30:18 +08:00
|
|
|
const int options = __WALL;
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
while (1)
|
|
|
|
{
|
2010-10-30 05:48:37 +08:00
|
|
|
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
|
2010-09-08 04:11:56 +08:00
|
|
|
if (log)
|
2013-08-28 04:58:59 +08:00
|
|
|
log->Printf("%s ::wait_pid (pid = %" PRIi32 ", &status, options = %i)...", function, pid, options);
|
2010-09-08 04:11:56 +08:00
|
|
|
|
|
|
|
// Wait for all child processes
|
|
|
|
::pthread_testcancel ();
|
2013-01-09 00:30:18 +08:00
|
|
|
// Get signals from all children with same process group of pid
|
2013-08-28 04:58:59 +08:00
|
|
|
const ::pid_t wait_pid = ::waitpid (pid, &status, options);
|
2010-09-08 04:11:56 +08:00
|
|
|
::pthread_testcancel ();
|
|
|
|
|
|
|
|
if (wait_pid == -1)
|
|
|
|
{
|
|
|
|
if (errno == EINTR)
|
|
|
|
continue;
|
|
|
|
else
|
2013-05-29 07:04:25 +08:00
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf ("%s (arg = %p) thread exiting because waitpid failed (%s)...", __FUNCTION__, arg, strerror(errno));
|
2010-09-08 04:11:56 +08:00
|
|
|
break;
|
2013-05-29 07:04:25 +08:00
|
|
|
}
|
2010-09-08 04:11:56 +08:00
|
|
|
}
|
2013-01-09 00:30:18 +08:00
|
|
|
else if (wait_pid > 0)
|
2010-09-08 04:11:56 +08:00
|
|
|
{
|
|
|
|
bool exited = false;
|
|
|
|
int signal = 0;
|
|
|
|
int exit_status = 0;
|
|
|
|
const char *status_cstr = NULL;
|
|
|
|
if (WIFSTOPPED(status))
|
|
|
|
{
|
|
|
|
signal = WSTOPSIG(status);
|
|
|
|
status_cstr = "STOPPED";
|
|
|
|
}
|
|
|
|
else if (WIFEXITED(status))
|
|
|
|
{
|
|
|
|
exit_status = WEXITSTATUS(status);
|
|
|
|
status_cstr = "EXITED";
|
2013-05-29 07:04:25 +08:00
|
|
|
exited = true;
|
2010-09-08 04:11:56 +08:00
|
|
|
}
|
|
|
|
else if (WIFSIGNALED(status))
|
|
|
|
{
|
|
|
|
signal = WTERMSIG(status);
|
|
|
|
status_cstr = "SIGNALED";
|
2013-09-05 00:06:04 +08:00
|
|
|
if (wait_pid == abs(pid)) {
|
2013-01-09 00:30:18 +08:00
|
|
|
exited = true;
|
|
|
|
exit_status = -1;
|
|
|
|
}
|
2010-09-08 04:11:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-07-20 03:48:13 +08:00
|
|
|
status_cstr = "(\?\?\?)";
|
2010-09-08 04:11:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Scope for pthread_cancel_disabler
|
|
|
|
{
|
|
|
|
ScopedPThreadCancelDisabler pthread_cancel_disabler;
|
|
|
|
|
2010-10-30 05:48:37 +08:00
|
|
|
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
|
2010-09-08 04:11:56 +08:00
|
|
|
if (log)
|
2013-08-28 04:58:59 +08:00
|
|
|
log->Printf ("%s ::waitpid (pid = %" PRIi32 ", &status, options = %i) => pid = %" PRIi32 ", status = 0x%8.8x (%s), signal = %i, exit_state = %i",
|
2010-09-08 04:11:56 +08:00
|
|
|
function,
|
|
|
|
wait_pid,
|
|
|
|
options,
|
|
|
|
pid,
|
|
|
|
status,
|
|
|
|
status_cstr,
|
|
|
|
signal,
|
|
|
|
exit_status);
|
|
|
|
|
|
|
|
if (exited || (signal != 0 && monitor_signals))
|
|
|
|
{
|
2011-11-16 13:37:56 +08:00
|
|
|
bool callback_return = false;
|
|
|
|
if (callback)
|
2013-01-09 00:30:18 +08:00
|
|
|
callback_return = callback (callback_baton, wait_pid, exited, signal, exit_status);
|
2010-09-08 04:11:56 +08:00
|
|
|
|
|
|
|
// If our process exited, then this thread should exit
|
2013-09-05 00:06:04 +08:00
|
|
|
if (exited && wait_pid == abs(pid))
|
2013-05-29 07:04:25 +08:00
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf ("%s (arg = %p) thread exiting because pid received exit signal...", __FUNCTION__, arg);
|
2010-09-08 04:11:56 +08:00
|
|
|
break;
|
2013-05-29 07:04:25 +08:00
|
|
|
}
|
2010-09-08 04:11:56 +08:00
|
|
|
// If the callback returns true, it means this process should
|
|
|
|
// exit
|
|
|
|
if (callback_return)
|
2013-05-29 07:04:25 +08:00
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf ("%s (arg = %p) thread exiting because callback returned true...", __FUNCTION__, arg);
|
2010-09-08 04:11:56 +08:00
|
|
|
break;
|
2013-05-29 07:04:25 +08:00
|
|
|
}
|
2010-09-08 04:11:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-30 05:48:37 +08:00
|
|
|
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
|
2010-09-08 04:11:56 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf ("%s (arg = %p) thread exiting...", __FUNCTION__, arg);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#endif // #if !defined (__APPLE__) && !defined (_WIN32)
|
|
|
|
|
|
|
|
#if !defined (__APPLE__)
|
2012-01-05 11:57:59 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
Host::SystemLog (SystemLogType type, const char *format, va_list args)
|
|
|
|
{
|
|
|
|
vfprintf (stderr, format, args);
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#endif
|
2011-11-16 13:37:56 +08:00
|
|
|
|
2012-01-05 11:57:59 +08:00
|
|
|
void
|
|
|
|
Host::SystemLog (SystemLogType type, const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start (args, format);
|
|
|
|
SystemLog (type, format, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
|
2010-07-03 03:28:44 +08:00
|
|
|
const ArchSpec &
|
2011-02-16 05:59:32 +08:00
|
|
|
Host::GetArchitecture (SystemDefaultArchitecture arch_kind)
|
2010-07-03 03:28:44 +08:00
|
|
|
{
|
2011-02-16 05:59:32 +08:00
|
|
|
static bool g_supports_32 = false;
|
|
|
|
static bool g_supports_64 = false;
|
|
|
|
static ArchSpec g_host_arch_32;
|
|
|
|
static ArchSpec g_host_arch_64;
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
#if defined (__APPLE__)
|
2011-02-16 05:59:32 +08:00
|
|
|
|
|
|
|
// Apple is different in that it can support both 32 and 64 bit executables
|
|
|
|
// in the same operating system running concurrently. Here we detect the
|
|
|
|
// correct host architectures for both 32 and 64 bit including if 64 bit
|
|
|
|
// executables are supported on the system.
|
|
|
|
|
|
|
|
if (g_supports_32 == false && g_supports_64 == false)
|
|
|
|
{
|
|
|
|
// All apple systems support 32 bit execution.
|
|
|
|
g_supports_32 = true;
|
2010-07-03 03:28:44 +08:00
|
|
|
uint32_t cputype, cpusubtype;
|
2011-02-16 05:59:32 +08:00
|
|
|
uint32_t is_64_bit_capable = false;
|
2010-07-03 03:28:44 +08:00
|
|
|
size_t len = sizeof(cputype);
|
2011-02-16 05:59:32 +08:00
|
|
|
ArchSpec host_arch;
|
|
|
|
// These will tell us about the kernel architecture, which even on a 64
|
|
|
|
// bit machine can be 32 bit...
|
2010-07-03 03:28:44 +08:00
|
|
|
if (::sysctlbyname("hw.cputype", &cputype, &len, NULL, 0) == 0)
|
|
|
|
{
|
2011-02-16 05:59:32 +08:00
|
|
|
len = sizeof (cpusubtype);
|
|
|
|
if (::sysctlbyname("hw.cpusubtype", &cpusubtype, &len, NULL, 0) != 0)
|
|
|
|
cpusubtype = CPU_TYPE_ANY;
|
|
|
|
|
2010-07-03 03:28:44 +08:00
|
|
|
len = sizeof (is_64_bit_capable);
|
|
|
|
if (::sysctlbyname("hw.cpu64bit_capable", &is_64_bit_capable, &len, NULL, 0) == 0)
|
|
|
|
{
|
|
|
|
if (is_64_bit_capable)
|
2011-02-16 05:59:32 +08:00
|
|
|
g_supports_64 = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_64_bit_capable)
|
|
|
|
{
|
2011-02-16 12:46:07 +08:00
|
|
|
#if defined (__i386__) || defined (__x86_64__)
|
|
|
|
if (cpusubtype == CPU_SUBTYPE_486)
|
|
|
|
cpusubtype = CPU_SUBTYPE_I386_ALL;
|
|
|
|
#endif
|
2011-02-16 05:59:32 +08:00
|
|
|
if (cputype & CPU_ARCH_ABI64)
|
|
|
|
{
|
|
|
|
// We have a 64 bit kernel on a 64 bit system
|
2011-03-25 05:19:54 +08:00
|
|
|
g_host_arch_32.SetArchitecture (eArchTypeMachO, ~(CPU_ARCH_MASK) & cputype, cpusubtype);
|
|
|
|
g_host_arch_64.SetArchitecture (eArchTypeMachO, cputype, cpusubtype);
|
2011-02-16 05:59:32 +08:00
|
|
|
}
|
|
|
|
else
|
2010-07-03 03:28:44 +08:00
|
|
|
{
|
2011-02-16 05:59:32 +08:00
|
|
|
// We have a 32 bit kernel on a 64 bit system
|
2011-03-25 05:19:54 +08:00
|
|
|
g_host_arch_32.SetArchitecture (eArchTypeMachO, cputype, cpusubtype);
|
2010-07-03 03:28:44 +08:00
|
|
|
cputype |= CPU_ARCH_ABI64;
|
2011-03-25 05:19:54 +08:00
|
|
|
g_host_arch_64.SetArchitecture (eArchTypeMachO, cputype, cpusubtype);
|
2010-07-03 03:28:44 +08:00
|
|
|
}
|
|
|
|
}
|
2011-02-16 05:59:32 +08:00
|
|
|
else
|
|
|
|
{
|
2011-03-25 05:19:54 +08:00
|
|
|
g_host_arch_32.SetArchitecture (eArchTypeMachO, cputype, cpusubtype);
|
2011-02-16 05:59:32 +08:00
|
|
|
g_host_arch_64.Clear();
|
|
|
|
}
|
2010-07-03 03:28:44 +08:00
|
|
|
}
|
2011-02-16 05:59:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#else // #if defined (__APPLE__)
|
2011-02-25 03:15:09 +08:00
|
|
|
|
2011-02-16 05:59:32 +08:00
|
|
|
if (g_supports_32 == false && g_supports_64 == false)
|
|
|
|
{
|
2011-11-05 09:35:31 +08:00
|
|
|
llvm::Triple triple(llvm::sys::getDefaultTargetTriple());
|
2011-02-16 05:59:32 +08:00
|
|
|
|
2011-02-25 03:15:09 +08:00
|
|
|
g_host_arch_32.Clear();
|
|
|
|
g_host_arch_64.Clear();
|
2011-02-16 05:59:32 +08:00
|
|
|
|
2012-10-12 01:38:58 +08:00
|
|
|
// If the OS is Linux, "unknown" in the vendor slot isn't what we want
|
|
|
|
// for the default triple. It's probably an artifact of config.guess.
|
|
|
|
if (triple.getOS() == llvm::Triple::Linux && triple.getVendor() == llvm::Triple::UnknownVendor)
|
2014-01-18 06:21:22 +08:00
|
|
|
triple.setVendorName ("");
|
2012-10-12 01:38:58 +08:00
|
|
|
|
2014-01-18 11:02:39 +08:00
|
|
|
const char* distribution_id = GetDistributionId ().AsCString();
|
|
|
|
|
2011-02-25 03:15:09 +08:00
|
|
|
switch (triple.getArch())
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
g_host_arch_32.SetTriple(triple);
|
2014-01-18 11:02:39 +08:00
|
|
|
g_host_arch_32.SetDistributionId (distribution_id);
|
2011-02-25 03:15:09 +08:00
|
|
|
g_supports_32 = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case llvm::Triple::x86_64:
|
2012-09-08 01:49:29 +08:00
|
|
|
g_host_arch_64.SetTriple(triple);
|
2014-01-18 11:02:39 +08:00
|
|
|
g_host_arch_64.SetDistributionId (distribution_id);
|
2012-09-08 01:49:29 +08:00
|
|
|
g_supports_64 = true;
|
|
|
|
g_host_arch_32.SetTriple(triple.get32BitArchVariant());
|
2014-01-18 11:02:39 +08:00
|
|
|
g_host_arch_32.SetDistributionId (distribution_id);
|
2012-09-08 01:49:29 +08:00
|
|
|
g_supports_32 = true;
|
|
|
|
break;
|
|
|
|
|
2014-04-02 02:06:45 +08:00
|
|
|
case llvm::Triple::mips64:
|
2011-02-25 03:15:09 +08:00
|
|
|
case llvm::Triple::sparcv9:
|
|
|
|
case llvm::Triple::ppc64:
|
|
|
|
g_host_arch_64.SetTriple(triple);
|
2014-01-18 11:02:39 +08:00
|
|
|
g_host_arch_64.SetDistributionId (distribution_id);
|
2011-02-25 03:15:09 +08:00
|
|
|
g_supports_64 = true;
|
|
|
|
break;
|
|
|
|
}
|
2011-02-17 10:05:38 +08:00
|
|
|
|
|
|
|
g_supports_32 = g_host_arch_32.IsValid();
|
|
|
|
g_supports_64 = g_host_arch_64.IsValid();
|
2010-09-08 04:11:56 +08:00
|
|
|
}
|
2011-02-16 05:59:32 +08:00
|
|
|
|
|
|
|
#endif // #else for #if defined (__APPLE__)
|
|
|
|
|
|
|
|
if (arch_kind == eSystemDefaultArchitecture32)
|
|
|
|
return g_host_arch_32;
|
|
|
|
else if (arch_kind == eSystemDefaultArchitecture64)
|
|
|
|
return g_host_arch_64;
|
|
|
|
|
|
|
|
if (g_supports_64)
|
|
|
|
return g_host_arch_64;
|
|
|
|
|
|
|
|
return g_host_arch_32;
|
2010-07-03 03:28:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const ConstString &
|
|
|
|
Host::GetVendorString()
|
|
|
|
{
|
|
|
|
static ConstString g_vendor;
|
|
|
|
if (!g_vendor)
|
|
|
|
{
|
2012-05-12 08:01:21 +08:00
|
|
|
const ArchSpec &host_arch = GetArchitecture (eSystemDefaultArchitecture);
|
|
|
|
const llvm::StringRef &str_ref = host_arch.GetTriple().getVendorName();
|
|
|
|
g_vendor.SetCStringWithLength(str_ref.data(), str_ref.size());
|
2010-07-03 03:28:44 +08:00
|
|
|
}
|
|
|
|
return g_vendor;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConstString &
|
|
|
|
Host::GetOSString()
|
|
|
|
{
|
2010-09-08 04:11:56 +08:00
|
|
|
static ConstString g_os_string;
|
|
|
|
if (!g_os_string)
|
|
|
|
{
|
2012-05-12 08:01:21 +08:00
|
|
|
const ArchSpec &host_arch = GetArchitecture (eSystemDefaultArchitecture);
|
|
|
|
const llvm::StringRef &str_ref = host_arch.GetTriple().getOSName();
|
|
|
|
g_os_string.SetCStringWithLength(str_ref.data(), str_ref.size());
|
2010-09-08 04:11:56 +08:00
|
|
|
}
|
2010-07-03 03:28:44 +08:00
|
|
|
return g_os_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConstString &
|
|
|
|
Host::GetTargetTriple()
|
|
|
|
{
|
|
|
|
static ConstString g_host_triple;
|
|
|
|
if (!(g_host_triple))
|
|
|
|
{
|
2012-05-12 08:01:21 +08:00
|
|
|
const ArchSpec &host_arch = GetArchitecture (eSystemDefaultArchitecture);
|
|
|
|
g_host_triple.SetCString(host_arch.GetTriple().getTriple().c_str());
|
2010-07-03 03:28:44 +08:00
|
|
|
}
|
|
|
|
return g_host_triple;
|
|
|
|
}
|
|
|
|
|
2014-01-18 04:18:59 +08:00
|
|
|
// See linux/Host.cpp for Linux-based implementations of this.
|
|
|
|
// Add your platform-specific implementation to the appropriate host file.
|
|
|
|
#if !defined(__linux__)
|
|
|
|
|
|
|
|
const ConstString &
|
|
|
|
Host::GetDistributionId ()
|
|
|
|
{
|
|
|
|
static ConstString s_distribution_id;
|
|
|
|
return s_distribution_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // #if !defined(__linux__)
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
lldb::pid_t
|
|
|
|
Host::GetCurrentProcessID()
|
|
|
|
{
|
|
|
|
return ::getpid();
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
lldb::tid_t
|
|
|
|
Host::GetCurrentThreadID()
|
|
|
|
{
|
|
|
|
#if defined (__APPLE__)
|
2013-12-06 17:35:53 +08:00
|
|
|
// Calling "mach_thread_self()" bumps the reference count on the thread
|
2012-09-19 02:19:49 +08:00
|
|
|
// port, so we need to deallocate it. mach_task_self() doesn't bump the ref
|
|
|
|
// count.
|
|
|
|
thread_port_t thread_self = mach_thread_self();
|
|
|
|
mach_port_deallocate(mach_task_self(), thread_self);
|
|
|
|
return thread_self;
|
2011-08-03 04:52:42 +08:00
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
return lldb::tid_t(pthread_getthreadid_np());
|
2013-08-02 02:51:08 +08:00
|
|
|
#elif defined(__linux__)
|
|
|
|
return lldb::tid_t(syscall(SYS_gettid));
|
2010-09-08 04:11:56 +08:00
|
|
|
#else
|
|
|
|
return lldb::tid_t(pthread_self());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-04-07 08:00:41 +08:00
|
|
|
lldb::thread_t
|
|
|
|
Host::GetCurrentThread ()
|
|
|
|
{
|
|
|
|
return lldb::thread_t(pthread_self());
|
|
|
|
}
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
const char *
|
|
|
|
Host::GetSignalAsCString (int signo)
|
|
|
|
{
|
|
|
|
switch (signo)
|
|
|
|
{
|
|
|
|
case SIGHUP: return "SIGHUP"; // 1 hangup
|
|
|
|
case SIGINT: return "SIGINT"; // 2 interrupt
|
|
|
|
case SIGQUIT: return "SIGQUIT"; // 3 quit
|
|
|
|
case SIGILL: return "SIGILL"; // 4 illegal instruction (not reset when caught)
|
|
|
|
case SIGTRAP: return "SIGTRAP"; // 5 trace trap (not reset when caught)
|
|
|
|
case SIGABRT: return "SIGABRT"; // 6 abort()
|
2013-12-13 02:12:16 +08:00
|
|
|
#if defined(SIGPOLL)
|
2013-12-13 17:51:39 +08:00
|
|
|
#if !defined(SIGIO) || (SIGPOLL != SIGIO)
|
|
|
|
// Under some GNU/Linux, SIGPOLL and SIGIO are the same. Causing the build to
|
|
|
|
// fail with 'multiple define cases with same value'
|
2010-09-08 04:11:56 +08:00
|
|
|
case SIGPOLL: return "SIGPOLL"; // 7 pollable event ([XSR] generated, not supported)
|
2011-11-05 00:06:40 +08:00
|
|
|
#endif
|
2013-12-13 17:51:39 +08:00
|
|
|
#endif
|
2013-12-13 02:12:16 +08:00
|
|
|
#if defined(SIGEMT)
|
2010-09-08 04:11:56 +08:00
|
|
|
case SIGEMT: return "SIGEMT"; // 7 EMT instruction
|
2011-11-05 00:06:40 +08:00
|
|
|
#endif
|
2010-09-08 04:11:56 +08:00
|
|
|
case SIGFPE: return "SIGFPE"; // 8 floating point exception
|
|
|
|
case SIGKILL: return "SIGKILL"; // 9 kill (cannot be caught or ignored)
|
|
|
|
case SIGBUS: return "SIGBUS"; // 10 bus error
|
|
|
|
case SIGSEGV: return "SIGSEGV"; // 11 segmentation violation
|
|
|
|
case SIGSYS: return "SIGSYS"; // 12 bad argument to system call
|
|
|
|
case SIGPIPE: return "SIGPIPE"; // 13 write on a pipe with no one to read it
|
|
|
|
case SIGALRM: return "SIGALRM"; // 14 alarm clock
|
|
|
|
case SIGTERM: return "SIGTERM"; // 15 software termination signal from kill
|
|
|
|
case SIGURG: return "SIGURG"; // 16 urgent condition on IO channel
|
|
|
|
case SIGSTOP: return "SIGSTOP"; // 17 sendable stop signal not from tty
|
|
|
|
case SIGTSTP: return "SIGTSTP"; // 18 stop signal from tty
|
|
|
|
case SIGCONT: return "SIGCONT"; // 19 continue a stopped process
|
|
|
|
case SIGCHLD: return "SIGCHLD"; // 20 to parent on child stop or exit
|
|
|
|
case SIGTTIN: return "SIGTTIN"; // 21 to readers pgrp upon background tty read
|
|
|
|
case SIGTTOU: return "SIGTTOU"; // 22 like TTIN for output if (tp->t_local<OSTOP)
|
2013-12-13 02:12:16 +08:00
|
|
|
#if defined(SIGIO)
|
2010-09-08 04:11:56 +08:00
|
|
|
case SIGIO: return "SIGIO"; // 23 input/output possible signal
|
|
|
|
#endif
|
|
|
|
case SIGXCPU: return "SIGXCPU"; // 24 exceeded CPU time limit
|
|
|
|
case SIGXFSZ: return "SIGXFSZ"; // 25 exceeded file size limit
|
|
|
|
case SIGVTALRM: return "SIGVTALRM"; // 26 virtual time alarm
|
|
|
|
case SIGPROF: return "SIGPROF"; // 27 profiling time alarm
|
2013-12-13 02:12:16 +08:00
|
|
|
#if defined(SIGWINCH)
|
2010-09-08 04:11:56 +08:00
|
|
|
case SIGWINCH: return "SIGWINCH"; // 28 window size changes
|
2013-12-13 02:12:16 +08:00
|
|
|
#endif
|
|
|
|
#if defined(SIGINFO)
|
2010-09-08 04:11:56 +08:00
|
|
|
case SIGINFO: return "SIGINFO"; // 29 information request
|
|
|
|
#endif
|
|
|
|
case SIGUSR1: return "SIGUSR1"; // 30 user defined signal 1
|
|
|
|
case SIGUSR2: return "SIGUSR2"; // 31 user defined signal 2
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#endif
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
void
|
|
|
|
Host::WillTerminate ()
|
|
|
|
{
|
|
|
|
}
|
2010-07-03 03:28:44 +08:00
|
|
|
|
2013-07-01 16:21:36 +08:00
|
|
|
#if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__FreeBSD_kernel__) && !defined (__linux__) // see macosx/Host.mm
|
2013-05-14 03:33:58 +08:00
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
void
|
|
|
|
Host::ThreadCreated (const char *thread_name)
|
2010-07-03 03:28:44 +08:00
|
|
|
{
|
|
|
|
}
|
2010-12-03 14:02:24 +08:00
|
|
|
|
2011-08-05 08:35:43 +08:00
|
|
|
void
|
2010-12-03 14:02:24 +08:00
|
|
|
Host::Backtrace (Stream &strm, uint32_t max_frames)
|
|
|
|
{
|
2013-07-17 08:26:30 +08:00
|
|
|
// TODO: Is there a way to backtrace the current process on other systems?
|
2010-12-03 14:02:24 +08:00
|
|
|
}
|
|
|
|
|
2010-12-04 08:10:17 +08:00
|
|
|
size_t
|
|
|
|
Host::GetEnvironment (StringList &env)
|
|
|
|
{
|
2013-07-17 08:26:30 +08:00
|
|
|
// TODO: Is there a way to the host environment for this process on other systems?
|
2010-12-04 08:10:17 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-01 16:21:36 +08:00
|
|
|
#endif // #if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__FreeBSD_kernel__) && !defined (__linux__)
|
2010-07-03 03:28:44 +08:00
|
|
|
|
|
|
|
struct HostThreadCreateInfo
|
|
|
|
{
|
|
|
|
std::string thread_name;
|
|
|
|
thread_func_t thread_fptr;
|
|
|
|
thread_arg_t thread_arg;
|
2010-09-08 04:11:56 +08:00
|
|
|
|
2010-07-03 03:28:44 +08:00
|
|
|
HostThreadCreateInfo (const char *name, thread_func_t fptr, thread_arg_t arg) :
|
|
|
|
thread_name (name ? name : ""),
|
|
|
|
thread_fptr (fptr),
|
|
|
|
thread_arg (arg)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static thread_result_t
|
2013-08-23 20:44:05 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
__stdcall
|
|
|
|
#endif
|
2010-07-03 03:28:44 +08:00
|
|
|
ThreadCreateTrampoline (thread_arg_t arg)
|
|
|
|
{
|
|
|
|
HostThreadCreateInfo *info = (HostThreadCreateInfo *)arg;
|
|
|
|
Host::ThreadCreated (info->thread_name.c_str());
|
|
|
|
thread_func_t thread_fptr = info->thread_fptr;
|
|
|
|
thread_arg_t thread_arg = info->thread_arg;
|
2010-09-08 04:11:56 +08:00
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
|
2010-07-03 03:28:44 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("thread created");
|
2010-09-08 04:11:56 +08:00
|
|
|
|
2010-07-03 03:28:44 +08:00
|
|
|
delete info;
|
|
|
|
return thread_fptr (thread_arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::thread_t
|
|
|
|
Host::ThreadCreate
|
|
|
|
(
|
|
|
|
const char *thread_name,
|
|
|
|
thread_func_t thread_fptr,
|
|
|
|
thread_arg_t thread_arg,
|
|
|
|
Error *error
|
|
|
|
)
|
|
|
|
{
|
|
|
|
lldb::thread_t thread = LLDB_INVALID_HOST_THREAD;
|
2010-09-08 04:11:56 +08:00
|
|
|
|
2010-07-03 03:28:44 +08:00
|
|
|
// Host::ThreadCreateTrampoline will delete this pointer for us.
|
|
|
|
HostThreadCreateInfo *info_ptr = new HostThreadCreateInfo (thread_name, thread_fptr, thread_arg);
|
2010-09-08 04:11:56 +08:00
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
thread = ::_beginthreadex(0, 0, ThreadCreateTrampoline, info_ptr, 0, NULL);
|
|
|
|
int err = thread <= 0 ? GetLastError() : 0;
|
|
|
|
#else
|
2010-07-03 03:28:44 +08:00
|
|
|
int err = ::pthread_create (&thread, NULL, ThreadCreateTrampoline, info_ptr);
|
2013-08-23 20:44:05 +08:00
|
|
|
#endif
|
2010-07-03 03:28:44 +08:00
|
|
|
if (err == 0)
|
|
|
|
{
|
|
|
|
if (error)
|
|
|
|
error->Clear();
|
|
|
|
return thread;
|
|
|
|
}
|
2010-09-08 04:11:56 +08:00
|
|
|
|
2010-07-03 03:28:44 +08:00
|
|
|
if (error)
|
|
|
|
error->SetError (err, eErrorTypePOSIX);
|
2010-09-08 04:11:56 +08:00
|
|
|
|
2010-07-03 03:28:44 +08:00
|
|
|
return LLDB_INVALID_HOST_THREAD;
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
2010-07-03 03:28:44 +08:00
|
|
|
bool
|
|
|
|
Host::ThreadCancel (lldb::thread_t thread, Error *error)
|
|
|
|
{
|
|
|
|
int err = ::pthread_cancel (thread);
|
|
|
|
if (error)
|
|
|
|
error->SetError(err, eErrorTypePOSIX);
|
|
|
|
return err == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Host::ThreadDetach (lldb::thread_t thread, Error *error)
|
|
|
|
{
|
|
|
|
int err = ::pthread_detach (thread);
|
|
|
|
if (error)
|
|
|
|
error->SetError(err, eErrorTypePOSIX);
|
|
|
|
return err == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Host::ThreadJoin (lldb::thread_t thread, thread_result_t *thread_result_ptr, Error *error)
|
|
|
|
{
|
|
|
|
int err = ::pthread_join (thread, thread_result_ptr);
|
|
|
|
if (error)
|
|
|
|
error->SetError(err, eErrorTypePOSIX);
|
|
|
|
return err == 0;
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
lldb::thread_key_t
|
|
|
|
Host::ThreadLocalStorageCreate(ThreadLocalStorageCleanupCallback callback)
|
|
|
|
{
|
|
|
|
pthread_key_t key;
|
|
|
|
::pthread_key_create (&key, callback);
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
Host::ThreadLocalStorageGet(lldb::thread_key_t key)
|
|
|
|
{
|
|
|
|
return ::pthread_getspecific (key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Host::ThreadLocalStorageSet(lldb::thread_key_t key, void *value)
|
|
|
|
{
|
|
|
|
::pthread_setspecific (key, value);
|
|
|
|
}
|
|
|
|
|
2013-05-14 03:33:58 +08:00
|
|
|
bool
|
2010-07-03 03:28:44 +08:00
|
|
|
Host::SetThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name)
|
|
|
|
{
|
2013-02-28 06:51:58 +08:00
|
|
|
#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5
|
2010-07-03 03:28:44 +08:00
|
|
|
lldb::pid_t curr_pid = Host::GetCurrentProcessID();
|
|
|
|
lldb::tid_t curr_tid = Host::GetCurrentThreadID();
|
|
|
|
if (pid == LLDB_INVALID_PROCESS_ID)
|
|
|
|
pid = curr_pid;
|
|
|
|
|
|
|
|
if (tid == LLDB_INVALID_THREAD_ID)
|
|
|
|
tid = curr_tid;
|
|
|
|
|
|
|
|
// Set the pthread name if possible
|
|
|
|
if (pid == curr_pid && tid == curr_tid)
|
|
|
|
{
|
2013-05-14 03:33:58 +08:00
|
|
|
if (::pthread_setname_np (name) == 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2013-07-26 03:10:32 +08:00
|
|
|
#elif defined (__FreeBSD__)
|
|
|
|
lldb::pid_t curr_pid = Host::GetCurrentProcessID();
|
|
|
|
lldb::tid_t curr_tid = Host::GetCurrentThreadID();
|
|
|
|
if (pid == LLDB_INVALID_PROCESS_ID)
|
|
|
|
pid = curr_pid;
|
|
|
|
|
|
|
|
if (tid == LLDB_INVALID_THREAD_ID)
|
|
|
|
tid = curr_tid;
|
|
|
|
|
|
|
|
// Set the pthread name if possible
|
|
|
|
if (pid == curr_pid && tid == curr_tid)
|
|
|
|
{
|
2013-08-02 02:51:08 +08:00
|
|
|
::pthread_set_name_np (::pthread_self(), name);
|
2013-07-26 03:10:32 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2013-07-01 16:21:36 +08:00
|
|
|
#elif defined (__linux__) || defined (__GLIBC__)
|
2013-05-14 03:33:58 +08:00
|
|
|
void *fn = dlsym (RTLD_DEFAULT, "pthread_setname_np");
|
|
|
|
if (fn)
|
|
|
|
{
|
|
|
|
lldb::pid_t curr_pid = Host::GetCurrentProcessID();
|
|
|
|
lldb::tid_t curr_tid = Host::GetCurrentThreadID();
|
|
|
|
if (pid == LLDB_INVALID_PROCESS_ID)
|
|
|
|
pid = curr_pid;
|
|
|
|
|
|
|
|
if (tid == LLDB_INVALID_THREAD_ID)
|
|
|
|
tid = curr_tid;
|
|
|
|
|
2013-08-02 02:51:08 +08:00
|
|
|
if (pid == curr_pid && tid == curr_tid)
|
2013-05-14 03:33:58 +08:00
|
|
|
{
|
2013-08-02 02:51:08 +08:00
|
|
|
int (*pthread_setname_np_func)(pthread_t thread, const char *name);
|
|
|
|
*reinterpret_cast<void **> (&pthread_setname_np_func) = fn;
|
|
|
|
|
|
|
|
if (pthread_setname_np_func (::pthread_self(), name) == 0)
|
2013-05-14 03:33:58 +08:00
|
|
|
return true;
|
|
|
|
}
|
2010-07-03 03:28:44 +08:00
|
|
|
}
|
2013-05-14 03:33:58 +08:00
|
|
|
return false;
|
2013-05-16 02:27:08 +08:00
|
|
|
#else
|
|
|
|
return false;
|
2010-07-03 03:28:44 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-07-26 03:10:32 +08:00
|
|
|
bool
|
|
|
|
Host::SetShortThreadName (lldb::pid_t pid, lldb::tid_t tid,
|
|
|
|
const char *thread_name, size_t len)
|
|
|
|
{
|
2014-02-12 11:37:33 +08:00
|
|
|
std::unique_ptr<char[]> namebuf(new char[len+1]);
|
|
|
|
|
2013-07-26 03:10:32 +08:00
|
|
|
// Thread names are coming in like '<lldb.comm.debugger.edit>' and
|
|
|
|
// '<lldb.comm.debugger.editline>'. So just chopping the end of the string
|
|
|
|
// off leads to a lot of similar named threads. Go through the thread name
|
|
|
|
// and search for the last dot and use that.
|
|
|
|
const char *lastdot = ::strrchr (thread_name, '.');
|
|
|
|
|
|
|
|
if (lastdot && lastdot != thread_name)
|
|
|
|
thread_name = lastdot + 1;
|
2014-02-12 11:37:33 +08:00
|
|
|
::strncpy (namebuf.get(), thread_name, len);
|
2013-07-26 03:10:32 +08:00
|
|
|
namebuf[len] = 0;
|
|
|
|
|
2014-02-12 11:37:33 +08:00
|
|
|
int namebuflen = strlen(namebuf.get());
|
2013-07-26 03:10:32 +08:00
|
|
|
if (namebuflen > 0)
|
|
|
|
{
|
|
|
|
if (namebuf[namebuflen - 1] == '(' || namebuf[namebuflen - 1] == '>')
|
|
|
|
{
|
|
|
|
// Trim off trailing '(' and '>' characters for a bit more cleanup.
|
|
|
|
namebuflen--;
|
|
|
|
namebuf[namebuflen] = 0;
|
|
|
|
}
|
2014-02-12 11:37:33 +08:00
|
|
|
return Host::SetThreadName (pid, tid, namebuf.get());
|
2013-07-26 03:10:32 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#endif
|
|
|
|
|
2010-07-03 03:28:44 +08:00
|
|
|
FileSpec
|
|
|
|
Host::GetProgramFileSpec ()
|
|
|
|
{
|
2010-09-08 04:11:56 +08:00
|
|
|
static FileSpec g_program_filespec;
|
|
|
|
if (!g_program_filespec)
|
2010-07-03 03:28:44 +08:00
|
|
|
{
|
2010-09-08 04:11:56 +08:00
|
|
|
#if defined (__APPLE__)
|
|
|
|
char program_fullpath[PATH_MAX];
|
|
|
|
// If DST is NULL, then return the number of bytes needed.
|
|
|
|
uint32_t len = sizeof(program_fullpath);
|
|
|
|
int err = _NSGetExecutablePath (program_fullpath, &len);
|
|
|
|
if (err == 0)
|
2011-01-13 09:23:43 +08:00
|
|
|
g_program_filespec.SetFile (program_fullpath, false);
|
2010-09-08 04:11:56 +08:00
|
|
|
else if (err == -1)
|
|
|
|
{
|
|
|
|
char *large_program_fullpath = (char *)::malloc (len + 1);
|
|
|
|
|
|
|
|
err = _NSGetExecutablePath (large_program_fullpath, &len);
|
|
|
|
if (err == 0)
|
2011-01-13 09:23:43 +08:00
|
|
|
g_program_filespec.SetFile (large_program_fullpath, false);
|
2010-09-08 04:11:56 +08:00
|
|
|
|
|
|
|
::free (large_program_fullpath);
|
|
|
|
}
|
|
|
|
#elif defined (__linux__)
|
|
|
|
char exe_path[PATH_MAX];
|
2011-01-12 12:21:21 +08:00
|
|
|
ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
|
|
|
|
if (len > 0) {
|
|
|
|
exe_path[len] = 0;
|
2011-01-13 09:23:43 +08:00
|
|
|
g_program_filespec.SetFile(exe_path, false);
|
2011-01-12 12:21:21 +08:00
|
|
|
}
|
2013-07-01 16:21:36 +08:00
|
|
|
#elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
|
2010-09-08 04:11:56 +08:00
|
|
|
int exe_path_mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, getpid() };
|
|
|
|
size_t exe_path_size;
|
|
|
|
if (sysctl(exe_path_mib, 4, NULL, &exe_path_size, NULL, 0) == 0)
|
|
|
|
{
|
2011-01-13 09:27:55 +08:00
|
|
|
char *exe_path = new char[exe_path_size];
|
|
|
|
if (sysctl(exe_path_mib, 4, exe_path, &exe_path_size, NULL, 0) == 0)
|
|
|
|
g_program_filespec.SetFile(exe_path, false);
|
|
|
|
delete[] exe_path;
|
2010-09-08 04:11:56 +08:00
|
|
|
}
|
|
|
|
#endif
|
2010-07-03 03:28:44 +08:00
|
|
|
}
|
2010-09-08 04:11:56 +08:00
|
|
|
return g_program_filespec;
|
2010-07-03 03:28:44 +08:00
|
|
|
}
|
|
|
|
|
2010-09-08 04:11:56 +08:00
|
|
|
#if !defined (__APPLE__) // see Host.mm
|
2012-02-14 07:10:39 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
Host::GetBundleDirectory (const FileSpec &file, FileSpec &bundle)
|
|
|
|
{
|
|
|
|
bundle.Clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-03 03:28:44 +08:00
|
|
|
bool
|
Added a new Host call to find LLDB related paths:
static bool
Host::GetLLDBPath (lldb::PathType path_type, FileSpec &file_spec);
This will fill in "file_spec" with an appropriate path that is appropriate
for the current Host OS. MacOSX will return paths within the LLDB.framework,
and other unixes will return the paths they want. The current PathType
enums are:
typedef enum PathType
{
ePathTypeLLDBShlibDir, // The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists
ePathTypeSupportExecutableDir, // Find LLDB support executable directory (debugserver, etc)
ePathTypeHeaderDir, // Find LLDB header file directory
ePathTypePythonDir // Find Python modules (PYTHONPATH) directory
} PathType;
All places that were finding executables are and python paths are now updated
to use this Host call.
Added another new host call to launch the inferior in a terminal. This ability
will be very host specific and doesn't need to be supported on all systems.
MacOSX currently will create a new .command file and tell Terminal.app to open
the .command file. It also uses the new "darwin-debug" app which is a small
app that uses posix to exec (no fork) and stop at the entry point of the
program. The GDB remote plug-in is almost able launch a process and attach to
it, it currently will spawn the process, but it won't attach to it just yet.
This will let LLDB not have to share the terminal with another process and a
new terminal window will pop up when you launch. This won't get hooked up
until we work out all of the kinks. The new Host function is:
static lldb::pid_t
Host::LaunchInNewTerminal (
const char **argv, // argv[0] is executable
const char **envp,
const ArchSpec *arch_spec,
bool stop_at_entry,
bool disable_aslr);
Cleaned up FileSpec::GetPath to not use strncpy() as it was always zero
filling the entire path buffer.
Fixed an issue with the dynamic checker function where I missed a '$' prefix
that should have been added.
llvm-svn: 116690
2010-10-18 06:03:32 +08:00
|
|
|
Host::ResolveExecutableInBundle (FileSpec &file)
|
2010-07-03 03:28:44 +08:00
|
|
|
{
|
Added a new Host call to find LLDB related paths:
static bool
Host::GetLLDBPath (lldb::PathType path_type, FileSpec &file_spec);
This will fill in "file_spec" with an appropriate path that is appropriate
for the current Host OS. MacOSX will return paths within the LLDB.framework,
and other unixes will return the paths they want. The current PathType
enums are:
typedef enum PathType
{
ePathTypeLLDBShlibDir, // The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists
ePathTypeSupportExecutableDir, // Find LLDB support executable directory (debugserver, etc)
ePathTypeHeaderDir, // Find LLDB header file directory
ePathTypePythonDir // Find Python modules (PYTHONPATH) directory
} PathType;
All places that were finding executables are and python paths are now updated
to use this Host call.
Added another new host call to launch the inferior in a terminal. This ability
will be very host specific and doesn't need to be supported on all systems.
MacOSX currently will create a new .command file and tell Terminal.app to open
the .command file. It also uses the new "darwin-debug" app which is a small
app that uses posix to exec (no fork) and stop at the entry point of the
program. The GDB remote plug-in is almost able launch a process and attach to
it, it currently will spawn the process, but it won't attach to it just yet.
This will let LLDB not have to share the terminal with another process and a
new terminal window will pop up when you launch. This won't get hooked up
until we work out all of the kinks. The new Host function is:
static lldb::pid_t
Host::LaunchInNewTerminal (
const char **argv, // argv[0] is executable
const char **envp,
const ArchSpec *arch_spec,
bool stop_at_entry,
bool disable_aslr);
Cleaned up FileSpec::GetPath to not use strncpy() as it was always zero
filling the entire path buffer.
Fixed an issue with the dynamic checker function where I missed a '$' prefix
that should have been added.
llvm-svn: 116690
2010-10-18 06:03:32 +08:00
|
|
|
return false;
|
2010-07-03 03:28:44 +08:00
|
|
|
}
|
2010-09-08 04:11:56 +08:00
|
|
|
#endif
|
2010-07-03 03:28:44 +08:00
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
2011-02-08 08:35:34 +08:00
|
|
|
// Opaque info that tracks a dynamic library that was loaded
|
|
|
|
struct DynamicLibraryInfo
|
|
|
|
{
|
|
|
|
DynamicLibraryInfo (const FileSpec &fs, int o, void *h) :
|
|
|
|
file_spec (fs),
|
|
|
|
open_options (o),
|
|
|
|
handle (h)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const FileSpec file_spec;
|
|
|
|
uint32_t open_options;
|
|
|
|
void * handle;
|
|
|
|
};
|
|
|
|
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
void *
|
2011-02-08 08:35:34 +08:00
|
|
|
Host::DynamicLibraryOpen (const FileSpec &file_spec, uint32_t options, Error &error)
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
{
|
|
|
|
char path[PATH_MAX];
|
|
|
|
if (file_spec.GetPath(path, sizeof(path)))
|
|
|
|
{
|
2011-02-08 08:35:34 +08:00
|
|
|
int mode = 0;
|
|
|
|
|
|
|
|
if (options & eDynamicLibraryOpenOptionLazy)
|
|
|
|
mode |= RTLD_LAZY;
|
2011-02-08 13:24:57 +08:00
|
|
|
else
|
|
|
|
mode |= RTLD_NOW;
|
|
|
|
|
2011-02-08 08:35:34 +08:00
|
|
|
|
|
|
|
if (options & eDynamicLibraryOpenOptionLocal)
|
|
|
|
mode |= RTLD_LOCAL;
|
|
|
|
else
|
|
|
|
mode |= RTLD_GLOBAL;
|
|
|
|
|
|
|
|
#ifdef LLDB_CONFIG_DLOPEN_RTLD_FIRST_SUPPORTED
|
|
|
|
if (options & eDynamicLibraryOpenOptionLimitGetSymbol)
|
|
|
|
mode |= RTLD_FIRST;
|
2011-02-08 01:43:47 +08:00
|
|
|
#endif
|
2011-02-08 08:35:34 +08:00
|
|
|
|
|
|
|
void * opaque = ::dlopen (path, mode);
|
|
|
|
|
|
|
|
if (opaque)
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
{
|
|
|
|
error.Clear();
|
2011-02-08 08:35:34 +08:00
|
|
|
return new DynamicLibraryInfo (file_spec, options, opaque);
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetErrorString(::dlerror());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetErrorString("failed to extract path");
|
|
|
|
}
|
2011-02-08 08:35:34 +08:00
|
|
|
return NULL;
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
2011-02-08 08:35:34 +08:00
|
|
|
Host::DynamicLibraryClose (void *opaque)
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
{
|
|
|
|
Error error;
|
2011-02-08 08:35:34 +08:00
|
|
|
if (opaque == NULL)
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
{
|
|
|
|
error.SetErrorString ("invalid dynamic library handle");
|
|
|
|
}
|
2011-02-08 08:35:34 +08:00
|
|
|
else
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
{
|
2011-02-08 08:35:34 +08:00
|
|
|
DynamicLibraryInfo *dylib_info = (DynamicLibraryInfo *) opaque;
|
|
|
|
if (::dlclose (dylib_info->handle) != 0)
|
|
|
|
{
|
|
|
|
error.SetErrorString(::dlerror());
|
|
|
|
}
|
|
|
|
|
|
|
|
dylib_info->open_options = 0;
|
|
|
|
dylib_info->handle = 0;
|
|
|
|
delete dylib_info;
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2011-02-08 08:35:34 +08:00
|
|
|
Host::DynamicLibraryGetSymbol (void *opaque, const char *symbol_name, Error &error)
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
{
|
2011-02-08 08:35:34 +08:00
|
|
|
if (opaque == NULL)
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
{
|
|
|
|
error.SetErrorString ("invalid dynamic library handle");
|
|
|
|
}
|
|
|
|
else
|
2011-02-08 08:35:34 +08:00
|
|
|
{
|
|
|
|
DynamicLibraryInfo *dylib_info = (DynamicLibraryInfo *) opaque;
|
|
|
|
|
|
|
|
void *symbol_addr = ::dlsym (dylib_info->handle, symbol_name);
|
|
|
|
if (symbol_addr)
|
|
|
|
{
|
|
|
|
#ifndef LLDB_CONFIG_DLOPEN_RTLD_FIRST_SUPPORTED
|
|
|
|
// This host doesn't support limiting searches to this shared library
|
|
|
|
// so we need to verify that the match came from this shared library
|
|
|
|
// if it was requested in the Host::DynamicLibraryOpen() function.
|
2011-02-08 13:24:57 +08:00
|
|
|
if (dylib_info->open_options & eDynamicLibraryOpenOptionLimitGetSymbol)
|
2011-02-08 08:35:34 +08:00
|
|
|
{
|
|
|
|
FileSpec match_dylib_spec (Host::GetModuleFileSpecForHostAddress (symbol_addr));
|
|
|
|
if (match_dylib_spec != dylib_info->file_spec)
|
|
|
|
{
|
|
|
|
char dylib_path[PATH_MAX];
|
|
|
|
if (dylib_info->file_spec.GetPath (dylib_path, sizeof(dylib_path)))
|
|
|
|
error.SetErrorStringWithFormat ("symbol not found in \"%s\"", dylib_path);
|
|
|
|
else
|
|
|
|
error.SetErrorString ("symbol not found");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
error.Clear();
|
|
|
|
return symbol_addr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetErrorString(::dlerror());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +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
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
FileSpec
|
|
|
|
Host::GetModuleFileSpecForHostAddress (const void *host_addr)
|
|
|
|
{
|
|
|
|
FileSpec module_filespec;
|
|
|
|
Dl_info info;
|
|
|
|
if (::dladdr (host_addr, &info))
|
|
|
|
{
|
|
|
|
if (info.dli_fname)
|
|
|
|
module_filespec.SetFile(info.dli_fname, true);
|
|
|
|
}
|
|
|
|
return module_filespec;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2014-03-25 07:10:19 +08:00
|
|
|
|
|
|
|
static void CleanupProcessSpecificLLDBTempDir ()
|
|
|
|
{
|
|
|
|
// Get the process specific LLDB temporary directory and delete it.
|
|
|
|
FileSpec tmpdir_file_spec;
|
|
|
|
if (Host::GetLLDBPath (ePathTypeLLDBTempSystemDir, tmpdir_file_spec))
|
|
|
|
{
|
|
|
|
// Remove the LLDB temporary directory if we have one. Set "recurse" to
|
|
|
|
// true to all files that were created for the LLDB process can be cleaned up.
|
|
|
|
const bool recurse = true;
|
|
|
|
Host::RemoveDirectory(tmpdir_file_spec.GetDirectory().GetCString(), recurse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
bool
|
|
|
|
Host::GetLLDBPath (PathType path_type, FileSpec &file_spec)
|
|
|
|
{
|
2011-01-09 04:28:42 +08:00
|
|
|
// To get paths related to LLDB we get the path to the executable that
|
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
|
|
|
// contains this function. On MacOSX this will be "LLDB.framework/.../LLDB",
|
|
|
|
// on linux this is assumed to be the "lldb" main executable. If LLDB on
|
2013-07-17 08:26:30 +08:00
|
|
|
// linux is actually in a shared library (liblldb.so) then this function will
|
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
|
|
|
// need to be modified to "do the right thing".
|
2013-11-23 02:48:24 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_HOST);
|
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
|
|
|
|
|
|
|
switch (path_type)
|
|
|
|
{
|
|
|
|
case ePathTypeLLDBShlibDir:
|
|
|
|
{
|
|
|
|
static ConstString g_lldb_so_dir;
|
|
|
|
if (!g_lldb_so_dir)
|
|
|
|
{
|
|
|
|
FileSpec lldb_file_spec (Host::GetModuleFileSpecForHostAddress ((void *)Host::GetLLDBPath));
|
|
|
|
g_lldb_so_dir = lldb_file_spec.GetDirectory();
|
2013-11-23 02:48:24 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("Host::GetLLDBPath(ePathTypeLLDBShlibDir) => '%s'", g_lldb_so_dir.GetCString());
|
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
|
|
|
}
|
|
|
|
file_spec.GetDirectory() = g_lldb_so_dir;
|
2013-10-04 06:27:29 +08:00
|
|
|
return (bool)file_spec.GetDirectory();
|
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
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ePathTypeSupportExecutableDir:
|
|
|
|
{
|
|
|
|
static ConstString g_lldb_support_exe_dir;
|
|
|
|
if (!g_lldb_support_exe_dir)
|
|
|
|
{
|
|
|
|
FileSpec lldb_file_spec;
|
|
|
|
if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec))
|
|
|
|
{
|
|
|
|
char raw_path[PATH_MAX];
|
|
|
|
char resolved_path[PATH_MAX];
|
|
|
|
lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
|
|
|
|
|
|
|
|
#if defined (__APPLE__)
|
|
|
|
char *framework_pos = ::strstr (raw_path, "LLDB.framework");
|
|
|
|
if (framework_pos)
|
|
|
|
{
|
|
|
|
framework_pos += strlen("LLDB.framework");
|
2014-07-09 09:29:05 +08:00
|
|
|
#if defined (__arm__) || defined (__arm64__) || defined (__aarch64__)
|
2013-11-23 02:48:24 +08:00
|
|
|
// Shallow bundle
|
|
|
|
*framework_pos = '\0';
|
|
|
|
#else
|
|
|
|
// Normal bundle
|
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
|
|
|
::strncpy (framework_pos, "/Resources", PATH_MAX - (framework_pos - raw_path));
|
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
|
|
|
}
|
2014-03-30 02:54:20 +08:00
|
|
|
#endif // #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
|
|
|
FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
|
|
|
|
g_lldb_support_exe_dir.SetCString(resolved_path);
|
|
|
|
}
|
2013-11-23 02:48:24 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("Host::GetLLDBPath(ePathTypeSupportExecutableDir) => '%s'", g_lldb_support_exe_dir.GetCString());
|
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
|
|
|
}
|
|
|
|
file_spec.GetDirectory() = g_lldb_support_exe_dir;
|
2013-10-04 06:27:29 +08:00
|
|
|
return (bool)file_spec.GetDirectory();
|
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
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ePathTypeHeaderDir:
|
|
|
|
{
|
|
|
|
static ConstString g_lldb_headers_dir;
|
|
|
|
if (!g_lldb_headers_dir)
|
|
|
|
{
|
|
|
|
#if defined (__APPLE__)
|
|
|
|
FileSpec lldb_file_spec;
|
|
|
|
if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec))
|
|
|
|
{
|
|
|
|
char raw_path[PATH_MAX];
|
|
|
|
char resolved_path[PATH_MAX];
|
|
|
|
lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
|
|
|
|
|
|
|
|
char *framework_pos = ::strstr (raw_path, "LLDB.framework");
|
|
|
|
if (framework_pos)
|
|
|
|
{
|
|
|
|
framework_pos += strlen("LLDB.framework");
|
|
|
|
::strncpy (framework_pos, "/Headers", PATH_MAX - (framework_pos - raw_path));
|
|
|
|
}
|
|
|
|
FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
|
|
|
|
g_lldb_headers_dir.SetCString(resolved_path);
|
|
|
|
}
|
|
|
|
#else
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
// TODO: Anyone know how we can determine this for linux? Other systems??
|
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
|
|
|
g_lldb_headers_dir.SetCString ("/opt/local/include/lldb");
|
|
|
|
#endif
|
2013-11-23 02:48:24 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("Host::GetLLDBPath(ePathTypeHeaderDir) => '%s'", g_lldb_headers_dir.GetCString());
|
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
|
|
|
}
|
|
|
|
file_spec.GetDirectory() = g_lldb_headers_dir;
|
2013-10-04 06:27:29 +08:00
|
|
|
return (bool)file_spec.GetDirectory();
|
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
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-09-26 01:52:18 +08:00
|
|
|
#ifdef LLDB_DISABLE_PYTHON
|
|
|
|
case ePathTypePythonDir:
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
case ePathTypePythonDir:
|
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
|
|
|
{
|
|
|
|
static ConstString g_lldb_python_dir;
|
|
|
|
if (!g_lldb_python_dir)
|
|
|
|
{
|
|
|
|
FileSpec lldb_file_spec;
|
|
|
|
if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec))
|
|
|
|
{
|
|
|
|
char raw_path[PATH_MAX];
|
|
|
|
char resolved_path[PATH_MAX];
|
|
|
|
lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
|
|
|
|
|
|
|
|
#if defined (__APPLE__)
|
|
|
|
char *framework_pos = ::strstr (raw_path, "LLDB.framework");
|
|
|
|
if (framework_pos)
|
|
|
|
{
|
|
|
|
framework_pos += strlen("LLDB.framework");
|
|
|
|
::strncpy (framework_pos, "/Resources/Python", PATH_MAX - (framework_pos - raw_path));
|
2014-01-18 16:05:32 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
llvm::SmallString<256> python_version_dir;
|
|
|
|
llvm::raw_svector_ostream os(python_version_dir);
|
|
|
|
os << "/python" << PY_MAJOR_VERSION << '.' << PY_MINOR_VERSION << "/site-packages";
|
|
|
|
os.flush();
|
2013-01-05 07:35:13 +08:00
|
|
|
|
2014-01-18 16:05:32 +08:00
|
|
|
// We may get our string truncated. Should we protect
|
|
|
|
// this with an assert?
|
2013-01-05 07:35:13 +08:00
|
|
|
|
2014-01-18 16:05:32 +08:00
|
|
|
::strncat(raw_path, python_version_dir.c_str(),
|
|
|
|
sizeof(raw_path) - strlen(raw_path) - 1);
|
2013-01-05 07:35:13 +08:00
|
|
|
|
2014-01-18 16:05:32 +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
|
|
|
#endif
|
|
|
|
FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
|
|
|
|
g_lldb_python_dir.SetCString(resolved_path);
|
|
|
|
}
|
2013-11-23 02:48:24 +08:00
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Printf("Host::GetLLDBPath(ePathTypePythonDir) => '%s'", g_lldb_python_dir.GetCString());
|
|
|
|
|
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
|
|
|
}
|
|
|
|
file_spec.GetDirectory() = g_lldb_python_dir;
|
2013-10-04 06:27:29 +08:00
|
|
|
return (bool)file_spec.GetDirectory();
|
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
|
|
|
}
|
|
|
|
break;
|
2013-07-03 03:30:52 +08:00
|
|
|
#endif
|
|
|
|
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
case ePathTypeLLDBSystemPlugins: // System plug-ins directory
|
|
|
|
{
|
2013-07-17 08:26:30 +08:00
|
|
|
#if defined (__APPLE__) || defined(__linux__)
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
static ConstString g_lldb_system_plugin_dir;
|
2011-03-24 12:28:38 +08:00
|
|
|
static bool g_lldb_system_plugin_dir_located = false;
|
|
|
|
if (!g_lldb_system_plugin_dir_located)
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
{
|
2011-03-24 12:28:38 +08:00
|
|
|
g_lldb_system_plugin_dir_located = true;
|
2013-07-17 08:26:30 +08:00
|
|
|
#if defined (__APPLE__)
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
FileSpec lldb_file_spec;
|
|
|
|
if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec))
|
|
|
|
{
|
|
|
|
char raw_path[PATH_MAX];
|
|
|
|
char resolved_path[PATH_MAX];
|
|
|
|
lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
|
|
|
|
|
|
|
|
char *framework_pos = ::strstr (raw_path, "LLDB.framework");
|
|
|
|
if (framework_pos)
|
|
|
|
{
|
|
|
|
framework_pos += strlen("LLDB.framework");
|
|
|
|
::strncpy (framework_pos, "/Resources/PlugIns", PATH_MAX - (framework_pos - raw_path));
|
2011-03-24 12:28:38 +08:00
|
|
|
FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
|
|
|
|
g_lldb_system_plugin_dir.SetCString(resolved_path);
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
}
|
2011-03-24 12:28:38 +08:00
|
|
|
return false;
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
}
|
2013-07-17 08:26:30 +08:00
|
|
|
#elif defined (__linux__)
|
|
|
|
FileSpec lldb_file_spec("/usr/lib/lldb", true);
|
|
|
|
if (lldb_file_spec.Exists())
|
|
|
|
{
|
|
|
|
g_lldb_system_plugin_dir.SetCString(lldb_file_spec.GetPath().c_str());
|
|
|
|
}
|
|
|
|
#endif // __APPLE__ || __linux__
|
2013-11-23 02:48:24 +08:00
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Printf("Host::GetLLDBPath(ePathTypeLLDBSystemPlugins) => '%s'", g_lldb_system_plugin_dir.GetCString());
|
|
|
|
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
}
|
2011-03-24 12:28:38 +08:00
|
|
|
|
|
|
|
if (g_lldb_system_plugin_dir)
|
|
|
|
{
|
|
|
|
file_spec.GetDirectory() = g_lldb_system_plugin_dir;
|
|
|
|
return true;
|
|
|
|
}
|
2013-07-17 08:26:30 +08:00
|
|
|
#else
|
|
|
|
// TODO: where would system LLDB plug-ins be located on other systems?
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
return false;
|
2013-07-17 08:26:30 +08:00
|
|
|
#endif
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ePathTypeLLDBUserPlugins: // User plug-ins directory
|
|
|
|
{
|
|
|
|
#if defined (__APPLE__)
|
|
|
|
static ConstString g_lldb_user_plugin_dir;
|
|
|
|
if (!g_lldb_user_plugin_dir)
|
|
|
|
{
|
|
|
|
char user_plugin_path[PATH_MAX];
|
|
|
|
if (FileSpec::Resolve ("~/Library/Application Support/LLDB/PlugIns",
|
|
|
|
user_plugin_path,
|
|
|
|
sizeof(user_plugin_path)))
|
|
|
|
{
|
|
|
|
g_lldb_user_plugin_dir.SetCString(user_plugin_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file_spec.GetDirectory() = g_lldb_user_plugin_dir;
|
2013-10-04 06:27:29 +08:00
|
|
|
return (bool)file_spec.GetDirectory();
|
2013-07-17 08:26:30 +08:00
|
|
|
#elif defined (__linux__)
|
|
|
|
static ConstString g_lldb_user_plugin_dir;
|
|
|
|
if (!g_lldb_user_plugin_dir)
|
|
|
|
{
|
|
|
|
// XDG Base Directory Specification
|
|
|
|
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
|
|
|
// If XDG_DATA_HOME exists, use that, otherwise use ~/.local/share/lldb.
|
|
|
|
FileSpec lldb_file_spec;
|
|
|
|
const char *xdg_data_home = getenv("XDG_DATA_HOME");
|
|
|
|
if (xdg_data_home && xdg_data_home[0])
|
|
|
|
{
|
|
|
|
std::string user_plugin_dir (xdg_data_home);
|
|
|
|
user_plugin_dir += "/lldb";
|
|
|
|
lldb_file_spec.SetFile (user_plugin_dir.c_str(), true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *home_dir = getenv("HOME");
|
|
|
|
if (home_dir && home_dir[0])
|
|
|
|
{
|
|
|
|
std::string user_plugin_dir (home_dir);
|
|
|
|
user_plugin_dir += "/.local/share/lldb";
|
|
|
|
lldb_file_spec.SetFile (user_plugin_dir.c_str(), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lldb_file_spec.Exists())
|
|
|
|
g_lldb_user_plugin_dir.SetCString(lldb_file_spec.GetPath().c_str());
|
2013-11-23 02:48:24 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("Host::GetLLDBPath(ePathTypeLLDBUserPlugins) => '%s'", g_lldb_user_plugin_dir.GetCString());
|
2013-07-17 08:26:30 +08:00
|
|
|
}
|
|
|
|
file_spec.GetDirectory() = g_lldb_user_plugin_dir;
|
2013-10-04 06:27:29 +08:00
|
|
|
return (bool)file_spec.GetDirectory();
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
#endif
|
2013-07-17 08:26:30 +08:00
|
|
|
// TODO: where would user LLDB plug-ins be located on other systems?
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
return false;
|
|
|
|
}
|
2013-12-05 02:53:50 +08:00
|
|
|
|
|
|
|
case ePathTypeLLDBTempSystemDir:
|
|
|
|
{
|
|
|
|
static ConstString g_lldb_tmp_dir;
|
|
|
|
if (!g_lldb_tmp_dir)
|
|
|
|
{
|
|
|
|
const char *tmpdir_cstr = getenv("TMPDIR");
|
|
|
|
if (tmpdir_cstr == NULL)
|
|
|
|
{
|
|
|
|
tmpdir_cstr = getenv("TMP");
|
|
|
|
if (tmpdir_cstr == NULL)
|
|
|
|
tmpdir_cstr = getenv("TEMP");
|
|
|
|
}
|
|
|
|
if (tmpdir_cstr)
|
|
|
|
{
|
2014-03-25 07:10:19 +08:00
|
|
|
StreamString pid_tmpdir;
|
|
|
|
pid_tmpdir.Printf("%s/lldb", tmpdir_cstr);
|
|
|
|
if (Host::MakeDirectory(pid_tmpdir.GetString().c_str(), eFilePermissionsDirectoryDefault).Success())
|
|
|
|
{
|
|
|
|
pid_tmpdir.Printf("/%" PRIu64, Host::GetCurrentProcessID());
|
|
|
|
if (Host::MakeDirectory(pid_tmpdir.GetString().c_str(), eFilePermissionsDirectoryDefault).Success())
|
|
|
|
{
|
|
|
|
// Make an atexit handler to clean up the process specify LLDB temp dir
|
|
|
|
// and all of its contents.
|
|
|
|
::atexit (CleanupProcessSpecificLLDBTempDir);
|
|
|
|
g_lldb_tmp_dir.SetCString(pid_tmpdir.GetString().c_str());
|
|
|
|
if (log)
|
|
|
|
log->Printf("Host::GetLLDBPath(ePathTypeLLDBTempSystemDir) => '%s'", g_lldb_tmp_dir.GetCString());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2013-12-05 02:53:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
file_spec.GetDirectory() = g_lldb_tmp_dir;
|
|
|
|
return (bool)file_spec.GetDirectory();
|
|
|
|
}
|
Added a new Host call to find LLDB related paths:
static bool
Host::GetLLDBPath (lldb::PathType path_type, FileSpec &file_spec);
This will fill in "file_spec" with an appropriate path that is appropriate
for the current Host OS. MacOSX will return paths within the LLDB.framework,
and other unixes will return the paths they want. The current PathType
enums are:
typedef enum PathType
{
ePathTypeLLDBShlibDir, // The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists
ePathTypeSupportExecutableDir, // Find LLDB support executable directory (debugserver, etc)
ePathTypeHeaderDir, // Find LLDB header file directory
ePathTypePythonDir // Find Python modules (PYTHONPATH) directory
} PathType;
All places that were finding executables are and python paths are now updated
to use this Host call.
Added another new host call to launch the inferior in a terminal. This ability
will be very host specific and doesn't need to be supported on all systems.
MacOSX currently will create a new .command file and tell Terminal.app to open
the .command file. It also uses the new "darwin-debug" app which is a small
app that uses posix to exec (no fork) and stop at the entry point of the
program. The GDB remote plug-in is almost able launch a process and attach to
it, it currently will spawn the process, but it won't attach to it just yet.
This will let LLDB not have to share the terminal with another process and a
new terminal window will pop up when you launch. This won't get hooked up
until we work out all of the kinks. The new Host function is:
static lldb::pid_t
Host::LaunchInNewTerminal (
const char **argv, // argv[0] is executable
const char **envp,
const ArchSpec *arch_spec,
bool stop_at_entry,
bool disable_aslr);
Cleaned up FileSpec::GetPath to not use strncpy() as it was always zero
filling the entire path buffer.
Fixed an issue with the dynamic checker function where I missed a '$' prefix
that should have been added.
llvm-svn: 116690
2010-10-18 06:03:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-24 12:28:38 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
Host::GetHostname (std::string &s)
|
|
|
|
{
|
|
|
|
char hostname[PATH_MAX];
|
|
|
|
hostname[sizeof(hostname) - 1] = '\0';
|
|
|
|
if (::gethostname (hostname, sizeof(hostname) - 1) == 0)
|
|
|
|
{
|
|
|
|
struct hostent* h = ::gethostbyname (hostname);
|
|
|
|
if (h)
|
|
|
|
s.assign (h->h_name);
|
|
|
|
else
|
|
|
|
s.assign (hostname);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
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
|
|
|
const char *
|
|
|
|
Host::GetUserName (uint32_t uid, std::string &user_name)
|
|
|
|
{
|
|
|
|
struct passwd user_info;
|
|
|
|
struct passwd *user_info_ptr = &user_info;
|
|
|
|
char user_buffer[PATH_MAX];
|
|
|
|
size_t user_buffer_size = sizeof(user_buffer);
|
|
|
|
if (::getpwuid_r (uid,
|
|
|
|
&user_info,
|
|
|
|
user_buffer,
|
|
|
|
user_buffer_size,
|
|
|
|
&user_info_ptr) == 0)
|
|
|
|
{
|
|
|
|
if (user_info_ptr)
|
|
|
|
{
|
|
|
|
user_name.assign (user_info_ptr->pw_name);
|
|
|
|
return user_name.c_str();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
user_name.clear();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
Host::GetGroupName (uint32_t gid, std::string &group_name)
|
|
|
|
{
|
|
|
|
char group_buffer[PATH_MAX];
|
|
|
|
size_t group_buffer_size = sizeof(group_buffer);
|
|
|
|
struct group group_info;
|
|
|
|
struct group *group_info_ptr = &group_info;
|
|
|
|
// Try the threadsafe version first
|
|
|
|
if (::getgrgid_r (gid,
|
|
|
|
&group_info,
|
|
|
|
group_buffer,
|
|
|
|
group_buffer_size,
|
|
|
|
&group_info_ptr) == 0)
|
|
|
|
{
|
|
|
|
if (group_info_ptr)
|
|
|
|
{
|
|
|
|
group_name.assign (group_info_ptr->gr_name);
|
|
|
|
return group_name.c_str();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The threadsafe version isn't currently working
|
|
|
|
// for me on darwin, but the non-threadsafe version
|
|
|
|
// is, so I am calling it below.
|
|
|
|
group_info_ptr = ::getgrgid (gid);
|
|
|
|
if (group_info_ptr)
|
|
|
|
{
|
|
|
|
group_name.assign (group_info_ptr->gr_name);
|
|
|
|
return group_name.c_str();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
group_name.clear();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-25 09:07:38 +08:00
|
|
|
uint32_t
|
|
|
|
Host::GetUserID ()
|
|
|
|
{
|
|
|
|
return getuid();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Host::GetGroupID ()
|
|
|
|
{
|
|
|
|
return getgid();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Host::GetEffectiveUserID ()
|
|
|
|
{
|
|
|
|
return geteuid();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Host::GetEffectiveGroupID ()
|
|
|
|
{
|
|
|
|
return getegid();
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__FreeBSD_kernel__) // see macosx/Host.mm
|
|
|
|
bool
|
|
|
|
Host::GetOSBuildString (std::string &s)
|
|
|
|
{
|
|
|
|
s.clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Host::GetOSKernelDescription (std::string &s)
|
|
|
|
{
|
|
|
|
s.clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-07-08 12:52:15 +08:00
|
|
|
#if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__FreeBSD_kernel__) \
|
|
|
|
&& !defined(__linux__) && !defined(_WIN32)
|
2011-03-09 06:40:15 +08:00
|
|
|
uint32_t
|
2011-04-12 13:54:46 +08:00
|
|
|
Host::FindProcesses (const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos)
|
2011-03-09 06:40:15 +08:00
|
|
|
{
|
|
|
|
process_infos.Clear();
|
|
|
|
return process_infos.GetSize();
|
2010-07-03 03:28:44 +08:00
|
|
|
}
|
|
|
|
|
2011-03-09 06:40:15 +08:00
|
|
|
bool
|
2011-04-12 13:54:46 +08:00
|
|
|
Host::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
|
2010-07-03 03:28:44 +08:00
|
|
|
{
|
2011-03-09 06:40:15 +08:00
|
|
|
process_info.Clear();
|
|
|
|
return false;
|
2010-07-03 03:28:44 +08:00
|
|
|
}
|
2011-08-03 04:52:42 +08:00
|
|
|
#endif
|
2010-07-03 03:28:44 +08:00
|
|
|
|
2013-06-01 06:00:07 +08:00
|
|
|
#if !defined(__linux__)
|
|
|
|
bool
|
|
|
|
Host::FindProcessThreads (const lldb::pid_t pid, TidMap &tids_to_attach)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-10-28 05:22:25 +08:00
|
|
|
lldb::TargetSP
|
|
|
|
Host::GetDummyTarget (lldb_private::Debugger &debugger)
|
|
|
|
{
|
2012-05-19 17:59:08 +08:00
|
|
|
static TargetSP g_dummy_target_sp;
|
|
|
|
|
|
|
|
// FIXME: Maybe the dummy target should be per-Debugger
|
|
|
|
if (!g_dummy_target_sp || !g_dummy_target_sp->IsValid())
|
|
|
|
{
|
|
|
|
ArchSpec arch(Target::GetDefaultArchitecture());
|
|
|
|
if (!arch.IsValid())
|
|
|
|
arch = Host::GetArchitecture ();
|
|
|
|
Error err = debugger.GetTargetList().CreateTarget(debugger,
|
2012-10-19 00:33:33 +08:00
|
|
|
NULL,
|
2012-05-19 17:59:08 +08:00
|
|
|
arch.GetTriple().getTriple().c_str(),
|
|
|
|
false,
|
|
|
|
NULL,
|
|
|
|
g_dummy_target_sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_dummy_target_sp;
|
2011-10-28 05:22:25 +08:00
|
|
|
}
|
|
|
|
|
2012-04-14 09:42:46 +08:00
|
|
|
struct ShellInfo
|
|
|
|
{
|
|
|
|
ShellInfo () :
|
|
|
|
process_reaped (false),
|
|
|
|
can_delete (false),
|
|
|
|
pid (LLDB_INVALID_PROCESS_ID),
|
|
|
|
signo(-1),
|
|
|
|
status(-1)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb_private::Predicate<bool> process_reaped;
|
|
|
|
lldb_private::Predicate<bool> can_delete;
|
|
|
|
lldb::pid_t pid;
|
|
|
|
int signo;
|
|
|
|
int status;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
MonitorShellCommand (void *callback_baton,
|
|
|
|
lldb::pid_t pid,
|
|
|
|
bool exited, // True if the process did exit
|
|
|
|
int signo, // Zero for no signal
|
|
|
|
int status) // Exit value of process if signal is zero
|
|
|
|
{
|
|
|
|
ShellInfo *shell_info = (ShellInfo *)callback_baton;
|
|
|
|
shell_info->pid = pid;
|
|
|
|
shell_info->signo = signo;
|
|
|
|
shell_info->status = status;
|
|
|
|
// Let the thread running Host::RunShellCommand() know that the process
|
|
|
|
// exited and that ShellInfo has been filled in by broadcasting to it
|
|
|
|
shell_info->process_reaped.SetValue(1, eBroadcastAlways);
|
|
|
|
// Now wait for a handshake back from that thread running Host::RunShellCommand
|
|
|
|
// so we know that we can delete shell_info_ptr
|
|
|
|
shell_info->can_delete.WaitForValueEqualTo(true);
|
|
|
|
// Sleep a bit to allow the shell_info->can_delete.SetValue() to complete...
|
|
|
|
usleep(1000);
|
|
|
|
// Now delete the shell info that was passed into this function
|
|
|
|
delete shell_info;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
|
|
|
Host::RunShellCommand (const char *command,
|
|
|
|
const char *working_dir,
|
|
|
|
int *status_ptr,
|
|
|
|
int *signo_ptr,
|
|
|
|
std::string *command_output_ptr,
|
2012-09-27 11:13:55 +08:00
|
|
|
uint32_t timeout_sec,
|
|
|
|
const char *shell)
|
2012-04-14 09:42:46 +08:00
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
ProcessLaunchInfo launch_info;
|
2012-09-27 11:13:55 +08:00
|
|
|
if (shell && shell[0])
|
|
|
|
{
|
|
|
|
// Run the command in a shell
|
|
|
|
launch_info.SetShell(shell);
|
|
|
|
launch_info.GetArguments().AppendArgument(command);
|
|
|
|
const bool localhost = true;
|
|
|
|
const bool will_debug = false;
|
|
|
|
const bool first_arg_is_full_shell_command = true;
|
|
|
|
launch_info.ConvertArgumentsForLaunchingInShell (error,
|
|
|
|
localhost,
|
|
|
|
will_debug,
|
2013-09-10 10:09:47 +08:00
|
|
|
first_arg_is_full_shell_command,
|
|
|
|
0);
|
2012-09-27 11:13:55 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No shell, just run it
|
|
|
|
Args args (command);
|
|
|
|
const bool first_arg_is_executable = true;
|
2012-10-18 06:57:12 +08:00
|
|
|
launch_info.SetArguments(args, first_arg_is_executable);
|
2012-09-27 11:13:55 +08:00
|
|
|
}
|
2012-04-14 09:42:46 +08:00
|
|
|
|
|
|
|
if (working_dir)
|
|
|
|
launch_info.SetWorkingDirectory(working_dir);
|
2013-12-05 02:53:50 +08:00
|
|
|
char output_file_path_buffer[PATH_MAX];
|
2012-04-14 09:42:46 +08:00
|
|
|
const char *output_file_path = NULL;
|
2013-12-05 02:53:50 +08:00
|
|
|
|
2012-04-14 09:42:46 +08:00
|
|
|
if (command_output_ptr)
|
|
|
|
{
|
|
|
|
// Create a temporary file to get the stdout/stderr and redirect the
|
|
|
|
// output of the command into this file. We will later read this file
|
|
|
|
// if all goes well and fill the data into "command_output_ptr"
|
2013-12-05 02:53:50 +08:00
|
|
|
FileSpec tmpdir_file_spec;
|
|
|
|
if (Host::GetLLDBPath (ePathTypeLLDBTempSystemDir, tmpdir_file_spec))
|
|
|
|
{
|
|
|
|
tmpdir_file_spec.GetFilename().SetCString("lldb-shell-output.XXXXXX");
|
|
|
|
strncpy(output_file_path_buffer, tmpdir_file_spec.GetPath().c_str(), sizeof(output_file_path_buffer));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strncpy(output_file_path_buffer, "/tmp/lldb-shell-output.XXXXXX", sizeof(output_file_path_buffer));
|
|
|
|
}
|
|
|
|
|
|
|
|
output_file_path = ::mktemp(output_file_path_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false);
|
|
|
|
if (output_file_path)
|
|
|
|
{
|
2012-04-14 09:42:46 +08:00
|
|
|
launch_info.AppendOpenFileAction(STDOUT_FILENO, output_file_path, false, true);
|
2012-09-27 11:13:55 +08:00
|
|
|
launch_info.AppendDuplicateFileAction(STDOUT_FILENO, STDERR_FILENO);
|
2012-04-14 09:42:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
launch_info.AppendSuppressFileAction (STDOUT_FILENO, false, true);
|
|
|
|
launch_info.AppendSuppressFileAction (STDERR_FILENO, false, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The process monitor callback will delete the 'shell_info_ptr' below...
|
2013-04-19 06:45:39 +08:00
|
|
|
std::unique_ptr<ShellInfo> shell_info_ap (new ShellInfo());
|
2012-04-14 09:42:46 +08:00
|
|
|
|
|
|
|
const bool monitor_signals = false;
|
|
|
|
launch_info.SetMonitorProcessCallback(MonitorShellCommand, shell_info_ap.get(), monitor_signals);
|
|
|
|
|
|
|
|
error = LaunchProcess (launch_info);
|
|
|
|
const lldb::pid_t pid = launch_info.GetProcessID();
|
2013-08-27 07:57:52 +08:00
|
|
|
|
|
|
|
if (error.Success() && pid == LLDB_INVALID_PROCESS_ID)
|
|
|
|
error.SetErrorString("failed to get process ID");
|
|
|
|
|
|
|
|
if (error.Success())
|
2012-04-14 09:42:46 +08:00
|
|
|
{
|
|
|
|
// The process successfully launched, so we can defer ownership of
|
|
|
|
// "shell_info" to the MonitorShellCommand callback function that will
|
2013-04-19 02:10:51 +08:00
|
|
|
// get called when the process dies. We release the unique pointer as it
|
2012-04-14 09:42:46 +08:00
|
|
|
// doesn't need to delete the ShellInfo anymore.
|
|
|
|
ShellInfo *shell_info = shell_info_ap.release();
|
2013-08-28 04:58:59 +08:00
|
|
|
TimeValue *timeout_ptr = nullptr;
|
2012-04-14 09:42:46 +08:00
|
|
|
TimeValue timeout_time(TimeValue::Now());
|
2013-08-28 04:58:59 +08:00
|
|
|
if (timeout_sec > 0) {
|
|
|
|
timeout_time.OffsetWithSeconds(timeout_sec);
|
|
|
|
timeout_ptr = &timeout_time;
|
|
|
|
}
|
2012-04-14 09:42:46 +08:00
|
|
|
bool timed_out = false;
|
2013-08-28 04:58:59 +08:00
|
|
|
shell_info->process_reaped.WaitForValueEqualTo(true, timeout_ptr, &timed_out);
|
2012-04-14 09:42:46 +08:00
|
|
|
if (timed_out)
|
|
|
|
{
|
|
|
|
error.SetErrorString("timed out waiting for shell command to complete");
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2014-07-02 05:22:11 +08:00
|
|
|
// Kill the process since it didn't complete within the timeout specified
|
2013-08-23 20:44:05 +08:00
|
|
|
Kill (pid, SIGKILL);
|
2012-04-14 09:42:46 +08:00
|
|
|
// Wait for the monitor callback to get the message
|
|
|
|
timeout_time = TimeValue::Now();
|
|
|
|
timeout_time.OffsetWithSeconds(1);
|
|
|
|
timed_out = false;
|
|
|
|
shell_info->process_reaped.WaitForValueEqualTo(true, &timeout_time, &timed_out);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (status_ptr)
|
|
|
|
*status_ptr = shell_info->status;
|
|
|
|
|
|
|
|
if (signo_ptr)
|
|
|
|
*signo_ptr = shell_info->signo;
|
|
|
|
|
|
|
|
if (command_output_ptr)
|
|
|
|
{
|
|
|
|
command_output_ptr->clear();
|
|
|
|
FileSpec file_spec(output_file_path, File::eOpenOptionRead);
|
|
|
|
uint64_t file_size = file_spec.GetByteSize();
|
|
|
|
if (file_size > 0)
|
|
|
|
{
|
|
|
|
if (file_size > command_output_ptr->max_size())
|
|
|
|
{
|
|
|
|
error.SetErrorStringWithFormat("shell command output is too large to fit into a std::string");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
command_output_ptr->resize(file_size);
|
|
|
|
file_spec.ReadFileContents(0, &((*command_output_ptr)[0]), command_output_ptr->size(), &error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
shell_info->can_delete.SetValue(true, eBroadcastAlways);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (output_file_path)
|
|
|
|
::unlink (output_file_path);
|
|
|
|
// Handshake with the monitor thread, or just let it know in advance that
|
|
|
|
// it can delete "shell_info" in case we timed out and were not able to kill
|
|
|
|
// the process...
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
// LaunchProcessPosixSpawn for Apple, Linux, FreeBSD and other GLIBC
|
|
|
|
// systems
|
|
|
|
|
2014-05-03 03:09:40 +08:00
|
|
|
#if defined (__APPLE__) || defined (__linux__) || defined (__FreeBSD__) || defined (__GLIBC__) || defined(__NetBSD__)
|
2014-01-23 08:52:28 +08:00
|
|
|
|
|
|
|
// this method needs to be visible to macosx/Host.cpp and
|
|
|
|
// common/Host.cpp.
|
|
|
|
|
|
|
|
short
|
|
|
|
Host::GetPosixspawnFlags (ProcessLaunchInfo &launch_info)
|
|
|
|
{
|
|
|
|
short flags = POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK;
|
|
|
|
|
|
|
|
#if defined (__APPLE__)
|
|
|
|
if (launch_info.GetFlags().Test (eLaunchFlagExec))
|
|
|
|
flags |= POSIX_SPAWN_SETEXEC; // Darwin specific posix_spawn flag
|
|
|
|
|
|
|
|
if (launch_info.GetFlags().Test (eLaunchFlagDebug))
|
|
|
|
flags |= POSIX_SPAWN_START_SUSPENDED; // Darwin specific posix_spawn flag
|
|
|
|
|
|
|
|
if (launch_info.GetFlags().Test (eLaunchFlagDisableASLR))
|
|
|
|
flags |= _POSIX_SPAWN_DISABLE_ASLR; // Darwin specific posix_spawn flag
|
|
|
|
|
|
|
|
if (launch_info.GetLaunchInSeparateProcessGroup())
|
|
|
|
flags |= POSIX_SPAWN_SETPGROUP;
|
|
|
|
|
|
|
|
#ifdef POSIX_SPAWN_CLOEXEC_DEFAULT
|
|
|
|
#if defined (__APPLE__) && (defined (__x86_64__) || defined (__i386__))
|
|
|
|
static LazyBool g_use_close_on_exec_flag = eLazyBoolCalculate;
|
|
|
|
if (g_use_close_on_exec_flag == eLazyBoolCalculate)
|
|
|
|
{
|
|
|
|
g_use_close_on_exec_flag = eLazyBoolNo;
|
|
|
|
|
|
|
|
uint32_t major, minor, update;
|
|
|
|
if (Host::GetOSVersion(major, minor, update))
|
|
|
|
{
|
|
|
|
// Kernel panic if we use the POSIX_SPAWN_CLOEXEC_DEFAULT on 10.7 or earlier
|
|
|
|
if (major > 10 || (major == 10 && minor > 7))
|
|
|
|
{
|
|
|
|
// Only enable for 10.8 and later OS versions
|
|
|
|
g_use_close_on_exec_flag = eLazyBoolYes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static LazyBool g_use_close_on_exec_flag = eLazyBoolYes;
|
|
|
|
#endif
|
|
|
|
// Close all files exception those with file actions if this is supported.
|
|
|
|
if (g_use_close_on_exec_flag == eLazyBoolYes)
|
|
|
|
flags |= POSIX_SPAWN_CLOEXEC_DEFAULT;
|
|
|
|
#endif
|
|
|
|
#endif // #if defined (__APPLE__)
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
|
|
|
Host::LaunchProcessPosixSpawn (const char *exe_path, ProcessLaunchInfo &launch_info, ::pid_t &pid)
|
2013-08-28 04:58:59 +08:00
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_HOST | LIBLLDB_LOG_PROCESS));
|
|
|
|
|
|
|
|
posix_spawnattr_t attr;
|
|
|
|
error.SetError( ::posix_spawnattr_init (&attr), eErrorTypePOSIX);
|
2014-01-23 08:52:28 +08:00
|
|
|
|
|
|
|
if (error.Fail() || log)
|
|
|
|
error.PutToLog(log, "::posix_spawnattr_init ( &attr )");
|
2013-08-28 04:58:59 +08:00
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
|
|
|
|
// Make a quick class that will cleanup the posix spawn attributes in case
|
|
|
|
// we return in the middle of this function.
|
|
|
|
lldb_utility::CleanUp <posix_spawnattr_t *, int> posix_spawnattr_cleanup(&attr, posix_spawnattr_destroy);
|
|
|
|
|
|
|
|
sigset_t no_signals;
|
|
|
|
sigset_t all_signals;
|
|
|
|
sigemptyset (&no_signals);
|
|
|
|
sigfillset (&all_signals);
|
2014-01-23 08:52:28 +08:00
|
|
|
::posix_spawnattr_setsigmask(&attr, &no_signals);
|
2014-01-24 01:07:54 +08:00
|
|
|
#if defined (__linux__) || defined (__FreeBSD__)
|
2013-08-28 04:58:59 +08:00
|
|
|
::posix_spawnattr_setsigdefault(&attr, &no_signals);
|
2014-01-23 08:52:28 +08:00
|
|
|
#else
|
|
|
|
::posix_spawnattr_setsigdefault(&attr, &all_signals);
|
|
|
|
#endif
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
short flags = GetPosixspawnFlags(launch_info);
|
2013-08-28 04:58:59 +08:00
|
|
|
|
|
|
|
error.SetError( ::posix_spawnattr_setflags (&attr, flags), eErrorTypePOSIX);
|
2014-01-23 08:52:28 +08:00
|
|
|
if (error.Fail() || log)
|
|
|
|
error.PutToLog(log, "::posix_spawnattr_setflags ( &attr, flags=0x%8.8x )", flags);
|
2013-08-28 04:58:59 +08:00
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
// posix_spawnattr_setbinpref_np appears to be an Apple extension per:
|
|
|
|
// http://www.unix.com/man-page/OSX/3/posix_spawnattr_setbinpref_np/
|
|
|
|
#if defined (__APPLE__) && !defined (__arm__)
|
2014-02-21 09:25:21 +08:00
|
|
|
|
|
|
|
// Don't set the binpref if a shell was provided. After all, that's only going to affect what version of the shell
|
|
|
|
// is launched, not what fork of the binary is launched. We insert "arch --arch <ARCH> as part of the shell invocation
|
|
|
|
// to do that job on OSX.
|
|
|
|
|
|
|
|
if (launch_info.GetShell() == nullptr)
|
2013-08-28 04:58:59 +08:00
|
|
|
{
|
2014-02-21 09:25:21 +08:00
|
|
|
// We don't need to do this for ARM, and we really shouldn't now that we
|
|
|
|
// have multiple CPU subtypes and no posix_spawnattr call that allows us
|
|
|
|
// to set which CPU subtype to launch...
|
|
|
|
const ArchSpec &arch_spec = launch_info.GetArchitecture();
|
|
|
|
cpu_type_t cpu = arch_spec.GetMachOCPUType();
|
|
|
|
cpu_type_t sub = arch_spec.GetMachOCPUSubType();
|
|
|
|
if (cpu != 0 &&
|
2014-04-02 11:51:35 +08:00
|
|
|
cpu != static_cast<cpu_type_t>(UINT32_MAX) &&
|
|
|
|
cpu != static_cast<cpu_type_t>(LLDB_INVALID_CPUTYPE) &&
|
2014-02-21 09:25:21 +08:00
|
|
|
!(cpu == 0x01000007 && sub == 8)) // If haswell is specified, don't try to set the CPU type or we will fail
|
|
|
|
{
|
|
|
|
size_t ocount = 0;
|
|
|
|
error.SetError( ::posix_spawnattr_setbinpref_np (&attr, 1, &cpu, &ocount), eErrorTypePOSIX);
|
|
|
|
if (error.Fail() || log)
|
|
|
|
error.PutToLog(log, "::posix_spawnattr_setbinpref_np ( &attr, 1, cpu_type = 0x%8.8x, count => %llu )", cpu, (uint64_t)ocount);
|
2014-01-23 08:52:28 +08:00
|
|
|
|
2014-02-21 09:25:21 +08:00
|
|
|
if (error.Fail() || ocount != 1)
|
|
|
|
return error;
|
|
|
|
}
|
2014-01-23 08:52:28 +08:00
|
|
|
}
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
#endif
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
const char *tmp_argv[2];
|
|
|
|
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;
|
2013-08-28 04:58:59 +08:00
|
|
|
}
|
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
#if !defined (__APPLE__)
|
|
|
|
// manage the working directory
|
2013-08-28 04:58:59 +08:00
|
|
|
char current_dir[PATH_MAX];
|
|
|
|
current_dir[0] = '\0';
|
2014-01-23 08:52:28 +08:00
|
|
|
#endif
|
2013-08-28 04:58:59 +08:00
|
|
|
|
|
|
|
const char *working_dir = launch_info.GetWorkingDirectory();
|
2014-01-23 08:52:28 +08:00
|
|
|
if (working_dir)
|
2013-08-28 04:58:59 +08:00
|
|
|
{
|
2014-01-23 08:52:28 +08:00
|
|
|
#if defined (__APPLE__)
|
|
|
|
// Set the working directory on this thread only
|
|
|
|
if (__pthread_chdir (working_dir) < 0) {
|
|
|
|
if (errno == ENOENT) {
|
|
|
|
error.SetErrorStringWithFormat("No such file or directory: %s", working_dir);
|
|
|
|
} else if (errno == ENOTDIR) {
|
|
|
|
error.SetErrorStringWithFormat("Path doesn't name a directory: %s", working_dir);
|
|
|
|
} else {
|
|
|
|
error.SetErrorStringWithFormat("An unknown error occurred when changing directory for process execution.");
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
#else
|
2013-08-28 04:58:59 +08:00
|
|
|
if (::getcwd(current_dir, sizeof(current_dir)) == NULL)
|
|
|
|
{
|
|
|
|
error.SetError(errno, eErrorTypePOSIX);
|
|
|
|
error.LogIfError(log, "unable to save the current directory");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (::chdir(working_dir) == -1)
|
|
|
|
{
|
|
|
|
error.SetError(errno, eErrorTypePOSIX);
|
|
|
|
error.LogIfError(log, "unable to change working directory to %s", working_dir);
|
|
|
|
return error;
|
|
|
|
}
|
2014-01-23 08:52:28 +08:00
|
|
|
#endif
|
2013-08-28 04:58:59 +08:00
|
|
|
}
|
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
const size_t num_file_actions = launch_info.GetNumFileActions ();
|
|
|
|
if (num_file_actions > 0)
|
2013-08-28 04:58:59 +08:00
|
|
|
{
|
2014-01-23 08:52:28 +08:00
|
|
|
posix_spawn_file_actions_t file_actions;
|
|
|
|
error.SetError( ::posix_spawn_file_actions_init (&file_actions), eErrorTypePOSIX);
|
|
|
|
if (error.Fail() || log)
|
|
|
|
error.PutToLog(log, "::posix_spawn_file_actions_init ( &file_actions )");
|
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
|
|
|
|
// Make a quick class that will cleanup the posix spawn attributes in case
|
|
|
|
// we return in the middle of this function.
|
|
|
|
lldb_utility::CleanUp <posix_spawn_file_actions_t *, int> posix_spawn_file_actions_cleanup (&file_actions, posix_spawn_file_actions_destroy);
|
|
|
|
|
|
|
|
for (size_t i=0; i<num_file_actions; ++i)
|
|
|
|
{
|
|
|
|
const ProcessLaunchInfo::FileAction *launch_file_action = launch_info.GetFileActionAtIndex(i);
|
|
|
|
if (launch_file_action)
|
|
|
|
{
|
|
|
|
if (!ProcessLaunchInfo::FileAction::AddPosixSpawnFileAction (&file_actions,
|
|
|
|
launch_file_action,
|
|
|
|
log,
|
|
|
|
error))
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
error.SetError (::posix_spawnp (&pid,
|
|
|
|
exe_path,
|
|
|
|
&file_actions,
|
|
|
|
&attr,
|
|
|
|
argv,
|
|
|
|
envp),
|
|
|
|
eErrorTypePOSIX);
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
if (error.Fail() || log)
|
|
|
|
{
|
|
|
|
error.PutToLog(log, "::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )",
|
2014-04-04 12:06:10 +08:00
|
|
|
pid, exe_path, static_cast<void*>(&file_actions),
|
|
|
|
static_cast<void*>(&attr),
|
|
|
|
reinterpret_cast<const void*>(argv),
|
|
|
|
reinterpret_cast<const void*>(envp));
|
2014-01-23 08:52:28 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
for (int ii=0; argv[ii]; ++ii)
|
|
|
|
log->Printf("argv[%i] = '%s'", ii, argv[ii]);
|
|
|
|
}
|
|
|
|
}
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetError (::posix_spawnp (&pid,
|
|
|
|
exe_path,
|
|
|
|
NULL,
|
|
|
|
&attr,
|
|
|
|
argv,
|
|
|
|
envp),
|
|
|
|
eErrorTypePOSIX);
|
|
|
|
|
|
|
|
if (error.Fail() || log)
|
|
|
|
{
|
|
|
|
error.PutToLog(log, "::posix_spawnp ( pid => %i, path = '%s', file_actions = NULL, attr = %p, argv = %p, envp = %p )",
|
2014-04-04 12:06:10 +08:00
|
|
|
pid, exe_path, static_cast<void*>(&attr),
|
|
|
|
reinterpret_cast<const void*>(argv),
|
|
|
|
reinterpret_cast<const void*>(envp));
|
2014-01-23 08:52:28 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
for (int ii=0; argv[ii]; ++ii)
|
|
|
|
log->Printf("argv[%i] = '%s'", ii, argv[ii]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (working_dir)
|
2013-08-28 04:58:59 +08:00
|
|
|
{
|
2014-01-23 08:52:28 +08:00
|
|
|
#if defined (__APPLE__)
|
|
|
|
// No more thread specific current working directory
|
|
|
|
__pthread_fchdir (-1);
|
|
|
|
#else
|
|
|
|
if (::chdir(current_dir) == -1 && error.Success())
|
|
|
|
{
|
|
|
|
error.SetError(errno, eErrorTypePOSIX);
|
|
|
|
error.LogIfError(log, "unable to change current directory back to %s",
|
|
|
|
current_dir);
|
|
|
|
}
|
|
|
|
#endif
|
2013-08-28 04:58:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
#endif // LaunchProcedssPosixSpawn: Apple, Linux, FreeBSD and other GLIBC systems
|
|
|
|
|
|
|
|
|
2014-05-03 03:09:40 +08:00
|
|
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__GLIBC__) || defined(__NetBSD__)
|
|
|
|
// The functions below implement process launching via posix_spawn() for Linux,
|
|
|
|
// FreeBSD and NetBSD.
|
2013-08-28 04:58:59 +08:00
|
|
|
|
|
|
|
Error
|
|
|
|
Host::LaunchProcess (ProcessLaunchInfo &launch_info)
|
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
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,
|
|
|
|
exe_module_sp,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(!launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY));
|
|
|
|
|
|
|
|
::pid_t pid = LLDB_INVALID_PROCESS_ID;
|
|
|
|
|
|
|
|
error = LaunchProcessPosixSpawn(exe_path, launch_info, pid);
|
|
|
|
|
|
|
|
if (pid != LLDB_INVALID_PROCESS_ID)
|
|
|
|
{
|
|
|
|
// If all went well, then set the process ID into the launch info
|
|
|
|
launch_info.SetProcessID(pid);
|
|
|
|
|
2014-01-23 08:52:28 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
|
|
|
|
|
2013-08-28 04:58:59 +08:00
|
|
|
// 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);
|
2014-01-23 08:52:28 +08:00
|
|
|
if (log)
|
|
|
|
log->PutCString ("monitored child process with default Process::SetProcessExitStatus.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->PutCString ("monitored child process with user-specified process monitor.");
|
2013-08-28 04:58:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Invalid process ID, something didn't go well
|
|
|
|
if (error.Success())
|
|
|
|
error.SetErrorString ("process launch failed for unknown reasons");
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2014-05-03 03:09:40 +08:00
|
|
|
#endif // defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
|
2013-08-28 04:58:59 +08:00
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
|
|
|
size_t
|
|
|
|
Host::GetPageSize()
|
|
|
|
{
|
|
|
|
return ::getpagesize();
|
|
|
|
}
|
2012-04-14 09:42:46 +08:00
|
|
|
|
2013-02-18 04:46:30 +08:00
|
|
|
uint32_t
|
|
|
|
Host::GetNumberCPUS ()
|
|
|
|
{
|
|
|
|
static uint32_t g_num_cores = UINT32_MAX;
|
|
|
|
if (g_num_cores == UINT32_MAX)
|
|
|
|
{
|
2013-07-01 16:21:36 +08:00
|
|
|
#if defined(__APPLE__) or defined (__linux__) or defined (__FreeBSD__) or defined (__FreeBSD_kernel__)
|
2013-02-18 04:46:30 +08:00
|
|
|
|
|
|
|
g_num_cores = ::sysconf(_SC_NPROCESSORS_ONLN);
|
2013-08-23 20:44:05 +08:00
|
|
|
|
2013-02-18 04:46:30 +08:00
|
|
|
#else
|
|
|
|
|
|
|
|
// Assume POSIX support if a host specific case has not been supplied above
|
|
|
|
g_num_cores = 0;
|
|
|
|
int num_cores = 0;
|
|
|
|
size_t num_cores_len = sizeof(num_cores);
|
2013-07-01 16:21:36 +08:00
|
|
|
#ifdef HW_AVAILCPU
|
2013-02-18 04:46:30 +08:00
|
|
|
int mib[] = { CTL_HW, HW_AVAILCPU };
|
2013-07-01 16:21:36 +08:00
|
|
|
#else
|
|
|
|
int mib[] = { CTL_HW, HW_NCPU };
|
|
|
|
#endif
|
2013-02-18 04:46:30 +08:00
|
|
|
|
|
|
|
/* get the number of CPUs from the system */
|
2014-06-27 13:17:41 +08:00
|
|
|
if (sysctl(mib, llvm::array_lengthof(mib), &num_cores, &num_cores_len, NULL, 0) == 0 && (num_cores > 0))
|
2013-02-18 04:46:30 +08:00
|
|
|
{
|
|
|
|
g_num_cores = num_cores;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mib[1] = HW_NCPU;
|
|
|
|
num_cores_len = sizeof(num_cores);
|
2014-06-27 13:17:41 +08:00
|
|
|
if (sysctl(mib, llvm::array_lengthof(mib), &num_cores, &num_cores_len, NULL, 0) == 0 && (num_cores > 0))
|
2013-02-18 04:46:30 +08:00
|
|
|
{
|
|
|
|
if (num_cores > 0)
|
|
|
|
g_num_cores = num_cores;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return g_num_cores;
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
void
|
|
|
|
Host::Kill(lldb::pid_t pid, int signo)
|
|
|
|
{
|
|
|
|
::kill(pid, signo);
|
|
|
|
}
|
2013-02-18 04:46:30 +08:00
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
#endif
|
2012-04-14 09:42:46 +08:00
|
|
|
|
2011-08-03 04:52:42 +08:00
|
|
|
#if !defined (__APPLE__)
|
2010-07-03 03:28:44 +08:00
|
|
|
bool
|
2010-12-18 09:54:34 +08:00
|
|
|
Host::OpenFileInExternalEditor (const FileSpec &file_spec, uint32_t line_no)
|
2010-07-03 03:28:44 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
Added a new Host call to find LLDB related paths:
static bool
Host::GetLLDBPath (lldb::PathType path_type, FileSpec &file_spec);
This will fill in "file_spec" with an appropriate path that is appropriate
for the current Host OS. MacOSX will return paths within the LLDB.framework,
and other unixes will return the paths they want. The current PathType
enums are:
typedef enum PathType
{
ePathTypeLLDBShlibDir, // The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists
ePathTypeSupportExecutableDir, // Find LLDB support executable directory (debugserver, etc)
ePathTypeHeaderDir, // Find LLDB header file directory
ePathTypePythonDir // Find Python modules (PYTHONPATH) directory
} PathType;
All places that were finding executables are and python paths are now updated
to use this Host call.
Added another new host call to launch the inferior in a terminal. This ability
will be very host specific and doesn't need to be supported on all systems.
MacOSX currently will create a new .command file and tell Terminal.app to open
the .command file. It also uses the new "darwin-debug" app which is a small
app that uses posix to exec (no fork) and stop at the entry point of the
program. The GDB remote plug-in is almost able launch a process and attach to
it, it currently will spawn the process, but it won't attach to it just yet.
This will let LLDB not have to share the terminal with another process and a
new terminal window will pop up when you launch. This won't get hooked up
until we work out all of the kinks. The new Host function is:
static lldb::pid_t
Host::LaunchInNewTerminal (
const char **argv, // argv[0] is executable
const char **envp,
const ArchSpec *arch_spec,
bool stop_at_entry,
bool disable_aslr);
Cleaned up FileSpec::GetPath to not use strncpy() as it was always zero
filling the entire path buffer.
Fixed an issue with the dynamic checker function where I missed a '$' prefix
that should have been added.
llvm-svn: 116690
2010-10-18 06:03:32 +08:00
|
|
|
|
2010-11-10 12:57:04 +08:00
|
|
|
void
|
|
|
|
Host::SetCrashDescriptionWithFormat (const char *format, ...)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Host::SetCrashDescription (const char *description)
|
|
|
|
{
|
|
|
|
}
|
Added a new Host call to find LLDB related paths:
static bool
Host::GetLLDBPath (lldb::PathType path_type, FileSpec &file_spec);
This will fill in "file_spec" with an appropriate path that is appropriate
for the current Host OS. MacOSX will return paths within the LLDB.framework,
and other unixes will return the paths they want. The current PathType
enums are:
typedef enum PathType
{
ePathTypeLLDBShlibDir, // The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists
ePathTypeSupportExecutableDir, // Find LLDB support executable directory (debugserver, etc)
ePathTypeHeaderDir, // Find LLDB header file directory
ePathTypePythonDir // Find Python modules (PYTHONPATH) directory
} PathType;
All places that were finding executables are and python paths are now updated
to use this Host call.
Added another new host call to launch the inferior in a terminal. This ability
will be very host specific and doesn't need to be supported on all systems.
MacOSX currently will create a new .command file and tell Terminal.app to open
the .command file. It also uses the new "darwin-debug" app which is a small
app that uses posix to exec (no fork) and stop at the entry point of the
program. The GDB remote plug-in is almost able launch a process and attach to
it, it currently will spawn the process, but it won't attach to it just yet.
This will let LLDB not have to share the terminal with another process and a
new terminal window will pop up when you launch. This won't get hooked up
until we work out all of the kinks. The new Host function is:
static lldb::pid_t
Host::LaunchInNewTerminal (
const char **argv, // argv[0] is executable
const char **envp,
const ArchSpec *arch_spec,
bool stop_at_entry,
bool disable_aslr);
Cleaned up FileSpec::GetPath to not use strncpy() as it was always zero
filling the entire path buffer.
Fixed an issue with the dynamic checker function where I missed a '$' prefix
that should have been added.
llvm-svn: 116690
2010-10-18 06:03:32 +08:00
|
|
|
|
|
|
|
lldb::pid_t
|
2013-08-27 07:57:52 +08:00
|
|
|
Host::LaunchApplication (const FileSpec &app_file_spec)
|
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 LLDB_INVALID_PROCESS_ID;
|
|
|
|
}
|
|
|
|
|
2013-11-21 05:07:01 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef LLDB_DISABLE_POSIX
|
|
|
|
|
|
|
|
Error
|
|
|
|
Host::MakeDirectory (const char* path, uint32_t mode)
|
|
|
|
{
|
|
|
|
Error error;
|
2013-11-26 23:10:46 +08:00
|
|
|
error.SetErrorStringWithFormat("%s in not implemented on this host", __PRETTY_FUNCTION__);
|
2013-11-21 05:07:01 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
|
|
|
Host::GetFilePermissions (const char* path, uint32_t &file_permissions)
|
|
|
|
{
|
|
|
|
Error error;
|
2013-11-26 23:10:46 +08:00
|
|
|
error.SetErrorStringWithFormat("%s is not supported on this host", __PRETTY_FUNCTION__);
|
2013-11-21 05:07:01 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
|
|
|
Host::SetFilePermissions (const char* path, uint32_t file_permissions)
|
|
|
|
{
|
|
|
|
Error error;
|
2013-11-26 23:10:46 +08:00
|
|
|
error.SetErrorStringWithFormat("%s is not supported on this host", __PRETTY_FUNCTION__);
|
2013-11-21 05:07:01 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
|
|
|
Host::Symlink (const char *src, const char *dst)
|
|
|
|
{
|
|
|
|
Error error;
|
2013-11-26 23:10:46 +08:00
|
|
|
error.SetErrorStringWithFormat("%s is not supported on this host", __PRETTY_FUNCTION__);
|
2013-11-21 05:07:01 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
|
|
|
Host::Readlink (const char *path, char *buf, size_t buf_len)
|
|
|
|
{
|
|
|
|
Error error;
|
2013-11-26 23:10:46 +08:00
|
|
|
error.SetErrorStringWithFormat("%s is not supported on this host", __PRETTY_FUNCTION__);
|
2013-11-21 05:07:01 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
|
|
|
Host::Unlink (const char *path)
|
|
|
|
{
|
|
|
|
Error error;
|
2013-11-26 23:10:46 +08:00
|
|
|
error.SetErrorStringWithFormat("%s is not supported on this host", __PRETTY_FUNCTION__);
|
2013-11-21 05:07:01 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2014-03-25 07:10:19 +08:00
|
|
|
Error
|
|
|
|
Host::RemoveDirectory (const char* path, bool recurse)
|
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
error.SetErrorStringWithFormat("%s is not supported on this host", __PRETTY_FUNCTION__);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2013-11-21 05:07:01 +08:00
|
|
|
#else
|
|
|
|
|
|
|
|
Error
|
|
|
|
Host::MakeDirectory (const char* path, uint32_t file_permissions)
|
|
|
|
{
|
|
|
|
Error error;
|
2013-11-23 09:58:15 +08:00
|
|
|
if (path && path[0])
|
|
|
|
{
|
|
|
|
if (::mkdir(path, file_permissions) != 0)
|
|
|
|
{
|
|
|
|
error.SetErrorToErrno();
|
|
|
|
switch (error.GetError())
|
|
|
|
{
|
|
|
|
case ENOENT:
|
|
|
|
{
|
|
|
|
// Parent directory doesn't exist, so lets make it if we can
|
|
|
|
FileSpec spec(path, false);
|
|
|
|
if (spec.GetDirectory() && spec.GetFilename())
|
|
|
|
{
|
|
|
|
// Make the parent directory and try again
|
|
|
|
Error error2 = Host::MakeDirectory(spec.GetDirectory().GetCString(), file_permissions);
|
|
|
|
if (error2.Success())
|
|
|
|
{
|
|
|
|
// Try and make the directory again now that the parent directory was made successfully
|
|
|
|
if (::mkdir(path, file_permissions) == 0)
|
|
|
|
error.Clear();
|
|
|
|
else
|
|
|
|
error.SetErrorToErrno();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EEXIST:
|
|
|
|
{
|
|
|
|
FileSpec path_spec(path, false);
|
|
|
|
if (path_spec.IsDirectory())
|
|
|
|
error.Clear(); // It is a directory and it already exists
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetErrorString("empty path");
|
|
|
|
}
|
2013-11-21 05:07:01 +08:00
|
|
|
return error;
|
|
|
|
}
|
2014-03-25 07:10:19 +08:00
|
|
|
|
|
|
|
Error
|
|
|
|
Host::RemoveDirectory (const char* path, bool recurse)
|
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
if (path && path[0])
|
|
|
|
{
|
|
|
|
if (recurse)
|
|
|
|
{
|
|
|
|
StreamString command;
|
|
|
|
command.Printf("rm -rf \"%s\"", path);
|
|
|
|
int status = ::system(command.GetString().c_str());
|
|
|
|
if (status != 0)
|
|
|
|
error.SetError(status, eErrorTypeGeneric);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (::rmdir(path) != 0)
|
|
|
|
error.SetErrorToErrno();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetErrorString("empty path");
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
2013-11-21 05:07:01 +08:00
|
|
|
|
|
|
|
Error
|
|
|
|
Host::GetFilePermissions (const char* path, uint32_t &file_permissions)
|
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
struct stat file_stats;
|
|
|
|
if (::stat (path, &file_stats) == 0)
|
|
|
|
{
|
|
|
|
// The bits in "st_mode" currently match the definitions
|
|
|
|
// for the file mode bits in unix.
|
|
|
|
file_permissions = file_stats.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetErrorToErrno();
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
|
|
|
Host::SetFilePermissions (const char* path, uint32_t file_permissions)
|
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
if (::chmod(path, file_permissions) != 0)
|
|
|
|
error.SetErrorToErrno();
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
|
|
|
Host::Symlink (const char *src, const char *dst)
|
2013-08-27 07:57:52 +08:00
|
|
|
{
|
2013-11-21 05:07:01 +08:00
|
|
|
Error error;
|
|
|
|
if (::symlink(dst, src) == -1)
|
|
|
|
error.SetErrorToErrno();
|
|
|
|
return error;
|
2013-08-27 07:57:52 +08:00
|
|
|
}
|
2013-11-21 05:07:01 +08:00
|
|
|
|
|
|
|
Error
|
|
|
|
Host::Unlink (const char *path)
|
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
if (::unlink(path) == -1)
|
|
|
|
error.SetErrorToErrno();
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
|
|
|
Host::Readlink (const char *path, char *buf, size_t buf_len)
|
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
ssize_t count = ::readlink(path, buf, buf_len);
|
|
|
|
if (count < 0)
|
|
|
|
error.SetErrorToErrno();
|
2014-04-02 11:51:35 +08:00
|
|
|
else if (static_cast<size_t>(count) < (buf_len-1))
|
2013-11-21 05:07:01 +08:00
|
|
|
buf[count] = '\0'; // Success
|
|
|
|
else
|
|
|
|
error.SetErrorString("'buf' buffer is too small to contain link contents");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-27 07:57:52 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef std::map<lldb::user_id_t, lldb::FileSP> FDToFileMap;
|
|
|
|
FDToFileMap& GetFDToFileMap()
|
|
|
|
{
|
|
|
|
static FDToFileMap g_fd2filemap;
|
|
|
|
return g_fd2filemap;
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::user_id_t
|
|
|
|
Host::OpenFile (const FileSpec& file_spec,
|
|
|
|
uint32_t flags,
|
2013-11-21 05:07:01 +08:00
|
|
|
uint32_t mode,
|
2013-08-27 07:57:52 +08:00
|
|
|
Error &error)
|
|
|
|
{
|
|
|
|
std::string path (file_spec.GetPath());
|
|
|
|
if (path.empty())
|
|
|
|
{
|
|
|
|
error.SetErrorString("empty path");
|
|
|
|
return UINT64_MAX;
|
|
|
|
}
|
|
|
|
FileSP file_sp(new File());
|
|
|
|
error = file_sp->Open(path.c_str(),flags,mode);
|
|
|
|
if (file_sp->IsValid() == false)
|
|
|
|
return UINT64_MAX;
|
|
|
|
lldb::user_id_t fd = file_sp->GetDescriptor();
|
|
|
|
GetFDToFileMap()[fd] = file_sp;
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Host::CloseFile (lldb::user_id_t fd, Error &error)
|
|
|
|
{
|
|
|
|
if (fd == UINT64_MAX)
|
|
|
|
{
|
|
|
|
error.SetErrorString ("invalid file descriptor");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
FDToFileMap& file_map = GetFDToFileMap();
|
|
|
|
FDToFileMap::iterator pos = file_map.find(fd);
|
|
|
|
if (pos == file_map.end())
|
|
|
|
{
|
|
|
|
error.SetErrorStringWithFormat ("invalid host file descriptor %" PRIu64, fd);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
FileSP file_sp = pos->second;
|
|
|
|
if (!file_sp)
|
|
|
|
{
|
|
|
|
error.SetErrorString ("invalid host backing file");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
error = file_sp->Close();
|
|
|
|
file_map.erase(pos);
|
|
|
|
return error.Success();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
Host::WriteFile (lldb::user_id_t fd, uint64_t offset, const void* src, uint64_t src_len, Error &error)
|
|
|
|
{
|
|
|
|
if (fd == UINT64_MAX)
|
|
|
|
{
|
|
|
|
error.SetErrorString ("invalid file descriptor");
|
|
|
|
return UINT64_MAX;
|
|
|
|
}
|
|
|
|
FDToFileMap& file_map = GetFDToFileMap();
|
|
|
|
FDToFileMap::iterator pos = file_map.find(fd);
|
|
|
|
if (pos == file_map.end())
|
|
|
|
{
|
|
|
|
error.SetErrorStringWithFormat("invalid host file descriptor %" PRIu64 , fd);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
FileSP file_sp = pos->second;
|
|
|
|
if (!file_sp)
|
|
|
|
{
|
|
|
|
error.SetErrorString ("invalid host backing file");
|
|
|
|
return UINT64_MAX;
|
|
|
|
}
|
2014-04-02 11:51:35 +08:00
|
|
|
if (static_cast<uint64_t>(file_sp->SeekFromStart(offset, &error)) != offset ||
|
|
|
|
error.Fail())
|
2013-08-27 07:57:52 +08:00
|
|
|
return UINT64_MAX;
|
|
|
|
size_t bytes_written = src_len;
|
|
|
|
error = file_sp->Write(src, bytes_written);
|
|
|
|
if (error.Fail())
|
|
|
|
return UINT64_MAX;
|
|
|
|
return bytes_written;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
Host::ReadFile (lldb::user_id_t fd, uint64_t offset, void* dst, uint64_t dst_len, Error &error)
|
|
|
|
{
|
|
|
|
if (fd == UINT64_MAX)
|
|
|
|
{
|
|
|
|
error.SetErrorString ("invalid file descriptor");
|
|
|
|
return UINT64_MAX;
|
|
|
|
}
|
|
|
|
FDToFileMap& file_map = GetFDToFileMap();
|
|
|
|
FDToFileMap::iterator pos = file_map.find(fd);
|
|
|
|
if (pos == file_map.end())
|
|
|
|
{
|
|
|
|
error.SetErrorStringWithFormat ("invalid host file descriptor %" PRIu64, fd);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
FileSP file_sp = pos->second;
|
|
|
|
if (!file_sp)
|
|
|
|
{
|
|
|
|
error.SetErrorString ("invalid host backing file");
|
|
|
|
return UINT64_MAX;
|
|
|
|
}
|
2014-04-02 11:51:35 +08:00
|
|
|
if (static_cast<uint64_t>(file_sp->SeekFromStart(offset, &error)) != offset ||
|
|
|
|
error.Fail())
|
2013-08-27 07:57:52 +08:00
|
|
|
return UINT64_MAX;
|
|
|
|
size_t bytes_read = dst_len;
|
|
|
|
error = file_sp->Read(dst ,bytes_read);
|
|
|
|
if (error.Fail())
|
|
|
|
return UINT64_MAX;
|
|
|
|
return bytes_read;
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::user_id_t
|
|
|
|
Host::GetFileSize (const FileSpec& file_spec)
|
|
|
|
{
|
|
|
|
return file_spec.GetByteSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Host::GetFileExists (const FileSpec& file_spec)
|
|
|
|
{
|
|
|
|
return file_spec.Exists();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Host::CalculateMD5 (const FileSpec& file_spec,
|
|
|
|
uint64_t &low,
|
|
|
|
uint64_t &high)
|
|
|
|
{
|
|
|
|
#if defined (__APPLE__)
|
|
|
|
StreamString md5_cmd_line;
|
|
|
|
md5_cmd_line.Printf("md5 -q '%s'", file_spec.GetPath().c_str());
|
|
|
|
std::string hash_string;
|
|
|
|
Error err = Host::RunShellCommand(md5_cmd_line.GetData(), NULL, NULL, NULL, &hash_string, 60);
|
|
|
|
if (err.Fail())
|
|
|
|
return false;
|
|
|
|
// a correctly formed MD5 is 16-bytes, that is 32 hex digits
|
|
|
|
// if the output is any other length it is probably wrong
|
|
|
|
if (hash_string.size() != 32)
|
|
|
|
return false;
|
|
|
|
std::string part1(hash_string,0,16);
|
|
|
|
std::string part2(hash_string,16);
|
|
|
|
const char* part1_cstr = part1.c_str();
|
|
|
|
const char* part2_cstr = part2.c_str();
|
|
|
|
high = ::strtoull(part1_cstr, NULL, 16);
|
|
|
|
low = ::strtoull(part2_cstr, NULL, 16);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
// your own MD5 implementation here
|
|
|
|
return false;
|
2010-09-08 04:11:56 +08:00
|
|
|
#endif
|
2013-08-27 07:57:52 +08:00
|
|
|
}
|