2010-06-09 00:52:24 +08:00
|
|
|
//===-- FileSpec.cpp --------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
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
|
|
|
#include <dirent.h>
|
2010-06-09 00:52:24 +08:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <libgen.h>
|
|
|
|
#include <sys/stat.h>
|
2011-02-08 01:41:11 +08:00
|
|
|
#include <string.h>
|
2011-02-08 03:42:39 +08:00
|
|
|
#include <fstream>
|
2011-02-05 10:27:52 +08:00
|
|
|
|
2011-02-08 03:42:39 +08:00
|
|
|
#include "lldb/Host/Config.h" // Have to include this before we test the define...
|
2011-02-08 08:35:34 +08:00
|
|
|
#ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
|
2010-07-01 09:48:53 +08:00
|
|
|
#include <pwd.h>
|
2011-02-05 10:27:52 +08:00
|
|
|
#endif
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-09-12 08:10:52 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2010-12-03 07:20:03 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
#include "llvm/Support/Program.h"
|
2010-09-12 08:10:52 +08:00
|
|
|
|
2012-01-05 06:56:43 +08:00
|
|
|
#include "lldb/Host/File.h"
|
2011-02-08 13:05:52 +08:00
|
|
|
#include "lldb/Host/FileSpec.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/DataBufferHeap.h"
|
|
|
|
#include "lldb/Core/DataBufferMemoryMap.h"
|
|
|
|
#include "lldb/Core/Stream.h"
|
2010-09-10 12:48:55 +08:00
|
|
|
#include "lldb/Host/Host.h"
|
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
|
|
|
#include "lldb/Utility/CleanUp.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
static bool
|
|
|
|
GetFileStats (const FileSpec *file_spec, struct stat *stats_ptr)
|
|
|
|
{
|
|
|
|
char resolved_path[PATH_MAX];
|
2011-04-23 10:04:55 +08:00
|
|
|
if (file_spec->GetPath (resolved_path, sizeof(resolved_path)))
|
2010-06-09 00:52:24 +08:00
|
|
|
return ::stat (resolved_path, stats_ptr) == 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-08 08:35:34 +08:00
|
|
|
#ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
|
2011-02-05 10:27:52 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
static const char*
|
|
|
|
GetCachedGlobTildeSlash()
|
|
|
|
{
|
|
|
|
static std::string g_tilde;
|
|
|
|
if (g_tilde.empty())
|
|
|
|
{
|
2010-07-01 09:48:53 +08:00
|
|
|
struct passwd *user_entry;
|
|
|
|
user_entry = getpwuid(geteuid());
|
|
|
|
if (user_entry != NULL)
|
|
|
|
g_tilde = user_entry->pw_dir;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (g_tilde.empty())
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return g_tilde.c_str();
|
|
|
|
}
|
|
|
|
|
2011-02-08 13:19:06 +08:00
|
|
|
#endif // #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
|
|
|
|
|
2010-07-01 09:48:53 +08:00
|
|
|
// Resolves the username part of a path of the form ~user/other/directories, and
|
|
|
|
// writes the result into dst_path.
|
|
|
|
// Returns 0 if there WAS a ~ in the path but the username couldn't be resolved.
|
|
|
|
// Otherwise returns the number of characters copied into dst_path. If the return
|
|
|
|
// is >= dst_len, then the resolved path is too long...
|
2010-07-10 04:39:50 +08:00
|
|
|
size_t
|
2010-07-01 09:48:53 +08:00
|
|
|
FileSpec::ResolveUsername (const char *src_path, char *dst_path, size_t dst_len)
|
|
|
|
{
|
2011-02-08 13:19:06 +08:00
|
|
|
if (src_path == NULL || src_path[0] == '\0')
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
#ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
|
|
|
|
|
2010-07-01 09:48:53 +08:00
|
|
|
char user_home[PATH_MAX];
|
|
|
|
const char *user_name;
|
|
|
|
|
2010-07-02 01:07:48 +08:00
|
|
|
|
2010-07-01 09:48:53 +08:00
|
|
|
// If there's no ~, then just copy src_path straight to dst_path (they may be the same string...)
|
|
|
|
if (src_path[0] != '~')
|
|
|
|
{
|
2010-07-10 04:39:50 +08:00
|
|
|
size_t len = strlen (src_path);
|
2010-07-01 09:48:53 +08:00
|
|
|
if (len >= dst_len)
|
|
|
|
{
|
2010-07-02 01:07:48 +08:00
|
|
|
::bcopy (src_path, dst_path, dst_len - 1);
|
|
|
|
dst_path[dst_len] = '\0';
|
2010-07-01 09:48:53 +08:00
|
|
|
}
|
|
|
|
else
|
2010-07-02 01:07:48 +08:00
|
|
|
::bcopy (src_path, dst_path, len + 1);
|
|
|
|
|
2010-07-01 09:48:53 +08:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2010-07-03 03:15:50 +08:00
|
|
|
const char *first_slash = ::strchr (src_path, '/');
|
2010-07-01 09:48:53 +08:00
|
|
|
char remainder[PATH_MAX];
|
|
|
|
|
|
|
|
if (first_slash == NULL)
|
|
|
|
{
|
|
|
|
// The whole name is the username (minus the ~):
|
|
|
|
user_name = src_path + 1;
|
|
|
|
remainder[0] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int user_name_len = first_slash - src_path - 1;
|
2010-07-02 01:07:48 +08:00
|
|
|
::memcpy (user_home, src_path + 1, user_name_len);
|
2010-07-01 09:48:53 +08:00
|
|
|
user_home[user_name_len] = '\0';
|
|
|
|
user_name = user_home;
|
|
|
|
|
2010-07-02 01:07:48 +08:00
|
|
|
::strcpy (remainder, first_slash);
|
2010-07-01 09:48:53 +08:00
|
|
|
}
|
2010-07-02 01:07:48 +08:00
|
|
|
|
2010-07-01 09:48:53 +08:00
|
|
|
if (user_name == NULL)
|
|
|
|
return 0;
|
|
|
|
// User name of "" means the current user...
|
|
|
|
|
|
|
|
struct passwd *user_entry;
|
2010-07-10 04:39:50 +08:00
|
|
|
const char *home_dir = NULL;
|
2010-07-01 09:48:53 +08:00
|
|
|
|
|
|
|
if (user_name[0] == '\0')
|
|
|
|
{
|
|
|
|
home_dir = GetCachedGlobTildeSlash();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-02 01:07:48 +08:00
|
|
|
user_entry = ::getpwnam (user_name);
|
2010-07-01 09:48:53 +08:00
|
|
|
if (user_entry != NULL)
|
|
|
|
home_dir = user_entry->pw_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (home_dir == NULL)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return ::snprintf (dst_path, dst_len, "%s%s", home_dir, remainder);
|
2011-02-08 13:19:06 +08:00
|
|
|
#else
|
|
|
|
// Resolving home directories is not supported, just copy the path...
|
|
|
|
return ::snprintf (dst_path, dst_len, "%s", src_path);
|
|
|
|
#endif // #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
|
2010-07-01 09:48:53 +08:00
|
|
|
}
|
|
|
|
|
2011-02-09 07:24:09 +08:00
|
|
|
size_t
|
|
|
|
FileSpec::ResolvePartialUsername (const char *partial_name, StringList &matches)
|
|
|
|
{
|
|
|
|
#ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
|
|
|
|
size_t extant_entries = matches.GetSize();
|
|
|
|
|
|
|
|
setpwent();
|
|
|
|
struct passwd *user_entry;
|
|
|
|
const char *name_start = partial_name + 1;
|
|
|
|
std::set<std::string> name_list;
|
|
|
|
|
|
|
|
while ((user_entry = getpwent()) != NULL)
|
|
|
|
{
|
|
|
|
if (strstr(user_entry->pw_name, name_start) == user_entry->pw_name)
|
|
|
|
{
|
|
|
|
std::string tmp_buf("~");
|
|
|
|
tmp_buf.append(user_entry->pw_name);
|
|
|
|
tmp_buf.push_back('/');
|
|
|
|
name_list.insert(tmp_buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::set<std::string>::iterator pos, end = name_list.end();
|
|
|
|
for (pos = name_list.begin(); pos != end; pos++)
|
|
|
|
{
|
|
|
|
matches.AppendString((*pos).c_str());
|
|
|
|
}
|
|
|
|
return matches.GetSize() - extant_entries;
|
|
|
|
#else
|
|
|
|
// Resolving home directories is not supported, just copy the path...
|
|
|
|
return 0;
|
|
|
|
#endif // #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-07-10 04:39:50 +08:00
|
|
|
size_t
|
2010-06-09 00:52:24 +08:00
|
|
|
FileSpec::Resolve (const char *src_path, char *dst_path, size_t dst_len)
|
|
|
|
{
|
|
|
|
if (src_path == NULL || src_path[0] == '\0')
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Glob if needed for ~/, otherwise copy in case src_path is same as dst_path...
|
|
|
|
char unglobbed_path[PATH_MAX];
|
2011-02-08 08:35:34 +08:00
|
|
|
#ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
|
2010-07-01 09:48:53 +08:00
|
|
|
if (src_path[0] == '~')
|
|
|
|
{
|
2010-07-10 04:39:50 +08:00
|
|
|
size_t return_count = ResolveUsername(src_path, unglobbed_path, sizeof(unglobbed_path));
|
2010-07-01 09:48:53 +08:00
|
|
|
|
|
|
|
// If we couldn't find the user referred to, or the resultant path was too long,
|
|
|
|
// then just copy over the src_path.
|
|
|
|
if (return_count == 0 || return_count >= sizeof(unglobbed_path))
|
|
|
|
::snprintf (unglobbed_path, sizeof(unglobbed_path), "%s", src_path);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2011-02-08 08:35:34 +08:00
|
|
|
#endif // #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
|
2011-02-05 10:27:52 +08:00
|
|
|
{
|
|
|
|
::snprintf(unglobbed_path, sizeof(unglobbed_path), "%s", src_path);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Now resolve the path if needed
|
|
|
|
char resolved_path[PATH_MAX];
|
|
|
|
if (::realpath (unglobbed_path, resolved_path))
|
|
|
|
{
|
|
|
|
// Success, copy the resolved path
|
|
|
|
return ::snprintf(dst_path, dst_len, "%s", resolved_path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Failed, just copy the unglobbed path
|
|
|
|
return ::snprintf(dst_path, dst_len, "%s", unglobbed_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSpec::FileSpec() :
|
|
|
|
m_directory(),
|
|
|
|
m_filename()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-16 08:57:33 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Default constructor that can take an optional full path to a
|
|
|
|
// file on disk.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
FileSpec::FileSpec(const char *pathname, bool resolve_path) :
|
|
|
|
m_directory(),
|
2010-11-08 08:28:40 +08:00
|
|
|
m_filename(),
|
|
|
|
m_is_resolved(false)
|
2010-09-16 08:57:33 +08:00
|
|
|
{
|
|
|
|
if (pathname && pathname[0])
|
|
|
|
SetFile(pathname, resolve_path);
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Copy constructor
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
FileSpec::FileSpec(const FileSpec& rhs) :
|
|
|
|
m_directory (rhs.m_directory),
|
2010-11-08 08:28:40 +08:00
|
|
|
m_filename (rhs.m_filename),
|
|
|
|
m_is_resolved (rhs.m_is_resolved)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Copy constructor
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
FileSpec::FileSpec(const FileSpec* rhs) :
|
|
|
|
m_directory(),
|
|
|
|
m_filename()
|
|
|
|
{
|
|
|
|
if (rhs)
|
|
|
|
*this = *rhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Virtual destrcuctor in case anyone inherits from this class.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
FileSpec::~FileSpec()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Assignment operator.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
const FileSpec&
|
|
|
|
FileSpec::operator= (const FileSpec& rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs)
|
|
|
|
{
|
|
|
|
m_directory = rhs.m_directory;
|
|
|
|
m_filename = rhs.m_filename;
|
2010-11-08 08:28:40 +08:00
|
|
|
m_is_resolved = rhs.m_is_resolved;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Update the contents of this object with a new path. The path will
|
|
|
|
// be split up into a directory and filename and stored as uniqued
|
|
|
|
// string values for quick comparison and efficient memory usage.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void
|
2010-11-08 08:28:40 +08:00
|
|
|
FileSpec::SetFile (const char *pathname, bool resolve)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
m_filename.Clear();
|
|
|
|
m_directory.Clear();
|
2010-11-08 08:28:40 +08:00
|
|
|
m_is_resolved = false;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (pathname == NULL || pathname[0] == '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
char resolved_path[PATH_MAX];
|
2010-09-16 08:57:33 +08:00
|
|
|
bool path_fit = true;
|
|
|
|
|
|
|
|
if (resolve)
|
|
|
|
{
|
|
|
|
path_fit = (FileSpec::Resolve (pathname, resolved_path, sizeof(resolved_path)) < sizeof(resolved_path) - 1);
|
2010-11-08 08:28:40 +08:00
|
|
|
m_is_resolved = path_fit;
|
2010-09-16 08:57:33 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-08 08:28:40 +08:00
|
|
|
// Copy the path because "basename" and "dirname" want to muck with the
|
|
|
|
// path buffer
|
|
|
|
if (::strlen (pathname) > sizeof(resolved_path) - 1)
|
2010-09-16 08:57:33 +08:00
|
|
|
path_fit = false;
|
|
|
|
else
|
2010-11-08 08:28:40 +08:00
|
|
|
::strcpy (resolved_path, pathname);
|
2010-09-16 08:57:33 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-09-16 08:57:33 +08:00
|
|
|
|
|
|
|
if (path_fit)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
char *filename = ::basename (resolved_path);
|
|
|
|
if (filename)
|
|
|
|
{
|
|
|
|
m_filename.SetCString (filename);
|
|
|
|
// Truncate the basename off the end of the resolved path
|
|
|
|
|
|
|
|
// Only attempt to get the dirname if it looks like we have a path
|
|
|
|
if (strchr(resolved_path, '/'))
|
|
|
|
{
|
|
|
|
char *directory = ::dirname (resolved_path);
|
|
|
|
|
|
|
|
// Make sure we didn't get our directory resolved to "." without having
|
|
|
|
// specified
|
|
|
|
if (directory)
|
|
|
|
m_directory.SetCString(directory);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *last_resolved_path_slash = strrchr(resolved_path, '/');
|
|
|
|
if (last_resolved_path_slash)
|
|
|
|
{
|
|
|
|
*last_resolved_path_slash = '\0';
|
|
|
|
m_directory.SetCString(resolved_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_directory.SetCString(resolved_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Convert to pointer operator. This allows code to check any FileSpec
|
|
|
|
// objects to see if they contain anything valid using code such as:
|
|
|
|
//
|
|
|
|
// if (file_spec)
|
|
|
|
// {}
|
|
|
|
//----------------------------------------------------------------------
|
2011-09-12 12:00:42 +08:00
|
|
|
FileSpec::operator bool() const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-09-12 12:00:42 +08:00
|
|
|
return m_filename || m_directory;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Logical NOT operator. This allows code to check any FileSpec
|
|
|
|
// objects to see if they are invalid using code such as:
|
|
|
|
//
|
|
|
|
// if (!file_spec)
|
|
|
|
// {}
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
FileSpec::operator!() const
|
|
|
|
{
|
|
|
|
return !m_directory && !m_filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Equal to operator
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
FileSpec::operator== (const FileSpec& rhs) const
|
|
|
|
{
|
2010-11-08 08:28:40 +08:00
|
|
|
if (m_filename == rhs.m_filename)
|
|
|
|
{
|
|
|
|
if (m_directory == rhs.m_directory)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// TODO: determine if we want to keep this code in here.
|
|
|
|
// The code below was added to handle a case where we were
|
|
|
|
// trying to set a file and line breakpoint and one path
|
|
|
|
// was resolved, and the other not and the directory was
|
|
|
|
// in a mount point that resolved to a more complete path:
|
|
|
|
// "/tmp/a.c" == "/private/tmp/a.c". I might end up pulling
|
|
|
|
// this out...
|
|
|
|
if (IsResolved() && rhs.IsResolved())
|
|
|
|
{
|
|
|
|
// Both paths are resolved, no need to look further...
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSpec resolved_lhs(*this);
|
|
|
|
|
|
|
|
// If "this" isn't resolved, resolve it
|
|
|
|
if (!IsResolved())
|
|
|
|
{
|
|
|
|
if (resolved_lhs.ResolvePath())
|
|
|
|
{
|
|
|
|
// This path wasn't resolved but now it is. Check if the resolved
|
|
|
|
// directory is the same as our unresolved directory, and if so,
|
|
|
|
// we can mark this object as resolved to avoid more future resolves
|
|
|
|
m_is_resolved = (m_directory == resolved_lhs.m_directory);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSpec resolved_rhs(rhs);
|
|
|
|
if (!rhs.IsResolved())
|
|
|
|
{
|
|
|
|
if (resolved_rhs.ResolvePath())
|
|
|
|
{
|
|
|
|
// rhs's path wasn't resolved but now it is. Check if the resolved
|
|
|
|
// directory is the same as rhs's unresolved directory, and if so,
|
|
|
|
// we can mark this object as resolved to avoid more future resolves
|
|
|
|
rhs.m_is_resolved = (m_directory == resolved_rhs.m_directory);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we reach this point in the code we were able to resolve both paths
|
|
|
|
// and since we only resolve the paths if the basenames are equal, then
|
|
|
|
// we can just check if both directories are equal...
|
|
|
|
return resolved_lhs.GetDirectory() == resolved_rhs.GetDirectory();
|
|
|
|
}
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Not equal to operator
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
FileSpec::operator!= (const FileSpec& rhs) const
|
|
|
|
{
|
2010-11-08 08:28:40 +08:00
|
|
|
return !(*this == rhs);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Less than operator
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
FileSpec::operator< (const FileSpec& rhs) const
|
|
|
|
{
|
|
|
|
return FileSpec::Compare(*this, rhs, true) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Dump a FileSpec object to a stream
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
Stream&
|
|
|
|
lldb_private::operator << (Stream &s, const FileSpec& f)
|
|
|
|
{
|
|
|
|
f.Dump(&s);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Clear this object by releasing both the directory and filename
|
|
|
|
// string values and making them both the empty string.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
FileSpec::Clear()
|
|
|
|
{
|
|
|
|
m_directory.Clear();
|
|
|
|
m_filename.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Compare two FileSpec objects. If "full" is true, then both
|
|
|
|
// the directory and the filename must match. If "full" is false,
|
|
|
|
// then the directory names for "a" and "b" are only compared if
|
|
|
|
// they are both non-empty. This allows a FileSpec object to only
|
|
|
|
// contain a filename and it can match FileSpec objects that have
|
|
|
|
// matching filenames with different paths.
|
|
|
|
//
|
|
|
|
// Return -1 if the "a" is less than "b", 0 if "a" is equal to "b"
|
|
|
|
// and "1" if "a" is greater than "b".
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
int
|
|
|
|
FileSpec::Compare(const FileSpec& a, const FileSpec& b, bool full)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
// If full is true, then we must compare both the directory and filename.
|
|
|
|
|
|
|
|
// If full is false, then if either directory is empty, then we match on
|
|
|
|
// the basename only, and if both directories have valid values, we still
|
|
|
|
// do a full compare. This allows for matching when we just have a filename
|
|
|
|
// in one of the FileSpec objects.
|
|
|
|
|
|
|
|
if (full || (a.m_directory && b.m_directory))
|
|
|
|
{
|
|
|
|
result = ConstString::Compare(a.m_directory, b.m_directory);
|
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return ConstString::Compare (a.m_filename, b.m_filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
FileSpec::Equal (const FileSpec& a, const FileSpec& b, bool full)
|
|
|
|
{
|
2011-09-23 08:54:11 +08:00
|
|
|
if (!full && (a.GetDirectory().IsEmpty() || b.GetDirectory().IsEmpty()))
|
2010-06-09 00:52:24 +08:00
|
|
|
return a.m_filename == b.m_filename;
|
2011-09-23 08:54:11 +08:00
|
|
|
else
|
|
|
|
return a == b;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Dump the object to the supplied stream. If the object contains
|
|
|
|
// a valid directory name, it will be displayed followed by a
|
|
|
|
// directory delimiter, and the filename.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
FileSpec::Dump(Stream *s) const
|
|
|
|
{
|
|
|
|
if (m_filename)
|
|
|
|
m_directory.Dump(s, ""); // Provide a default for m_directory when we dump it in case it is invalid
|
|
|
|
|
|
|
|
if (m_directory)
|
|
|
|
{
|
|
|
|
// If dirname was valid, then we need to print a slash between
|
|
|
|
// the directory and the filename
|
|
|
|
s->PutChar('/');
|
|
|
|
}
|
|
|
|
m_filename.Dump(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Returns true if the file exists.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
FileSpec::Exists () const
|
|
|
|
{
|
|
|
|
struct stat file_stats;
|
|
|
|
return GetFileStats (this, &file_stats);
|
2010-09-10 12:48:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
FileSpec::ResolveExecutableLocation ()
|
|
|
|
{
|
2010-10-21 04:54:39 +08:00
|
|
|
if (!m_directory)
|
2010-09-12 08:10:52 +08:00
|
|
|
{
|
2011-01-26 05:32:01 +08:00
|
|
|
const char *file_cstr = m_filename.GetCString();
|
|
|
|
if (file_cstr)
|
2010-09-12 08:10:52 +08:00
|
|
|
{
|
2011-01-26 05:32:01 +08:00
|
|
|
const std::string file_str (file_cstr);
|
|
|
|
llvm::sys::Path path = llvm::sys::Program::FindProgramByName (file_str);
|
|
|
|
const std::string &path_str = path.str();
|
|
|
|
llvm::StringRef dir_ref = llvm::sys::path::parent_path(path_str);
|
|
|
|
//llvm::StringRef dir_ref = path.getDirname();
|
|
|
|
if (! dir_ref.empty())
|
2010-09-12 08:10:52 +08:00
|
|
|
{
|
2011-01-26 05:32:01 +08:00
|
|
|
// FindProgramByName returns "." if it can't find the file.
|
|
|
|
if (strcmp (".", dir_ref.data()) == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_directory.SetCString (dir_ref.data());
|
|
|
|
if (Exists())
|
2010-09-12 08:10:52 +08:00
|
|
|
return true;
|
2011-01-26 05:32:01 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// If FindProgramByName found the file, it returns the directory + filename in its return results.
|
|
|
|
// We need to separate them.
|
|
|
|
FileSpec tmp_file (dir_ref.data(), false);
|
|
|
|
if (tmp_file.Exists())
|
|
|
|
{
|
|
|
|
m_directory = tmp_file.m_directory;
|
|
|
|
return true;
|
|
|
|
}
|
2010-09-12 08:10:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-09-16 08:57:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
FileSpec::ResolvePath ()
|
|
|
|
{
|
2010-11-08 08:28:40 +08:00
|
|
|
if (m_is_resolved)
|
|
|
|
return true; // We have already resolved this path
|
|
|
|
|
|
|
|
char path_buf[PATH_MAX];
|
2010-09-16 08:57:33 +08:00
|
|
|
if (!GetPath (path_buf, PATH_MAX))
|
|
|
|
return false;
|
2010-11-08 08:28:40 +08:00
|
|
|
// SetFile(...) will set m_is_resolved correctly if it can resolve the path
|
2010-09-16 08:57:33 +08:00
|
|
|
SetFile (path_buf, true);
|
2010-11-08 08:28:40 +08:00
|
|
|
return m_is_resolved;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
FileSpec::GetByteSize() const
|
|
|
|
{
|
|
|
|
struct stat file_stats;
|
|
|
|
if (GetFileStats (this, &file_stats))
|
|
|
|
return file_stats.st_size;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSpec::FileType
|
|
|
|
FileSpec::GetFileType () const
|
|
|
|
{
|
|
|
|
struct stat file_stats;
|
|
|
|
if (GetFileStats (this, &file_stats))
|
|
|
|
{
|
|
|
|
mode_t file_type = file_stats.st_mode & S_IFMT;
|
|
|
|
switch (file_type)
|
|
|
|
{
|
|
|
|
case S_IFDIR: return eFileTypeDirectory;
|
|
|
|
case S_IFIFO: return eFileTypePipe;
|
|
|
|
case S_IFREG: return eFileTypeRegular;
|
|
|
|
case S_IFSOCK: return eFileTypeSocket;
|
|
|
|
case S_IFLNK: return eFileTypeSymbolicLink;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
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 eFileTypeUnknown;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return eFileTypeInvalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeValue
|
|
|
|
FileSpec::GetModificationTime () const
|
|
|
|
{
|
|
|
|
TimeValue mod_time;
|
|
|
|
struct stat file_stats;
|
|
|
|
if (GetFileStats (this, &file_stats))
|
2010-06-11 12:52:22 +08:00
|
|
|
mod_time.OffsetWithSeconds(file_stats.st_mtime);
|
2010-06-09 00:52:24 +08:00
|
|
|
return mod_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Directory string get accessor.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
ConstString &
|
|
|
|
FileSpec::GetDirectory()
|
|
|
|
{
|
|
|
|
return m_directory;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Directory string const get accessor.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
const ConstString &
|
|
|
|
FileSpec::GetDirectory() const
|
|
|
|
{
|
|
|
|
return m_directory;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Filename string get accessor.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
ConstString &
|
|
|
|
FileSpec::GetFilename()
|
|
|
|
{
|
|
|
|
return m_filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Filename string const get accessor.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
const ConstString &
|
|
|
|
FileSpec::GetFilename() const
|
|
|
|
{
|
|
|
|
return m_filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Extract the directory and path into a fixed buffer. This is
|
|
|
|
// needed as the directory and path are stored in separate string
|
|
|
|
// values.
|
|
|
|
//------------------------------------------------------------------
|
2010-10-31 11:01:06 +08:00
|
|
|
size_t
|
|
|
|
FileSpec::GetPath(char *path, size_t path_max_len) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-31 11:01:06 +08:00
|
|
|
if (path_max_len)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-31 11:01:06 +08:00
|
|
|
const char *dirname = m_directory.GetCString();
|
|
|
|
const char *filename = m_filename.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
|
|
|
if (dirname)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
Added a new Host call to find LLDB related paths:
static bool
Host::GetLLDBPath (lldb::PathType path_type, FileSpec &file_spec);
This will fill in "file_spec" with an appropriate path that is appropriate
for the current Host OS. MacOSX will return paths within the LLDB.framework,
and other unixes will return the paths they want. The current PathType
enums are:
typedef enum PathType
{
ePathTypeLLDBShlibDir, // The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists
ePathTypeSupportExecutableDir, // Find LLDB support executable directory (debugserver, etc)
ePathTypeHeaderDir, // Find LLDB header file directory
ePathTypePythonDir // Find Python modules (PYTHONPATH) directory
} PathType;
All places that were finding executables are and python paths are now updated
to use this Host call.
Added another new host call to launch the inferior in a terminal. This ability
will be very host specific and doesn't need to be supported on all systems.
MacOSX currently will create a new .command file and tell Terminal.app to open
the .command file. It also uses the new "darwin-debug" app which is a small
app that uses posix to exec (no fork) and stop at the entry point of the
program. The GDB remote plug-in is almost able launch a process and attach to
it, it currently will spawn the process, but it won't attach to it just yet.
This will let LLDB not have to share the terminal with another process and a
new terminal window will pop up when you launch. This won't get hooked up
until we work out all of the kinks. The new Host function is:
static lldb::pid_t
Host::LaunchInNewTerminal (
const char **argv, // argv[0] is executable
const char **envp,
const ArchSpec *arch_spec,
bool stop_at_entry,
bool disable_aslr);
Cleaned up FileSpec::GetPath to not use strncpy() as it was always zero
filling the entire path buffer.
Fixed an issue with the dynamic checker function where I missed a '$' prefix
that should have been added.
llvm-svn: 116690
2010-10-18 06:03:32 +08:00
|
|
|
if (filename)
|
2010-10-31 11:01:06 +08:00
|
|
|
return ::snprintf (path, path_max_len, "%s/%s", dirname, filename);
|
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
|
|
|
else
|
2010-10-31 11:01:06 +08:00
|
|
|
return ::snprintf (path, path_max_len, "%s", dirname);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
Added a new Host call to find LLDB related paths:
static bool
Host::GetLLDBPath (lldb::PathType path_type, FileSpec &file_spec);
This will fill in "file_spec" with an appropriate path that is appropriate
for the current Host OS. MacOSX will return paths within the LLDB.framework,
and other unixes will return the paths they want. The current PathType
enums are:
typedef enum PathType
{
ePathTypeLLDBShlibDir, // The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists
ePathTypeSupportExecutableDir, // Find LLDB support executable directory (debugserver, etc)
ePathTypeHeaderDir, // Find LLDB header file directory
ePathTypePythonDir // Find Python modules (PYTHONPATH) directory
} PathType;
All places that were finding executables are and python paths are now updated
to use this Host call.
Added another new host call to launch the inferior in a terminal. This ability
will be very host specific and doesn't need to be supported on all systems.
MacOSX currently will create a new .command file and tell Terminal.app to open
the .command file. It also uses the new "darwin-debug" app which is a small
app that uses posix to exec (no fork) and stop at the entry point of the
program. The GDB remote plug-in is almost able launch a process and attach to
it, it currently will spawn the process, but it won't attach to it just yet.
This will let LLDB not have to share the terminal with another process and a
new terminal window will pop up when you launch. This won't get hooked up
until we work out all of the kinks. The new Host function is:
static lldb::pid_t
Host::LaunchInNewTerminal (
const char **argv, // argv[0] is executable
const char **envp,
const ArchSpec *arch_spec,
bool stop_at_entry,
bool disable_aslr);
Cleaned up FileSpec::GetPath to not use strncpy() as it was always zero
filling the entire path buffer.
Fixed an issue with the dynamic checker function where I missed a '$' prefix
that should have been added.
llvm-svn: 116690
2010-10-18 06:03:32 +08:00
|
|
|
else if (filename)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-31 11:01:06 +08:00
|
|
|
return ::snprintf (path, path_max_len, "%s", filename);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2011-10-18 05:45:27 +08:00
|
|
|
if (path)
|
|
|
|
path[0] = '\0';
|
2010-10-31 11:01:06 +08:00
|
|
|
return 0;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-10-18 05:45:27 +08:00
|
|
|
ConstString
|
|
|
|
FileSpec::GetFileNameExtension () const
|
|
|
|
{
|
|
|
|
const char *filename = m_filename.GetCString();
|
|
|
|
if (filename == NULL)
|
|
|
|
return ConstString();
|
|
|
|
|
2011-10-19 03:28:30 +08:00
|
|
|
const char* dot_pos = strrchr(filename, '.');
|
2011-10-18 05:45:27 +08:00
|
|
|
if (dot_pos == NULL)
|
|
|
|
return ConstString();
|
|
|
|
|
|
|
|
return ConstString(dot_pos+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstString
|
|
|
|
FileSpec::GetFileNameStrippingExtension () const
|
|
|
|
{
|
|
|
|
const char *filename = m_filename.GetCString();
|
|
|
|
if (filename == NULL)
|
|
|
|
return ConstString();
|
|
|
|
|
2011-10-19 03:28:30 +08:00
|
|
|
const char* dot_pos = strrchr(filename, '.');
|
2011-10-18 05:45:27 +08:00
|
|
|
if (dot_pos == NULL)
|
|
|
|
return m_filename;
|
|
|
|
|
|
|
|
return ConstString(filename, dot_pos-filename);
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Returns a shared pointer to a data buffer that contains all or
|
|
|
|
// part of the contents of a file. The data is memory mapped and
|
|
|
|
// will lazily page in data from the file as memory is accessed.
|
|
|
|
// The data that is mappped will start "file_offset" bytes into the
|
|
|
|
// file, and "file_size" bytes will be mapped. If "file_size" is
|
|
|
|
// greater than the number of bytes available in the file starting
|
|
|
|
// at "file_offset", the number of bytes will be appropriately
|
|
|
|
// truncated. The final number of bytes that get mapped can be
|
|
|
|
// verified using the DataBuffer::GetByteSize() function.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
DataBufferSP
|
|
|
|
FileSpec::MemoryMapFileContents(off_t file_offset, size_t file_size) const
|
|
|
|
{
|
|
|
|
DataBufferSP data_sp;
|
|
|
|
auto_ptr<DataBufferMemoryMap> mmap_data(new DataBufferMemoryMap());
|
|
|
|
if (mmap_data.get())
|
|
|
|
{
|
|
|
|
if (mmap_data->MemoryMapFromFileSpec (this, file_offset, file_size) >= file_size)
|
|
|
|
data_sp.reset(mmap_data.release());
|
|
|
|
}
|
|
|
|
return data_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Return the size in bytes that this object takes in memory. This
|
|
|
|
// returns the size in bytes of this object, not any shared string
|
|
|
|
// values it may refer to.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
size_t
|
|
|
|
FileSpec::MemorySize() const
|
|
|
|
{
|
|
|
|
return m_filename.MemorySize() + m_directory.MemorySize();
|
|
|
|
}
|
|
|
|
|
2010-07-01 07:03:03 +08:00
|
|
|
|
|
|
|
size_t
|
2012-01-06 10:01:06 +08:00
|
|
|
FileSpec::ReadFileContents (off_t file_offset, void *dst, size_t dst_len, Error *error_ptr) const
|
2010-07-01 07:03:03 +08:00
|
|
|
{
|
2012-01-06 10:01:06 +08:00
|
|
|
Error error;
|
2010-07-01 07:03:03 +08:00
|
|
|
size_t bytes_read = 0;
|
|
|
|
char resolved_path[PATH_MAX];
|
|
|
|
if (GetPath(resolved_path, sizeof(resolved_path)))
|
|
|
|
{
|
2012-01-05 06:56:43 +08:00
|
|
|
File file;
|
|
|
|
error = file.Open(resolved_path, File::eOpenOptionRead);
|
|
|
|
if (error.Success())
|
2010-07-01 07:03:03 +08:00
|
|
|
{
|
2012-01-05 06:56:43 +08:00
|
|
|
off_t file_offset_after_seek = file_offset;
|
|
|
|
bytes_read = dst_len;
|
|
|
|
error = file.Read(dst, bytes_read, file_offset_after_seek);
|
2010-07-01 07:03:03 +08:00
|
|
|
}
|
|
|
|
}
|
2012-01-06 10:01:06 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetErrorString("invalid file specification");
|
|
|
|
}
|
|
|
|
if (error_ptr)
|
|
|
|
*error_ptr = error;
|
2010-07-01 07:03:03 +08:00
|
|
|
return bytes_read;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Returns a shared pointer to a data buffer that contains all or
|
|
|
|
// part of the contents of a file. The data copies into a heap based
|
|
|
|
// buffer that lives in the DataBuffer shared pointer object returned.
|
|
|
|
// The data that is cached will start "file_offset" bytes into the
|
|
|
|
// file, and "file_size" bytes will be mapped. If "file_size" is
|
|
|
|
// greater than the number of bytes available in the file starting
|
|
|
|
// at "file_offset", the number of bytes will be appropriately
|
|
|
|
// truncated. The final number of bytes that get mapped can be
|
|
|
|
// verified using the DataBuffer::GetByteSize() function.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
DataBufferSP
|
2012-01-06 10:01:06 +08:00
|
|
|
FileSpec::ReadFileContents (off_t file_offset, size_t file_size, Error *error_ptr) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-01-06 10:01:06 +08:00
|
|
|
Error error;
|
2010-06-09 00:52:24 +08:00
|
|
|
DataBufferSP data_sp;
|
|
|
|
char resolved_path[PATH_MAX];
|
|
|
|
if (GetPath(resolved_path, sizeof(resolved_path)))
|
|
|
|
{
|
2012-01-05 06:56:43 +08:00
|
|
|
File file;
|
|
|
|
error = file.Open(resolved_path, File::eOpenOptionRead);
|
|
|
|
if (error.Success())
|
|
|
|
error = file.Read (file_size, file_offset, data_sp);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2012-01-06 10:01:06 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetErrorString("invalid file specification");
|
|
|
|
}
|
|
|
|
if (error_ptr)
|
|
|
|
*error_ptr = error;
|
2010-06-09 00:52:24 +08:00
|
|
|
return data_sp;
|
|
|
|
}
|
|
|
|
|
2010-10-21 06:52:05 +08:00
|
|
|
size_t
|
2010-06-09 00:52:24 +08:00
|
|
|
FileSpec::ReadFileLines (STLStringArray &lines)
|
|
|
|
{
|
|
|
|
lines.clear();
|
2010-10-21 06:52:05 +08:00
|
|
|
char path[PATH_MAX];
|
|
|
|
if (GetPath(path, sizeof(path)))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-21 06:52:05 +08:00
|
|
|
ifstream file_stream (path);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-10-21 06:52:05 +08:00
|
|
|
if (file_stream)
|
|
|
|
{
|
|
|
|
std::string line;
|
|
|
|
while (getline (file_stream, line))
|
|
|
|
lines.push_back (line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lines.size();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
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::EnumerateDirectoryResult
|
|
|
|
FileSpec::EnumerateDirectory
|
|
|
|
(
|
|
|
|
const char *dir_path,
|
|
|
|
bool find_directories,
|
|
|
|
bool find_files,
|
|
|
|
bool find_other,
|
|
|
|
EnumerateDirectoryCallbackType callback,
|
|
|
|
void *callback_baton
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (dir_path && dir_path[0])
|
|
|
|
{
|
|
|
|
lldb_utility::CleanUp <DIR *, int> dir_path_dir (opendir(dir_path), NULL, closedir);
|
|
|
|
if (dir_path_dir.is_valid())
|
|
|
|
{
|
|
|
|
struct dirent* dp;
|
|
|
|
while ((dp = readdir(dir_path_dir.get())) != NULL)
|
|
|
|
{
|
|
|
|
// Only search directories
|
|
|
|
if (dp->d_type == DT_DIR || dp->d_type == DT_UNKNOWN)
|
|
|
|
{
|
2011-02-08 01:41:11 +08:00
|
|
|
size_t len = strlen(dp->d_name);
|
|
|
|
|
|
|
|
if (len == 1 && dp->d_name[0] == '.')
|
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
|
|
|
continue;
|
|
|
|
|
2011-02-08 01:41:11 +08:00
|
|
|
if (len == 2 && dp->d_name[0] == '.' && dp->d_name[1] == '.')
|
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
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool call_callback = false;
|
|
|
|
FileSpec::FileType file_type = eFileTypeUnknown;
|
|
|
|
|
|
|
|
switch (dp->d_type)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case DT_UNKNOWN: file_type = eFileTypeUnknown; call_callback = true; break;
|
|
|
|
case DT_FIFO: file_type = eFileTypePipe; call_callback = find_other; break;
|
|
|
|
case DT_CHR: file_type = eFileTypeOther; call_callback = find_other; break;
|
|
|
|
case DT_DIR: file_type = eFileTypeDirectory; call_callback = find_directories; break;
|
|
|
|
case DT_BLK: file_type = eFileTypeOther; call_callback = find_other; break;
|
|
|
|
case DT_REG: file_type = eFileTypeRegular; call_callback = find_files; break;
|
|
|
|
case DT_LNK: file_type = eFileTypeSymbolicLink; call_callback = find_other; break;
|
|
|
|
case DT_SOCK: file_type = eFileTypeSocket; call_callback = find_other; break;
|
2011-04-02 02:18:34 +08:00
|
|
|
#if !defined(__OpenBSD__)
|
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 DT_WHT: file_type = eFileTypeOther; call_callback = find_other; break;
|
2011-04-02 02:18:34 +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
|
|
|
}
|
|
|
|
|
|
|
|
if (call_callback)
|
|
|
|
{
|
|
|
|
char child_path[PATH_MAX];
|
|
|
|
const int child_path_len = ::snprintf (child_path, sizeof(child_path), "%s/%s", dir_path, dp->d_name);
|
2011-07-20 03:48:13 +08:00
|
|
|
if (child_path_len < (int)(sizeof(child_path) - 1))
|
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
|
|
|
{
|
|
|
|
// Don't resolve the file type or path
|
|
|
|
FileSpec child_path_spec (child_path, false);
|
|
|
|
|
|
|
|
EnumerateDirectoryResult result = callback (callback_baton, file_type, child_path_spec);
|
|
|
|
|
|
|
|
switch (result)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case eEnumerateDirectoryResultNext:
|
|
|
|
// Enumerate next entry in the current directory. We just
|
|
|
|
// exit this switch and will continue enumerating the
|
|
|
|
// current directory as we currently are...
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eEnumerateDirectoryResultEnter: // Recurse into the current entry if it is a directory or symlink, or next if not
|
|
|
|
if (FileSpec::EnumerateDirectory (child_path,
|
|
|
|
find_directories,
|
|
|
|
find_files,
|
|
|
|
find_other,
|
|
|
|
callback,
|
|
|
|
callback_baton) == eEnumerateDirectoryResultQuit)
|
|
|
|
{
|
|
|
|
// The subdirectory returned Quit, which means to
|
|
|
|
// stop all directory enumerations at all levels.
|
|
|
|
return eEnumerateDirectoryResultQuit;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eEnumerateDirectoryResultExit: // Exit from the current directory at the current level.
|
|
|
|
// Exit from this directory level and tell parent to
|
|
|
|
// keep enumerating.
|
|
|
|
return eEnumerateDirectoryResultNext;
|
|
|
|
|
|
|
|
case eEnumerateDirectoryResultQuit: // Stop directory enumerations at any level
|
|
|
|
return eEnumerateDirectoryResultQuit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// By default when exiting a directory, we tell the parent enumeration
|
|
|
|
// to continue enumerating.
|
|
|
|
return eEnumerateDirectoryResultNext;
|
|
|
|
}
|
|
|
|
|