summaryrefslogtreecommitdiff
path: root/include/lldb/Host/FileSystem.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/lldb/Host/FileSystem.h')
-rw-r--r--include/lldb/Host/FileSystem.h81
1 files changed, 50 insertions, 31 deletions
diff --git a/include/lldb/Host/FileSystem.h b/include/lldb/Host/FileSystem.h
index 9e36649b0046..865b09b23103 100644
--- a/include/lldb/Host/FileSystem.h
+++ b/include/lldb/Host/FileSystem.h
@@ -1,9 +1,8 @@
//===-- FileSystem.h --------------------------------------------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -12,6 +11,7 @@
#include "lldb/Host/File.h"
#include "lldb/Utility/DataBufferLLVM.h"
+#include "lldb/Utility/FileCollector.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Status.h"
@@ -31,8 +31,15 @@ public:
static const char *DEV_NULL;
static const char *PATH_CONVERSION_ERROR;
- FileSystem() : m_fs(llvm::vfs::getRealFileSystem()) {}
- FileSystem(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs) : m_fs(fs) {}
+ FileSystem()
+ : m_fs(llvm::vfs::getRealFileSystem()), m_collector(nullptr),
+ m_mapped(false) {}
+ FileSystem(FileCollector &collector)
+ : m_fs(llvm::vfs::getRealFileSystem()), m_collector(&collector),
+ m_mapped(false) {}
+ FileSystem(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
+ bool mapped = false)
+ : m_fs(fs), m_collector(nullptr), m_mapped(mapped) {}
FileSystem(const FileSystem &fs) = delete;
FileSystem &operator=(const FileSystem &fs) = delete;
@@ -40,6 +47,8 @@ public:
static FileSystem &Instance();
static void Initialize();
+ static void Initialize(FileCollector &collector);
+ static llvm::Error Initialize(const FileSpec &mapping);
static void Initialize(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs);
static void Terminate();
@@ -55,90 +64,91 @@ public:
int Open(const char *path, int flags, int mode);
Status Open(File &File, const FileSpec &file_spec, uint32_t options,
- uint32_t permissions = lldb::eFilePermissionsFileDefault);
+ uint32_t permissions = lldb::eFilePermissionsFileDefault,
+ bool should_close_fd = true);
/// Get a directory iterator.
- /// @{
+ /// \{
llvm::vfs::directory_iterator DirBegin(const FileSpec &file_spec,
std::error_code &ec);
llvm::vfs::directory_iterator DirBegin(const llvm::Twine &dir,
std::error_code &ec);
- /// @}
+ /// \}
/// Returns the Status object for the given file.
- /// @{
+ /// \{
llvm::ErrorOr<llvm::vfs::Status> GetStatus(const FileSpec &file_spec) const;
llvm::ErrorOr<llvm::vfs::Status> GetStatus(const llvm::Twine &path) const;
- /// @}
+ /// \}
/// Returns the modification time of the given file.
- /// @{
+ /// \{
llvm::sys::TimePoint<> GetModificationTime(const FileSpec &file_spec) const;
llvm::sys::TimePoint<> GetModificationTime(const llvm::Twine &path) const;
- /// @}
+ /// \}
/// Returns the on-disk size of the given file in bytes.
- /// @{
+ /// \{
uint64_t GetByteSize(const FileSpec &file_spec) const;
uint64_t GetByteSize(const llvm::Twine &path) const;
- /// @}
+ /// \}
/// Return the current permissions of the given file.
///
/// Returns a bitmask for the current permissions of the file (zero or more
/// of the permission bits defined in File::Permissions).
- /// @{
+ /// \{
uint32_t GetPermissions(const FileSpec &file_spec) const;
uint32_t GetPermissions(const llvm::Twine &path) const;
uint32_t GetPermissions(const FileSpec &file_spec, std::error_code &ec) const;
uint32_t GetPermissions(const llvm::Twine &path, std::error_code &ec) const;
- /// @}
+ /// \}
/// Returns whether the given file exists.
- /// @{
+ /// \{
bool Exists(const FileSpec &file_spec) const;
bool Exists(const llvm::Twine &path) const;
- /// @}
+ /// \}
/// Returns whether the given file is readable.
- /// @{
+ /// \{
bool Readable(const FileSpec &file_spec) const;
bool Readable(const llvm::Twine &path) const;
- /// @}
+ /// \}
/// Returns whether the given path is a directory.
- /// @{
+ /// \{
bool IsDirectory(const FileSpec &file_spec) const;
bool IsDirectory(const llvm::Twine &path) const;
- /// @}
+ /// \}
/// Returns whether the given path is local to the file system.
- /// @{
+ /// \{
bool IsLocal(const FileSpec &file_spec) const;
bool IsLocal(const llvm::Twine &path) const;
- /// @}
+ /// \}
/// Make the given file path absolute.
- /// @{
+ /// \{
std::error_code MakeAbsolute(llvm::SmallVectorImpl<char> &path) const;
std::error_code MakeAbsolute(FileSpec &file_spec) const;
- /// @}
+ /// \}
/// Resolve path to make it canonical.
- /// @{
+ /// \{
void Resolve(llvm::SmallVectorImpl<char> &path);
void Resolve(FileSpec &file_spec);
- /// @}
+ /// \}
//// Create memory buffer from path.
- /// @{
+ /// \{
std::shared_ptr<DataBufferLLVM> CreateDataBuffer(const llvm::Twine &path,
uint64_t size = 0,
uint64_t offset = 0);
std::shared_ptr<DataBufferLLVM> CreateDataBuffer(const FileSpec &file_spec,
uint64_t size = 0,
uint64_t offset = 0);
- /// @}
+ /// \}
/// Call into the Host to see if it can help find the file.
bool ResolveExecutableLocation(FileSpec &file_spec);
@@ -168,9 +178,18 @@ public:
std::error_code GetRealPath(const llvm::Twine &path,
llvm::SmallVectorImpl<char> &output) const;
+ llvm::ErrorOr<std::string> GetExternalPath(const llvm::Twine &path);
+ llvm::ErrorOr<std::string> GetExternalPath(const FileSpec &file_spec);
+
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> GetVirtualFileSystem() {
+ return m_fs;
+ }
+
private:
static llvm::Optional<FileSystem> &InstanceImpl();
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> m_fs;
+ FileCollector *m_collector;
+ bool m_mapped;
};
} // namespace lldb_private