diff options
| author | Med Ismail Bennani <medismail.bennani@gmail.com> | 2022-11-18 13:53:57 -0800 |
|---|---|---|
| committer | Med Ismail Bennani <medismail.bennani@gmail.com> | 2022-11-18 13:56:48 -0800 |
| commit | 7e01924e4e5634a6fa7d500574aeca58c8f36873 (patch) | |
| tree | 564584938cc29e0de71ad0b4682da79f5617ffba /lldb/test/API/functionalities/scripted_process | |
| parent | 288843a161f71148d7028e5153038006dd87e363 (diff) | |
| download | llvm-7e01924e4e5634a6fa7d500574aeca58c8f36873.tar.gz llvm-7e01924e4e5634a6fa7d500574aeca58c8f36873.tar.bz2 llvm-7e01924e4e5634a6fa7d500574aeca58c8f36873.zip | |
[lldb/Plugins] Improve error reporting with reading memory in Scripted Process
This patch improves the ScriptedPythonInterface::Dispatch method to
support passing lldb_private types to the python implementation.
This will allow, for instance, the Scripted Process python implementation
to report errors when reading memory back to lldb.
To do so, the Dispatch method will transform the private types in the
parameter pack into `PythonObject`s to be able to pass them down to the
python methods.
Then, if the call succeeded, the transformed arguments will be converted
back to their original type and re-assigned in the parameter pack, to
ensure pointers and references behaviours are preserved.
This patch also updates various scripted process python class and tests
to reflect this change.
rdar://100030995
Differential Revision: https://reviews.llvm.org/D134033
Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
Diffstat (limited to 'lldb/test/API/functionalities/scripted_process')
4 files changed, 18 insertions, 6 deletions
diff --git a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py index 909413c0c293..619e47cfe483 100644 --- a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py +++ b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py @@ -77,6 +77,12 @@ class ScriptedProcesTestCase(TestBase): self.assertEqual(process.GetProcessID(), 666) self.assertEqual(process.GetNumThreads(), 0) + addr = 0x500000000 + buff = process.ReadMemory(addr, 4, error) + self.assertEqual(buff, None) + self.assertTrue(error.Fail()) + self.assertEqual(error.GetCString(), "This is an invalid scripted process!") + with open(log_file, 'r') as f: log = f.read() @@ -109,9 +115,14 @@ class ScriptedProcesTestCase(TestBase): process = target.Launch(launch_info, error) self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID) self.assertEqual(process.GetProcessID(), 42) - self.assertEqual(process.GetNumThreads(), 1) + addr = 0x500000000 + message = "Hello, world!" + buff = process.ReadCStringFromMemory(addr, len(message) + 1, error) + self.assertSuccess(error) + self.assertEqual(buff, message) + thread = process.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 a687870e1f89..d4f795390734 100644 --- a/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py +++ b/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py @@ -20,11 +20,12 @@ class DummyScriptedProcess(ScriptedProcess): def get_registers_for_thread(self, tid: int): return {} - def read_memory_at_address(self, addr: int, size: int) -> lldb.SBData: + 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, world!") + return data def get_loaded_images(self): diff --git a/lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py b/lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py index 62623d567919..62db547a1baf 100644 --- a/lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py +++ b/lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py @@ -20,8 +20,9 @@ class InvalidScriptedProcess(ScriptedProcess): def get_registers_for_thread(self, tid: int): return {} - def read_memory_at_address(self, addr: int, size: int) -> lldb.SBData: - return None + def read_memory_at_address(self, addr: int, size: int, error: lldb.SBError) -> lldb.SBData: + error.SetErrorString("This is an invalid scripted process!") + return lldb.SBData() def get_loaded_images(self): return self.loaded_images diff --git a/lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py b/lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py index 67a1e53b7fbd..67a1256c8eef 100644 --- a/lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py +++ b/lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py @@ -65,9 +65,8 @@ class StackCoreScriptedProcess(ScriptedProcess): def get_registers_for_thread(self, tid: int): return {} - def read_memory_at_address(self, addr: int, size: int) -> lldb.SBData: + def read_memory_at_address(self, addr: int, size: int, error: lldb.SBError) -> lldb.SBData: data = lldb.SBData() - error = lldb.SBError() bytes_read = self.corefile_process.ReadMemory(addr, size, error) if error.Fail(): |
