[lldb] Extend SWIG SBProcess interface with WriteMemoryAsCString method
authorMed Ismail Bennani <medismail.bennani@gmail.com>
Sat, 4 Mar 2023 02:52:15 +0000 (18:52 -0800)
committerMed Ismail Bennani <medismail.bennani@gmail.com>
Sat, 4 Mar 2023 03:33:01 +0000 (19:33 -0800)
commite6cac17b563f2e2bc7d04347b0b40a9fe12334c9
treee4f2ac75ed4233b950633d28a06f51e025b405a8
parentc7af9ae577bb04c5fe120fc07844a500818c8f47
[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>
lldb/bindings/interface/SBProcessExtensions.i
lldb/test/API/python_api/process/TestProcessAPI.py