diff options
author | Med Ismail Bennani <medismail.bennani@gmail.com> | 2023-03-03 19:30:56 -0800 |
---|---|---|
committer | Med Ismail Bennani <medismail.bennani@gmail.com> | 2023-03-03 19:33:02 -0800 |
commit | f190ec6882706d30c606e62986512371925288a9 (patch) | |
tree | a8f45942a38b3bf8ab67aacff8eda3c4c4a02ad6 /lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp | |
parent | e02a355f9846d5ec9cd64b086674770ecc795c26 (diff) | |
download | llvm-f190ec6882706d30c606e62986512371925288a9.zip llvm-f190ec6882706d30c606e62986512371925288a9.tar.gz llvm-f190ec6882706d30c606e62986512371925288a9.tar.bz2 |
[lldb/Plugins] Add memory writing capabilities to Scripted Process
This patch adds memory writing capabilities to the Scripted Process plugin.
This allows to user to get a target address and a memory buffer on the
python scripted process implementation that the user can make processing
on before performing the actual write.
This will also be used to write trap instruction to a real process
memory to set a breakpoint.
Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
Diffstat (limited to 'lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp')
-rw-r--r-- | lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp index 84e9dea..948ee69 100644 --- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp +++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp @@ -255,7 +255,31 @@ size_t ScriptedProcess::DoReadMemory(lldb::addr_t addr, void *buf, size_t size, return ScriptedInterface::ErrorWithMessage<size_t>( LLVM_PRETTY_FUNCTION, "Failed to copy read memory to buffer.", error); - return size; + // FIXME: We should use the diagnostic system to report a warning if the + // `bytes_copied` is different from `size`. + + return bytes_copied; +} + +size_t ScriptedProcess::DoWriteMemory(lldb::addr_t vm_addr, const void *buf, + size_t size, Status &error) { + lldb::DataExtractorSP data_extractor_sp = std::make_shared<DataExtractor>( + buf, size, GetByteOrder(), GetAddressByteSize()); + + if (!data_extractor_sp || !data_extractor_sp->GetByteSize()) + return 0; + + size_t bytes_written = + GetInterface().WriteMemoryAtAddress(vm_addr, data_extractor_sp, error); + + if (!bytes_written || bytes_written == LLDB_INVALID_OFFSET) + return ScriptedInterface::ErrorWithMessage<size_t>( + LLVM_PRETTY_FUNCTION, "Failed to copy write buffer to memory.", error); + + // FIXME: We should use the diagnostic system to report a warning if the + // `bytes_written` is different from `size`. + + return bytes_written; } ArchSpec ScriptedProcess::GetArchitecture() { |