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.benn...@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()
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()
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits