diff options
| author | Med Ismail Bennani <medismail.bennani@gmail.com> | 2023-03-03 18:52:15 -0800 |
|---|---|---|
| committer | Med Ismail Bennani <medismail.bennani@gmail.com> | 2023-03-03 19:33:01 -0800 |
| commit | e6cac17b563f2e2bc7d04347b0b40a9fe12334c9 (patch) | |
| tree | e4f2ac75ed4233b950633d28a06f51e025b405a8 /lldb/test/API/python_api | |
| parent | c7af9ae577bb04c5fe120fc07844a500818c8f47 (diff) | |
| download | llvm-e6cac17b563f2e2bc7d04347b0b40a9fe12334c9.zip llvm-e6cac17b563f2e2bc7d04347b0b40a9fe12334c9.tar.gz llvm-e6cac17b563f2e2bc7d04347b0b40a9fe12334c9.tar.bz2 | |
[lldb] Extend SWIG SBProcess interface with WriteMemoryAsCString method
This patch tries to address an interoperability issue when writing
python string into the process memory.
Since the python string is not null-terminated, it would still be
written to memory however, when trying to read it again with
`SBProcess::ReadCStringFromMemory`, the memory read would fail, since
the read string doens't contain a null-terminator, and therefore is not
a valid C string.
To address that, this patch extends the `SBProcess` SWIG interface to
expose a new `WriteMemoryAsCString` method that is only exposed to the
SWIG target language. That method checks that the buffer to write is
null-terminated and otherwise, it appends a null byte at the end of it.
Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
Diffstat (limited to 'lldb/test/API/python_api')
| -rw-r--r-- | lldb/test/API/python_api/process/TestProcessAPI.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lldb/test/API/python_api/process/TestProcessAPI.py b/lldb/test/API/python_api/process/TestProcessAPI.py index c56053d..edb5070 100644 --- a/lldb/test/API/python_api/process/TestProcessAPI.py +++ b/lldb/test/API/python_api/process/TestProcessAPI.py @@ -186,6 +186,32 @@ class ProcessAPITestCase(TestBase): exe=False, startstr=b'a') + # Get the SBValue for the global variable 'my_cstring'. + val = frame.FindValue("my_cstring", lldb.eValueTypeVariableGlobal) + self.DebugSBValue(val) + + addr = val.AddressOf().GetValueAsUnsigned() + + # Write an empty string to memory + bytes_written = process.WriteMemoryAsCString(addr, "", error) + self.assertEqual(bytes_written, 0) + if not error.Success(): + self.fail("SBProcess.WriteMemoryAsCString() failed") + + message = "Hello!" + bytes_written = process.WriteMemoryAsCString(addr, message, error) + self.assertEqual(bytes_written, len(message) + 1) + if not error.Success(): + self.fail("SBProcess.WriteMemoryAsCString() failed") + + cstring = process.ReadCStringFromMemory( + val.AddressOf().GetValueAsUnsigned(), 256, error) + if not error.Success(): + self.fail("SBProcess.ReadCStringFromMemory() failed") + + self.assertEqual(cstring, message) + + def test_access_my_int(self): """Test access 'my_int' using Python SBProcess.GetByteOrder() and other APIs.""" self.build() |
