diff options
Diffstat (limited to 'lldb/source/Host/common/FileSystem.cpp')
-rw-r--r-- | lldb/source/Host/common/FileSystem.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lldb/source/Host/common/FileSystem.cpp b/lldb/source/Host/common/FileSystem.cpp index a9ed5bd1847..95b453073cc 100644 --- a/lldb/source/Host/common/FileSystem.cpp +++ b/lldb/source/Host/common/FileSystem.cpp @@ -135,6 +135,16 @@ bool FileSystem::IsDirectory(const FileSpec &file_spec) const { return IsDirectory(file_spec.GetPath()); } +bool FileSystem::IsLocal(const Twine &path) const { + bool b; + m_fs->isLocal(path, b); + return b; +} + +bool FileSystem::IsLocal(const FileSpec &file_spec) const { + return IsLocal(file_spec.GetPath()); +} + void FileSystem::EnumerateDirectory(Twine path, bool find_directories, bool find_files, bool find_other, EnumerateDirectoryCallbackType callback, @@ -218,6 +228,34 @@ void FileSystem::Resolve(FileSpec &file_spec) { file_spec.SetIsResolved(true); } +std::shared_ptr<DataBufferLLVM> +FileSystem::CreateDataBuffer(const llvm::Twine &path, uint64_t size, + uint64_t offset) { + const bool is_volatile = !IsLocal(path); + + std::unique_ptr<llvm::WritableMemoryBuffer> buffer; + if (size == 0) { + auto buffer_or_error = + llvm::WritableMemoryBuffer::getFile(path, -1, is_volatile); + if (!buffer_or_error) + return nullptr; + buffer = std::move(*buffer_or_error); + } else { + auto buffer_or_error = llvm::WritableMemoryBuffer::getFileSlice( + path, size, offset, is_volatile); + if (!buffer_or_error) + return nullptr; + buffer = std::move(*buffer_or_error); + } + return std::shared_ptr<DataBufferLLVM>(new DataBufferLLVM(std::move(buffer))); +} + +std::shared_ptr<DataBufferLLVM> +FileSystem::CreateDataBuffer(const FileSpec &file_spec, uint64_t size, + uint64_t offset) { + return CreateDataBuffer(file_spec.GetPath(), size, offset); +} + bool FileSystem::ResolveExecutableLocation(FileSpec &file_spec) { // If the directory is set there's nothing to do. const ConstString &directory = file_spec.GetDirectory(); |