Author: davide Date: Mon Nov 12 11:08:19 2018 New Revision: 346694 URL: http://llvm.org/viewvc/llvm-project?rev=346694&view=rev Log: Revert "Extract construction of DataBufferLLVM into FileSystem"
It broke the lldb sanitizer bots. Modified: lldb/trunk/include/lldb/Host/FileSystem.h lldb/trunk/include/lldb/Utility/DataBufferLLVM.h lldb/trunk/source/API/SBSection.cpp lldb/trunk/source/Commands/CommandObjectMemory.cpp lldb/trunk/source/Core/SourceManager.cpp lldb/trunk/source/Host/common/FileSystem.cpp lldb/trunk/source/Host/common/Host.cpp lldb/trunk/source/Host/linux/Host.cpp lldb/trunk/source/Interpreter/OptionValueFileSpec.cpp lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp lldb/trunk/source/Plugins/Process/mach-core/ProcessMachCore.cpp lldb/trunk/source/Plugins/Process/minidump/ProcessMinidump.cpp lldb/trunk/source/Symbol/ObjectFile.cpp lldb/trunk/source/Utility/DataBufferLLVM.cpp lldb/trunk/unittests/Process/minidump/MinidumpParserTest.cpp Modified: lldb/trunk/include/lldb/Host/FileSystem.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSystem.h?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/include/lldb/Host/FileSystem.h (original) +++ lldb/trunk/include/lldb/Host/FileSystem.h Mon Nov 12 11:08:19 2018 @@ -11,7 +11,6 @@ #define liblldb_Host_FileSystem_h #include "lldb/Host/File.h" -#include "lldb/Utility/DataBufferLLVM.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/Status.h" @@ -95,12 +94,6 @@ public: 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; @@ -113,16 +106,6 @@ public: 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); Modified: lldb/trunk/include/lldb/Utility/DataBufferLLVM.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/DataBufferLLVM.h?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/include/lldb/Utility/DataBufferLLVM.h (original) +++ lldb/trunk/include/lldb/Utility/DataBufferLLVM.h Mon Nov 12 11:08:19 2018 @@ -23,11 +23,16 @@ class Twine; namespace lldb_private { -class FileSystem; class DataBufferLLVM : public DataBuffer { public: ~DataBufferLLVM(); + static std::shared_ptr<DataBufferLLVM> + CreateSliceFromPath(const llvm::Twine &Path, uint64_t Size, uint64_t Offset); + + static std::shared_ptr<DataBufferLLVM> + CreateFromPath(const llvm::Twine &Path); + uint8_t *GetBytes() override; const uint8_t *GetBytes() const override; lldb::offset_t GetByteSize() const override; @@ -35,7 +40,6 @@ public: char *GetChars() { return reinterpret_cast<char *>(GetBytes()); } private: - friend FileSystem; /// Construct a DataBufferLLVM from \p Buffer. \p Buffer must be a valid /// pointer. explicit DataBufferLLVM(std::unique_ptr<llvm::WritableMemoryBuffer> Buffer); Modified: lldb/trunk/source/API/SBSection.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSection.cpp?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/source/API/SBSection.cpp (original) +++ lldb/trunk/source/API/SBSection.cpp Mon Nov 12 11:08:19 2018 @@ -14,6 +14,7 @@ #include "lldb/Core/Section.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Utility/DataBuffer.h" +#include "lldb/Utility/DataBufferLLVM.h" #include "lldb/Utility/DataExtractor.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/StreamString.h" @@ -165,7 +166,7 @@ SBData SBSection::GetSectionData(uint64_ else file_size = 0; } - auto data_buffer_sp = FileSystem::Instance().CreateDataBuffer( + auto data_buffer_sp = DataBufferLLVM::CreateSliceFromPath( objfile->GetFileSpec().GetPath(), file_size, file_offset); if (data_buffer_sp && data_buffer_sp->GetByteSize() > 0) { DataExtractorSP data_extractor_sp( Modified: lldb/trunk/source/Commands/CommandObjectMemory.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMemory.cpp?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectMemory.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectMemory.cpp Mon Nov 12 11:08:19 2018 @@ -1357,7 +1357,7 @@ protected: size_t length = SIZE_MAX; if (item_byte_size > 1) length = item_byte_size; - auto data_sp = FileSystem::Instance().CreateDataBuffer( + auto data_sp = DataBufferLLVM::CreateSliceFromPath( m_memory_options.m_infile.GetPath(), length, m_memory_options.m_infile_offset); if (data_sp) { Modified: lldb/trunk/source/Core/SourceManager.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/SourceManager.cpp?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/source/Core/SourceManager.cpp (original) +++ lldb/trunk/source/Core/SourceManager.cpp Mon Nov 12 11:08:19 2018 @@ -442,7 +442,7 @@ void SourceManager::File::CommonInitiali } if (m_mod_time != llvm::sys::TimePoint<>()) - m_data_sp = FileSystem::Instance().CreateDataBuffer(m_file_spec); + m_data_sp = DataBufferLLVM::CreateFromPath(m_file_spec.GetPath()); } uint32_t SourceManager::File::GetLineOffset(uint32_t line) { @@ -520,7 +520,7 @@ void SourceManager::File::UpdateIfNeeded if (curr_mod_time != llvm::sys::TimePoint<>() && m_mod_time != curr_mod_time) { m_mod_time = curr_mod_time; - m_data_sp = FileSystem::Instance().CreateDataBuffer(m_file_spec); + m_data_sp = DataBufferLLVM::CreateFromPath(m_file_spec.GetPath()); m_offsets.clear(); } } Modified: lldb/trunk/source/Host/common/FileSystem.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSystem.cpp?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/source/Host/common/FileSystem.cpp (original) +++ lldb/trunk/source/Host/common/FileSystem.cpp Mon Nov 12 11:08:19 2018 @@ -135,16 +135,6 @@ bool FileSystem::IsDirectory(const FileS 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, @@ -228,34 +218,6 @@ void FileSystem::Resolve(FileSpec &file_ 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(); Modified: lldb/trunk/source/Host/common/Host.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/source/Host/common/Host.cpp (original) +++ lldb/trunk/source/Host/common/Host.cpp Mon Nov 12 11:08:19 2018 @@ -564,7 +564,7 @@ Status Host::RunShellCommand(const Args "shell command output is too large to fit into a std::string"); } else { auto Buffer = - FileSystem::Instance().CreateDataBuffer(output_file_spec); + DataBufferLLVM::CreateFromPath(output_file_spec.GetPath()); if (error.Success()) command_output_ptr->assign(Buffer->GetChars(), Buffer->GetByteSize()); Modified: lldb/trunk/source/Host/linux/Host.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/linux/Host.cpp?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/source/Host/linux/Host.cpp (original) +++ lldb/trunk/source/Host/linux/Host.cpp Mon Nov 12 11:08:19 2018 @@ -28,6 +28,7 @@ #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" #include "lldb/Host/linux/Support.h" +#include "lldb/Utility/DataBufferLLVM.h" #include "lldb/Utility/DataExtractor.h" using namespace lldb; @@ -121,7 +122,7 @@ static bool IsDirNumeric(const char *dna static ArchSpec GetELFProcessCPUType(llvm::StringRef exe_path) { Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); - auto buffer_sp = FileSystem::Instance().CreateDataBuffer(exe_path, 0x20, 0); + auto buffer_sp = DataBufferLLVM::CreateSliceFromPath(exe_path, 0x20, 0); if (!buffer_sp) return ArchSpec(); Modified: lldb/trunk/source/Interpreter/OptionValueFileSpec.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueFileSpec.cpp?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/OptionValueFileSpec.cpp (original) +++ lldb/trunk/source/Interpreter/OptionValueFileSpec.cpp Mon Nov 12 11:08:19 2018 @@ -14,6 +14,7 @@ #include "lldb/Interpreter/CommandCompletions.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Utility/Args.h" +#include "lldb/Utility/DataBufferLLVM.h" #include "lldb/Utility/State.h" using namespace lldb; @@ -113,8 +114,7 @@ const lldb::DataBufferSP &OptionValueFil const auto file_mod_time = FileSystem::Instance().GetModificationTime(m_current_value); if (m_data_sp && m_data_mod_time == file_mod_time) return m_data_sp; - m_data_sp = - FileSystem::Instance().CreateDataBuffer(m_current_value.GetPath()); + m_data_sp = DataBufferLLVM::CreateFromPath(m_current_value.GetPath()); m_data_mod_time = file_mod_time; } return m_data_sp; Modified: lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp Mon Nov 12 11:08:19 2018 @@ -36,6 +36,7 @@ #include "lldb/Target/Thread.h" #include "lldb/Utility/Args.h" #include "lldb/Utility/ConstString.h" +#include "lldb/Utility/DataBufferLLVM.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/RegisterValue.h" #include "lldb/Utility/RegularExpression.h" @@ -2539,7 +2540,7 @@ bool RenderScriptRuntime::LoadAllocation } // Read file into data buffer - auto data_sp = FileSystem::Instance().CreateDataBuffer(file.GetPath()); + auto data_sp = DataBufferLLVM::CreateFromPath(file.GetPath()); // Cast start of buffer to FileHeader and use pointer to read metadata void *file_buf = data_sp->GetBytes(); @@ -3080,8 +3081,7 @@ bool RSModuleDescriptor::ParseRSInfo() { const addr_t size = info_sym->GetByteSize(); const FileSpec fs = m_module->GetFileSpec(); - auto buffer = - FileSystem::Instance().CreateDataBuffer(fs.GetPath(), size, addr); + auto buffer = DataBufferLLVM::CreateSliceFromPath(fs.GetPath(), size, addr); if (!buffer) return false; Modified: lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp (original) +++ lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp Mon Nov 12 11:08:19 2018 @@ -33,6 +33,7 @@ typedef struct ar_hdr { #include "lldb/Host/FileSystem.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Utility/ArchSpec.h" +#include "lldb/Utility/DataBufferLLVM.h" #include "lldb/Utility/Stream.h" #include "lldb/Utility/Timer.h" @@ -312,7 +313,7 @@ ObjectContainer *ObjectContainerBSDArchi // file gets updated by a new build while this .a file is being used for // debugging DataBufferSP archive_data_sp = - FileSystem::Instance().CreateDataBuffer(*file, length, file_offset); + DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset); if (!archive_data_sp) return nullptr; @@ -467,7 +468,7 @@ size_t ObjectContainerBSDArchive::GetMod if (!archive_sp) { set_archive_arch = true; data_sp = - FileSystem::Instance().CreateDataBuffer(file, file_size, file_offset); + DataBufferLLVM::CreateSliceFromPath(file.GetPath(), file_size, file_offset); if (data_sp) { data.SetData(data_sp, 0, data_sp->GetByteSize()); archive_sp = Archive::ParseAndCacheArchiveForFile( Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original) +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Mon Nov 12 11:08:19 2018 @@ -30,6 +30,7 @@ #include "lldb/Target/Platform.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataBufferLLVM.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/Timer.h" @@ -1166,7 +1167,7 @@ const char *PlatformDarwin::GetDeveloper xcode_dir_path.append("/usr/share/xcode-select/xcode_dir_path"); temp_file_spec.SetFile(xcode_dir_path, FileSpec::Style::native); auto dir_buffer = - FileSystem::Instance().CreateDataBuffer(temp_file_spec.GetPath()); + DataBufferLLVM::CreateFromPath(temp_file_spec.GetPath()); if (dir_buffer && dir_buffer->GetByteSize() > 0) { llvm::StringRef path_ref(dir_buffer->GetChars()); // Trim tailing newlines and make sure there is enough room for a null Modified: lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp (original) +++ lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp Mon Nov 12 11:08:19 2018 @@ -20,6 +20,7 @@ #include "lldb/Target/Target.h" #include "lldb/Target/UnixSignals.h" #include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/DataBufferLLVM.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/State.h" @@ -57,8 +58,8 @@ lldb::ProcessSP ProcessElfCore::CreateIn // the header extension. const size_t header_size = sizeof(llvm::ELF::Elf64_Ehdr); - auto data_sp = FileSystem::Instance().CreateDataBuffer( - crash_file->GetPath(), header_size, 0); + auto data_sp = DataBufferLLVM::CreateSliceFromPath(crash_file->GetPath(), + header_size, 0); if (data_sp && data_sp->GetByteSize() == header_size && elf::ELFHeader::MagicBytesMatch(data_sp->GetBytes())) { elf::ELFHeader elf_header; Modified: lldb/trunk/source/Plugins/Process/mach-core/ProcessMachCore.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/mach-core/ProcessMachCore.cpp?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/mach-core/ProcessMachCore.cpp (original) +++ lldb/trunk/source/Plugins/Process/mach-core/ProcessMachCore.cpp Mon Nov 12 11:08:19 2018 @@ -26,6 +26,7 @@ #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Utility/DataBuffer.h" +#include "lldb/Utility/DataBufferLLVM.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/State.h" @@ -62,8 +63,8 @@ lldb::ProcessSP ProcessMachCore::CreateI lldb::ProcessSP process_sp; if (crash_file) { const size_t header_size = sizeof(llvm::MachO::mach_header); - auto data_sp = FileSystem::Instance().CreateDataBuffer( - crash_file->GetPath(), header_size, 0); + auto data_sp = + DataBufferLLVM::CreateSliceFromPath(crash_file->GetPath(), header_size, 0); if (data_sp && data_sp->GetByteSize() == header_size) { DataExtractor data(data_sp, lldb::eByteOrderLittle, 4); Modified: lldb/trunk/source/Plugins/Process/minidump/ProcessMinidump.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/minidump/ProcessMinidump.cpp?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/minidump/ProcessMinidump.cpp (original) +++ lldb/trunk/source/Plugins/Process/minidump/ProcessMinidump.cpp Mon Nov 12 11:08:19 2018 @@ -19,6 +19,7 @@ #include "lldb/Target/SectionLoadList.h" #include "lldb/Target/Target.h" #include "lldb/Target/UnixSignals.h" +#include "lldb/Utility/DataBufferLLVM.h" #include "lldb/Utility/LLDBAssert.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/State.h" @@ -98,8 +99,8 @@ lldb::ProcessSP ProcessMinidump::CreateI lldb::ProcessSP process_sp; // Read enough data for the Minidump header constexpr size_t header_size = sizeof(MinidumpHeader); - auto DataPtr = FileSystem::Instance().CreateDataBuffer(crash_file->GetPath(), - header_size, 0); + auto DataPtr = + DataBufferLLVM::CreateSliceFromPath(crash_file->GetPath(), header_size, 0); if (!DataPtr) return nullptr; @@ -111,8 +112,7 @@ lldb::ProcessSP ProcessMinidump::CreateI if (header == nullptr) return nullptr; - auto AllData = - FileSystem::Instance().CreateDataBuffer(crash_file->GetPath(), -1, 0); + auto AllData = DataBufferLLVM::CreateSliceFromPath(crash_file->GetPath(), -1, 0); if (!AllData) return nullptr; Modified: lldb/trunk/source/Symbol/ObjectFile.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ObjectFile.cpp?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ObjectFile.cpp (original) +++ lldb/trunk/source/Symbol/ObjectFile.cpp Mon Nov 12 11:08:19 2018 @@ -19,6 +19,7 @@ #include "lldb/Target/Target.h" #include "lldb/Utility/DataBuffer.h" #include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/DataBufferLLVM.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/RegularExpression.h" #include "lldb/Utility/Timer.h" @@ -74,8 +75,8 @@ ObjectFile::FindPlugin(const lldb::Modul // container plug-ins can use these bytes to see if they can parse this // file. if (file_size > 0) { - data_sp = FileSystem::Instance().CreateDataBuffer(file->GetPath(), - 512, file_offset); + data_sp = + DataBufferLLVM::CreateSliceFromPath(file->GetPath(), 512, file_offset); data_offset = 0; } } @@ -119,8 +120,8 @@ ObjectFile::FindPlugin(const lldb::Modul } // We failed to find any cached object files in the container plug- // ins, so lets read the first 512 bytes and try again below... - data_sp = FileSystem::Instance().CreateDataBuffer( - archive_file.GetPath(), 512, file_offset); + data_sp = DataBufferLLVM::CreateSliceFromPath(archive_file.GetPath(), + 512, file_offset); } } } @@ -208,8 +209,7 @@ size_t ObjectFile::GetModuleSpecificatio lldb::offset_t file_offset, lldb::offset_t file_size, ModuleSpecList &specs) { - DataBufferSP data_sp = - FileSystem::Instance().CreateDataBuffer(file.GetPath(), 512, file_offset); + DataBufferSP data_sp = DataBufferLLVM::CreateSliceFromPath(file.GetPath(), 512, file_offset); if (data_sp) { if (file_size == 0) { const lldb::offset_t actual_file_size = @@ -682,5 +682,5 @@ void ObjectFile::RelocateSection(lldb_pr DataBufferSP ObjectFile::MapFileData(const FileSpec &file, uint64_t Size, uint64_t Offset) { - return FileSystem::Instance().CreateDataBuffer(file.GetPath(), Size, Offset); + return DataBufferLLVM::CreateSliceFromPath(file.GetPath(), Size, Offset); } Modified: lldb/trunk/source/Utility/DataBufferLLVM.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/DataBufferLLVM.cpp?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/source/Utility/DataBufferLLVM.cpp (original) +++ lldb/trunk/source/Utility/DataBufferLLVM.cpp Mon Nov 12 11:08:19 2018 @@ -27,6 +27,34 @@ DataBufferLLVM::DataBufferLLVM( DataBufferLLVM::~DataBufferLLVM() {} +std::shared_ptr<DataBufferLLVM> +DataBufferLLVM::CreateSliceFromPath(const llvm::Twine &Path, uint64_t Size, + uint64_t Offset) { + // If the file resides non-locally, pass the volatile flag so that we don't + // mmap it. + bool IsVolatile = !llvm::sys::fs::is_local(Path); + + auto Buffer = + llvm::WritableMemoryBuffer::getFileSlice(Path, Size, Offset, IsVolatile); + if (!Buffer) + return nullptr; + return std::shared_ptr<DataBufferLLVM>( + new DataBufferLLVM(std::move(*Buffer))); +} + +std::shared_ptr<DataBufferLLVM> +DataBufferLLVM::CreateFromPath(const llvm::Twine &Path) { + // If the file resides non-locally, pass the volatile flag so that we don't + // mmap it. + bool IsVolatile = !llvm::sys::fs::is_local(Path); + + auto Buffer = llvm::WritableMemoryBuffer::getFile(Path, -1, IsVolatile); + if (!Buffer) + return nullptr; + return std::shared_ptr<DataBufferLLVM>( + new DataBufferLLVM(std::move(*Buffer))); +} + uint8_t *DataBufferLLVM::GetBytes() { return reinterpret_cast<uint8_t *>(Buffer->getBufferStart()); } Modified: lldb/trunk/unittests/Process/minidump/MinidumpParserTest.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Process/minidump/MinidumpParserTest.cpp?rev=346694&r1=346693&r2=346694&view=diff ============================================================================== --- lldb/trunk/unittests/Process/minidump/MinidumpParserTest.cpp (original) +++ lldb/trunk/unittests/Process/minidump/MinidumpParserTest.cpp Mon Nov 12 11:08:19 2018 @@ -15,9 +15,9 @@ #include "Plugins/Process/minidump/RegisterContextMinidump_x86_64.h" #include "TestingSupport/TestUtilities.h" -#include "lldb/Host/FileSystem.h" #include "lldb/Target/MemoryRegionInfo.h" #include "lldb/Utility/ArchSpec.h" +#include "lldb/Utility/DataBufferLLVM.h" #include "lldb/Utility/DataExtractor.h" #include "lldb/Utility/FileSpec.h" #include "llvm/ADT/ArrayRef.h" @@ -37,13 +37,9 @@ using namespace minidump; class MinidumpParserTest : public testing::Test { public: - void SetUp() override { FileSystem::Initialize(); } - - void TearDown() override { FileSystem::Terminate(); } - void SetUpData(const char *minidump_filename) { std::string filename = GetInputFilePath(minidump_filename); - auto BufferPtr = FileSystem::Instance().CreateDataBuffer(filename, -1, 0); + auto BufferPtr = DataBufferLLVM::CreateSliceFromPath(filename, -1, 0); ASSERT_NE(BufferPtr, nullptr); llvm::Optional<MinidumpParser> optional_parser = MinidumpParser::Create(BufferPtr); @@ -57,7 +53,7 @@ public: void InvalidMinidump(const char *minidump_filename, uint64_t load_size) { std::string filename = GetInputFilePath(minidump_filename); auto BufferPtr = - FileSystem::Instance().CreateDataBuffer(filename, load_size, 0); + DataBufferLLVM::CreateSliceFromPath(filename, load_size, 0); ASSERT_NE(BufferPtr, nullptr); llvm::Optional<MinidumpParser> optional_parser = @@ -92,7 +88,7 @@ TEST_F(MinidumpParserTest, GetThreadList // after the thread count. SetUpData("thread-list-not-padded.dmp"); llvm::ArrayRef<MinidumpThread> thread_list; - + thread_list = parser->GetThreads(); ASSERT_EQ(2UL, thread_list.size()); EXPECT_EQ(0x11223344UL, thread_list[0].thread_id); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits