2010-06-08 16:52:24 +00: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.
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
|
2013-08-23 12:44:05 +00:00
|
|
|
#ifndef _WIN32
|
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 02:24:04 +00:00
|
|
|
#include <dirent.h>
|
2013-08-23 12:44:05 +00:00
|
|
|
#else
|
|
|
|
|
#include "lldb/Host/windows/windows.h"
|
|
|
|
|
#endif
|
2010-06-08 16:52:24 +00:00
|
|
|
#include <fcntl.h>
|
2013-09-20 22:35:22 +00:00
|
|
|
#ifndef _MSC_VER
|
2010-06-08 16:52:24 +00:00
|
|
|
#include <libgen.h>
|
2013-09-20 22:35:22 +00:00
|
|
|
#endif
|
2010-06-08 16:52:24 +00:00
|
|
|
#include <sys/stat.h>
|
2013-06-13 20:10:23 +00:00
|
|
|
#include <set>
|
2011-02-07 17:41:11 +00:00
|
|
|
#include <string.h>
|
2011-02-07 19:42:39 +00:00
|
|
|
#include <fstream>
|
2011-02-05 02:27:52 +00:00
|
|
|
|
2011-02-07 19:42:39 +00:00
|
|
|
#include "lldb/Host/Config.h" // Have to include this before we test the define...
|
2011-02-08 00:35:34 +00:00
|
|
|
#ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
|
2010-07-01 01:48:53 +00:00
|
|
|
#include <pwd.h>
|
2011-02-05 02:27:52 +00:00
|
|
|
#endif
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2015-05-09 01:21:32 +00:00
|
|
|
#include "lldb/Core/ArchSpec.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Core/DataBufferHeap.h"
|
|
|
|
|
#include "lldb/Core/DataBufferMemoryMap.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-29 21:13:06 +00:00
|
|
|
#include "lldb/Core/RegularExpression.h"
|
2014-08-15 22:04:21 +00:00
|
|
|
#include "lldb/Core/StreamString.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Core/Stream.h"
|
2014-08-15 22:04:21 +00:00
|
|
|
#include "lldb/Host/File.h"
|
|
|
|
|
#include "lldb/Host/FileSpec.h"
|
|
|
|
|
#include "lldb/Host/FileSystem.h"
|
2010-09-10 04:48:55 +00: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 02:24:04 +00:00
|
|
|
#include "lldb/Utility/CleanUp.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2014-08-15 22:04:21 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
|
#include "llvm/Support/Program.h"
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
2015-05-28 17:02:45 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
PathSyntaxIsPosix(FileSpec::PathSyntax syntax)
|
|
|
|
|
{
|
|
|
|
|
return (syntax == FileSpec::ePathSyntaxPosix ||
|
|
|
|
|
(syntax == FileSpec::ePathSyntaxHostNative &&
|
|
|
|
|
FileSystem::GetNativePathSyntax() == FileSpec::ePathSyntaxPosix));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char
|
|
|
|
|
GetPathSeparator(FileSpec::PathSyntax syntax)
|
|
|
|
|
{
|
|
|
|
|
return PathSyntaxIsPosix(syntax) ? '/' : '\\';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Normalize(llvm::SmallVectorImpl<char> &path, FileSpec::PathSyntax syntax)
|
|
|
|
|
{
|
|
|
|
|
if (PathSyntaxIsPosix(syntax)) return;
|
|
|
|
|
|
|
|
|
|
std::replace(path.begin(), path.end(), '\\', '/');
|
|
|
|
|
// Windows path can have \\ slashes which can be changed by replace
|
|
|
|
|
// call above to //. Here we remove the duplicate.
|
|
|
|
|
auto iter = std::unique ( path.begin(), path.end(),
|
|
|
|
|
[]( char &c1, char &c2 ){
|
|
|
|
|
return (c1 == '/' && c2 == '/');});
|
|
|
|
|
path.erase(iter, path.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Denormalize(llvm::SmallVectorImpl<char> &path, FileSpec::PathSyntax syntax)
|
|
|
|
|
{
|
|
|
|
|
if (PathSyntaxIsPosix(syntax)) return;
|
|
|
|
|
|
|
|
|
|
std::replace(path.begin(), path.end(), '/', '\\');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
2010-06-08 16:52:24 +00:00
|
|
|
GetFileStats (const FileSpec *file_spec, struct stat *stats_ptr)
|
|
|
|
|
{
|
|
|
|
|
char resolved_path[PATH_MAX];
|
2011-04-23 02:04:55 +00:00
|
|
|
if (file_spec->GetPath (resolved_path, sizeof(resolved_path)))
|
2010-06-08 16:52:24 +00:00
|
|
|
return ::stat (resolved_path, stats_ptr) == 0;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-28 17:02:45 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-01 01:48:53 +00:00
|
|
|
// Resolves the username part of a path of the form ~user/other/directories, and
|
2014-09-12 23:50:36 +00:00
|
|
|
// writes the result into dst_path. This will also resolve "~" to the current user.
|
|
|
|
|
// If you want to complete "~" to the list of users, pass it to ResolvePartialUsername.
|
2014-08-07 17:33:36 +00:00
|
|
|
void
|
|
|
|
|
FileSpec::ResolveUsername (llvm::SmallVectorImpl<char> &path)
|
2010-07-01 01:48:53 +00:00
|
|
|
{
|
2014-08-07 17:33:36 +00:00
|
|
|
#if LLDB_CONFIG_TILDE_RESOLVES_TO_USER
|
|
|
|
|
if (path.empty() || path[0] != '~')
|
|
|
|
|
return;
|
2010-07-01 17:07:48 +00:00
|
|
|
|
2015-01-20 04:20:42 +00:00
|
|
|
llvm::StringRef path_str(path.data(), path.size());
|
2014-08-07 17:33:36 +00:00
|
|
|
size_t slash_pos = path_str.find_first_of("/", 1);
|
2014-09-12 23:50:36 +00:00
|
|
|
if (slash_pos == 1 || path.size() == 1)
|
2010-07-01 01:48:53 +00:00
|
|
|
{
|
2014-09-12 23:04:40 +00:00
|
|
|
// A path of ~/ resolves to the current user's home dir
|
2014-08-07 17:33:36 +00:00
|
|
|
llvm::SmallString<64> home_dir;
|
|
|
|
|
if (!llvm::sys::path::home_directory(home_dir))
|
|
|
|
|
return;
|
2010-07-01 17:07:48 +00:00
|
|
|
|
2014-08-07 17:33:36 +00:00
|
|
|
// Overwrite the ~ with the first character of the homedir, and insert
|
|
|
|
|
// the rest. This way we only trigger one move, whereas an insert
|
|
|
|
|
// followed by a delete (or vice versa) would trigger two.
|
|
|
|
|
path[0] = home_dir[0];
|
|
|
|
|
path.insert(path.begin() + 1, home_dir.begin() + 1, home_dir.end());
|
|
|
|
|
return;
|
2010-07-01 01:48:53 +00:00
|
|
|
}
|
2010-07-01 17:07:48 +00:00
|
|
|
|
2014-08-07 17:33:36 +00:00
|
|
|
auto username_begin = path.begin()+1;
|
|
|
|
|
auto username_end = (slash_pos == llvm::StringRef::npos)
|
|
|
|
|
? path.end()
|
|
|
|
|
: (path.begin() + slash_pos);
|
|
|
|
|
size_t replacement_length = std::distance(path.begin(), username_end);
|
|
|
|
|
|
|
|
|
|
llvm::SmallString<20> username(username_begin, username_end);
|
|
|
|
|
struct passwd *user_entry = ::getpwnam(username.c_str());
|
|
|
|
|
if (user_entry != nullptr)
|
2010-07-01 01:48:53 +00:00
|
|
|
{
|
2014-08-07 17:33:36 +00:00
|
|
|
// Copy over the first n characters of the path, where n is the smaller of the length
|
|
|
|
|
// of the home directory and the slash pos.
|
|
|
|
|
llvm::StringRef homedir(user_entry->pw_dir);
|
|
|
|
|
size_t initial_copy_length = std::min(homedir.size(), replacement_length);
|
|
|
|
|
auto src_begin = homedir.begin();
|
|
|
|
|
auto src_end = src_begin + initial_copy_length;
|
|
|
|
|
std::copy(src_begin, src_end, path.begin());
|
|
|
|
|
if (replacement_length > homedir.size())
|
|
|
|
|
{
|
|
|
|
|
// We copied the entire home directory, but the ~username portion of the path was
|
|
|
|
|
// longer, so there's characters that need to be removed.
|
|
|
|
|
path.erase(path.begin() + initial_copy_length, username_end);
|
|
|
|
|
}
|
|
|
|
|
else if (replacement_length < homedir.size())
|
|
|
|
|
{
|
|
|
|
|
// We copied all the way up to the slash in the destination, but there's still more
|
|
|
|
|
// characters that need to be inserted.
|
|
|
|
|
path.insert(username_end, src_end, homedir.end());
|
|
|
|
|
}
|
2010-07-01 01:48:53 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-08-07 17:33:36 +00:00
|
|
|
// Unable to resolve username (user doesn't exist?)
|
|
|
|
|
path.clear();
|
2010-07-01 01:48:53 +00:00
|
|
|
}
|
2014-08-07 17:33:36 +00:00
|
|
|
#endif
|
2010-07-01 01:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-08 23:24:09 +00: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
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 17:33:36 +00:00
|
|
|
void
|
|
|
|
|
FileSpec::Resolve (llvm::SmallVectorImpl<char> &path)
|
2010-06-08 16:52:24 +00:00
|
|
|
{
|
2014-08-07 17:33:36 +00:00
|
|
|
if (path.empty())
|
|
|
|
|
return;
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2011-02-08 00:35:34 +00:00
|
|
|
#ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
|
2014-08-07 17:33:36 +00:00
|
|
|
if (path[0] == '~')
|
|
|
|
|
ResolveUsername(path);
|
2011-02-08 00:35:34 +00:00
|
|
|
#endif // #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2015-02-25 02:35:25 +00:00
|
|
|
// Save a copy of the original path that's passed in
|
|
|
|
|
llvm::SmallString<PATH_MAX> original_path(path.begin(), path.end());
|
|
|
|
|
|
2014-08-07 17:33:36 +00:00
|
|
|
llvm::sys::fs::make_absolute(path);
|
2015-02-25 02:35:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
path.push_back(0); // Be sure we have a nul terminated string
|
|
|
|
|
path.pop_back();
|
|
|
|
|
struct stat file_stats;
|
|
|
|
|
if (::stat (path.data(), &file_stats) != 0)
|
|
|
|
|
{
|
|
|
|
|
path.clear();
|
|
|
|
|
path.append(original_path.begin(), original_path.end());
|
|
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2014-10-15 03:04:33 +00:00
|
|
|
FileSpec::FileSpec() :
|
|
|
|
|
m_directory(),
|
|
|
|
|
m_filename(),
|
|
|
|
|
m_syntax(FileSystem::GetNativePathSyntax())
|
2010-06-08 16:52:24 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-16 00:57:33 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
// Default constructor that can take an optional full path to a
|
|
|
|
|
// file on disk.
|
|
|
|
|
//------------------------------------------------------------------
|
2014-08-07 17:33:07 +00:00
|
|
|
FileSpec::FileSpec(const char *pathname, bool resolve_path, PathSyntax syntax) :
|
2010-09-16 00:57:33 +00:00
|
|
|
m_directory(),
|
2010-11-08 00:28:40 +00:00
|
|
|
m_filename(),
|
2014-10-15 03:04:33 +00:00
|
|
|
m_is_resolved(false),
|
|
|
|
|
m_syntax(syntax)
|
2010-09-16 00:57:33 +00:00
|
|
|
{
|
|
|
|
|
if (pathname && pathname[0])
|
2014-08-07 17:33:07 +00:00
|
|
|
SetFile(pathname, resolve_path, syntax);
|
2010-09-16 00:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-09 01:21:32 +00:00
|
|
|
FileSpec::FileSpec(const char *pathname, bool resolve_path, ArchSpec arch) :
|
2015-05-29 19:52:29 +00:00
|
|
|
FileSpec{pathname, resolve_path, arch.GetTriple().isOSWindows() ? ePathSyntaxWindows : ePathSyntaxPosix}
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileSpec::FileSpec(const std::string &path, bool resolve_path, PathSyntax syntax) :
|
|
|
|
|
FileSpec{path.c_str(), resolve_path, syntax}
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileSpec::FileSpec(const std::string &path, bool resolve_path, ArchSpec arch) :
|
|
|
|
|
FileSpec{path.c_str(), resolve_path, arch}
|
2015-05-09 01:21:32 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
// Copy constructor
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
FileSpec::FileSpec(const FileSpec& rhs) :
|
|
|
|
|
m_directory (rhs.m_directory),
|
2010-11-08 00:28:40 +00:00
|
|
|
m_filename (rhs.m_filename),
|
2014-08-07 17:33:07 +00:00
|
|
|
m_is_resolved (rhs.m_is_resolved),
|
|
|
|
|
m_syntax (rhs.m_syntax)
|
2010-06-08 16:52:24 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
// Copy constructor
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
FileSpec::FileSpec(const FileSpec* rhs) :
|
|
|
|
|
m_directory(),
|
|
|
|
|
m_filename()
|
|
|
|
|
{
|
|
|
|
|
if (rhs)
|
|
|
|
|
*this = *rhs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
2014-07-01 21:22:11 +00:00
|
|
|
// Virtual destructor in case anyone inherits from this class.
|
2010-06-08 16:52:24 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
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 00:28:40 +00:00
|
|
|
m_is_resolved = rhs.m_is_resolved;
|
2014-08-07 17:33:07 +00:00
|
|
|
m_syntax = rhs.m_syntax;
|
2010-06-08 16:52:24 +00: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
|
2014-08-07 17:33:07 +00:00
|
|
|
FileSpec::SetFile (const char *pathname, bool resolve, PathSyntax syntax)
|
2010-06-08 16:52:24 +00:00
|
|
|
{
|
|
|
|
|
m_filename.Clear();
|
|
|
|
|
m_directory.Clear();
|
2010-11-08 00:28:40 +00:00
|
|
|
m_is_resolved = false;
|
2014-08-15 22:04:21 +00:00
|
|
|
m_syntax = (syntax == ePathSyntaxHostNative) ? FileSystem::GetNativePathSyntax() : syntax;
|
2014-08-07 17:33:07 +00:00
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
if (pathname == NULL || pathname[0] == '\0')
|
|
|
|
|
return;
|
|
|
|
|
|
2014-08-07 17:33:36 +00:00
|
|
|
llvm::SmallString<64> normalized(pathname);
|
2014-08-07 17:33:07 +00:00
|
|
|
|
2010-09-16 00:57:33 +00:00
|
|
|
if (resolve)
|
|
|
|
|
{
|
2014-08-07 17:33:36 +00:00
|
|
|
FileSpec::Resolve (normalized);
|
|
|
|
|
m_is_resolved = true;
|
2010-09-16 00:57:33 +00:00
|
|
|
}
|
2014-12-01 23:13:32 +00:00
|
|
|
|
|
|
|
|
// Only normalize after resolving the path. Resolution will modify the path
|
|
|
|
|
// string, potentially adding wrong kinds of slashes to the path, that need
|
|
|
|
|
// to be re-normalized.
|
|
|
|
|
Normalize(normalized, syntax);
|
|
|
|
|
|
2014-08-07 17:33:36 +00:00
|
|
|
llvm::StringRef resolve_path_ref(normalized.c_str());
|
|
|
|
|
llvm::StringRef filename_ref = llvm::sys::path::filename(resolve_path_ref);
|
|
|
|
|
if (!filename_ref.empty())
|
2010-06-08 16:52:24 +00:00
|
|
|
{
|
2014-08-07 17:33:36 +00:00
|
|
|
m_filename.SetString (filename_ref);
|
|
|
|
|
llvm::StringRef directory_ref = llvm::sys::path::parent_path(resolve_path_ref);
|
|
|
|
|
if (!directory_ref.empty())
|
|
|
|
|
m_directory.SetString(directory_ref);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2014-08-07 17:33:36 +00:00
|
|
|
else
|
|
|
|
|
m_directory.SetCString(normalized.c_str());
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-29 19:52:29 +00:00
|
|
|
void
|
|
|
|
|
FileSpec::SetFile(const std::string &pathname, bool resolve, PathSyntax syntax)
|
|
|
|
|
{
|
|
|
|
|
return SetFile(pathname.c_str(), resolve, syntax);
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
// 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 04:00:42 +00:00
|
|
|
FileSpec::operator bool() const
|
2010-06-08 16:52:24 +00:00
|
|
|
{
|
2011-09-12 04:00:42 +00:00
|
|
|
return m_filename || m_directory;
|
2010-06-08 16:52:24 +00: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 00:28:40 +00: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
|
2012-11-03 02:12:46 +00:00
|
|
|
rhs.m_is_resolved = (rhs.m_directory == resolved_rhs.m_directory);
|
2010-11-08 00:28:40 +00:00
|
|
|
}
|
|
|
|
|
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-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
// Not equal to operator
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
bool
|
|
|
|
|
FileSpec::operator!= (const FileSpec& rhs) const
|
|
|
|
|
{
|
2010-11-08 00:28:40 +00:00
|
|
|
return !(*this == rhs);
|
2010-06-08 16:52:24 +00: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
|
2014-11-15 01:54:26 +00:00
|
|
|
FileSpec::Equal (const FileSpec& a, const FileSpec& b, bool full, bool remove_backups)
|
2010-06-08 16:52:24 +00:00
|
|
|
{
|
2011-09-23 00:54:11 +00:00
|
|
|
if (!full && (a.GetDirectory().IsEmpty() || b.GetDirectory().IsEmpty()))
|
2010-06-08 16:52:24 +00:00
|
|
|
return a.m_filename == b.m_filename;
|
2014-11-15 01:54:26 +00:00
|
|
|
else if (remove_backups == false)
|
2011-09-23 00:54:11 +00:00
|
|
|
return a == b;
|
2014-11-15 01:54:26 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (a.m_filename != b.m_filename)
|
|
|
|
|
return false;
|
|
|
|
|
if (a.m_directory == b.m_directory)
|
|
|
|
|
return true;
|
|
|
|
|
ConstString a_without_dots;
|
|
|
|
|
ConstString b_without_dots;
|
|
|
|
|
|
|
|
|
|
RemoveBackupDots (a.m_directory, a_without_dots);
|
|
|
|
|
RemoveBackupDots (b.m_directory, b_without_dots);
|
|
|
|
|
return a_without_dots == b_without_dots;
|
|
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-15 01:54:26 +00:00
|
|
|
void
|
|
|
|
|
FileSpec::RemoveBackupDots (const ConstString &input_const_str, ConstString &result_const_str)
|
|
|
|
|
{
|
|
|
|
|
const char *input = input_const_str.GetCString();
|
|
|
|
|
result_const_str.Clear();
|
|
|
|
|
if (!input || input[0] == '\0')
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const char win_sep = '\\';
|
|
|
|
|
const char unix_sep = '/';
|
|
|
|
|
char found_sep;
|
|
|
|
|
const char *win_backup = "\\..";
|
|
|
|
|
const char *unix_backup = "/..";
|
|
|
|
|
|
|
|
|
|
bool is_win = false;
|
|
|
|
|
|
|
|
|
|
// Determine the platform for the path (win or unix):
|
|
|
|
|
|
|
|
|
|
if (input[0] == win_sep)
|
|
|
|
|
is_win = true;
|
|
|
|
|
else if (input[0] == unix_sep)
|
|
|
|
|
is_win = false;
|
|
|
|
|
else if (input[1] == ':')
|
|
|
|
|
is_win = true;
|
|
|
|
|
else if (strchr(input, unix_sep) != nullptr)
|
|
|
|
|
is_win = false;
|
|
|
|
|
else if (strchr(input, win_sep) != nullptr)
|
|
|
|
|
is_win = true;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// No separators at all, no reason to do any work here.
|
|
|
|
|
result_const_str = input_const_str;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
llvm::StringRef backup_sep;
|
|
|
|
|
if (is_win)
|
|
|
|
|
{
|
|
|
|
|
found_sep = win_sep;
|
|
|
|
|
backup_sep = win_backup;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
found_sep = unix_sep;
|
|
|
|
|
backup_sep = unix_backup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
llvm::StringRef input_ref(input);
|
|
|
|
|
llvm::StringRef curpos(input);
|
|
|
|
|
|
|
|
|
|
bool had_dots = false;
|
|
|
|
|
std::string result;
|
|
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
// Start of loop
|
|
|
|
|
llvm::StringRef before_sep;
|
|
|
|
|
std::pair<llvm::StringRef, llvm::StringRef> around_sep = curpos.split(backup_sep);
|
|
|
|
|
|
|
|
|
|
before_sep = around_sep.first;
|
|
|
|
|
curpos = around_sep.second;
|
|
|
|
|
|
|
|
|
|
if (curpos.empty())
|
|
|
|
|
{
|
|
|
|
|
if (had_dots)
|
|
|
|
|
{
|
2015-05-05 20:26:58 +00:00
|
|
|
while (before_sep.startswith("//"))
|
|
|
|
|
before_sep = before_sep.substr(1);
|
2014-11-15 01:54:26 +00:00
|
|
|
if (!before_sep.empty())
|
|
|
|
|
{
|
|
|
|
|
result.append(before_sep.data(), before_sep.size());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
had_dots = true;
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2014-11-15 01:54:26 +00:00
|
|
|
unsigned num_backups = 1;
|
|
|
|
|
while (curpos.startswith(backup_sep))
|
|
|
|
|
{
|
|
|
|
|
num_backups++;
|
|
|
|
|
curpos = curpos.slice(backup_sep.size(), curpos.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t end_pos = before_sep.size();
|
|
|
|
|
while (num_backups-- > 0)
|
|
|
|
|
{
|
|
|
|
|
end_pos = before_sep.rfind(found_sep, end_pos);
|
|
|
|
|
if (end_pos == llvm::StringRef::npos)
|
|
|
|
|
{
|
|
|
|
|
result_const_str = input_const_str;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result.append(before_sep.data(), end_pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (had_dots)
|
|
|
|
|
result_const_str.SetCString(result.c_str());
|
|
|
|
|
else
|
|
|
|
|
result_const_str = input_const_str;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-06-08 16:52:24 +00: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
|
2015-05-28 17:02:45 +00:00
|
|
|
FileSpec::Dump(Stream *s) const
|
2010-06-08 16:52:24 +00:00
|
|
|
{
|
2012-11-03 00:09:46 +00:00
|
|
|
if (s)
|
|
|
|
|
{
|
2015-05-28 17:02:45 +00:00
|
|
|
std::string path{GetPath(true)};
|
|
|
|
|
s->PutCString(path.c_str());
|
|
|
|
|
char path_separator = GetPathSeparator(m_syntax);
|
|
|
|
|
if (!m_filename && !path.empty() && path.back() != path_separator)
|
|
|
|
|
s->PutChar(path_separator);
|
2012-11-03 00:09:46 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
// Returns true if the file exists.
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
bool
|
|
|
|
|
FileSpec::Exists () const
|
|
|
|
|
{
|
|
|
|
|
struct stat file_stats;
|
|
|
|
|
return GetFileStats (this, &file_stats);
|
2010-09-10 04:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-15 18:00:45 +00:00
|
|
|
bool
|
|
|
|
|
FileSpec::Readable () const
|
|
|
|
|
{
|
|
|
|
|
const uint32_t permissions = GetPermissions();
|
|
|
|
|
if (permissions & eFilePermissionsEveryoneR)
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-10 04:48:55 +00:00
|
|
|
bool
|
|
|
|
|
FileSpec::ResolveExecutableLocation ()
|
|
|
|
|
{
|
2010-10-20 20:54:39 +00:00
|
|
|
if (!m_directory)
|
2010-09-12 00:10:52 +00:00
|
|
|
{
|
2011-01-25 21:32:01 +00:00
|
|
|
const char *file_cstr = m_filename.GetCString();
|
|
|
|
|
if (file_cstr)
|
2010-09-12 00:10:52 +00:00
|
|
|
{
|
2011-01-25 21:32:01 +00:00
|
|
|
const std::string file_str (file_cstr);
|
2014-11-04 19:33:45 +00:00
|
|
|
llvm::ErrorOr<std::string> error_or_path = llvm::sys::findProgramByName (file_str);
|
|
|
|
|
if (!error_or_path)
|
|
|
|
|
return false;
|
|
|
|
|
std::string path = error_or_path.get();
|
2013-06-13 19:25:41 +00:00
|
|
|
llvm::StringRef dir_ref = llvm::sys::path::parent_path(path);
|
2014-05-30 21:06:57 +00:00
|
|
|
if (!dir_ref.empty())
|
2010-09-12 00:10:52 +00:00
|
|
|
{
|
2011-01-25 21:32:01 +00: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 00:10:52 +00:00
|
|
|
return true;
|
2011-01-25 21:32:01 +00: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 00:10:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2010-09-16 00:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
FileSpec::ResolvePath ()
|
|
|
|
|
{
|
2010-11-08 00:28:40 +00:00
|
|
|
if (m_is_resolved)
|
|
|
|
|
return true; // We have already resolved this path
|
|
|
|
|
|
|
|
|
|
char path_buf[PATH_MAX];
|
2014-08-07 17:33:07 +00:00
|
|
|
if (!GetPath (path_buf, PATH_MAX, false))
|
2010-09-16 00:57:33 +00:00
|
|
|
return false;
|
2010-11-08 00:28:40 +00:00
|
|
|
// SetFile(...) will set m_is_resolved correctly if it can resolve the path
|
2010-09-16 00:57:33 +00:00
|
|
|
SetFile (path_buf, true);
|
2010-11-08 00:28:40 +00:00
|
|
|
return m_is_resolved;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
|
FileSpec::GetByteSize() const
|
|
|
|
|
{
|
|
|
|
|
struct stat file_stats;
|
|
|
|
|
if (GetFileStats (this, &file_stats))
|
|
|
|
|
return file_stats.st_size;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 17:33:07 +00:00
|
|
|
FileSpec::PathSyntax
|
|
|
|
|
FileSpec::GetPathSyntax() const
|
|
|
|
|
{
|
|
|
|
|
return m_syntax;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
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_IFREG: return eFileTypeRegular;
|
2013-08-23 12:44:05 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
case S_IFIFO: return eFileTypePipe;
|
2010-06-08 16:52:24 +00:00
|
|
|
case S_IFSOCK: return eFileTypeSocket;
|
|
|
|
|
case S_IFLNK: return eFileTypeSymbolicLink;
|
2013-08-23 12:44:05 +00:00
|
|
|
#endif
|
2010-06-08 16:52:24 +00:00
|
|
|
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 02:24:04 +00:00
|
|
|
return eFileTypeUnknown;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
return eFileTypeInvalid;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-20 21:07:01 +00:00
|
|
|
uint32_t
|
|
|
|
|
FileSpec::GetPermissions () const
|
|
|
|
|
{
|
|
|
|
|
uint32_t file_permissions = 0;
|
|
|
|
|
if (*this)
|
2015-05-29 19:52:29 +00:00
|
|
|
FileSystem::GetFilePermissions(*this, file_permissions);
|
2013-11-20 21:07:01 +00:00
|
|
|
return file_permissions;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
TimeValue
|
|
|
|
|
FileSpec::GetModificationTime () const
|
|
|
|
|
{
|
|
|
|
|
TimeValue mod_time;
|
|
|
|
|
struct stat file_stats;
|
|
|
|
|
if (GetFileStats (this, &file_stats))
|
2010-06-11 04:52:22 +00:00
|
|
|
mod_time.OffsetWithSeconds(file_stats.st_mtime);
|
2010-06-08 16:52:24 +00: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 03:01:06 +00:00
|
|
|
size_t
|
2014-08-07 17:33:07 +00:00
|
|
|
FileSpec::GetPath(char *path, size_t path_max_len, bool denormalize) const
|
2010-06-08 16:52:24 +00:00
|
|
|
{
|
2014-08-08 23:54:35 +00:00
|
|
|
if (!path)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2014-08-07 17:33:07 +00:00
|
|
|
std::string result = GetPath(denormalize);
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-27 19:43:08 +00:00
|
|
|
::snprintf(path, path_max_len, "%s", result.c_str());
|
|
|
|
|
return std::min(path_max_len-1, result.length());
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-29 16:36:27 +00:00
|
|
|
std::string
|
2015-04-09 18:08:50 +00:00
|
|
|
FileSpec::GetPath(bool denormalize) const
|
2013-04-29 09:46:43 +00:00
|
|
|
{
|
2014-08-07 17:33:07 +00:00
|
|
|
llvm::SmallString<64> result;
|
2015-04-09 18:08:50 +00:00
|
|
|
GetPath(result, denormalize);
|
|
|
|
|
return std::string(result.begin(), result.end());
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-29 19:52:29 +00:00
|
|
|
const char *
|
|
|
|
|
FileSpec::GetCString(bool denormalize) const
|
|
|
|
|
{
|
|
|
|
|
return ConstString{GetPath(denormalize)}.AsCString(NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-09 18:08:50 +00:00
|
|
|
void
|
|
|
|
|
FileSpec::GetPath(llvm::SmallVectorImpl<char> &path, bool denormalize) const
|
|
|
|
|
{
|
2015-05-28 17:02:45 +00:00
|
|
|
path.append(m_directory.GetStringRef().begin(), m_directory.GetStringRef().end());
|
|
|
|
|
if (m_directory)
|
|
|
|
|
path.insert(path.end(), '/');
|
|
|
|
|
path.append(m_filename.GetStringRef().begin(), m_filename.GetStringRef().end());
|
2015-04-09 18:08:50 +00:00
|
|
|
Normalize(path, m_syntax);
|
2015-05-28 17:02:45 +00:00
|
|
|
if (path.size() > 1 && path.back() == '/') path.pop_back();
|
2015-04-09 18:08:50 +00:00
|
|
|
if (denormalize && !path.empty())
|
2015-05-28 17:02:45 +00:00
|
|
|
Denormalize(path, m_syntax);
|
2013-04-29 09:46:43 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-17 21:45:27 +00:00
|
|
|
ConstString
|
|
|
|
|
FileSpec::GetFileNameExtension () const
|
|
|
|
|
{
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-29 21:13:06 +00:00
|
|
|
if (m_filename)
|
|
|
|
|
{
|
|
|
|
|
const char *filename = m_filename.GetCString();
|
|
|
|
|
const char* dot_pos = strrchr(filename, '.');
|
|
|
|
|
if (dot_pos && dot_pos[1] != '\0')
|
|
|
|
|
return ConstString(dot_pos+1);
|
|
|
|
|
}
|
|
|
|
|
return ConstString();
|
2011-10-17 21:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConstString
|
|
|
|
|
FileSpec::GetFileNameStrippingExtension () const
|
|
|
|
|
{
|
|
|
|
|
const char *filename = m_filename.GetCString();
|
|
|
|
|
if (filename == NULL)
|
|
|
|
|
return ConstString();
|
|
|
|
|
|
2011-10-18 19:28:30 +00:00
|
|
|
const char* dot_pos = strrchr(filename, '.');
|
2011-10-17 21:45:27 +00:00
|
|
|
if (dot_pos == NULL)
|
|
|
|
|
return m_filename;
|
|
|
|
|
|
|
|
|
|
return ConstString(filename, dot_pos-filename);
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00: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.
|
2014-07-01 21:22:11 +00:00
|
|
|
// The data that is mapped will start "file_offset" bytes into the
|
2010-06-08 16:52:24 +00:00
|
|
|
// 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;
|
2013-04-18 22:45:39 +00:00
|
|
|
std::unique_ptr<DataBufferMemoryMap> mmap_data(new DataBufferMemoryMap());
|
2010-06-08 16:52:24 +00:00
|
|
|
if (mmap_data.get())
|
|
|
|
|
{
|
2013-04-20 00:23:26 +00:00
|
|
|
const size_t mapped_length = mmap_data->MemoryMapFromFileSpec (this, file_offset, file_size);
|
|
|
|
|
if (((file_size == SIZE_MAX) && (mapped_length > 0)) || (mapped_length >= file_size))
|
2010-06-08 16:52:24 +00:00
|
|
|
data_sp.reset(mmap_data.release());
|
|
|
|
|
}
|
|
|
|
|
return data_sp;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-23 23:47:09 +00:00
|
|
|
DataBufferSP
|
|
|
|
|
FileSpec::MemoryMapFileContentsIfLocal(off_t file_offset, size_t file_size) const
|
|
|
|
|
{
|
|
|
|
|
if (FileSystem::IsLocal(*this))
|
|
|
|
|
return MemoryMapFileContents(file_offset, file_size);
|
|
|
|
|
else
|
|
|
|
|
return ReadFileContents(file_offset, file_size, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
// 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-06-30 23:03:03 +00:00
|
|
|
|
|
|
|
|
size_t
|
2012-01-06 02:01:06 +00:00
|
|
|
FileSpec::ReadFileContents (off_t file_offset, void *dst, size_t dst_len, Error *error_ptr) const
|
2010-06-30 23:03:03 +00:00
|
|
|
{
|
2012-01-06 02:01:06 +00:00
|
|
|
Error error;
|
2010-06-30 23:03:03 +00:00
|
|
|
size_t bytes_read = 0;
|
|
|
|
|
char resolved_path[PATH_MAX];
|
|
|
|
|
if (GetPath(resolved_path, sizeof(resolved_path)))
|
|
|
|
|
{
|
2012-01-04 22:56:43 +00:00
|
|
|
File file;
|
|
|
|
|
error = file.Open(resolved_path, File::eOpenOptionRead);
|
|
|
|
|
if (error.Success())
|
2010-06-30 23:03:03 +00:00
|
|
|
{
|
2012-01-04 22:56:43 +00:00
|
|
|
off_t file_offset_after_seek = file_offset;
|
|
|
|
|
bytes_read = dst_len;
|
|
|
|
|
error = file.Read(dst, bytes_read, file_offset_after_seek);
|
2010-06-30 23:03:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-01-06 02:01:06 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
error.SetErrorString("invalid file specification");
|
|
|
|
|
}
|
|
|
|
|
if (error_ptr)
|
|
|
|
|
*error_ptr = error;
|
2010-06-30 23:03:03 +00:00
|
|
|
return bytes_read;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00: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 02:01:06 +00:00
|
|
|
FileSpec::ReadFileContents (off_t file_offset, size_t file_size, Error *error_ptr) const
|
2010-06-08 16:52:24 +00:00
|
|
|
{
|
2012-01-06 02:01:06 +00:00
|
|
|
Error error;
|
2010-06-08 16:52:24 +00:00
|
|
|
DataBufferSP data_sp;
|
|
|
|
|
char resolved_path[PATH_MAX];
|
|
|
|
|
if (GetPath(resolved_path, sizeof(resolved_path)))
|
|
|
|
|
{
|
2012-01-04 22:56:43 +00:00
|
|
|
File file;
|
|
|
|
|
error = file.Open(resolved_path, File::eOpenOptionRead);
|
|
|
|
|
if (error.Success())
|
2012-08-30 18:15:10 +00:00
|
|
|
{
|
|
|
|
|
const bool null_terminate = false;
|
|
|
|
|
error = file.Read (file_size, file_offset, null_terminate, data_sp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
error.SetErrorString("invalid file specification");
|
|
|
|
|
}
|
|
|
|
|
if (error_ptr)
|
|
|
|
|
*error_ptr = error;
|
|
|
|
|
return data_sp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DataBufferSP
|
|
|
|
|
FileSpec::ReadFileContentsAsCString(Error *error_ptr)
|
|
|
|
|
{
|
|
|
|
|
Error error;
|
|
|
|
|
DataBufferSP data_sp;
|
|
|
|
|
char resolved_path[PATH_MAX];
|
|
|
|
|
if (GetPath(resolved_path, sizeof(resolved_path)))
|
|
|
|
|
{
|
|
|
|
|
File file;
|
|
|
|
|
error = file.Open(resolved_path, File::eOpenOptionRead);
|
|
|
|
|
if (error.Success())
|
|
|
|
|
{
|
|
|
|
|
off_t offset = 0;
|
|
|
|
|
size_t length = SIZE_MAX;
|
|
|
|
|
const bool null_terminate = true;
|
|
|
|
|
error = file.Read (length, offset, null_terminate, data_sp);
|
|
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2012-01-06 02:01:06 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
error.SetErrorString("invalid file specification");
|
|
|
|
|
}
|
|
|
|
|
if (error_ptr)
|
|
|
|
|
*error_ptr = error;
|
2010-06-08 16:52:24 +00:00
|
|
|
return data_sp;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-20 22:52:05 +00:00
|
|
|
size_t
|
2010-06-08 16:52:24 +00:00
|
|
|
FileSpec::ReadFileLines (STLStringArray &lines)
|
|
|
|
|
{
|
|
|
|
|
lines.clear();
|
2010-10-20 22:52:05 +00:00
|
|
|
char path[PATH_MAX];
|
|
|
|
|
if (GetPath(path, sizeof(path)))
|
2010-06-08 16:52:24 +00:00
|
|
|
{
|
2013-04-18 18:10:51 +00:00
|
|
|
std::ifstream file_stream (path);
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2010-10-20 22:52:05 +00:00
|
|
|
if (file_stream)
|
|
|
|
|
{
|
|
|
|
|
std::string line;
|
|
|
|
|
while (getline (file_stream, line))
|
|
|
|
|
lines.push_back (line);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return lines.size();
|
2010-06-08 16:52:24 +00: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 02:24:04 +00: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])
|
|
|
|
|
{
|
2013-08-23 12:44:05 +00:00
|
|
|
#if _WIN32
|
2014-03-12 10:53:50 +00:00
|
|
|
std::string szDir(dir_path);
|
|
|
|
|
szDir += "\\*";
|
2013-08-23 12:44:05 +00:00
|
|
|
|
|
|
|
|
WIN32_FIND_DATA ffd;
|
2014-03-12 10:53:50 +00:00
|
|
|
HANDLE hFind = FindFirstFile(szDir.c_str(), &ffd);
|
2013-08-23 12:44:05 +00:00
|
|
|
|
|
|
|
|
if (hFind == INVALID_HANDLE_VALUE)
|
|
|
|
|
{
|
|
|
|
|
return eEnumerateDirectoryResultNext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
bool call_callback = false;
|
|
|
|
|
FileSpec::FileType file_type = eFileTypeUnknown;
|
|
|
|
|
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
|
{
|
|
|
|
|
size_t len = strlen(ffd.cFileName);
|
|
|
|
|
|
|
|
|
|
if (len == 1 && ffd.cFileName[0] == '.')
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (len == 2 && ffd.cFileName[0] == '.' && ffd.cFileName[1] == '.')
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
file_type = eFileTypeDirectory;
|
|
|
|
|
call_callback = find_directories;
|
|
|
|
|
}
|
|
|
|
|
else if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DEVICE)
|
|
|
|
|
{
|
|
|
|
|
file_type = eFileTypeOther;
|
|
|
|
|
call_callback = find_other;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
file_type = eFileTypeRegular;
|
|
|
|
|
call_callback = find_files;
|
|
|
|
|
}
|
|
|
|
|
if (call_callback)
|
|
|
|
|
{
|
|
|
|
|
char child_path[MAX_PATH];
|
|
|
|
|
const int child_path_len = ::snprintf (child_path, sizeof(child_path), "%s\\%s", dir_path, ffd.cFileName);
|
|
|
|
|
if (child_path_len < (int)(sizeof(child_path) - 1))
|
|
|
|
|
{
|
|
|
|
|
// 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)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} while (FindNextFile(hFind, &ffd) != 0);
|
|
|
|
|
|
|
|
|
|
FindClose(hFind);
|
|
|
|
|
#else
|
|
|
|
|
lldb_utility::CleanUp <DIR *, int> dir_path_dir(opendir(dir_path), NULL, closedir);
|
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 02:24:04 +00:00
|
|
|
if (dir_path_dir.is_valid())
|
|
|
|
|
{
|
2014-09-12 23:39:38 +00:00
|
|
|
char dir_path_last_char = dir_path[strlen(dir_path) - 1];
|
|
|
|
|
|
2013-04-04 03:19:27 +00:00
|
|
|
long path_max = fpathconf (dirfd (dir_path_dir.get()), _PC_NAME_MAX);
|
|
|
|
|
#if defined (__APPLE_) && defined (__DARWIN_MAXPATHLEN)
|
|
|
|
|
if (path_max < __DARWIN_MAXPATHLEN)
|
|
|
|
|
path_max = __DARWIN_MAXPATHLEN;
|
|
|
|
|
#endif
|
|
|
|
|
struct dirent *buf, *dp;
|
|
|
|
|
buf = (struct dirent *) malloc (offsetof (struct dirent, d_name) + path_max + 1);
|
|
|
|
|
|
|
|
|
|
while (buf && readdir_r(dir_path_dir.get(), buf, &dp) == 0 && dp)
|
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 02:24:04 +00:00
|
|
|
{
|
|
|
|
|
// Only search directories
|
|
|
|
|
if (dp->d_type == DT_DIR || dp->d_type == DT_UNKNOWN)
|
|
|
|
|
{
|
2011-02-07 17:41:11 +00: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 02:24:04 +00:00
|
|
|
continue;
|
|
|
|
|
|
2011-02-07 17:41:11 +00: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 02:24:04 +00: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-01 18:18:34 +00: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 02:24:04 +00:00
|
|
|
case DT_WHT: file_type = eFileTypeOther; call_callback = find_other; break;
|
2011-04-01 18:18:34 +00: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 02:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (call_callback)
|
|
|
|
|
{
|
|
|
|
|
char child_path[PATH_MAX];
|
2014-09-12 23:39:38 +00:00
|
|
|
|
|
|
|
|
// Don't make paths with "/foo//bar", that just confuses everybody.
|
|
|
|
|
int child_path_len;
|
|
|
|
|
if (dir_path_last_char == '/')
|
|
|
|
|
child_path_len = ::snprintf (child_path, sizeof(child_path), "%s%s", dir_path, dp->d_name);
|
|
|
|
|
else
|
|
|
|
|
child_path_len = ::snprintf (child_path, sizeof(child_path), "%s/%s", dir_path, dp->d_name);
|
|
|
|
|
|
2011-07-19 19:48:13 +00: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 02:24:04 +00: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)
|
|
|
|
|
{
|
|
|
|
|
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.
|
2013-05-15 18:27:08 +00:00
|
|
|
if (buf)
|
|
|
|
|
free (buf);
|
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 02:24:04 +00:00
|
|
|
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.
|
2013-05-04 00:39:52 +00:00
|
|
|
if (buf)
|
|
|
|
|
free (buf);
|
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 02:24:04 +00:00
|
|
|
return eEnumerateDirectoryResultNext;
|
|
|
|
|
|
|
|
|
|
case eEnumerateDirectoryResultQuit: // Stop directory enumerations at any level
|
2013-05-04 00:39:52 +00:00
|
|
|
if (buf)
|
|
|
|
|
free (buf);
|
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 02:24:04 +00:00
|
|
|
return eEnumerateDirectoryResultQuit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-04 03:19:27 +00:00
|
|
|
if (buf)
|
|
|
|
|
{
|
|
|
|
|
free (buf);
|
|
|
|
|
}
|
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 02:24:04 +00:00
|
|
|
}
|
2013-08-23 12:44:05 +00: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 02:24:04 +00:00
|
|
|
}
|
|
|
|
|
// By default when exiting a directory, we tell the parent enumeration
|
|
|
|
|
// to continue enumerating.
|
|
|
|
|
return eEnumerateDirectoryResultNext;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-26 23:57:52 +00:00
|
|
|
FileSpec
|
|
|
|
|
FileSpec::CopyByAppendingPathComponent (const char *new_path) const
|
|
|
|
|
{
|
|
|
|
|
const bool resolve = false;
|
|
|
|
|
if (m_filename.IsEmpty() && m_directory.IsEmpty())
|
|
|
|
|
return FileSpec(new_path,resolve);
|
|
|
|
|
StreamString stream;
|
|
|
|
|
if (m_filename.IsEmpty())
|
|
|
|
|
stream.Printf("%s/%s",m_directory.GetCString(),new_path);
|
|
|
|
|
else if (m_directory.IsEmpty())
|
|
|
|
|
stream.Printf("%s/%s",m_filename.GetCString(),new_path);
|
|
|
|
|
else
|
|
|
|
|
stream.Printf("%s/%s/%s",m_directory.GetCString(), m_filename.GetCString(),new_path);
|
|
|
|
|
return FileSpec(stream.GetData(),resolve);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileSpec
|
|
|
|
|
FileSpec::CopyByRemovingLastPathComponent () const
|
|
|
|
|
{
|
|
|
|
|
const bool resolve = false;
|
|
|
|
|
if (m_filename.IsEmpty() && m_directory.IsEmpty())
|
|
|
|
|
return FileSpec("",resolve);
|
|
|
|
|
if (m_directory.IsEmpty())
|
|
|
|
|
return FileSpec("",resolve);
|
|
|
|
|
if (m_filename.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
const char* dir_cstr = m_directory.GetCString();
|
|
|
|
|
const char* last_slash_ptr = ::strrchr(dir_cstr, '/');
|
|
|
|
|
|
|
|
|
|
// check for obvious cases before doing the full thing
|
|
|
|
|
if (!last_slash_ptr)
|
|
|
|
|
return FileSpec("",resolve);
|
|
|
|
|
if (last_slash_ptr == dir_cstr)
|
|
|
|
|
return FileSpec("/",resolve);
|
|
|
|
|
|
|
|
|
|
size_t last_slash_pos = last_slash_ptr - dir_cstr+1;
|
|
|
|
|
ConstString new_path(dir_cstr,last_slash_pos);
|
|
|
|
|
return FileSpec(new_path.GetCString(),resolve);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return FileSpec(m_directory.GetCString(),resolve);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-20 21:07:01 +00:00
|
|
|
ConstString
|
2013-08-26 23:57:52 +00:00
|
|
|
FileSpec::GetLastPathComponent () const
|
|
|
|
|
{
|
2013-11-20 21:07:01 +00:00
|
|
|
if (m_filename)
|
|
|
|
|
return m_filename;
|
|
|
|
|
if (m_directory)
|
2013-08-26 23:57:52 +00:00
|
|
|
{
|
|
|
|
|
const char* dir_cstr = m_directory.GetCString();
|
|
|
|
|
const char* last_slash_ptr = ::strrchr(dir_cstr, '/');
|
|
|
|
|
if (last_slash_ptr == NULL)
|
2013-11-20 21:07:01 +00:00
|
|
|
return m_directory;
|
2013-08-26 23:57:52 +00:00
|
|
|
if (last_slash_ptr == dir_cstr)
|
|
|
|
|
{
|
|
|
|
|
if (last_slash_ptr[1] == 0)
|
2013-11-20 21:07:01 +00:00
|
|
|
return ConstString(last_slash_ptr);
|
2013-08-26 23:57:52 +00:00
|
|
|
else
|
2013-11-20 21:07:01 +00:00
|
|
|
return ConstString(last_slash_ptr+1);
|
2013-08-26 23:57:52 +00:00
|
|
|
}
|
|
|
|
|
if (last_slash_ptr[1] != 0)
|
2013-11-20 21:07:01 +00:00
|
|
|
return ConstString(last_slash_ptr+1);
|
2013-08-26 23:57:52 +00:00
|
|
|
const char* penultimate_slash_ptr = last_slash_ptr;
|
|
|
|
|
while (*penultimate_slash_ptr)
|
|
|
|
|
{
|
|
|
|
|
--penultimate_slash_ptr;
|
|
|
|
|
if (penultimate_slash_ptr == dir_cstr)
|
|
|
|
|
break;
|
|
|
|
|
if (*penultimate_slash_ptr == '/')
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-11-20 21:07:01 +00:00
|
|
|
ConstString result(penultimate_slash_ptr+1,last_slash_ptr-penultimate_slash_ptr);
|
|
|
|
|
return result;
|
2013-08-26 23:57:52 +00:00
|
|
|
}
|
2013-11-20 21:07:01 +00:00
|
|
|
return ConstString();
|
2013-08-26 23:57:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FileSpec::AppendPathComponent (const char *new_path)
|
|
|
|
|
{
|
|
|
|
|
const bool resolve = false;
|
|
|
|
|
if (m_filename.IsEmpty() && m_directory.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
SetFile(new_path,resolve);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
StreamString stream;
|
|
|
|
|
if (m_filename.IsEmpty())
|
|
|
|
|
stream.Printf("%s/%s",m_directory.GetCString(),new_path);
|
|
|
|
|
else if (m_directory.IsEmpty())
|
|
|
|
|
stream.Printf("%s/%s",m_filename.GetCString(),new_path);
|
|
|
|
|
else
|
|
|
|
|
stream.Printf("%s/%s/%s",m_directory.GetCString(), m_filename.GetCString(),new_path);
|
|
|
|
|
SetFile(stream.GetData(), resolve);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-29 19:52:29 +00:00
|
|
|
void
|
|
|
|
|
FileSpec::AppendPathComponent(const std::string &new_path)
|
|
|
|
|
{
|
|
|
|
|
return AppendPathComponent(new_path.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-26 23:57:52 +00:00
|
|
|
void
|
|
|
|
|
FileSpec::RemoveLastPathComponent ()
|
|
|
|
|
{
|
|
|
|
|
const bool resolve = false;
|
|
|
|
|
if (m_filename.IsEmpty() && m_directory.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
SetFile("",resolve);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (m_directory.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
SetFile("",resolve);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (m_filename.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
const char* dir_cstr = m_directory.GetCString();
|
|
|
|
|
const char* last_slash_ptr = ::strrchr(dir_cstr, '/');
|
|
|
|
|
|
|
|
|
|
// check for obvious cases before doing the full thing
|
|
|
|
|
if (!last_slash_ptr)
|
|
|
|
|
{
|
|
|
|
|
SetFile("",resolve);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (last_slash_ptr == dir_cstr)
|
|
|
|
|
{
|
|
|
|
|
SetFile("/",resolve);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
size_t last_slash_pos = last_slash_ptr - dir_cstr+1;
|
|
|
|
|
ConstString new_path(dir_cstr,last_slash_pos);
|
|
|
|
|
SetFile(new_path.GetCString(),resolve);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
SetFile(m_directory.GetCString(),resolve);
|
|
|
|
|
}
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-29 21:13:06 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
/// Returns true if the filespec represents an implementation source
|
|
|
|
|
/// file (files with a ".c", ".cpp", ".m", ".mm" (many more)
|
|
|
|
|
/// extension).
|
|
|
|
|
///
|
|
|
|
|
/// @return
|
|
|
|
|
/// \b true if the filespec represents an implementation source
|
|
|
|
|
/// file, \b false otherwise.
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
bool
|
|
|
|
|
FileSpec::IsSourceImplementationFile () const
|
|
|
|
|
{
|
|
|
|
|
ConstString extension (GetFileNameExtension());
|
|
|
|
|
if (extension)
|
|
|
|
|
{
|
2015-01-21 21:51:02 +00:00
|
|
|
static RegularExpression g_source_file_regex ("^([cC]|[mM]|[mM][mM]|[cC][pP][pP]|[cC]\\+\\+|[cC][xX][xX]|[cC][cC]|[cC][pP]|[sS]|[aA][sS][mM]|[fF]|[fF]77|[fF]90|[fF]95|[fF]03|[fF][oO][rR]|[fF][tT][nN]|[fF][pP][pP]|[aA][dD][aA]|[aA][dD][bB]|[aA][dD][sS])$");
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-29 21:13:06 +00:00
|
|
|
return g_source_file_regex.Execute (extension.GetCString());
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-18 16:33:33 +00:00
|
|
|
bool
|
|
|
|
|
FileSpec::IsRelativeToCurrentWorkingDirectory () const
|
|
|
|
|
{
|
2014-12-08 21:36:42 +00:00
|
|
|
const char *dir = m_directory.GetCString();
|
|
|
|
|
llvm::StringRef directory(dir ? dir : "");
|
|
|
|
|
|
|
|
|
|
if (directory.size() > 0)
|
2012-10-18 16:33:33 +00:00
|
|
|
{
|
2015-05-28 17:02:45 +00:00
|
|
|
if (PathSyntaxIsPosix(m_syntax))
|
2014-12-08 21:36:42 +00:00
|
|
|
{
|
|
|
|
|
// If the path doesn't start with '/' or '~', return true
|
|
|
|
|
switch (directory[0])
|
|
|
|
|
{
|
|
|
|
|
case '/':
|
|
|
|
|
case '~':
|
|
|
|
|
return false;
|
|
|
|
|
default:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-28 17:02:45 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (directory.size() >= 2 && directory[1] == ':')
|
|
|
|
|
return false;
|
|
|
|
|
if (directory[0] == '/')
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-10-18 16:33:33 +00:00
|
|
|
}
|
|
|
|
|
else if (m_filename)
|
|
|
|
|
{
|
|
|
|
|
// No directory, just a basename, return true
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|