llvm-capstone/lldb/bindings
Raphael Isemann 61b6a4e826 [lldb] Fix that SBThread.GetStopDescription is returning strings with uninitialized memory at the end.
Summary:
`SBThread.GetStopDescription` is a curious API as it takes a buffer length as a parameter that specifies
how many bytes the buffer we pass has. Then we fill the buffer until the specified length (or the length
of the stop description string) and return the string length. If the buffer is a nullptr however, we instead
return how many bytes we would have written to the buffer so that the user can allocate a buffer with
the right size and pass that size to a subsequent `SBThread.GetStopDescription` call.

Funnily enough, it is not possible to pass a nullptr via the Python SWIG bindings, so that might be the
first API in LLDB that is not only hard to use correctly but impossible to use correctly. The only way to
call this function via Python is to throw in a large size limit that is hopefully large enough to contain the
stop description (otherwise we only get the truncated stop description).

Currently passing a size limit that is smaller than the returned stop description doesn't cause the
Python bindings to return the stop description but instead the truncated stop description + uninitialized characters
at the end of the string. The reason for this is that we return the result of `snprintf` from the method
which returns the amount of bytes that *would* have been written (which is larger than the buffer).
This causes our Python bindings to return a string that is as large as full stop description but the
buffer that has been filled is only as large as the passed in buffer size.

This patch fixes this issue by just recalculating the string length in our buffer instead of relying on the wrong
return value. We also have to do this in a new type map as the old type map is also used for all methods
with the given argument pair `char *dst, size_t dst_len` (e.g. SBProcess.GetSTDOUT`). These methods have
different semantics for these arguments and don't null-terminate the returned buffer (they instead return the
size in bytes) so we can't change the existing typemap without breaking them.

Reviewers: labath, jingham

Reviewed By: labath

Subscribers: clayborg, shafik, abidh, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D72086
2020-01-14 09:34:32 +01:00
..
interface [lldb] Fix that SBThread.GetStopDescription is returning strings with uninitialized memory at the end. 2020-01-14 09:34:32 +01:00
lua [lldb/Lua] Add lua typemaps for INOUT params 2020-01-09 14:51:13 -08:00
python [lldb] Fix that SBThread.GetStopDescription is returning strings with uninitialized memory at the end. 2020-01-14 09:34:32 +01:00
CMakeLists.txt
headers.swig
interfaces.swig
lua.swig [lldb/Lua] Add lua typemaps for INOUT params 2020-01-09 14:51:13 -08:00
macros.swig
python.swig [lldb/SWIG] Undo incorrect substitution 2020-01-09 09:55:39 -08:00