aboutsummaryrefslogtreecommitdiff
path: root/lldb/test/API/functionalities/scripted_process
diff options
context:
space:
mode:
authorMed Ismail Bennani <medismail.bennani@gmail.com>2023-03-03 19:30:56 -0800
committerMed Ismail Bennani <medismail.bennani@gmail.com>2023-03-03 19:33:02 -0800
commitf190ec6882706d30c606e62986512371925288a9 (patch)
treea8f45942a38b3bf8ab67aacff8eda3c4c4a02ad6 /lldb/test/API/functionalities/scripted_process
parente02a355f9846d5ec9cd64b086674770ecc795c26 (diff)
downloadllvm-f190ec6882706d30c606e62986512371925288a9.tar.gz
llvm-f190ec6882706d30c606e62986512371925288a9.tar.bz2
llvm-f190ec6882706d30c606e62986512371925288a9.zip
[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/test/API/functionalities/scripted_process')
-rw-r--r--lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py13
-rw-r--r--lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py15
2 files changed, 23 insertions, 5 deletions
diff --git a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
index 053654c14421..5a198cc95704 100644
--- a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -150,7 +150,6 @@ class ScriptedProcesTestCase(TestBase):
self.assertEqual(process_1.GetNumThreads(), 1)
# ... then try reading from target #1 process ...
- addr = 0x500000000
message = "Hello, target 1"
buff = process_1.ReadCStringFromMemory(addr, len(message) + 1, error)
self.assertSuccess(error)
@@ -158,12 +157,22 @@ class ScriptedProcesTestCase(TestBase):
# ... now, reading again from target #0 process to make sure the call
# gets dispatched to the right target.
- addr = 0x500000000
message = "Hello, target 0"
buff = process_0.ReadCStringFromMemory(addr, len(message) + 1, error)
self.assertSuccess(error)
self.assertEqual(buff, message)
+ # Let's write some memory.
+ message = "Hello, world!"
+ bytes_written = process_0.WriteMemoryAsCString(addr, message, error)
+ self.assertSuccess(error)
+ self.assertEqual(bytes_written, len(message) + 1)
+
+ # ... and check if that memory was saved properly.
+ buff = process_0.ReadCStringFromMemory(addr, len(message) + 1, error)
+ self.assertSuccess(error)
+ self.assertEqual(buff, message)
+
thread = process_0.GetSelectedThread()
self.assertTrue(thread, "Invalid thread.")
self.assertEqual(thread.GetThreadID(), 0x19)
diff --git a/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py b/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
index 47038144bb08..3f6ce6c1f9fe 100644
--- a/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
+++ b/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
@@ -7,20 +7,29 @@ from lldb.plugins.scripted_process import ScriptedProcess
from lldb.plugins.scripted_process import ScriptedThread
class DummyScriptedProcess(ScriptedProcess):
+ memory = None
+
def __init__(self, exe_ctx: lldb.SBExecutionContext, args : lldb.SBStructuredData):
super().__init__(exe_ctx, args)
self.threads[0] = DummyScriptedThread(self, None)
-
- def read_memory_at_address(self, addr: int, size: int, error: lldb.SBError) -> lldb.SBData:
+ self.memory = {}
+ addr = 0x500000000
debugger = self.target.GetDebugger()
index = debugger.GetIndexOfTarget(self.target)
+ self.memory[addr] = "Hello, target " + str(index)
+
+ def read_memory_at_address(self, addr: int, size: int, error: lldb.SBError) -> lldb.SBData:
data = lldb.SBData().CreateDataFromCString(
self.target.GetByteOrder(),
self.target.GetCodeByteSize(),
- "Hello, target " + str(index))
+ self.memory[addr])
return data
+ def write_memory_at_address(self, addr, data, error):
+ self.memory[addr] = data.GetString(error, 0)
+ return len(self.memory[addr]) + 1
+
def get_loaded_images(self):
return self.loaded_images