diff options
Diffstat (limited to 'lldb/source/Plugins')
9 files changed, 47 insertions, 34 deletions
diff --git a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp index d1f1a3bb12b..a4bd1c99855 100644 --- a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp @@ -39,6 +39,7 @@ #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Utility/ConstString.h" +#include "lldb/Utility/DataBufferLLVM.h" #include "lldb/Utility/Error.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/RegularExpression.h" @@ -2536,7 +2537,7 @@ bool RenderScriptRuntime::LoadAllocation(Stream &strm, const uint32_t alloc_id, } // Read file into data buffer - DataBufferSP data_sp(file.ReadFileContents()); + 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(); @@ -3074,7 +3075,7 @@ bool RSModuleDescriptor::ParseRSInfo() { const addr_t size = info_sym->GetByteSize(); const FileSpec fs = m_module->GetFileSpec(); - const DataBufferSP buffer = fs.ReadFileContents(addr, size); + auto buffer = DataBufferLLVM::CreateSliceFromPath(fs.GetPath(), size, addr); if (!buffer) return false; diff --git a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp index 2113876e6c1..b74da330017 100644 --- a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp +++ b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp @@ -314,7 +314,7 @@ ObjectContainer *ObjectContainerBSDArchive::CreateInstance( // file gets updated by a new build while this .a file is being used for // debugging DataBufferSP archive_data_sp = - DataBufferLLVM::CreateFromPath(file->GetPath(), length, file_offset); + DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset); if (!archive_data_sp) return nullptr; @@ -469,7 +469,7 @@ size_t ObjectContainerBSDArchive::GetModuleSpecifications( if (!archive_sp) { set_archive_arch = true; data_sp = - DataBufferLLVM::CreateFromPath(file.GetPath(), 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( diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index 8a4734bd337..10213f572b8 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -388,7 +388,7 @@ ObjectFile *ObjectFileELF::CreateInstance(const lldb::ModuleSP &module_sp, lldb::offset_t length) { if (!data_sp) { data_sp = - DataBufferLLVM::CreateFromPath(file->GetPath(), length, file_offset); + DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset); if (!data_sp) return nullptr; data_offset = 0; @@ -406,7 +406,7 @@ ObjectFile *ObjectFileELF::CreateInstance(const lldb::ModuleSP &module_sp, // Update the data to contain the entire file if it doesn't already if (data_sp->GetByteSize() < length) { data_sp = - DataBufferLLVM::CreateFromPath(file->GetPath(), length, file_offset); + DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset); if (!data_sp) return nullptr; data_offset = 0; @@ -665,7 +665,7 @@ size_t ObjectFileELF::GetModuleSpecifications( size_t section_header_end = header.e_shoff + header.e_shentsize; if (header.HasHeaderExtension() && section_header_end > data_sp->GetByteSize()) { - data_sp = DataBufferLLVM::CreateFromPath( + data_sp = DataBufferLLVM::CreateSliceFromPath( file.GetPath(), section_header_end, file_offset); if (data_sp) { data.SetData(data_sp); @@ -679,7 +679,7 @@ size_t ObjectFileELF::GetModuleSpecifications( section_header_end = header.e_shoff + header.e_shnum * header.e_shentsize; if (section_header_end > data_sp->GetByteSize()) { - data_sp = DataBufferLLVM::CreateFromPath( + data_sp = DataBufferLLVM::CreateSliceFromPath( file.GetPath(), section_header_end, file_offset); if (data_sp) data.SetData(data_sp); @@ -724,7 +724,7 @@ size_t ObjectFileELF::GetModuleSpecifications( size_t program_headers_end = header.e_phoff + header.e_phnum * header.e_phentsize; if (program_headers_end > data_sp->GetByteSize()) { - data_sp = DataBufferLLVM::CreateFromPath( + data_sp = DataBufferLLVM::CreateSliceFromPath( file.GetPath(), program_headers_end, file_offset); if (data_sp) data.SetData(data_sp); @@ -740,7 +740,7 @@ size_t ObjectFileELF::GetModuleSpecifications( } if (segment_data_end > data_sp->GetByteSize()) { - data_sp = DataBufferLLVM::CreateFromPath( + data_sp = DataBufferLLVM::CreateSliceFromPath( file.GetPath(), segment_data_end, file_offset); if (data_sp) data.SetData(data_sp); @@ -750,7 +750,7 @@ size_t ObjectFileELF::GetModuleSpecifications( CalculateELFNotesSegmentsCRC32(program_headers, data); } else { // Need to map entire file into memory to calculate the crc. - data_sp = DataBufferLLVM::CreateFromPath(file.GetPath(), -1, + data_sp = DataBufferLLVM::CreateSliceFromPath(file.GetPath(), -1, file_offset); if (data_sp) { data.SetData(data_sp); diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 5901a1b4935..a6d5a85e2d4 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -860,7 +860,7 @@ ObjectFile *ObjectFileMachO::CreateInstance(const lldb::ModuleSP &module_sp, lldb::offset_t length) { if (!data_sp) { data_sp = - DataBufferLLVM::CreateFromPath(file->GetPath(), length, file_offset); + DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset); if (!data_sp) return nullptr; data_offset = 0; @@ -872,7 +872,7 @@ ObjectFile *ObjectFileMachO::CreateInstance(const lldb::ModuleSP &module_sp, // Update the data to contain the entire file if it doesn't already if (data_sp->GetByteSize() < length) { data_sp = - DataBufferLLVM::CreateFromPath(file->GetPath(), length, file_offset); + DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset); if (!data_sp) return nullptr; data_offset = 0; @@ -911,7 +911,8 @@ size_t ObjectFileMachO::GetModuleSpecifications( size_t header_and_load_cmds = header.sizeofcmds + MachHeaderSizeFromMagic(header.magic); if (header_and_load_cmds >= data_sp->GetByteSize()) { - data_sp = file.ReadFileContents(file_offset, header_and_load_cmds); + data_sp = DataBufferLLVM::CreateSliceFromPath( + file.GetPath(), header_and_load_cmds, file_offset); data.SetData(data_sp); data_offset = MachHeaderSizeFromMagic(header.magic); } @@ -1123,8 +1124,8 @@ bool ObjectFileMachO::ParseHeader() { ReadMemory(process_sp, m_memory_addr, header_and_lc_size); } else { // Read in all only the load command data from the file on disk - data_sp = - m_file.ReadFileContents(m_file_offset, header_and_lc_size); + data_sp = DataBufferLLVM::CreateSliceFromPath( + m_file.GetPath(), header_and_lc_size, m_file_offset); if (data_sp->GetByteSize() != header_and_lc_size) return false; } @@ -2095,7 +2096,7 @@ UUID ObjectFileMachO::GetSharedCacheUUID(FileSpec dyld_shared_cache, const ByteOrder byte_order, const uint32_t addr_byte_size) { UUID dsc_uuid; - DataBufferSP DscData = DataBufferLLVM::CreateFromPath( + DataBufferSP DscData = DataBufferLLVM::CreateSliceFromPath( dyld_shared_cache.GetPath(), sizeof(struct lldb_copy_dyld_cache_header_v1), 0); if (!DscData) @@ -2703,7 +2704,7 @@ size_t ObjectFileMachO::ParseSymtab() { // Process the dyld shared cache header to find the unmapped symbols - DataBufferSP dsc_data_sp = DataBufferLLVM::CreateFromPath( + DataBufferSP dsc_data_sp = DataBufferLLVM::CreateSliceFromPath( dsc_filespec.GetPath(), sizeof(struct lldb_copy_dyld_cache_header_v1), 0); if (!dsc_uuid.IsValid()) { @@ -2738,7 +2739,7 @@ size_t ObjectFileMachO::ParseSymtab() { mappingOffset >= sizeof(struct lldb_copy_dyld_cache_header_v1)) { DataBufferSP dsc_mapping_info_data_sp = - DataBufferLLVM::CreateFromPath( + DataBufferLLVM::CreateSliceFromPath( dsc_filespec.GetPath(), sizeof(struct lldb_copy_dyld_cache_mapping_info), mappingOffset); @@ -2765,7 +2766,7 @@ size_t ObjectFileMachO::ParseSymtab() { if (localSymbolsOffset && localSymbolsSize) { // Map the local symbols DataBufferSP dsc_local_symbols_data_sp = - DataBufferLLVM::CreateFromPath(dsc_filespec.GetPath(), + DataBufferLLVM::CreateSliceFromPath(dsc_filespec.GetPath(), localSymbolsSize, localSymbolsOffset); diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp index b9577b5d1f2..df665129ae2 100644 --- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp @@ -68,7 +68,7 @@ ObjectFile *ObjectFilePECOFF::CreateInstance(const lldb::ModuleSP &module_sp, lldb::offset_t length) { if (!data_sp) { data_sp = - DataBufferLLVM::CreateFromPath(file->GetPath(), length, file_offset); + DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset); if (!data_sp) return nullptr; data_offset = 0; @@ -80,7 +80,7 @@ ObjectFile *ObjectFilePECOFF::CreateInstance(const lldb::ModuleSP &module_sp, // Update the data to contain the entire file if it doesn't already if (data_sp->GetByteSize() < length) { data_sp = - DataBufferLLVM::CreateFromPath(file->GetPath(), length, file_offset); + DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset); if (!data_sp) return nullptr; } @@ -430,7 +430,10 @@ bool ObjectFilePECOFF::ParseCOFFOptionalHeader(lldb::offset_t *offset_ptr) { DataExtractor ObjectFilePECOFF::ReadImageData(uint32_t offset, size_t size) { if (m_file) { - DataBufferSP buffer_sp(m_file.ReadFileContents(offset, size)); + // A bit of a hack, but we intend to write to this buffer, so we can't + // mmap it. + auto buffer_sp = + DataBufferLLVM::CreateSliceFromPath(m_file.GetPath(), size, offset, true); return DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()); } ProcessSP process_sp(m_process_wp.lock()); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index b1937efe553..75311078f74 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -37,6 +37,7 @@ #include "lldb/Symbol/SymbolVendor.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataBufferLLVM.h" #include "lldb/Utility/Error.h" #include "lldb/Utility/Log.h" #include "llvm/ADT/STLExtras.h" @@ -1154,13 +1155,16 @@ const char *PlatformDarwin::GetDeveloperDirectory() { xcode_dir_path.append(xcode_select_prefix_dir); xcode_dir_path.append("/usr/share/xcode-select/xcode_dir_path"); temp_file_spec.SetFile(xcode_dir_path, false); - size_t bytes_read = temp_file_spec.ReadFileContents( - 0, developer_dir_path, sizeof(developer_dir_path), NULL); - if (bytes_read > 0) { - developer_dir_path[bytes_read] = '\0'; - while (developer_dir_path[bytes_read - 1] == '\r' || - developer_dir_path[bytes_read - 1] == '\n') - developer_dir_path[--bytes_read] = '\0'; + auto dir_buffer = + DataBufferLLVM::CreateFromPath(temp_file_spec.GetPath(), true); + 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 + // terminator. + path_ref = + path_ref.rtrim("\r\n").take_front(sizeof(developer_dir_path) - 1); + ::memcpy(developer_dir_path, path_ref.data(), path_ref.size()); + developer_dir_path[path_ref.size()] = '\0'; developer_dir_path_valid = true; } } diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp index adb199ef166..99c1b7d3733 100644 --- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp +++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp @@ -24,6 +24,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 "llvm/Support/ELF.h" @@ -61,7 +62,8 @@ lldb::ProcessSP ProcessElfCore::CreateInstance(lldb::TargetSP target_sp, // to ignore possible presence of the header extension. const size_t header_size = sizeof(llvm::ELF::Elf64_Ehdr); - lldb::DataBufferSP data_sp(crash_file->ReadFileContents(0, header_size)); + 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; diff --git a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp index 9941c632f3a..665fcd169b0 100644 --- a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp +++ b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp @@ -30,6 +30,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" // Project includes @@ -66,7 +67,8 @@ lldb::ProcessSP ProcessMachCore::CreateInstance(lldb::TargetSP target_sp, lldb::ProcessSP process_sp; if (crash_file) { const size_t header_size = sizeof(llvm::MachO::mach_header); - lldb::DataBufferSP data_sp(crash_file->ReadFileContents(0, header_size)); + 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); diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp index 352e33b1f36..f3f4664ad6e 100644 --- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp +++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp @@ -53,7 +53,7 @@ lldb::ProcessSP ProcessMinidump::CreateInstance(lldb::TargetSP target_sp, // Read enough data for the Minidump header constexpr size_t header_size = sizeof(MinidumpHeader); auto DataPtr = - DataBufferLLVM::CreateFromPath(crash_file->GetPath(), header_size, 0); + DataBufferLLVM::CreateSliceFromPath(crash_file->GetPath(), header_size, 0); if (!DataPtr) return nullptr; @@ -65,7 +65,7 @@ lldb::ProcessSP ProcessMinidump::CreateInstance(lldb::TargetSP target_sp, if (header == nullptr) return nullptr; - auto AllData = DataBufferLLVM::CreateFromPath(crash_file->GetPath(), -1, 0); + auto AllData = DataBufferLLVM::CreateSliceFromPath(crash_file->GetPath(), -1, 0); if (!AllData) return nullptr; |