[Lldb-commits] [PATCH] D144224: [lldb] Extend SWIG SBProcess interface with WriteCStringToMemory method
Med Ismail Bennani via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Thu Feb 16 15:25:28 PST 2023
mib created this revision.
mib added a reviewer: bulbazord.
mib added a project: LLDB.
Herald added a subscriber: JDevlieghere.
Herald added a project: All.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.
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 `WriteCStringToMemory` 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 at gmail.com>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D144224
Files:
lldb/bindings/interface/SBProcessExtensions.i
Index: lldb/bindings/interface/SBProcessExtensions.i
===================================================================
--- lldb/bindings/interface/SBProcessExtensions.i
+++ lldb/bindings/interface/SBProcessExtensions.i
@@ -2,6 +2,11 @@
%extend lldb::SBProcess {
#ifdef SWIGPYTHON
%pythoncode %{
+ def WriteCStringToMemory(self, addr, str, error):
+ if not str[-1] == '\0':
+ str += '\0'
+ return self.WriteMemory(addr, str, error)
+
def __get_is_alive__(self):
'''Returns "True" if the process is currently alive, "False" otherwise'''
s = self.GetState()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144224.498168.patch
Type: text/x-patch
Size: 643 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230216/e808a666/attachment.bin>
More information about the lldb-commits
mailing list