[lldb/Reproducers] Change the way we instrument void* arguments

The reproducer instrumentation cannot automatically serialize and
deserialize void* arguments. Currently we deal with this by explicitly
preventing these methods from being instrumented. This has the undesired
side effect of breaking replay when that method returns a value later
used by another SB API call.

The solution is to change our approach and instrument these methods.
Instead of using the DUMMY macro, we just make (de)serialization of the
void pointer a NOOP and always return a nullptr.
This commit is contained in:
Jonas Devlieghere 2020-02-04 19:00:10 -08:00
parent a1c338d70b
commit b453caf111
4 changed files with 54 additions and 27 deletions

View file

@ -371,7 +371,9 @@ private:
template <> const char *Deserializer::Deserialize<const char *>();
template <> const char **Deserializer::Deserialize<const char **>();
template <> const uint8_t *Deserializer::Deserialize<const uint8_t *>();
template <> const void *Deserializer::Deserialize<const void *>();
template <> char *Deserializer::Deserialize<char *>();
template <> void *Deserializer::Deserialize<void *>();
/// Helpers to auto-synthesize function replay code. It deserializes the replay
/// function's arguments one by one and finally calls the corresponding
@ -598,9 +600,12 @@ private:
}
}
void Serialize(const void *v) {
// FIXME: Support void*
}
void Serialize(void *v) {
// FIXME: Support void*
llvm_unreachable("void* is currently unsupported.");
}
void Serialize(const char *t) {

View file

@ -677,9 +677,9 @@ SBTarget::ResolveSymbolContextForAddress(const SBAddress &addr,
size_t SBTarget::ReadMemory(const SBAddress addr, void *buf, size_t size,
lldb::SBError &error) {
LLDB_RECORD_DUMMY(size_t, SBTarget, ReadMemory,
(const lldb::SBAddress, void *, size_t, lldb::SBError &),
addr, buf, size, error);
LLDB_RECORD_METHOD(size_t, SBTarget, ReadMemory,
(const lldb::SBAddress, void *, size_t, lldb::SBError &),
addr, buf, size, error);
SBError sb_error;
size_t bytes_read = 0;
@ -2054,21 +2054,22 @@ lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
lldb::SBInstructionList SBTarget::GetInstructions(lldb::SBAddress base_addr,
const void *buf,
size_t size) {
LLDB_RECORD_DUMMY(lldb::SBInstructionList, SBTarget, GetInstructions,
(lldb::SBAddress, const void *, size_t), base_addr, buf,
size);
LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, GetInstructions,
(lldb::SBAddress, const void *, size_t), base_addr, buf,
size);
return GetInstructionsWithFlavor(base_addr, nullptr, buf, size);
return LLDB_RECORD_RESULT(
GetInstructionsWithFlavor(base_addr, nullptr, buf, size));
}
lldb::SBInstructionList
SBTarget::GetInstructionsWithFlavor(lldb::SBAddress base_addr,
const char *flavor_string, const void *buf,
size_t size) {
LLDB_RECORD_DUMMY(lldb::SBInstructionList, SBTarget,
GetInstructionsWithFlavor,
(lldb::SBAddress, const char *, const void *, size_t),
base_addr, flavor_string, buf, size);
LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget,
GetInstructionsWithFlavor,
(lldb::SBAddress, const char *, const void *, size_t),
base_addr, flavor_string, buf, size);
SBInstructionList sb_instructions;
@ -2086,30 +2087,31 @@ SBTarget::GetInstructionsWithFlavor(lldb::SBAddress base_addr,
UINT32_MAX, data_from_file));
}
return sb_instructions;
return LLDB_RECORD_RESULT(sb_instructions);
}
lldb::SBInstructionList SBTarget::GetInstructions(lldb::addr_t base_addr,
const void *buf,
size_t size) {
LLDB_RECORD_DUMMY(lldb::SBInstructionList, SBTarget, GetInstructions,
(lldb::addr_t, const void *, size_t), base_addr, buf, size);
LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, GetInstructions,
(lldb::addr_t, const void *, size_t), base_addr, buf,
size);
return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), nullptr, buf,
size);
return LLDB_RECORD_RESULT(GetInstructionsWithFlavor(
ResolveLoadAddress(base_addr), nullptr, buf, size));
}
lldb::SBInstructionList
SBTarget::GetInstructionsWithFlavor(lldb::addr_t base_addr,
const char *flavor_string, const void *buf,
size_t size) {
LLDB_RECORD_DUMMY(lldb::SBInstructionList, SBTarget,
GetInstructionsWithFlavor,
(lldb::addr_t, const char *, const void *, size_t),
base_addr, flavor_string, buf, size);
LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget,
GetInstructionsWithFlavor,
(lldb::addr_t, const char *, const void *, size_t),
base_addr, flavor_string, buf, size);
return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), flavor_string,
buf, size);
return LLDB_RECORD_RESULT(GetInstructionsWithFlavor(
ResolveLoadAddress(base_addr), flavor_string, buf, size));
}
SBError SBTarget::SetSectionLoadAddress(lldb::SBSection section,
@ -2628,6 +2630,19 @@ void RegisterMethods<SBTarget>(Registry &R) {
LLDB_REGISTER_METHOD_CONST(lldb::SBLaunchInfo, SBTarget, GetLaunchInfo, ());
LLDB_REGISTER_METHOD(void, SBTarget, SetLaunchInfo,
(const lldb::SBLaunchInfo &));
LLDB_REGISTER_METHOD(
size_t, SBTarget, ReadMemory,
(const lldb::SBAddress, void *, size_t, lldb::SBError &));
LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, GetInstructions,
(lldb::SBAddress, const void *, size_t));
LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget,
GetInstructionsWithFlavor,
(lldb::SBAddress, const char *, const void *, size_t));
LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, GetInstructions,
(lldb::addr_t, const void *, size_t));
LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget,
GetInstructionsWithFlavor,
(lldb::addr_t, const char *, const void *, size_t));
}
}

View file

@ -27,6 +27,14 @@ template <> const uint8_t *Deserializer::Deserialize<const uint8_t *>() {
return Deserialize<uint8_t *>();
}
template <> void *Deserializer::Deserialize<void *>() {
return const_cast<void *>(Deserialize<const void *>());
}
template <> const void *Deserializer::Deserialize<const void *>() {
return nullptr;
}
template <> char *Deserializer::Deserialize<char *>() {
return const_cast<char *>(Deserialize<const char *>());
}

View file

@ -194,10 +194,9 @@ public:
ParamTypes.push_back(T.getAsString(Policy));
ParamNames.push_back(P->getNameAsString());
// Currently we don't support functions that have void pointers or
// function pointers as an argument, in which case we insert a dummy
// macro.
ShouldInsertDummy |= T->isFunctionPointerType() || T->isVoidPointerType();
// Currently we don't support functions that have function pointers as an
// argument, in which case we insert a dummy macro.
ShouldInsertDummy |= T->isFunctionPointerType();
}
// Convert the two lists to string for the macros.