[lldb/Reproducers] Implement custom replayers for (char *, size_t)

Some SB API methods returns strings through a char* and a length. This
is a problem for the deserializer, which considers a single type at a
time, and therefore cannot know how many bytes to allocate for the
character buffer.

We can solve this problem by implementing a custom replayer, which
ignores the passed-in char* and allocates a buffer of the correct size
itself, before invoking the original API method or function.

This patch adds three new macros to register a custom replayer for
methods that take a char* and a size_t. It supports arbitrary return
values (some functions return a bool while others return a size_t).
This commit is contained in:
Jonas Devlieghere
2020-02-05 19:41:09 -08:00
parent 25aa2eef99
commit 2f025bb87c
6 changed files with 70 additions and 31 deletions

View File

@@ -313,7 +313,7 @@ SBThread::GetStopReasonExtendedBacktraces(InstrumentationRuntimeType type) {
}
size_t SBThread::GetStopDescription(char *dst, size_t dst_len) {
LLDB_RECORD_DUMMY(size_t, SBThread, GetStopDescription, (char *, size_t),
LLDB_RECORD_METHOD(size_t, SBThread, GetStopDescription, (char *, size_t),
dst, dst_len);
std::unique_lock<std::recursive_mutex> lock;
@@ -1444,8 +1444,6 @@ void RegisterMethods<SBThread>(Registry &R) {
LLDB_REGISTER_METHOD(lldb::SBThreadCollection, SBThread,
GetStopReasonExtendedBacktraces,
(lldb::InstrumentationRuntimeType));
LLDB_REGISTER_METHOD(size_t, SBThread, GetStopDescription,
(char *, size_t));
LLDB_REGISTER_METHOD(lldb::SBValue, SBThread, GetStopReturnValue, ());
LLDB_REGISTER_METHOD_CONST(lldb::tid_t, SBThread, GetThreadID, ());
LLDB_REGISTER_METHOD_CONST(uint32_t, SBThread, GetIndexID, ());
@@ -1522,6 +1520,7 @@ void RegisterMethods<SBThread>(Registry &R) {
LLDB_REGISTER_METHOD(lldb::SBThread, SBThread, GetCurrentExceptionBacktrace,
());
LLDB_REGISTER_METHOD(bool, SBThread, SafeToCallFunctions, ());
LLDB_REGISTER_CHAR_PTR_REDIRECT(size_t, SBThread, GetStopDescription);
}
}