Index: lldb/include/lldb/Core/ValueObject.h =================================================================== --- lldb/include/lldb/Core/ValueObject.h +++ lldb/include/lldb/Core/ValueObject.h @@ -679,7 +679,7 @@ bool IsCStringContainer(bool check_pointer = false); std::pair - ReadPointedString(lldb::DataBufferSP &buffer_sp, Status &error, + ReadPointedString(lldb::WritableDataBufferSP &buffer_sp, Status &error, uint32_t max_length = 0, bool honor_array = true, lldb::Format item_format = lldb::eFormatCharArray); Index: lldb/include/lldb/Host/FileSystem.h =================================================================== --- lldb/include/lldb/Host/FileSystem.h +++ lldb/include/lldb/Host/FileSystem.h @@ -148,6 +148,12 @@ std::shared_ptr CreateDataBuffer(const FileSpec &file_spec, uint64_t size = 0, uint64_t offset = 0); + std::shared_ptr + CreateWritableDataBuffer(const llvm::Twine &path, uint64_t size = 0, + uint64_t offset = 0); + std::shared_ptr + CreateWritableDataBuffer(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. Index: lldb/include/lldb/Symbol/CompactUnwindInfo.h =================================================================== --- lldb/include/lldb/Symbol/CompactUnwindInfo.h +++ lldb/include/lldb/Symbol/CompactUnwindInfo.h @@ -138,9 +138,10 @@ ObjectFile &m_objfile; lldb::SectionSP m_section_sp; - lldb::DataBufferSP m_section_contents_if_encrypted; // if the binary is - // encrypted, read the - // sect contents + lldb::WritableDataBufferSP + m_section_contents_if_encrypted; // if the binary is + // encrypted, read the + // sect contents // out of live memory and cache them here std::mutex m_mutex; std::vector m_indexes; Index: lldb/include/lldb/Target/ProcessStructReader.h =================================================================== --- lldb/include/lldb/Target/ProcessStructReader.h +++ lldb/include/lldb/Target/ProcessStructReader.h @@ -69,7 +69,7 @@ auto total_size = struct_type.GetByteSize(nullptr); if (!total_size) return; - lldb::DataBufferSP buffer_sp(new DataBufferHeap(*total_size, 0)); + lldb::WritableDataBufferSP buffer_sp(new DataBufferHeap(*total_size, 0)); Status error; process->ReadMemoryFromInferior(base_addr, buffer_sp->GetBytes(), *total_size, error); Index: lldb/include/lldb/Target/RegisterCheckpoint.h =================================================================== --- lldb/include/lldb/Target/RegisterCheckpoint.h +++ lldb/include/lldb/Target/RegisterCheckpoint.h @@ -35,12 +35,12 @@ ~RegisterCheckpoint() = default; - lldb::DataBufferSP &GetData() { return m_data_sp; } + lldb::WritableDataBufferSP &GetData() { return m_data_sp; } - const lldb::DataBufferSP &GetData() const { return m_data_sp; } + const lldb::WritableDataBufferSP &GetData() const { return m_data_sp; } protected: - lldb::DataBufferSP m_data_sp; + lldb::WritableDataBufferSP m_data_sp; Reason m_reason; // Make RegisterCheckpointSP if you wish to share the data in this class. Index: lldb/include/lldb/Target/RegisterContext.h =================================================================== --- lldb/include/lldb/Target/RegisterContext.h +++ lldb/include/lldb/Target/RegisterContext.h @@ -43,7 +43,7 @@ virtual bool WriteRegister(const RegisterInfo *reg_info, const RegisterValue ®_value) = 0; - virtual bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) { + virtual bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) { return false; } Index: lldb/include/lldb/Target/RegisterContextUnwind.h =================================================================== --- lldb/include/lldb/Target/RegisterContextUnwind.h +++ lldb/include/lldb/Target/RegisterContextUnwind.h @@ -50,7 +50,7 @@ bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value) override; - bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; + bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override; bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; Index: lldb/include/lldb/Utility/DataBuffer.h =================================================================== --- lldb/include/lldb/Utility/DataBuffer.h +++ lldb/include/lldb/Utility/DataBuffer.h @@ -20,12 +20,12 @@ namespace lldb_private { /// \class DataBuffer DataBuffer.h "lldb/Core/DataBuffer.h" -/// A pure virtual protocol class for abstracted data buffers. +/// A pure virtual protocol class for abstracted read only data buffers. /// -/// DataBuffer is an abstract class that gets packaged into a shared pointer -/// that can use to implement various ways to store data (on the heap, memory -/// mapped, cached inferior memory). It gets used by DataExtractor so many -/// DataExtractor objects can share the same data and sub-ranges of that +/// DataBuffer is an abstract class that gets packaged into a shared +/// pointer that can use to implement various ways to store data (on the heap, +/// memory mapped, cached inferior memory). It gets used by DataExtractor so +/// many DataExtractor objects can share the same data and sub-ranges of that /// shared data, and the last object that contains a reference to the shared /// data will free it. /// @@ -41,6 +41,44 @@ /// calls being made, but we can modify it to optionally get data on demand /// with some extra function calls to load the data before it gets accessed. class DataBuffer { +public: + virtual ~DataBuffer() = default; + + /// Get the number of bytes in the data buffer. + /// + /// \return + /// The number of bytes this object currently contains. + virtual lldb::offset_t GetByteSize() const = 0; + + /// Get a const pointer to the data. + /// + /// \return + /// A const pointer to the bytes owned by this object, or NULL + /// if the object contains no bytes. + virtual const uint8_t *GetBytesImpl() const = 0; + + /// Get a const pointer to the data. + /// + /// \return + /// A const pointer to the bytes owned by this object, or NULL + /// if the object contains no bytes. + const uint8_t *GetBytes() const { return GetBytesImpl(); } + + llvm::ArrayRef GetData() const { + return llvm::ArrayRef(GetBytes(), GetByteSize()); + } +}; + +/// \class DataBuffer DataBuffer.h "lldb/Core/DataBuffer.h" +/// A pure virtual protocol class for abstracted writable data buffers. +/// +/// DataBuffer is an abstract class that gets packaged into a shared pointer +/// that can use to implement various ways to store data (on the heap, memory +/// mapped, cached inferior memory). It gets used by DataExtractor so many +/// DataExtractor objects can share the same data and sub-ranges of that +/// shared data, and the last object that contains a reference to the shared +/// data will free it. +class WritableDataBuffer : public DataBuffer { public: /// Destructor /// @@ -48,44 +86,37 @@ /// and be downcast to the DataBuffer pure virtual interface. The virtual /// destructor ensures that destructing the base class will destruct the /// class that inherited from it correctly. - virtual ~DataBuffer() = default; + virtual ~WritableDataBuffer() = default; /// Get a pointer to the data. /// /// \return /// A pointer to the bytes owned by this object, or NULL if the /// object contains no bytes. - virtual uint8_t *GetBytes() = 0; + uint8_t *GetBytes() { return const_cast(GetBytesImpl()); } /// Get a const pointer to the data. /// /// \return /// A const pointer to the bytes owned by this object, or NULL /// if the object contains no bytes. - virtual const uint8_t *GetBytes() const = 0; + const uint8_t *GetBytes() const { return GetBytesImpl(); } - /// Get the number of bytes in the data buffer. - /// - /// \return - /// The number of bytes this object currently contains. - virtual lldb::offset_t GetByteSize() const = 0; + llvm::MutableArrayRef GetData() { + return llvm::MutableArrayRef(GetBytes(), GetByteSize()); + } llvm::ArrayRef GetData() const { return llvm::ArrayRef(GetBytes(), GetByteSize()); } - - llvm::MutableArrayRef GetData() { - return llvm::MutableArrayRef(GetBytes(), GetByteSize()); - } }; -class DataBufferUnowned : public DataBuffer { +class DataBufferUnowned : public WritableDataBuffer { public: DataBufferUnowned(uint8_t *bytes, lldb::offset_t size) : m_bytes(bytes), m_size(size) {} - uint8_t *GetBytes() override { return m_bytes; } - const uint8_t *GetBytes() const override { return m_bytes; } + const uint8_t *GetBytesImpl() const override { return m_bytes; } lldb::offset_t GetByteSize() const override { return m_size; } private: Index: lldb/include/lldb/Utility/DataBufferHeap.h =================================================================== --- lldb/include/lldb/Utility/DataBufferHeap.h +++ lldb/include/lldb/Utility/DataBufferHeap.h @@ -27,7 +27,7 @@ /// pages in. Large amounts of data that comes from files should probably use /// DataBufferLLVM, which can intelligently determine when memory mapping is /// optimal. -class DataBufferHeap : public DataBuffer { +class DataBufferHeap : public WritableDataBuffer { public: /// Default constructor /// @@ -60,11 +60,8 @@ /// class #DataBuffer. ~DataBufferHeap() override; - /// \copydoc DataBuffer::GetBytes() - uint8_t *GetBytes() override; - /// \copydoc DataBuffer::GetBytes() const - const uint8_t *GetBytes() const override; + const uint8_t *GetBytesImpl() const override; /// \copydoc DataBuffer::GetByteSize() const lldb::offset_t GetByteSize() const override; Index: lldb/include/lldb/Utility/DataBufferLLVM.h =================================================================== --- lldb/include/lldb/Utility/DataBufferLLVM.h +++ lldb/include/lldb/Utility/DataBufferLLVM.h @@ -17,25 +17,42 @@ namespace llvm { class WritableMemoryBuffer; +class MemoryBuffer; class Twine; } // namespace llvm namespace lldb_private { - class FileSystem; -class DataBufferLLVM : public DataBuffer { + +class DataBufferLLVM : public WritableDataBuffer { public: ~DataBufferLLVM() override; - uint8_t *GetBytes() override; - const uint8_t *GetBytes() const override; + const uint8_t *GetBytesImpl() const override; + lldb::offset_t GetByteSize() const override; + +private: + friend FileSystem; + /// Construct a DataBufferLLVM from \p Buffer. \p Buffer must be a valid + /// pointer. + explicit DataBufferLLVM(std::unique_ptr Buffer); + + std::unique_ptr Buffer; +}; + +class WritableDataBufferLLVM : public WritableDataBuffer { +public: + ~WritableDataBufferLLVM() override; + + const uint8_t *GetBytesImpl() const override; lldb::offset_t GetByteSize() const override; private: friend FileSystem; /// Construct a DataBufferLLVM from \p Buffer. \p Buffer must be a valid /// pointer. - explicit DataBufferLLVM(std::unique_ptr Buffer); + explicit WritableDataBufferLLVM( + std::unique_ptr Buffer); std::unique_ptr Buffer; }; Index: lldb/include/lldb/lldb-forward.h =================================================================== --- lldb/include/lldb/lldb-forward.h +++ lldb/include/lldb/lldb-forward.h @@ -67,6 +67,7 @@ class DWARFDataExtractor; class DWARFExpression; class DataBuffer; +class WritableDataBuffer; class DataBufferHeap; class DataEncoder; class DataExtractor; @@ -309,6 +310,7 @@ typedef std::shared_ptr ConnectionSP; typedef std::shared_ptr CompUnitSP; typedef std::shared_ptr DataBufferSP; +typedef std::shared_ptr WritableDataBufferSP; typedef std::shared_ptr DataExtractorSP; typedef std::shared_ptr DebuggerSP; typedef std::weak_ptr DebuggerWP; Index: lldb/source/Commands/CommandObjectMemory.cpp =================================================================== --- lldb/source/Commands/CommandObjectMemory.cpp +++ lldb/source/Commands/CommandObjectMemory.cpp @@ -639,7 +639,7 @@ return false; } - DataBufferSP data_sp; + WritableDataBufferSP data_sp; size_t bytes_read = 0; if (compiler_type.GetOpaqueQualType()) { // Make sure we don't display our type as ASCII bytes like the default Index: lldb/source/Core/SourceManager.cpp =================================================================== --- lldb/source/Core/SourceManager.cpp +++ lldb/source/Core/SourceManager.cpp @@ -644,7 +644,7 @@ if (m_data_sp.get() == nullptr) return false; - const char *start = (char *)m_data_sp->GetBytes(); + const char *start = (const char *)m_data_sp->GetBytes(); if (start) { const char *end = start + m_data_sp->GetByteSize(); @@ -694,7 +694,7 @@ if (end_offset == UINT32_MAX) { end_offset = m_data_sp->GetByteSize(); } - buffer.assign((char *)m_data_sp->GetBytes() + start_offset, + buffer.assign((const char *)m_data_sp->GetBytes() + start_offset, end_offset - start_offset); return true; Index: lldb/source/Core/ValueObject.cpp =================================================================== --- lldb/source/Core/ValueObject.cpp +++ lldb/source/Core/ValueObject.cpp @@ -848,7 +848,7 @@ } static bool CopyStringDataToBufferSP(const StreamString &source, - lldb::DataBufferSP &destination) { + lldb::WritableDataBufferSP &destination) { llvm::StringRef src = source.GetString(); src = src.rtrim('\0'); destination = std::make_shared(src.size(), 0); @@ -857,9 +857,9 @@ } std::pair -ValueObject::ReadPointedString(lldb::DataBufferSP &buffer_sp, Status &error, - uint32_t max_length, bool honor_array, - Format item_format) { +ValueObject::ReadPointedString(lldb::WritableDataBufferSP &buffer_sp, + Status &error, uint32_t max_length, + bool honor_array, Format item_format) { bool was_capped = false; StreamString s; ExecutionContext exe_ctx(GetExecutionContextRef()); @@ -1184,7 +1184,7 @@ eFormatVectorOfChar)) // print char[] & char* directly { Status error; - lldb::DataBufferSP buffer_sp; + lldb::WritableDataBufferSP buffer_sp; std::pair read_string = ReadPointedString( buffer_sp, error, 0, (custom_format == eFormatVectorOfChar) || (custom_format == eFormatCharArray)); Index: lldb/source/DataFormatters/StringPrinter.cpp =================================================================== --- lldb/source/DataFormatters/StringPrinter.cpp +++ lldb/source/DataFormatters/StringPrinter.cpp @@ -293,7 +293,7 @@ data_ptr = (const SourceDataType *)data.GetDataStart(); } - lldb::DataBufferSP utf8_data_buffer_sp; + lldb::WritableDataBufferSP utf8_data_buffer_sp; llvm::UTF8 *utf8_data_ptr = nullptr; llvm::UTF8 *utf8_data_end_ptr = nullptr; @@ -450,7 +450,7 @@ } const int bufferSPSize = sourceSize * type_width; - lldb::DataBufferSP buffer_sp(new DataBufferHeap(bufferSPSize, 0)); + lldb::WritableDataBufferSP buffer_sp(new DataBufferHeap(bufferSPSize, 0)); // Check if we got bytes. We never get any bytes if we have an empty // string, but we still continue so that we end up actually printing Index: lldb/source/Expression/IRExecutionUnit.cpp =================================================================== --- lldb/source/Expression/IRExecutionUnit.cpp +++ lldb/source/Expression/IRExecutionUnit.cpp @@ -151,7 +151,8 @@ return ret; } - lldb::DataBufferSP buffer_sp(new DataBufferHeap(func_range.second, 0)); + lldb::WritableDataBufferSP buffer_sp( + new DataBufferHeap(func_range.second, 0)); Process *process = exe_ctx.GetProcessPtr(); Status err; Index: lldb/source/Host/common/FileSystem.cpp =================================================================== --- lldb/source/Host/common/FileSystem.cpp +++ lldb/source/Host/common/FileSystem.cpp @@ -273,27 +273,50 @@ file_spec.SetIsResolved(true); } -std::shared_ptr -FileSystem::CreateDataBuffer(const llvm::Twine &path, uint64_t size, - uint64_t offset) { - const bool is_volatile = !IsLocal(path); - std::unique_ptr buffer; +template +static std::unique_ptr GetMemoryBuffer(const llvm::Twine &path, + uint64_t size, uint64_t offset, + bool is_volatile) { + std::unique_ptr buffer; if (size == 0) { - auto buffer_or_error = - llvm::WritableMemoryBuffer::getFile(path, is_volatile); + auto buffer_or_error = T::getFile(path, 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); + auto buffer_or_error = T::getFileSlice(path, size, offset, is_volatile); if (!buffer_or_error) return nullptr; buffer = std::move(*buffer_or_error); } + return buffer; +} + +std::shared_ptr +FileSystem::CreateWritableDataBuffer(const llvm::Twine &path, uint64_t size, + uint64_t offset) { + const bool is_volatile = !IsLocal(path); + auto buffer = GetMemoryBuffer(path, size, offset, + is_volatile); + return std::shared_ptr( + new WritableDataBufferLLVM(std::move(buffer))); +} + +std::shared_ptr +FileSystem::CreateDataBuffer(const llvm::Twine &path, uint64_t size, + uint64_t offset) { + const bool is_volatile = !IsLocal(path); + auto buffer = + GetMemoryBuffer(path, size, offset, is_volatile); return std::shared_ptr(new DataBufferLLVM(std::move(buffer))); } +std::shared_ptr +FileSystem::CreateWritableDataBuffer(const FileSpec &file_spec, uint64_t size, + uint64_t offset) { + return CreateWritableDataBuffer(file_spec.GetPath(), size, offset); +} + std::shared_ptr FileSystem::CreateDataBuffer(const FileSpec &file_spec, uint64_t size, uint64_t offset) { Index: lldb/source/Host/common/Host.cpp =================================================================== --- lldb/source/Host/common/Host.cpp +++ lldb/source/Host/common/Host.cpp @@ -524,8 +524,9 @@ error.SetErrorStringWithFormat( "shell command output is too large to fit into a std::string"); } else { - auto Buffer = - FileSystem::Instance().CreateDataBuffer(output_file_spec); + WritableDataBufferSP Buffer = + FileSystem::Instance().CreateWritableDataBuffer( + output_file_spec); if (error.Success()) command_output_ptr->assign( reinterpret_cast(Buffer->GetBytes()), Index: lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp =================================================================== --- lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp +++ lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp @@ -1668,7 +1668,7 @@ ProcessSP process_sp(thread.GetProcess()); ByteOrder byte_order = process_sp->GetByteOrder(); - DataBufferSP data_sp(new DataBufferHeap(*byte_size, 0)); + WritableDataBufferSP data_sp(new DataBufferHeap(*byte_size, 0)); uint32_t data_offset = 0; for (uint32_t reg_index = 0; reg_index < vfp_count; reg_index++) { Index: lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp =================================================================== --- lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp +++ lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp @@ -873,7 +873,7 @@ DataExtractor f1_data; reg_ctx->ReadRegister(f1_info, f1_value); DataExtractor *copy_from_extractor = nullptr; - DataBufferSP data_sp(new DataBufferHeap(8, 0)); + WritableDataBufferSP data_sp(new DataBufferHeap(8, 0)); DataExtractor return_ext( data_sp, target_byte_order, target->GetArchitecture().GetAddressByteSize()); Index: lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp =================================================================== --- lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp +++ lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp @@ -827,7 +827,7 @@ DataExtractor f2_data; reg_ctx->ReadRegister(f2_info, f2_value); DataExtractor *copy_from_extractor = nullptr; - DataBufferSP data_sp(new DataBufferHeap(16, 0)); + WritableDataBufferSP data_sp(new DataBufferHeap(16, 0)); DataExtractor return_ext( data_sp, target_byte_order, target->GetArchitecture().GetAddressByteSize()); @@ -867,7 +867,7 @@ type_flags & eTypeIsVector) { // Any structure of up to 16 bytes in size is returned in the registers. if (*byte_size <= 16) { - DataBufferSP data_sp(new DataBufferHeap(16, 0)); + WritableDataBufferSP data_sp(new DataBufferHeap(16, 0)); DataExtractor return_ext(data_sp, target_byte_order, target->GetArchitecture().GetAddressByteSize()); Index: lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp =================================================================== --- lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp +++ lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp @@ -666,7 +666,7 @@ bool is_memory = true; if (*bit_width <= 128) { ByteOrder target_byte_order = target->GetArchitecture().GetByteOrder(); - DataBufferSP data_sp(new DataBufferHeap(16, 0)); + WritableDataBufferSP data_sp(new DataBufferHeap(16, 0)); DataExtractor return_ext(data_sp, target_byte_order, target->GetArchitecture().GetAddressByteSize()); Index: lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp =================================================================== --- lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp +++ lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp @@ -645,7 +645,7 @@ 0, aggregate_field_offsets, aggregate_compiler_types)) { ByteOrder byte_order = target->GetArchitecture().GetByteOrder(); - DataBufferSP data_sp(new DataBufferHeap(16, 0)); + WritableDataBufferSP data_sp(new DataBufferHeap(16, 0)); DataExtractor return_ext(data_sp, byte_order, target->GetArchitecture().GetAddressByteSize()); Index: lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp =================================================================== --- lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp +++ lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp @@ -642,7 +642,7 @@ 0, aggregate_field_offsets, aggregate_compiler_types)) { ByteOrder byte_order = target->GetArchitecture().GetByteOrder(); - DataBufferSP data_sp( + WritableDataBufferSP data_sp( new DataBufferHeap(max_register_value_bit_width / 8, 0)); DataExtractor return_ext(data_sp, byte_order, target->GetArchitecture().GetAddressByteSize()); Index: lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp =================================================================== --- lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -804,7 +804,8 @@ return true; // We were able to read the mach_header and weren't asked // to read the load command bytes - DataBufferSP load_cmd_data_sp(new DataBufferHeap(header->sizeofcmds, 0)); + WritableDataBufferSP load_cmd_data_sp( + new DataBufferHeap(header->sizeofcmds, 0)); size_t load_cmd_bytes_read = m_process->ReadMemory(load_cmd_addr, load_cmd_data_sp->GetBytes(), Index: lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp =================================================================== --- lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -296,7 +296,7 @@ llvm::Optional size = tree_node_type.GetByteSize(nullptr); if (!size) return false; - DataBufferSP buffer_sp(new DataBufferHeap(*size, 0)); + WritableDataBufferSP buffer_sp(new DataBufferHeap(*size, 0)); ProcessSP process_sp(target_sp->GetProcessSP()); Status error; process_sp->ReadMemory(addr, buffer_sp->GetBytes(), Index: lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp =================================================================== --- lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp +++ lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp @@ -214,7 +214,7 @@ llvm::Optional size = m_bool_type.GetByteSize(nullptr); if (!size) return {}; - DataBufferSP buffer_sp(new DataBufferHeap(*size, 0)); + WritableDataBufferSP buffer_sp(new DataBufferHeap(*size, 0)); if (bit_set && buffer_sp && buffer_sp->GetBytes()) { // regardless of endianness, anything non-zero is true *(buffer_sp->GetBytes()) = 1; Index: lldb/source/Plugins/Language/ObjC/CF.cpp =================================================================== --- lldb/source/Plugins/Language/ObjC/CF.cpp +++ lldb/source/Plugins/Language/ObjC/CF.cpp @@ -158,7 +158,7 @@ // make sure we do not try to read huge amounts of data if (num_bytes > 1024) num_bytes = 1024; - DataBufferSP buffer_sp(new DataBufferHeap(num_bytes, 0)); + WritableDataBufferSP buffer_sp(new DataBufferHeap(num_bytes, 0)); num_bytes = process_sp->ReadMemory(data_ptr, buffer_sp->GetBytes(), num_bytes, error); if (error.Fail() || num_bytes == 0) Index: lldb/source/Plugins/Language/ObjC/NSDictionary.cpp =================================================================== --- lldb/source/Plugins/Language/ObjC/NSDictionary.cpp +++ lldb/source/Plugins/Language/ObjC/NSDictionary.cpp @@ -713,7 +713,7 @@ if (!m_pair_type.IsValid()) return ValueObjectSP(); - DataBufferSP buffer_sp(new DataBufferHeap(2 * m_ptr_size, 0)); + WritableDataBufferSP buffer_sp(new DataBufferHeap(2 * m_ptr_size, 0)); if (m_ptr_size == 8) { uint64_t *data_ptr = (uint64_t *)buffer_sp->GetBytes(); @@ -840,7 +840,7 @@ if (!m_pair_type.IsValid()) return ValueObjectSP(); - DataBufferSP buffer_sp(new DataBufferHeap(2 * m_ptr_size, 0)); + WritableDataBufferSP buffer_sp(new DataBufferHeap(2 * m_ptr_size, 0)); switch (m_ptr_size) { case 0: // architecture has no clue - fail @@ -961,7 +961,7 @@ if (!m_pair_type.IsValid()) return ValueObjectSP(); - DataBufferSP buffer_sp(new DataBufferHeap(2 * m_ptr_size, 0)); + WritableDataBufferSP buffer_sp(new DataBufferHeap(2 * m_ptr_size, 0)); if (m_ptr_size == 8) { uint64_t *data_ptr = (uint64_t *)buffer_sp->GetBytes(); @@ -1038,7 +1038,7 @@ auto pair_type = GetLLDBNSPairType(process_sp->GetTarget().shared_from_this()); - DataBufferSP buffer_sp(new DataBufferHeap(2 * ptr_size, 0)); + WritableDataBufferSP buffer_sp(new DataBufferHeap(2 * ptr_size, 0)); if (ptr_size == 8) { uint64_t *data_ptr = (uint64_t *)buffer_sp->GetBytes(); @@ -1203,7 +1203,7 @@ if (!m_pair_type.IsValid()) return ValueObjectSP(); - DataBufferSP buffer_sp(new DataBufferHeap(2 * m_ptr_size, 0)); + WritableDataBufferSP buffer_sp(new DataBufferHeap(2 * m_ptr_size, 0)); if (m_ptr_size == 8) { uint64_t *data_ptr = (uint64_t *)buffer_sp->GetBytes(); @@ -1357,7 +1357,7 @@ if (!m_pair_type.IsValid()) return ValueObjectSP(); - DataBufferSP buffer_sp(new DataBufferHeap(2 * m_ptr_size, 0)); + WritableDataBufferSP buffer_sp(new DataBufferHeap(2 * m_ptr_size, 0)); if (m_ptr_size == 8) { uint64_t *data_ptr = (uint64_t *)buffer_sp->GetBytes(); Index: lldb/source/Plugins/Language/ObjC/NSSet.cpp =================================================================== --- lldb/source/Plugins/Language/ObjC/NSSet.cpp +++ lldb/source/Plugins/Language/ObjC/NSSet.cpp @@ -635,7 +635,7 @@ SetItemDescriptor &set_item = m_children[idx]; if (!set_item.valobj_sp) { - DataBufferSP buffer_sp(new DataBufferHeap(m_ptr_size, 0)); + WritableDataBufferSP buffer_sp(new DataBufferHeap(m_ptr_size, 0)); switch (m_ptr_size) { case 0: // architecture has no clue - fail Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp =================================================================== --- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp +++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp @@ -343,7 +343,7 @@ // Ingest the whole descriptor array: const lldb::addr_t desc_ptr = m_header_addr + header_size; const size_t desc_array_size = num_descriptors * descriptor_size; - DataBufferSP data_sp(new DataBufferHeap(desc_array_size, '\0')); + WritableDataBufferSP data_sp(new DataBufferHeap(desc_array_size, '\0')); uint8_t *dst = (uint8_t *)data_sp->GetBytes(); DataExtractor desc_extractor(dst, desc_array_size, process_sp->GetByteOrder(), Index: lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp =================================================================== --- lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp +++ lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp @@ -2442,7 +2442,7 @@ auto data_sp = FileSystem::Instance().CreateDataBuffer(file.GetPath()); // Cast start of buffer to FileHeader and use pointer to read metadata - void *file_buf = data_sp->GetBytes(); + const void *file_buf = data_sp->GetBytes(); if (file_buf == nullptr || data_sp->GetByteSize() < (sizeof(AllocationDetails::FileHeader) + sizeof(AllocationDetails::ElementHeader))) { @@ -2451,7 +2451,7 @@ return false; } const AllocationDetails::FileHeader *file_header = - static_cast(file_buf); + static_cast(file_buf); // Check file starts with ascii characters "RSAD" if (memcmp(file_header->ident, "RSAD", 4)) { @@ -2463,8 +2463,9 @@ // Look at the type of the root element in the header AllocationDetails::ElementHeader root_el_hdr; - memcpy(&root_el_hdr, static_cast(file_buf) + - sizeof(AllocationDetails::FileHeader), + memcpy(&root_el_hdr, + static_cast(file_buf) + + sizeof(AllocationDetails::FileHeader), sizeof(AllocationDetails::ElementHeader)); LLDB_LOGF(log, "%s - header type %" PRIu32 ", element size %" PRIu32, @@ -2515,7 +2516,7 @@ } // Advance buffer past header - file_buf = static_cast(file_buf) + file_header->hdr_size; + file_buf = static_cast(file_buf) + file_header->hdr_size; // Calculate size of allocation data in file size_t size = data_sp->GetByteSize() - file_header->hdr_size; Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp =================================================================== --- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -2616,6 +2616,7 @@ } else { switch (reloc_type(rel)) { case R_AARCH64_ABS64: +#if 0 case R_X86_64_64: { symbol = symtab->FindSymbolByID(reloc_symbol(rel)); if (symbol) { @@ -2629,8 +2630,10 @@ } break; } +#endif case R_X86_64_32: case R_X86_64_32S: +#if 0 case R_AARCH64_ABS32: { symbol = symtab->FindSymbolByID(reloc_symbol(rel)); if (symbol) { @@ -2654,6 +2657,7 @@ } break; } +#endif case R_X86_64_PC32: default: assert(false && "unexpected relocation type"); Index: lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp =================================================================== --- lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp +++ lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp @@ -43,7 +43,7 @@ llvm::file_magic::wasm_object) return false; - uint8_t *Ptr = data_sp->GetBytes() + sizeof(llvm::wasm::WasmMagic); + const uint8_t *Ptr = data_sp->GetBytes() + sizeof(llvm::wasm::WasmMagic); uint32_t version = llvm::support::endian::read32le(Ptr); return version == llvm::wasm::WasmVersion; Index: lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp =================================================================== --- lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -229,7 +229,7 @@ } if (error.Success()) { - lldb::DataBufferSP buffer_sp(new DataBufferHeap(1024, 0)); + lldb::WritableDataBufferSP buffer_sp(new DataBufferHeap(1024, 0)); uint64_t offset = 0; error.Clear(); while (error.Success()) { Index: lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.h =================================================================== --- lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.h +++ lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.h @@ -66,7 +66,7 @@ bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue ®_value) override; - bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; + bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override; bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; Index: lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp =================================================================== --- lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp +++ lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp @@ -1236,7 +1236,7 @@ } bool RegisterContextDarwin_arm::ReadAllRegisterValues( - lldb::DataBufferSP &data_sp) { + lldb::WritableDataBufferSP &data_sp) { data_sp = std::make_shared(REG_CONTEXT_SIZE, 0); if (data_sp && ReadGPR(false) == KERN_SUCCESS && ReadFPU(false) == KERN_SUCCESS && ReadEXC(false) == KERN_SUCCESS) { Index: lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.h =================================================================== --- lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.h +++ lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.h @@ -48,7 +48,7 @@ bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue ®_value) override; - bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; + bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override; bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; Index: lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp =================================================================== --- lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp +++ lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp @@ -643,7 +643,7 @@ } bool RegisterContextDarwin_arm64::ReadAllRegisterValues( - lldb::DataBufferSP &data_sp) { + lldb::WritableDataBufferSP &data_sp) { data_sp = std::make_shared(REG_CONTEXT_SIZE, 0); if (ReadGPR(false) == KERN_SUCCESS && ReadFPU(false) == KERN_SUCCESS && ReadEXC(false) == KERN_SUCCESS) { Index: lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.h =================================================================== --- lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.h +++ lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.h @@ -35,7 +35,7 @@ bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value) override; - bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; + bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override; bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; Index: lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp =================================================================== --- lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp +++ lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp @@ -793,7 +793,7 @@ } bool RegisterContextDarwin_i386::ReadAllRegisterValues( - lldb::DataBufferSP &data_sp) { + lldb::WritableDataBufferSP &data_sp) { data_sp = std::make_shared(REG_CONTEXT_SIZE, 0); if (ReadGPR(false) == 0 && ReadFPU(false) == 0 && ReadEXC(false) == 0) { uint8_t *dst = data_sp->GetBytes(); Index: lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.h =================================================================== --- lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.h +++ lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.h @@ -35,7 +35,7 @@ bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value) override; - bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; + bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override; bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; Index: lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp =================================================================== --- lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp +++ lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp @@ -852,7 +852,7 @@ } bool RegisterContextDarwin_x86_64::ReadAllRegisterValues( - lldb::DataBufferSP &data_sp) { + lldb::WritableDataBufferSP &data_sp) { data_sp = std::make_shared(REG_CONTEXT_SIZE, 0); if (ReadGPR(false) == 0 && ReadFPU(false) == 0 && ReadEXC(false) == 0) { uint8_t *dst = data_sp->GetBytes(); Index: lldb/source/Plugins/Process/Utility/RegisterContextDummy.h =================================================================== --- lldb/source/Plugins/Process/Utility/RegisterContextDummy.h +++ lldb/source/Plugins/Process/Utility/RegisterContextDummy.h @@ -43,7 +43,7 @@ bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value) override; - bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; + bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override; bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; Index: lldb/source/Plugins/Process/Utility/RegisterContextDummy.cpp =================================================================== --- lldb/source/Plugins/Process/Utility/RegisterContextDummy.cpp +++ lldb/source/Plugins/Process/Utility/RegisterContextDummy.cpp @@ -102,7 +102,8 @@ return false; } -bool RegisterContextDummy::ReadAllRegisterValues(lldb::DataBufferSP &data_sp) { +bool RegisterContextDummy::ReadAllRegisterValues( + lldb::WritableDataBufferSP &data_sp) { return false; } Index: lldb/source/Plugins/Process/Utility/RegisterContextHistory.h =================================================================== --- lldb/source/Plugins/Process/Utility/RegisterContextHistory.h +++ lldb/source/Plugins/Process/Utility/RegisterContextHistory.h @@ -43,7 +43,7 @@ bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value) override; - bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; + bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override; bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; Index: lldb/source/Plugins/Process/Utility/RegisterContextHistory.cpp =================================================================== --- lldb/source/Plugins/Process/Utility/RegisterContextHistory.cpp +++ lldb/source/Plugins/Process/Utility/RegisterContextHistory.cpp @@ -104,7 +104,7 @@ } bool RegisterContextHistory::ReadAllRegisterValues( - lldb::DataBufferSP &data_sp) { + lldb::WritableDataBufferSP &data_sp) { return false; } Index: lldb/source/Plugins/Process/Utility/RegisterContextMemory.h =================================================================== --- lldb/source/Plugins/Process/Utility/RegisterContextMemory.h +++ lldb/source/Plugins/Process/Utility/RegisterContextMemory.h @@ -50,7 +50,7 @@ bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue ®_value) override; - bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; + bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override; bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; @@ -61,6 +61,7 @@ lldb_private::DynamicRegisterInfo &m_reg_infos; std::vector m_reg_valid; + lldb::WritableDataBufferSP m_data; lldb_private::DataExtractor m_reg_data; lldb::addr_t m_reg_data_addr; // If this is valid, then we have a register // context that is stored in memmory Index: lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp =================================================================== --- lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp +++ lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp @@ -32,9 +32,9 @@ m_reg_valid.resize(num_regs); // Make a heap based buffer that is big enough to store all registers - DataBufferSP reg_data_sp( - new DataBufferHeap(reg_infos.GetRegisterDataByteSize(), 0)); - m_reg_data.SetData(reg_data_sp); + m_data = + std::make_shared(reg_infos.GetRegisterDataByteSize(), 0); + m_reg_data.SetData(m_data); } // Destructor @@ -76,7 +76,7 @@ RegisterValue ®_value) { const uint32_t reg_num = reg_info->kinds[eRegisterKindLLDB]; if (!m_reg_valid[reg_num]) { - if (!ReadAllRegisterValues(m_reg_data.GetSharedDataBuffer())) + if (!ReadAllRegisterValues(m_data)) return false; } const bool partial_data_ok = false; @@ -99,7 +99,8 @@ return false; } -bool RegisterContextMemory::ReadAllRegisterValues(DataBufferSP &data_sp) { +bool RegisterContextMemory::ReadAllRegisterValues( + WritableDataBufferSP &data_sp) { if (m_reg_data_addr != LLDB_INVALID_ADDRESS) { ProcessSP process_sp(CalculateProcess()); if (process_sp) { Index: lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h =================================================================== --- lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h +++ lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h @@ -51,7 +51,7 @@ // is a somewhat disruptive operation, // so these API's should only be used when this behavior is needed. - bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; + bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override; bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; Index: lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp =================================================================== --- lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp +++ lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp @@ -107,7 +107,7 @@ } bool RegisterContextThreadMemory::ReadAllRegisterValues( - lldb::DataBufferSP &data_sp) { + lldb::WritableDataBufferSP &data_sp) { UpdateRegisterContext(); if (m_reg_ctx_sp) return m_reg_ctx_sp->ReadAllRegisterValues(data_sp); Index: lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.h =================================================================== --- lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.h +++ lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.h @@ -30,7 +30,7 @@ bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value) override; - bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; + bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override; bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; Index: lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.cpp =================================================================== --- lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.cpp +++ lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.cpp @@ -55,7 +55,7 @@ } bool RegisterContextCorePOSIX_arm::ReadAllRegisterValues( - lldb::DataBufferSP &data_sp) { + lldb::WritableDataBufferSP &data_sp) { return false; } Index: lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h =================================================================== --- lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h +++ lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h @@ -31,7 +31,7 @@ bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value) override; - bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; + bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override; bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; Index: lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp =================================================================== --- lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp +++ lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp @@ -230,7 +230,7 @@ } bool RegisterContextCorePOSIX_arm64::ReadAllRegisterValues( - lldb::DataBufferSP &data_sp) { + lldb::WritableDataBufferSP &data_sp) { return false; } Index: lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h =================================================================== --- lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h +++ lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h @@ -30,7 +30,7 @@ bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value) override; - bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; + bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override; bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; Index: lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp =================================================================== --- lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp +++ lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp @@ -72,7 +72,7 @@ } bool RegisterContextCorePOSIX_mips64::ReadAllRegisterValues( - lldb::DataBufferSP &data_sp) { + lldb::WritableDataBufferSP &data_sp) { return false; } Index: lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.h =================================================================== --- lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.h +++ lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.h @@ -29,7 +29,7 @@ bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value) override; - bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; + bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override; bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; Index: lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.cpp =================================================================== --- lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.cpp +++ lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.cpp @@ -92,7 +92,7 @@ } bool RegisterContextCorePOSIX_powerpc::ReadAllRegisterValues( - lldb::DataBufferSP &data_sp) { + lldb::WritableDataBufferSP &data_sp) { return false; } Index: lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.h =================================================================== --- lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.h +++ lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.h @@ -29,7 +29,7 @@ bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value) override; - bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; + bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override; bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; Index: lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.cpp =================================================================== --- lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.cpp +++ lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.cpp @@ -77,7 +77,7 @@ } bool RegisterContextCorePOSIX_s390x::ReadAllRegisterValues( - lldb::DataBufferSP &data_sp) { + lldb::WritableDataBufferSP &data_sp) { return false; } Index: lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.h =================================================================== --- lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.h +++ lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.h @@ -26,7 +26,7 @@ bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value) override; - bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; + bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override; bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; Index: lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp =================================================================== --- lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp +++ lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp @@ -80,7 +80,7 @@ } bool RegisterContextCorePOSIX_x86_64::ReadAllRegisterValues( - lldb::DataBufferSP &data_sp) { + lldb::WritableDataBufferSP &data_sp) { return false; } Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -407,7 +407,7 @@ uint32_t reg_num); // Must be the eRegisterKindProcessPlugin register number - lldb::DataBufferSP ReadAllRegisters(lldb::tid_t tid); + lldb::WritableDataBufferSP ReadAllRegisters(lldb::tid_t tid); bool WriteRegister(lldb::tid_t tid, Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -643,7 +643,7 @@ } size_t expected_bytes = response.GetBytesLeft() / 2; - DataBufferSP buffer_sp(new DataBufferHeap(expected_bytes, 0)); + WritableDataBufferSP buffer_sp(new DataBufferHeap(expected_bytes, 0)); size_t got_bytes = response.GetHexBytesAvail(buffer_sp->GetData()); // Check both because in some situations chars are consumed even // if the decoding fails. @@ -3442,13 +3442,14 @@ !response.IsNormalResponse()) return nullptr; - DataBufferSP buffer_sp( + WritableDataBufferSP buffer_sp( new DataBufferHeap(response.GetStringRef().size() / 2, 0)); response.GetHexBytes(buffer_sp->GetData(), '\xcc'); return buffer_sp; } -DataBufferSP GDBRemoteCommunicationClient::ReadAllRegisters(lldb::tid_t tid) { +WritableDataBufferSP +GDBRemoteCommunicationClient::ReadAllRegisters(lldb::tid_t tid) { StreamString payload; payload.PutChar('g'); StringExtractorGDBRemote response; @@ -3457,7 +3458,7 @@ !response.IsNormalResponse()) return nullptr; - DataBufferSP buffer_sp( + WritableDataBufferSP buffer_sp( new DataBufferHeap(response.GetStringRef().size() / 2, 0)); response.GetHexBytes(buffer_sp->GetData(), '\xcc'); return buffer_sp; Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h @@ -65,7 +65,7 @@ bool WriteRegister(const RegisterInfo *reg_info, const RegisterValue &value) override; - bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; + bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override; bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp @@ -517,7 +517,7 @@ } bool GDBRemoteRegisterContext::ReadAllRegisterValues( - lldb::DataBufferSP &data_sp) { + lldb::WritableDataBufferSP &data_sp) { ExecutionContext exe_ctx(CalculateThread()); Process *process = exe_ctx.GetProcessPtr(); Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp =================================================================== --- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -1671,7 +1671,7 @@ for (const auto &pair : expedited_register_map) { StringExtractor reg_value_extractor(pair.second); - DataBufferSP buffer_sp(new DataBufferHeap( + WritableDataBufferSP buffer_sp(new DataBufferHeap( reg_value_extractor.GetStringRef().size() / 2, 0)); reg_value_extractor.GetHexBytes(buffer_sp->GetData(), '\xcc'); uint32_t lldb_regnum = @@ -2050,7 +2050,8 @@ bytes.SetFilePos(0); const size_t byte_size = bytes.GetStringRef().size() / 2; - DataBufferSP data_buffer_sp(new DataBufferHeap(byte_size, 0)); + WritableDataBufferSP data_buffer_sp( + new DataBufferHeap(byte_size, 0)); const size_t bytes_copied = bytes.GetHexBytes(data_buffer_sp->GetData(), 0); if (bytes_copied == byte_size) @@ -2212,7 +2213,8 @@ if (!addr_str.getAsInteger(0, mem_cache_addr)) { StringExtractor bytes(bytes_str); const size_t byte_size = bytes.GetBytesLeft() / 2; - DataBufferSP data_buffer_sp(new DataBufferHeap(byte_size, 0)); + WritableDataBufferSP data_buffer_sp( + new DataBufferHeap(byte_size, 0)); const size_t bytes_copied = bytes.GetHexBytes(data_buffer_sp->GetData(), 0); if (bytes_copied == byte_size) Index: lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_32.cpp =================================================================== --- lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_32.cpp +++ lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_32.cpp @@ -27,7 +27,7 @@ const RegisterInfo *reg_info = target_reg_interface->GetRegisterInfo(); - lldb::DataBufferSP result_context_buf( + lldb::WritableDataBufferSP result_context_buf( new DataBufferHeap(target_reg_interface->GetGPRSize(), 0)); uint8_t *result_base = result_context_buf->GetBytes(); Index: lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp =================================================================== --- lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp +++ lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp @@ -50,7 +50,7 @@ const RegisterInfo *reg_info = target_reg_interface->GetRegisterInfo(); - lldb::DataBufferSP result_context_buf( + lldb::WritableDataBufferSP result_context_buf( new DataBufferHeap(target_reg_interface->GetGPRSize(), 0)); uint8_t *result_base = result_context_buf->GetBytes(); Index: lldb/source/Target/Platform.cpp =================================================================== --- lldb/source/Target/Platform.cpp +++ lldb/source/Target/Platform.cpp @@ -1342,7 +1342,7 @@ return error; if (dest_file == UINT64_MAX) return Status("unable to open target file"); - lldb::DataBufferSP buffer_sp(new DataBufferHeap(1024 * 16, 0)); + lldb::WritableDataBufferSP buffer_sp(new DataBufferHeap(1024 * 16, 0)); uint64_t offset = 0; for (;;) { size_t bytes_read = buffer_sp->GetByteSize(); Index: lldb/source/Target/RegisterContextUnwind.cpp =================================================================== --- lldb/source/Target/RegisterContextUnwind.cpp +++ lldb/source/Target/RegisterContextUnwind.cpp @@ -2231,7 +2231,8 @@ } // Don't need to implement this one -bool RegisterContextUnwind::ReadAllRegisterValues(lldb::DataBufferSP &data_sp) { +bool RegisterContextUnwind::ReadAllRegisterValues( + lldb::WritableDataBufferSP &data_sp) { return false; } Index: lldb/source/Utility/DataBufferHeap.cpp =================================================================== --- lldb/source/Utility/DataBufferHeap.cpp +++ lldb/source/Utility/DataBufferHeap.cpp @@ -29,15 +29,9 @@ // Virtual destructor since this class inherits from a pure virtual base class. DataBufferHeap::~DataBufferHeap() = default; -// Return a pointer to the bytes owned by this object, or nullptr if the object -// contains no bytes. -uint8_t *DataBufferHeap::GetBytes() { - return (m_data.empty() ? nullptr : m_data.data()); -} - // Return a const pointer to the bytes owned by this object, or nullptr if the // object contains no bytes. -const uint8_t *DataBufferHeap::GetBytes() const { +const uint8_t *DataBufferHeap::GetBytesImpl() const { return (m_data.empty() ? nullptr : m_data.data()); } Index: lldb/source/Utility/DataBufferLLVM.cpp =================================================================== --- lldb/source/Utility/DataBufferLLVM.cpp +++ lldb/source/Utility/DataBufferLLVM.cpp @@ -14,8 +14,7 @@ using namespace lldb_private; -DataBufferLLVM::DataBufferLLVM( - std::unique_ptr MemBuffer) +DataBufferLLVM::DataBufferLLVM(std::unique_ptr MemBuffer) : Buffer(std::move(MemBuffer)) { assert(Buffer != nullptr && "Cannot construct a DataBufferLLVM with a null buffer"); @@ -23,14 +22,27 @@ DataBufferLLVM::~DataBufferLLVM() = default; -uint8_t *DataBufferLLVM::GetBytes() { - return reinterpret_cast(Buffer->getBufferStart()); +const uint8_t *DataBufferLLVM::GetBytesImpl() const { + return reinterpret_cast(Buffer->getBufferStart()); +} + +lldb::offset_t DataBufferLLVM::GetByteSize() const { + return Buffer->getBufferSize(); +} + +WritableDataBufferLLVM::WritableDataBufferLLVM( + std::unique_ptr MemBuffer) + : Buffer(std::move(MemBuffer)) { + assert(Buffer != nullptr && + "Cannot construct a DataBufferLLVM with a null buffer"); } -const uint8_t *DataBufferLLVM::GetBytes() const { +WritableDataBufferLLVM::~WritableDataBufferLLVM() = default; + +const uint8_t *WritableDataBufferLLVM::GetBytesImpl() const { return reinterpret_cast(Buffer->getBufferStart()); } -lldb::offset_t DataBufferLLVM::GetByteSize() const { +lldb::offset_t WritableDataBufferLLVM::GetByteSize() const { return Buffer->getBufferSize(); }