JDevlieghere updated this revision to Diff 420540.
JDevlieghere marked an inline comment as done.
JDevlieghere added a comment.
I don't really like the idea of making the argument to createInstance writable.
That seems like an implementation detail. Instead I added a virtual method
IsWritable() to the DataBuffer and an assert to ObjectFileELF that ensures we
always have a writable buffer.
@labath: does that cover your concerns?
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D122856/new/
https://reviews.llvm.org/D122856
Files:
lldb/include/lldb/Core/ValueObject.h
lldb/include/lldb/Host/FileSystem.h
lldb/include/lldb/Symbol/CompactUnwindInfo.h
lldb/include/lldb/Symbol/ObjectFile.h
lldb/include/lldb/Target/ProcessStructReader.h
lldb/include/lldb/Target/RegisterCheckpoint.h
lldb/include/lldb/Target/RegisterContext.h
lldb/include/lldb/Target/RegisterContextUnwind.h
lldb/include/lldb/Utility/DataBuffer.h
lldb/include/lldb/Utility/DataBufferHeap.h
lldb/include/lldb/Utility/DataBufferLLVM.h
lldb/include/lldb/lldb-forward.h
lldb/source/Commands/CommandObjectMemory.cpp
lldb/source/Core/SourceManager.cpp
lldb/source/Core/ValueObject.cpp
lldb/source/DataFormatters/StringPrinter.cpp
lldb/source/DataFormatters/TypeFormat.cpp
lldb/source/Expression/IRExecutionUnit.cpp
lldb/source/Host/common/FileSystem.cpp
lldb/source/Host/common/Host.cpp
lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp
lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp
lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp
lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp
lldb/source/Plugins/Language/ObjC/CF.cpp
lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
lldb/source/Plugins/Language/ObjC/NSSet.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.h
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.h
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.h
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.h
lldb/source/Plugins/Process/Utility/RegisterContextDummy.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDummy.h
lldb/source/Plugins/Process/Utility/RegisterContextHistory.cpp
lldb/source/Plugins/Process/Utility/RegisterContextHistory.h
lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp
lldb/source/Plugins/Process/Utility/RegisterContextMemory.h
lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp
lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.cpp
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.h
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.cpp
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.h
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.cpp
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.h
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.h
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_32.cpp
lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp
lldb/source/Symbol/ObjectFile.cpp
lldb/source/Target/Platform.cpp
lldb/source/Target/RegisterContextUnwind.cpp
lldb/source/Utility/DataBufferHeap.cpp
lldb/source/Utility/DataBufferLLVM.cpp
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<llvm::WritableMemoryBuffer> MemBuffer)
+DataBufferLLVM::DataBufferLLVM(std::unique_ptr<llvm::MemoryBuffer> 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<uint8_t *>(Buffer->getBufferStart());
+const uint8_t *DataBufferLLVM::GetBytesImpl() const {
+ return reinterpret_cast<const uint8_t *>(Buffer->getBufferStart());
}
-const uint8_t *DataBufferLLVM::GetBytes() const {
+lldb::offset_t DataBufferLLVM::GetByteSize() const {
+ return Buffer->getBufferSize();
+}
+
+WritableDataBufferLLVM::WritableDataBufferLLVM(
+ std::unique_ptr<llvm::WritableMemoryBuffer> MemBuffer)
+ : Buffer(std::move(MemBuffer)) {
+ assert(Buffer != nullptr &&
+ "Cannot construct a WritableDataBufferLLVM with a null buffer");
+}
+
+WritableDataBufferLLVM::~WritableDataBufferLLVM() = default;
+
+const uint8_t *WritableDataBufferLLVM::GetBytesImpl() const {
return reinterpret_cast<const uint8_t *>(Buffer->getBufferStart());
}
-lldb::offset_t DataBufferLLVM::GetByteSize() const {
+lldb::offset_t WritableDataBufferLLVM::GetByteSize() const {
return Buffer->getBufferSize();
}
Index: lldb/source/Utility/DataBufferHeap.cpp
===================================================================
--- lldb/source/Utility/DataBufferHeap.cpp
+++ lldb/source/Utility/DataBufferHeap.cpp
@@ -26,18 +26,16 @@
CopyData(src, src_len);
}
+DataBufferHeap::DataBufferHeap(const DataBuffer &data_buffer) : m_data() {
+ CopyData(data_buffer.GetBytes(), data_buffer.GetByteSize());
+}
+
// 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/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/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/Symbol/ObjectFile.cpp
===================================================================
--- lldb/source/Symbol/ObjectFile.cpp
+++ lldb/source/Symbol/ObjectFile.cpp
@@ -30,6 +30,7 @@
using namespace lldb_private;
char ObjectFile::ID;
+size_t ObjectFile::g_initial_bytes_to_read = 512;
static ObjectFileSP
CreateObjectFromContainer(const lldb::ModuleSP &module_sp, const FileSpec *file,
@@ -81,8 +82,8 @@
// 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 = FileSystem::Instance().CreateDataBuffer(
+ file->GetPath(), g_initial_bytes_to_read, file_offset);
data_offset = 0;
}
}
@@ -115,7 +116,7 @@
// 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);
+ archive_file.GetPath(), g_initial_bytes_to_read, file_offset);
}
}
}
@@ -189,8 +190,8 @@
ModuleSpecList &specs,
DataBufferSP data_sp) {
if (!data_sp)
- data_sp = FileSystem::Instance().CreateDataBuffer(file.GetPath(), 512,
- file_offset);
+ data_sp = FileSystem::Instance().CreateDataBuffer(
+ file.GetPath(), g_initial_bytes_to_read, file_offset);
if (data_sp) {
if (file_size == 0) {
const lldb::offset_t actual_file_size =
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/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/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/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();
@@ -536,9 +536,13 @@
if (gdb_comm.SyncThreadState(m_thread.GetProtocolID()))
InvalidateAllRegisters();
- if (use_g_packet &&
- (data_sp = gdb_comm.ReadAllRegisters(m_thread.GetProtocolID())))
- return true;
+ if (use_g_packet) {
+ if (DataBufferSP data_buffer =
+ gdb_comm.ReadAllRegisters(m_thread.GetProtocolID())) {
+ data_sp = std::make_shared<DataBufferHeap>(*data_buffer);
+ return true;
+ }
+ }
// We're going to read each register
// individually and store them as binary data in a buffer.
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,7 +3442,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;
@@ -3457,7 +3457,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/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/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_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_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_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_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/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/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<bool> 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<DataBufferHeap>(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/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/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/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<DataBufferHeap>(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_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<DataBufferHeap>(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_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<DataBufferHeap>(REG_CONTEXT_SIZE, 0);
if (ReadGPR(false) == KERN_SUCCESS && ReadFPU(false) == KERN_SUCCESS &&
ReadEXC(false) == KERN_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<DataBufferHeap>(REG_CONTEXT_SIZE, 0);
if (data_sp && ReadGPR(false) == KERN_SUCCESS &&
ReadFPU(false) == KERN_SUCCESS && ReadEXC(false) == KERN_SUCCESS) {
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/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/ObjectFile/ELF/ObjectFileELF.h
===================================================================
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -159,6 +159,10 @@
std::vector<LoadableData>
GetLoadableData(lldb_private::Target &target) override;
+ static lldb::WritableDataBufferSP
+ MapFileDataWritable(const lldb_private::FileSpec &file, uint64_t Size,
+ uint64_t Offset);
+
private:
ObjectFileELF(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset, const lldb_private::FileSpec *file,
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===================================================================
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -342,7 +342,7 @@
lldb::offset_t file_offset,
lldb::offset_t length) {
if (!data_sp) {
- data_sp = MapFileData(*file, length, file_offset);
+ data_sp = MapFileDataWritable(*file, length, file_offset);
if (!data_sp)
return nullptr;
data_offset = 0;
@@ -359,13 +359,17 @@
// Update the data to contain the entire file if it doesn't already
if (data_sp->GetByteSize() < length) {
- data_sp = MapFileData(*file, length, file_offset);
+ data_sp = MapFileDataWritable(*file, length, file_offset);
if (!data_sp)
return nullptr;
data_offset = 0;
magic = data_sp->GetBytes();
}
+ // ObjectFileELF requires a writable data buffer. Ensure that we were passed
+ // in a writable buffer or that we mapped it as writable ourselves.
+ assert(data_sp->IsWritable());
+
unsigned address_size = ELFHeader::AddressSizeInBytes(magic);
if (address_size == 4 || address_size == 8) {
std::unique_ptr<ObjectFileELF> objfile_up(new ObjectFileELF(
@@ -2621,8 +2625,11 @@
if (symbol) {
addr_t value = symbol->GetAddressRef().GetFileAddress();
DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
+ // ObjectFileELF creates a WritableDataBuffer in CreateInstance.
+ WritableDataBuffer *data_buffer =
+ static_cast<WritableDataBuffer *>(data_buffer_sp.get());
uint64_t *dst = reinterpret_cast<uint64_t *>(
- data_buffer_sp->GetBytes() + rel_section->GetFileOffset() +
+ data_buffer->GetBytes() + rel_section->GetFileOffset() +
ELFRelocation::RelocOffset64(rel));
uint64_t val_offset = value + ELFRelocation::RelocAddend64(rel);
memcpy(dst, &val_offset, sizeof(uint64_t));
@@ -2647,8 +2654,11 @@
}
uint32_t truncated_addr = (value & 0xFFFFFFFF);
DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
+ // ObjectFileELF creates a WritableDataBuffer in CreateInstance.
+ WritableDataBuffer *data_buffer =
+ static_cast<WritableDataBuffer *>(data_buffer_sp.get());
uint32_t *dst = reinterpret_cast<uint32_t *>(
- data_buffer_sp->GetBytes() + rel_section->GetFileOffset() +
+ data_buffer->GetBytes() + rel_section->GetFileOffset() +
ELFRelocation::RelocOffset32(rel));
memcpy(dst, &truncated_addr, sizeof(uint32_t));
}
@@ -3412,3 +3422,10 @@
}
return loadables;
}
+
+lldb::WritableDataBufferSP
+ObjectFileELF::MapFileDataWritable(const FileSpec &file, uint64_t Size,
+ uint64_t Offset) {
+ return FileSystem::Instance().CreateWritableDataBuffer(file.GetPath(), Size,
+ Offset);
+}
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<AllocationDetails::FileHeader *>(file_buf);
+ static_cast<const AllocationDetails::FileHeader *>(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<uint8_t *>(file_buf) +
- sizeof(AllocationDetails::FileHeader),
+ memcpy(&root_el_hdr,
+ static_cast<const uint8_t *>(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<uint8_t *>(file_buf) + file_header->hdr_size;
+ file_buf = static_cast<const uint8_t *>(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/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/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp
===================================================================
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp
@@ -222,7 +222,7 @@
return;
}
- lldb::DataBufferSP buffer_sp(new DataBufferHeap(1024, 0));
+ lldb::WritableDataBufferSP buffer_sp(new DataBufferHeap(1024, 0));
size_t count = process_sp->ReadCStringFromMemory(
name_ptr, (char *)buffer_sp->GetBytes(), 1024, error);
@@ -233,7 +233,7 @@
}
if (count)
- m_name = ConstString((char *)buffer_sp->GetBytes());
+ m_name = ConstString(reinterpret_cast<const char *>(buffer_sp->GetBytes()));
else
m_name = ConstString();
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/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/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/CPlusPlus/LibCxxVector.cpp
===================================================================
--- lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp
@@ -214,7 +214,7 @@
llvm::Optional<uint64_t> 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/CPlusPlus/LibCxx.cpp
===================================================================
--- lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -296,7 +296,7 @@
llvm::Optional<uint64_t> 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/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/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/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/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/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/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/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/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<char *>(Buffer->GetBytes()),
Index: lldb/source/Host/common/FileSystem.cpp
===================================================================
--- lldb/source/Host/common/FileSystem.cpp
+++ lldb/source/Host/common/FileSystem.cpp
@@ -273,27 +273,54 @@
file_spec.SetIsResolved(true);
}
-std::shared_ptr<DataBuffer>
-FileSystem::CreateDataBuffer(const llvm::Twine &path, uint64_t size,
- uint64_t offset) {
- const bool is_volatile = !IsLocal(path);
- std::unique_ptr<llvm::WritableMemoryBuffer> buffer;
+template <typename T>
+static std::unique_ptr<T> GetMemoryBuffer(const llvm::Twine &path,
+ uint64_t size, uint64_t offset,
+ bool is_volatile) {
+ std::unique_ptr<T> 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<WritableDataBuffer>
+FileSystem::CreateWritableDataBuffer(const llvm::Twine &path, uint64_t size,
+ uint64_t offset) {
+ const bool is_volatile = !IsLocal(path);
+ auto buffer = GetMemoryBuffer<llvm::WritableMemoryBuffer>(path, size, offset,
+ is_volatile);
+ if (!buffer)
+ return {};
+ return std::shared_ptr<WritableDataBufferLLVM>(
+ new WritableDataBufferLLVM(std::move(buffer)));
+}
+
+std::shared_ptr<DataBuffer>
+FileSystem::CreateDataBuffer(const llvm::Twine &path, uint64_t size,
+ uint64_t offset) {
+ const bool is_volatile = !IsLocal(path);
+ auto buffer =
+ GetMemoryBuffer<llvm::MemoryBuffer>(path, size, offset, is_volatile);
+ if (!buffer)
+ return {};
return std::shared_ptr<DataBufferLLVM>(new DataBufferLLVM(std::move(buffer)));
}
+std::shared_ptr<WritableDataBuffer>
+FileSystem::CreateWritableDataBuffer(const FileSpec &file_spec, uint64_t size,
+ uint64_t offset) {
+ return CreateWritableDataBuffer(file_spec.GetPath(), size, offset);
+}
+
std::shared_ptr<DataBuffer>
FileSystem::CreateDataBuffer(const FileSpec &file_spec, uint64_t size,
uint64_t offset) {
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/DataFormatters/TypeFormat.cpp
===================================================================
--- lldb/source/DataFormatters/TypeFormat.cpp
+++ lldb/source/DataFormatters/TypeFormat.cpp
@@ -77,7 +77,8 @@
if (target_sp) {
size_t max_len = target_sp->GetMaximumSizeOfStringSummary();
Status error;
- DataBufferSP buffer_sp(new DataBufferHeap(max_len + 1, 0));
+ WritableDataBufferSP buffer_sp(
+ new DataBufferHeap(max_len + 1, 0));
Address address(valobj->GetPointerValue());
if (target_sp->ReadCStringFromMemory(
address, (char *)buffer_sp->GetBytes(), max_len, error) &&
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/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<DataBufferHeap>(src.size(), 0);
@@ -857,9 +857,9 @@
}
std::pair<size_t, bool>
-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<size_t, bool> read_string = ReadPointedString(
buffer_sp, error, 0, (custom_format == eFormatVectorOfChar) ||
(custom_format == eFormatCharArray));
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/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/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<lldb_private::Connection> ConnectionSP;
typedef std::shared_ptr<lldb_private::CompileUnit> CompUnitSP;
typedef std::shared_ptr<lldb_private::DataBuffer> DataBufferSP;
+typedef std::shared_ptr<lldb_private::WritableDataBuffer> WritableDataBufferSP;
typedef std::shared_ptr<lldb_private::DataExtractor> DataExtractorSP;
typedef std::shared_ptr<lldb_private::Debugger> DebuggerSP;
typedef std::weak_ptr<lldb_private::Debugger> DebuggerWP;
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<llvm::MemoryBuffer> Buffer);
+
+ std::unique_ptr<llvm::MemoryBuffer> 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<llvm::WritableMemoryBuffer> Buffer);
+ explicit WritableDataBufferLLVM(
+ std::unique_ptr<llvm::WritableMemoryBuffer> Buffer);
std::unique_ptr<llvm::WritableMemoryBuffer> Buffer;
};
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
///
@@ -54,17 +54,20 @@
/// The number of bytes in \a src to copy.
DataBufferHeap(const void *src, lldb::offset_t src_len);
+ /// Construct by making a copy of a DataBuffer.
+ ///
+ /// \param[in] data_buffer
+ /// A read only data buffer to copy.
+ DataBufferHeap(const DataBuffer &data_buffer);
+
/// Destructor.
///
/// Virtual destructor since this class inherits from a pure virtual base
/// 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/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.
///
@@ -42,50 +42,78 @@
/// with some extra function calls to load the data before it gets accessed.
class DataBuffer {
public:
- /// Destructor
- ///
- /// The destructor is virtual as other classes will inherit from this class
- /// 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;
- /// Get a pointer to the data.
+ /// Get the number of bytes in the data buffer.
///
/// \return
- /// A pointer to the bytes owned by this object, or NULL if the
- /// object contains no bytes.
- virtual uint8_t *GetBytes() = 0;
+ /// 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 *GetBytes() const = 0;
-
- /// 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;
+ const uint8_t *GetBytes() const { return GetBytesImpl(); }
llvm::ArrayRef<uint8_t> GetData() const {
return llvm::ArrayRef<uint8_t>(GetBytes(), GetByteSize());
}
+ virtual bool IsWritable() const { return false; }
+
+protected:
+ /// 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;
+};
+
+/// \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
+ ///
+ /// The destructor is virtual as other classes will inherit from this class
+ /// 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 ~WritableDataBuffer() = default;
+
+ using DataBuffer::GetBytes;
+ using DataBuffer::GetData;
+
+ /// Get a pointer to the data.
+ ///
+ /// \return
+ /// A pointer to the bytes owned by this object, or NULL if the
+ /// object contains no bytes.
+ uint8_t *GetBytes() { return const_cast<uint8_t *>(GetBytesImpl()); }
+
llvm::MutableArrayRef<uint8_t> GetData() {
return llvm::MutableArrayRef<uint8_t>(GetBytes(), GetByteSize());
}
+
+ virtual bool IsWritable() const override { return true; }
};
-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/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/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/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/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/Symbol/ObjectFile.h
===================================================================
--- lldb/include/lldb/Symbol/ObjectFile.h
+++ lldb/include/lldb/Symbol/ObjectFile.h
@@ -759,6 +759,9 @@
/// false otherwise.
bool SetModulesArchitecture(const ArchSpec &new_arch);
+ /// The number of bytes to read when going through the plugins.
+ static size_t g_initial_bytes_to_read;
+
static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size,
uint64_t Offset);
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<UnwindIndex> m_indexes;
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<DataBuffer> CreateDataBuffer(const FileSpec &file_spec,
uint64_t size = 0,
uint64_t offset = 0);
+ std::shared_ptr<WritableDataBuffer>
+ CreateWritableDataBuffer(const llvm::Twine &path, uint64_t size = 0,
+ uint64_t offset = 0);
+ std::shared_ptr<WritableDataBuffer>
+ 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/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<size_t, bool>
- 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);
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits