summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host/common
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Host/common')
-rw-r--r--lldb/source/Host/common/FileSystem.cpp38
-rw-r--r--lldb/source/Host/common/Host.cpp2
2 files changed, 39 insertions, 1 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();
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index 65534b9b551..2cc3f296388 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -565,7 +565,7 @@ Status Host::RunShellCommand(const Args &args, const FileSpec &working_dir,
"shell command output is too large to fit into a std::string");
} else {
auto Buffer =
- DataBufferLLVM::CreateFromPath(output_file_spec.GetPath());
+ FileSystem::Instance().CreateDataBuffer(output_file_spec);
if (error.Success())
command_output_ptr->assign(Buffer->GetChars(),
Buffer->GetByteSize());
OpenPOWER on IntegriCloud