[Lldb-commits] [lldb] b453caf - [lldb/Reproducers] Change the way we instrument void* arguments

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Feb 4 19:05:20 PST 2020


Author: Jonas Devlieghere
Date: 2020-02-04T19:05:13-08:00
New Revision: b453caf1112f0e89eddcd03aa667368fab6d13d6

URL: https://github.com/llvm/llvm-project/commit/b453caf1112f0e89eddcd03aa667368fab6d13d6
DIFF: https://github.com/llvm/llvm-project/commit/b453caf1112f0e89eddcd03aa667368fab6d13d6.diff

LOG: [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.

Added: 
    

Modified: 
    lldb/include/lldb/Utility/ReproducerInstrumentation.h
    lldb/source/API/SBTarget.cpp
    lldb/source/Utility/ReproducerInstrumentation.cpp
    lldb/tools/lldb-instr/Instrument.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Utility/ReproducerInstrumentation.h b/lldb/include/lldb/Utility/ReproducerInstrumentation.h
index d3c46d07c6cf..9039a7f1d162 100644
--- a/lldb/include/lldb/Utility/ReproducerInstrumentation.h
+++ b/lldb/include/lldb/Utility/ReproducerInstrumentation.h
@@ -371,7 +371,9 @@ class Deserializer {
 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 @@ class Serializer {
     }
   }
 
+  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 868bf547f2a7..3f7847e4d9f2 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<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));
 }
 
 }

diff  --git a/lldb/source/Utility/ReproducerInstrumentation.cpp b/lldb/source/Utility/ReproducerInstrumentation.cpp
index eb41acb5a3f3..4c32d9407830 100644
--- a/lldb/source/Utility/ReproducerInstrumentation.cpp
+++ b/lldb/source/Utility/ReproducerInstrumentation.cpp
@@ -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 *>());
 }

diff  --git a/lldb/tools/lldb-instr/Instrument.cpp b/lldb/tools/lldb-instr/Instrument.cpp
index 9b2970030cb0..8ec01304891b 100644
--- a/lldb/tools/lldb-instr/Instrument.cpp
+++ b/lldb/tools/lldb-instr/Instrument.cpp
@@ -194,10 +194,9 @@ class SBVisitor : public RecursiveASTVisitor<SBVisitor> {
       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.


        


More information about the lldb-commits mailing list