From: Jonas Devlieghere Date: Wed, 5 Feb 2020 03:00:10 +0000 (-0800) Subject: [lldb/Reproducers] Change the way we instrument void* arguments X-Git-Tag: llvmorg-12-init~15733 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b453caf1112f0e89eddcd03aa667368fab6d13d6;p=platform%2Fupstream%2Fllvm.git [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. --- diff --git a/lldb/include/lldb/Utility/ReproducerInstrumentation.h b/lldb/include/lldb/Utility/ReproducerInstrumentation.h index d3c46d0..9039a7f 100644 --- a/lldb/include/lldb/Utility/ReproducerInstrumentation.h +++ b/lldb/include/lldb/Utility/ReproducerInstrumentation.h @@ -371,7 +371,9 @@ private: template <> const char *Deserializer::Deserialize(); template <> const char **Deserializer::Deserialize(); template <> const uint8_t *Deserializer::Deserialize(); +template <> const void *Deserializer::Deserialize(); template <> char *Deserializer::Deserialize(); +template <> void *Deserializer::Deserialize(); /// 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) { diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 868bf54..3f7847e 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -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(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)); } } diff --git a/lldb/source/Utility/ReproducerInstrumentation.cpp b/lldb/source/Utility/ReproducerInstrumentation.cpp index eb41acb..4c32d94 100644 --- a/lldb/source/Utility/ReproducerInstrumentation.cpp +++ b/lldb/source/Utility/ReproducerInstrumentation.cpp @@ -27,6 +27,14 @@ template <> const uint8_t *Deserializer::Deserialize() { return Deserialize(); } +template <> void *Deserializer::Deserialize() { + return const_cast(Deserialize()); +} + +template <> const void *Deserializer::Deserialize() { + return nullptr; +} + template <> char *Deserializer::Deserialize() { return const_cast(Deserialize()); } diff --git a/lldb/tools/lldb-instr/Instrument.cpp b/lldb/tools/lldb-instr/Instrument.cpp index 9b29700..8ec0130 100644 --- a/lldb/tools/lldb-instr/Instrument.cpp +++ b/lldb/tools/lldb-instr/Instrument.cpp @@ -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.