summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Host')
-rw-r--r--lldb/source/Host/common/FileSpec.cpp143
-rw-r--r--lldb/source/Host/common/MonitoringProcessLauncher.cpp13
-rw-r--r--lldb/source/Host/common/Symbols.cpp2
-rw-r--r--lldb/source/Host/macosx/Host.mm10
-rw-r--r--lldb/source/Host/macosx/HostInfoMacOSX.mm3
-rw-r--r--lldb/source/Host/macosx/Symbols.cpp26
-rw-r--r--lldb/source/Host/posix/FileSystem.cpp8
7 files changed, 84 insertions, 121 deletions
diff --git a/lldb/source/Host/common/FileSpec.cpp b/lldb/source/Host/common/FileSpec.cpp
index 10bbea448e0..08c0f7e6904 100644
--- a/lldb/source/Host/common/FileSpec.cpp
+++ b/lldb/source/Host/common/FileSpec.cpp
@@ -27,7 +27,6 @@
#include "lldb/Core/StringList.h"
#include "lldb/Host/FileSpec.h"
-#include "lldb/Host/FileSystem.h"
#include "lldb/Utility/CleanUp.h"
#include "lldb/Utility/RegularExpression.h"
#include "lldb/Utility/Stream.h"
@@ -45,10 +44,18 @@ using namespace lldb_private;
namespace {
+static constexpr FileSpec::PathSyntax GetNativeSyntax() {
+#if defined(LLVM_ON_WIN32)
+ return FileSpec::ePathSyntaxWindows;
+#else
+ return FileSpec::ePathSyntaxPosix;
+#endif
+}
+
bool PathSyntaxIsPosix(FileSpec::PathSyntax syntax) {
return (syntax == FileSpec::ePathSyntaxPosix ||
(syntax == FileSpec::ePathSyntaxHostNative &&
- FileSystem::GetNativePathSyntax() == FileSpec::ePathSyntaxPosix));
+ GetNativeSyntax() == FileSpec::ePathSyntaxPosix));
}
const char *GetPathSeparators(FileSpec::PathSyntax syntax) {
@@ -84,13 +91,6 @@ void Denormalize(llvm::SmallVectorImpl<char> &path,
std::replace(path.begin(), path.end(), '/', '\\');
}
-bool GetFileStats(const FileSpec *file_spec, struct stat *stats_ptr) {
- char resolved_path[PATH_MAX];
- if (file_spec->GetPath(resolved_path, sizeof(resolved_path)))
- return FileSystem::Stat(resolved_path, stats_ptr) == 0;
- return false;
-}
-
size_t FilenamePos(llvm::StringRef str, FileSpec::PathSyntax syntax) {
if (str.size() == 2 && IsPathSeparator(str[0], syntax) && str[0] == str[1])
return 0;
@@ -273,7 +273,7 @@ void FileSpec::Resolve(llvm::SmallVectorImpl<char> &path) {
}
}
-FileSpec::FileSpec() : m_syntax(FileSystem::GetNativePathSyntax()) {}
+FileSpec::FileSpec() : m_syntax(GetNativeSyntax()) {}
//------------------------------------------------------------------
// Default constructor that can take an optional full path to a
@@ -336,9 +336,7 @@ void FileSpec::SetFile(llvm::StringRef pathname, bool resolve,
m_filename.Clear();
m_directory.Clear();
m_is_resolved = false;
- m_syntax = (syntax == ePathSyntaxHostNative)
- ? FileSystem::GetNativePathSyntax()
- : syntax;
+ m_syntax = (syntax == ePathSyntaxHostNative) ? GetNativeSyntax() : syntax;
if (pathname.empty())
return;
@@ -615,16 +613,10 @@ void FileSpec::Dump(Stream *s) const {
//------------------------------------------------------------------
// Returns true if the file exists.
//------------------------------------------------------------------
-bool FileSpec::Exists() const {
- struct stat file_stats;
- return GetFileStats(this, &file_stats);
-}
+bool FileSpec::Exists() const { return llvm::sys::fs::exists(GetPath()); }
bool FileSpec::Readable() const {
- const uint32_t permissions = GetPermissions();
- if (permissions & eFilePermissionsEveryoneR)
- return true;
- return false;
+ return GetPermissions() & llvm::sys::fs::perms::all_read;
}
bool FileSpec::ResolveExecutableLocation() {
@@ -677,67 +669,21 @@ bool FileSpec::ResolvePath() {
}
uint64_t FileSpec::GetByteSize() const {
- struct stat file_stats;
- if (GetFileStats(this, &file_stats))
- return file_stats.st_size;
- return 0;
+ uint64_t Size = 0;
+ if (llvm::sys::fs::file_size(GetPath(), Size))
+ return 0;
+ return Size;
}
FileSpec::PathSyntax FileSpec::GetPathSyntax() const { return m_syntax; }
-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;
-#ifndef _WIN32
- case S_IFIFO:
- return eFileTypePipe;
- case S_IFSOCK:
- return eFileTypeSocket;
- case S_IFLNK:
- return eFileTypeSymbolicLink;
-#endif
- default:
- break;
- }
- return eFileTypeUnknown;
- }
- return eFileTypeInvalid;
-}
-
-bool FileSpec::IsSymbolicLink() const {
- char resolved_path[PATH_MAX];
- if (!GetPath(resolved_path, sizeof(resolved_path)))
- return false;
-
-#ifdef _WIN32
- std::wstring wpath;
- if (!llvm::ConvertUTF8toWide(resolved_path, wpath))
- return false;
- auto attrs = ::GetFileAttributesW(wpath.c_str());
- if (attrs == INVALID_FILE_ATTRIBUTES)
- return false;
-
- return (attrs & FILE_ATTRIBUTE_REPARSE_POINT);
-#else
- struct stat file_stats;
- if (::lstat(resolved_path, &file_stats) != 0)
- return false;
-
- return (file_stats.st_mode & S_IFMT) == S_IFLNK;
-#endif
-}
-
uint32_t FileSpec::GetPermissions() const {
- uint32_t file_permissions = 0;
- if (*this)
- FileSystem::GetFilePermissions(*this, file_permissions);
- return file_permissions;
+ namespace fs = llvm::sys::fs;
+ fs::file_status st;
+ if (fs::status(GetPath(), st, false))
+ return fs::perms::perms_not_known;
+
+ return st.permissions();
}
//------------------------------------------------------------------
@@ -853,7 +799,8 @@ FileSpec::ForEachItemInDirectory(llvm::StringRef dir_path,
}
do {
- FileSpec::FileType file_type = eFileTypeUnknown;
+ namespace fs = llvm::sys::fs;
+ fs::file_type ft = fs::file_type::type_unknown;
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
size_t len = wcslen(ffd.cFileName);
@@ -863,11 +810,11 @@ FileSpec::ForEachItemInDirectory(llvm::StringRef dir_path,
if (len == 2 && ffd.cFileName[0] == L'.' && ffd.cFileName[1] == L'.')
continue;
- file_type = eFileTypeDirectory;
+ ft = fs::file_type::directory_file;
} else if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DEVICE) {
- file_type = eFileTypeOther;
+ ft = fs::file_type::type_unknown;
} else {
- file_type = eFileTypeRegular;
+ ft = fs::file_type::regular_file;
}
std::string fileName;
@@ -879,7 +826,7 @@ FileSpec::ForEachItemInDirectory(llvm::StringRef dir_path,
// Don't resolve the file type or path
FileSpec child_path_spec(child_path.data(), false);
- EnumerateDirectoryResult result = callback(file_type, child_path_spec);
+ EnumerateDirectoryResult result = callback(ft, child_path_spec);
switch (result) {
case eEnumerateDirectoryResultNext:
@@ -940,37 +887,38 @@ FileSpec::ForEachItemInDirectory(llvm::StringRef dir_path,
continue;
}
- FileSpec::FileType file_type = eFileTypeUnknown;
+ using namespace llvm::sys::fs;
+ file_type ft = file_type::type_unknown;
switch (dp->d_type) {
default:
case DT_UNKNOWN:
- file_type = eFileTypeUnknown;
+ ft = file_type::type_unknown;
break;
case DT_FIFO:
- file_type = eFileTypePipe;
+ ft = file_type::fifo_file;
break;
case DT_CHR:
- file_type = eFileTypeOther;
+ ft = file_type::character_file;
break;
case DT_DIR:
- file_type = eFileTypeDirectory;
+ ft = file_type::directory_file;
break;
case DT_BLK:
- file_type = eFileTypeOther;
+ ft = file_type::block_file;
break;
case DT_REG:
- file_type = eFileTypeRegular;
+ ft = file_type::regular_file;
break;
case DT_LNK:
- file_type = eFileTypeSymbolicLink;
+ ft = file_type::symlink_file;
break;
case DT_SOCK:
- file_type = eFileTypeSocket;
+ ft = file_type::socket_file;
break;
#if !defined(__OpenBSD__)
case DT_WHT:
- file_type = eFileTypeOther;
+ ft = file_type::type_unknown;
break;
#endif
}
@@ -985,8 +933,7 @@ FileSpec::ForEachItemInDirectory(llvm::StringRef dir_path,
// Don't resolve the file type or path
FileSpec child_path_spec(child_path, false);
- EnumerateDirectoryResult result =
- callback(file_type, child_path_spec);
+ EnumerateDirectoryResult result = callback(ft, child_path_spec);
switch (result) {
case eEnumerateDirectoryResultNext:
@@ -1040,14 +987,14 @@ FileSpec::EnumerateDirectory(llvm::StringRef dir_path, bool find_directories,
void *callback_baton) {
return ForEachItemInDirectory(
dir_path,
- [&find_directories, &find_files, &find_other, &callback,
- &callback_baton](FileType file_type, const FileSpec &file_spec) {
+ [&find_directories, &find_files, &find_other, &callback, &callback_baton](
+ llvm::sys::fs::file_type file_type, const FileSpec &file_spec) {
switch (file_type) {
- case FileType::eFileTypeDirectory:
+ case llvm::sys::fs::file_type::directory_file:
if (find_directories)
return callback(callback_baton, file_type, file_spec);
break;
- case FileType::eFileTypeRegular:
+ case llvm::sys::fs::file_type::regular_file:
if (find_files)
return callback(callback_baton, file_type, file_spec);
break;
diff --git a/lldb/source/Host/common/MonitoringProcessLauncher.cpp b/lldb/source/Host/common/MonitoringProcessLauncher.cpp
index b94c3d24283..2aa6c7f50b6 100644
--- a/lldb/source/Host/common/MonitoringProcessLauncher.cpp
+++ b/lldb/source/Host/common/MonitoringProcessLauncher.cpp
@@ -17,6 +17,8 @@
#include "lldb/Utility/Error.h"
#include "lldb/Utility/Log.h"
+#include "llvm/Support/FileSystem.h"
+
using namespace lldb;
using namespace lldb_private;
@@ -38,8 +40,9 @@ MonitoringProcessLauncher::LaunchProcess(const ProcessLaunchInfo &launch_info,
FileSpec exe_spec(resolved_info.GetExecutableFile());
- FileSpec::FileType file_type = exe_spec.GetFileType();
- if (file_type != FileSpec::eFileTypeRegular) {
+ llvm::sys::fs::file_status stats;
+ status(exe_spec.GetPath(), stats);
+ if (!is_regular_file(stats)) {
ModuleSpec module_spec(exe_spec, arch_spec);
lldb::ModuleSP exe_module_sp;
error =
@@ -48,11 +51,13 @@ MonitoringProcessLauncher::LaunchProcess(const ProcessLaunchInfo &launch_info,
if (error.Fail())
return HostProcess();
- if (exe_module_sp)
+ if (exe_module_sp) {
exe_spec = exe_module_sp->GetFileSpec();
+ status(exe_spec.GetPath(), stats);
+ }
}
- if (exe_spec.Exists()) {
+ if (exists(stats)) {
exe_spec.GetPath(exe_path, sizeof(exe_path));
} else {
resolved_info.GetExecutableFile().GetPath(exe_path, sizeof(exe_path));
diff --git a/lldb/source/Host/common/Symbols.cpp b/lldb/source/Host/common/Symbols.cpp
index 9850625cbc4..e3d5bdfab7b 100644
--- a/lldb/source/Host/common/Symbols.cpp
+++ b/lldb/source/Host/common/Symbols.cpp
@@ -229,7 +229,7 @@ FileSpec Symbols::LocateExecutableSymbolFile(const ModuleSpec &module_spec) {
for (size_t idx = 0; idx < num_directories; ++idx) {
FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex(idx);
dirspec.ResolvePath();
- if (!dirspec.Exists() || !dirspec.IsDirectory())
+ if (!llvm::sys::fs::is_directory(dirspec.GetPath()))
continue;
std::vector<std::string> files;
diff --git a/lldb/source/Host/macosx/Host.mm b/lldb/source/Host/macosx/Host.mm
index 1ecf62da4ef..2e29d87e967 100644
--- a/lldb/source/Host/macosx/Host.mm
+++ b/lldb/source/Host/macosx/Host.mm
@@ -75,6 +75,8 @@
#include "lldb/Utility/NameMatches.h"
#include "lldb/Utility/StreamString.h"
+#include "llvm/Support/FileSystem.h"
+
#include "cfcpp/CFCBundle.h"
#include "cfcpp/CFCMutableArray.h"
#include "cfcpp/CFCMutableDictionary.h"
@@ -101,7 +103,7 @@ using namespace lldb_private;
bool Host::GetBundleDirectory(const FileSpec &file,
FileSpec &bundle_directory) {
#if defined(__APPLE__)
- if (file.GetFileType() == FileSpec::eFileTypeDirectory) {
+ if (llvm::sys::fs::is_directory(file.GetPath())) {
char path[PATH_MAX];
if (file.GetPath(path, sizeof(path))) {
CFCBundle bundle(path);
@@ -118,7 +120,7 @@ bool Host::GetBundleDirectory(const FileSpec &file,
bool Host::ResolveExecutableInBundle(FileSpec &file) {
#if defined(__APPLE__)
- if (file.GetFileType() == FileSpec::eFileTypeDirectory) {
+ if (llvm::sys::fs::is_directory(file.GetPath())) {
char path[PATH_MAX];
if (file.GetPath(path, sizeof(path))) {
CFCBundle bundle(path);
@@ -1184,8 +1186,8 @@ Error Host::LaunchProcess(ProcessLaunchInfo &launch_info) {
ModuleSpec exe_module_spec(launch_info.GetExecutableFile(),
launch_info.GetArchitecture());
- FileSpec::FileType file_type = exe_module_spec.GetFileSpec().GetFileType();
- if (file_type != FileSpec::eFileTypeRegular) {
+ if (!llvm::sys::fs::is_regular_file(
+ exe_module_spec.GetFileSpec().GetPath())) {
lldb::ModuleSP exe_module_sp;
error = host_platform_sp->ResolveExecutable(exe_module_spec, exe_module_sp,
NULL);
diff --git a/lldb/source/Host/macosx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/HostInfoMacOSX.mm
index ba90a01eefb..5bfac343f46 100644
--- a/lldb/source/Host/macosx/HostInfoMacOSX.mm
+++ b/lldb/source/Host/macosx/HostInfoMacOSX.mm
@@ -18,6 +18,7 @@
#include "lldb/Utility/SafeMachO.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_ostream.h"
// C++ Includes
@@ -152,7 +153,7 @@ bool HostInfoMacOSX::ComputeSupportExeDirectory(FileSpec &file_spec) {
// the lldb driver.
raw_path.append("/../bin");
FileSpec support_dir_spec(raw_path, true);
- if (!support_dir_spec.Exists() || !support_dir_spec.IsDirectory()) {
+ if (!llvm::sys::fs::is_directory(support_dir_spec.GetPath())) {
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
if (log)
log->Printf("HostInfoMacOSX::%s(): failed to find support directory",
diff --git a/lldb/source/Host/macosx/Symbols.cpp b/lldb/source/Host/macosx/Symbols.cpp
index ff4b8e972be..17a130236e8 100644
--- a/lldb/source/Host/macosx/Symbols.cpp
+++ b/lldb/source/Host/macosx/Symbols.cpp
@@ -38,6 +38,8 @@
#include "lldb/Utility/UUID.h"
#include "mach/machine.h"
+#include "llvm/Support/FileSystem.h"
+
using namespace lldb;
using namespace lldb_private;
using namespace llvm::MachO;
@@ -101,7 +103,7 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
}
FileSpec dsym_filespec(path, path[0] == '~');
- if (dsym_filespec.GetFileType() == FileSpec::eFileTypeDirectory) {
+ if (llvm::sys::fs::is_directory(dsym_filespec.GetPath())) {
dsym_filespec =
Symbols::FindSymbolFileInBundle(dsym_filespec, uuid, arch);
++items_found;
@@ -164,8 +166,10 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
FileSpec file_spec(path, true);
ModuleSpecList module_specs;
ModuleSpec matched_module_spec;
- switch (file_spec.GetFileType()) {
- case FileSpec::eFileTypeDirectory: // Bundle directory?
+ using namespace llvm::sys::fs;
+ switch (get_file_type(file_spec.GetPath())) {
+
+ case file_type::directory_file: // Bundle directory?
{
CFCBundle bundle(path);
CFCReleaser<CFURLRef> bundle_exe_url(
@@ -193,15 +197,17 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
}
} break;
- case FileSpec::eFileTypePipe: // Forget pipes
- case FileSpec::eFileTypeSocket: // We can't process socket files
- case FileSpec::eFileTypeInvalid: // File doesn't exist...
+ case file_type::fifo_file: // Forget pipes
+ case file_type::socket_file: // We can't process socket files
+ case file_type::file_not_found: // File doesn't exist...
+ case file_type::status_error:
break;
- case FileSpec::eFileTypeUnknown:
- case FileSpec::eFileTypeRegular:
- case FileSpec::eFileTypeSymbolicLink:
- case FileSpec::eFileTypeOther:
+ case file_type::type_unknown:
+ case file_type::regular_file:
+ case file_type::symlink_file:
+ case file_type::block_file:
+ case file_type::character_file:
if (ObjectFile::GetModuleSpecifications(file_spec, 0, 0,
module_specs) &&
module_specs.FindMatchingModuleSpec(module_spec,
diff --git a/lldb/source/Host/posix/FileSystem.cpp b/lldb/source/Host/posix/FileSystem.cpp
index fa38f07665b..b5264d10097 100644
--- a/lldb/source/Host/posix/FileSystem.cpp
+++ b/lldb/source/Host/posix/FileSystem.cpp
@@ -29,6 +29,8 @@
#include "lldb/Utility/Error.h"
#include "lldb/Utility/StreamString.h"
+#include "llvm/Support/FileSystem.h"
+
using namespace lldb;
using namespace lldb_private;
@@ -61,7 +63,7 @@ Error FileSystem::MakeDirectory(const FileSpec &file_spec,
return error;
} break;
case EEXIST: {
- if (file_spec.IsDirectory())
+ if (llvm::sys::fs::is_directory(file_spec.GetPath()))
return Error(); // It is a directory and it already exists
} break;
}
@@ -83,9 +85,9 @@ Error FileSystem::DeleteDirectory(const FileSpec &file_spec, bool recurse) {
FileSpec::ForEachItemInDirectory(
file_spec.GetCString(),
[&error, &sub_directories](
- FileSpec::FileType file_type,
+ llvm::sys::fs::file_type ft,
const FileSpec &spec) -> FileSpec::EnumerateDirectoryResult {
- if (file_type == FileSpec::eFileTypeDirectory) {
+ if (ft == llvm::sys::fs::file_type::directory_file) {
// Save all directorires and process them after iterating through
// this directory
sub_directories.push_back(spec);
OpenPOWER on IntegriCloud