[Lldb-commits] [PATCH] D58566: [Reproducers] Add more logging capabilities to reproducer instrumentation

2019-02-27 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLDB355002: [Reproducers] Add more logging to reproducer 
instrumentation (authored by JDevlieghere, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D58566?vs=188492&id=188557#toc

Repository:
  rLLDB LLDB

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58566/new/

https://reviews.llvm.org/D58566

Files:
  include/lldb/Utility/ReproducerInstrumentation.h
  source/Utility/ReproducerInstrumentation.cpp

Index: source/Utility/ReproducerInstrumentation.cpp
===
--- source/Utility/ReproducerInstrumentation.cpp
+++ source/Utility/ReproducerInstrumentation.cpp
@@ -43,23 +43,33 @@
 }
 
 bool Registry::Replay(llvm::StringRef buffer) {
+#ifndef LLDB_REPRO_INSTR_TRACE
   Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_API);
+#endif
 
   Deserializer deserializer(buffer);
   while (deserializer.HasData(1)) {
 unsigned id = deserializer.Deserialize();
-LLDB_LOG(log, "Replaying function #{0}", id);
-m_ids[id]->operator()(deserializer);
+
+#ifndef LLDB_REPRO_INSTR_TRACE
+LLDB_LOG(log, "Replaying {0}: {1}", id, GetSignature(id));
+#else
+llvm::errs() << "Replaying " << id << ": " << GetSignature(id) << "\n";
+#endif
+
+GetReplayer(id)->operator()(deserializer);
   }
 
   return true;
 }
 
-void Registry::DoRegister(uintptr_t RunID, std::unique_ptr replayer) {
+void Registry::DoRegister(uintptr_t RunID, std::unique_ptr replayer,
+  SignatureStr signature) {
   const unsigned id = m_replayers.size() + 1;
   assert(m_replayers.find(RunID) == m_replayers.end());
   m_replayers[RunID] = std::make_pair(std::move(replayer), id);
-  m_ids[id] = m_replayers[RunID].first.get();
+  m_ids[id] =
+  std::make_pair(m_replayers[RunID].first.get(), std::move(signature));
 }
 
 unsigned Registry::GetID(uintptr_t addr) {
@@ -68,6 +78,21 @@
   return id;
 }
 
+std::string Registry::GetSignature(unsigned id) {
+  assert(m_ids.count(id) != 0 && "ID not in registry");
+  return m_ids[id].second.ToString();
+}
+
+Replayer *Registry::GetReplayer(unsigned id) {
+  assert(m_ids.count(id) != 0 && "ID not in registry");
+  return m_ids[id].first;
+}
+
+std::string Registry::SignatureStr::ToString() const {
+  return (result + (result.empty() ? "" : " ") + scope + "::" + name + args)
+  .str();
+}
+
 unsigned ObjectToIndex::GetIndexForObjectImpl(const void *object) {
   unsigned index = m_mapping.size() + 1;
   auto it = m_mapping.find(object);
Index: include/lldb/Utility/ReproducerInstrumentation.h
===
--- include/lldb/Utility/ReproducerInstrumentation.h
+++ include/lldb/Utility/ReproducerInstrumentation.h
@@ -18,15 +18,24 @@
 
 #include 
 
+// Define LLDB_REPRO_INSTR_TRACE to trace to stderr instead of LLDB's log
+// infrastructure. This is useful when you need to see traces before the logger
+// is initialized or enabled.
+#define LLDB_REPRO_INSTR_TRACE
+
 #define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)\
-  Register(&construct::doit)
+  Register(&construct::doit, "", #Class,   \
+  #Class, #Signature)
 #define LLDB_REGISTER_METHOD(Result, Class, Method, Signature) \
-  Register(&invoke::method<&Class::Method>::doit)
+  Register(&invoke::method<&Class::Method>::doit,  \
+   #Result, #Class, #Method, #Signature)
 #define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)   \
   Register(&invoke::method_const<&Class::Method>::doit)
+   Signature const>::method_const<&Class::Method>::doit,   \
+   #Result, #Class, #Method, #Signature)
 #define LLDB_REGISTER_STATIC_METHOD(Result, Class, Method, Signature)  \
-  Register(static_cast(&Class::Method))
+  Register(static_cast(&Class::Method), \
+ #Result, #Class, #Method, #Signature)
 
 #define LLDB_RECORD_CONSTRUCTOR(Class, Signature, ...) \
   LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), "{0}",   \
@@ -224,6 +233,9 @@
 
   /// Deserialize and interpret value as T.
   template  T Deserialize() {
+#ifdef LLDB_REPRO_INSTR_TRACE
+llvm::errs() << "Deserializing with " << LLVM_PRETTY_FUNCTION << "\n";
+#endif
 return Read(typename serializer_tag::type());
   }
 
@@ -371,19 +383,41 @@
 /// IDs can be serialized and deserialized to replay a function. Functions need
 /// to be registered with the registry for this to work.
 class Registry {
+private:
+  struct SignatureStr {
+SignatureStr(llvm::StringRef result = {}, llvm::StringRef scope = {},
+ llvm::StringRef name = {}, llvm::StringRef args = {})
+: result(result), scope(scope), name(name), args(args) {}
+
+std::string ToString() const;
+
+llvm::StringRef result;
+llvm::StringRef scope;
+llvm::StringRef 

[Lldb-commits] [PATCH] D58566: [Reproducers] Add more logging capabilities to reproducer instrumentation

2019-02-26 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 188492.
JDevlieghere added a comment.

Simplify record function


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58566/new/

https://reviews.llvm.org/D58566

Files:
  lldb/include/lldb/Utility/ReproducerInstrumentation.h
  lldb/source/Utility/ReproducerInstrumentation.cpp

Index: lldb/source/Utility/ReproducerInstrumentation.cpp
===
--- lldb/source/Utility/ReproducerInstrumentation.cpp
+++ lldb/source/Utility/ReproducerInstrumentation.cpp
@@ -43,23 +43,33 @@
 }
 
 bool Registry::Replay(llvm::StringRef buffer) {
+#ifndef LLDB_REPRO_INSTR_TRACE
   Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_API);
+#endif
 
   Deserializer deserializer(buffer);
   while (deserializer.HasData(1)) {
 unsigned id = deserializer.Deserialize();
-LLDB_LOG(log, "Replaying function #{0}", id);
-m_ids[id]->operator()(deserializer);
+
+#ifndef LLDB_REPRO_INSTR_TRACE
+LLDB_LOG(log, "Replaying {0}: {1}", id, GetSignature(id));
+#else
+llvm::errs() << "Replaying " << id << ": " << GetSignature(id) << "\n";
+#endif
+
+GetReplayer(id)->operator()(deserializer);
   }
 
   return true;
 }
 
-void Registry::DoRegister(uintptr_t RunID, std::unique_ptr replayer) {
+void Registry::DoRegister(uintptr_t RunID, std::unique_ptr replayer,
+  SignatureStr signature) {
   const unsigned id = m_replayers.size() + 1;
   assert(m_replayers.find(RunID) == m_replayers.end());
   m_replayers[RunID] = std::make_pair(std::move(replayer), id);
-  m_ids[id] = m_replayers[RunID].first.get();
+  m_ids[id] =
+  std::make_pair(m_replayers[RunID].first.get(), std::move(signature));
 }
 
 unsigned Registry::GetID(uintptr_t addr) {
@@ -68,6 +78,21 @@
   return id;
 }
 
+std::string Registry::GetSignature(unsigned id) {
+  assert(m_ids.count(id) != 0 && "ID not in registry");
+  return m_ids[id].second.ToString();
+}
+
+Replayer *Registry::GetReplayer(unsigned id) {
+  assert(m_ids.count(id) != 0 && "ID not in registry");
+  return m_ids[id].first;
+}
+
+std::string Registry::SignatureStr::ToString() const {
+  return (result + (result.empty() ? "" : " ") + scope + "::" + name + args)
+  .str();
+}
+
 unsigned ObjectToIndex::GetIndexForObjectImpl(const void *object) {
   unsigned index = m_mapping.size() + 1;
   auto it = m_mapping.find(object);
Index: lldb/include/lldb/Utility/ReproducerInstrumentation.h
===
--- lldb/include/lldb/Utility/ReproducerInstrumentation.h
+++ lldb/include/lldb/Utility/ReproducerInstrumentation.h
@@ -18,15 +18,24 @@
 
 #include 
 
+// Define LLDB_REPRO_INSTR_TRACE to trace to stderr instead of LLDB's log
+// infrastructure. This is useful when you need to see traces before the logger
+// is initialized or enabled.
+#define LLDB_REPRO_INSTR_TRACE
+
 #define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)\
-  Register(&construct::doit)
+  Register(&construct::doit, "", #Class,   \
+  #Class, #Signature)
 #define LLDB_REGISTER_METHOD(Result, Class, Method, Signature) \
-  Register(&invoke::method<&Class::Method>::doit)
+  Register(&invoke::method<&Class::Method>::doit,  \
+   #Result, #Class, #Method, #Signature)
 #define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)   \
   Register(&invoke::method_const<&Class::Method>::doit)
+   Signature const>::method_const<&Class::Method>::doit,   \
+   #Result, #Class, #Method, #Signature)
 #define LLDB_REGISTER_STATIC_METHOD(Result, Class, Method, Signature)  \
-  Register(static_cast(&Class::Method))
+  Register(static_cast(&Class::Method), \
+ #Result, #Class, #Method, #Signature)
 
 #define LLDB_RECORD_CONSTRUCTOR(Class, Signature, ...) \
   LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), "{0}",   \
@@ -224,6 +233,9 @@
 
   /// Deserialize and interpret value as T.
   template  T Deserialize() {
+#ifdef LLDB_REPRO_INSTR_TRACE
+llvm::errs() << "Deserializing with " << LLVM_PRETTY_FUNCTION << "\n";
+#endif
 return Read(typename serializer_tag::type());
   }
 
@@ -371,19 +383,41 @@
 /// IDs can be serialized and deserialized to replay a function. Functions need
 /// to be registered with the registry for this to work.
 class Registry {
+private:
+  struct SignatureStr {
+SignatureStr(llvm::StringRef result = {}, llvm::StringRef scope = {},
+ llvm::StringRef name = {}, llvm::StringRef args = {})
+: result(result), scope(scope), name(name), args(args) {}
+
+std::string ToString() const;
+
+llvm::StringRef result;
+llvm::StringRef scope;
+llvm::StringRef name;
+llvm::StringRef args;
+  };
+
 public:
   Registry() = default;
   virtual ~Registry() = default;
 
   /// Register a default replayer for a function.
-  templa

[Lldb-commits] [PATCH] D58566: [Reproducers] Add more logging capabilities to reproducer instrumentation

2019-02-26 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere marked an inline comment as done.
JDevlieghere added inline comments.



Comment at: lldb/include/lldb/Utility/ReproducerInstrumentation.h:591
 
-LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), "Recording ({0}) 
'{1}'",
+#ifndef LLDB_REPRO_INSTR_TRACE
+LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), "Recording {0}: {1}",

labath wrote:
> aprantl wrote:
> > Who defines this macro? I'm asking because it's unusual for LLDB to emit 
> > anything on stderr.
> I'm guessing it's the kind of thing you define by editing the source/cmake 
> config, when you're really desperate to figure out what's going wrong.
Correct, see the #define on line 24. I'll comment it out before landing of 
course.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58566/new/

https://reviews.llvm.org/D58566



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D58566: [Reproducers] Add more logging capabilities to reproducer instrumentation

2019-02-26 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

The overall idea seems fine to me, though I think it would be better to keep 
the macros simpler by moving all of the logic into the single `Register` call. 
I.e. the Register function would take extra StringRef arguments, which the 
macros would fill out. Then you could store the computed signature in the 
(possibly renamed) `m_ids` map, instead of having two maps with the same set of 
keys. That should save some space too.




Comment at: lldb/include/lldb/Utility/ReproducerInstrumentation.h:591
 
-LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), "Recording ({0}) 
'{1}'",
+#ifndef LLDB_REPRO_INSTR_TRACE
+LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), "Recording {0}: {1}",

aprantl wrote:
> Who defines this macro? I'm asking because it's unusual for LLDB to emit 
> anything on stderr.
I'm guessing it's the kind of thing you define by editing the source/cmake 
config, when you're really desperate to figure out what's going wrong.


Repository:
  rLLDB LLDB

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58566/new/

https://reviews.llvm.org/D58566



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D58566: [Reproducers] Add more logging capabilities to reproducer instrumentation

2019-02-25 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added inline comments.



Comment at: lldb/include/lldb/Utility/ReproducerInstrumentation.h:591
 
-LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), "Recording ({0}) 
'{1}'",
+#ifndef LLDB_REPRO_INSTR_TRACE
+LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), "Recording {0}: {1}",

Who defines this macro? I'm asking because it's unusual for LLDB to emit 
anything on stderr.


Repository:
  rLLDB LLDB

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58566/new/

https://reviews.llvm.org/D58566



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D58566: [Reproducers] Add more logging capabilities to reproducer instrumentation

2019-02-22 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, davide, aprantl.
JDevlieghere added a project: LLDB.

Debugging issues with instrumentation capture and replay can be particularly 
tricky, especially because part of the process takes places even before the 
debugger is initialized. This patch adds more logging capabilities to these 
classes, hidden behind a macro define.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D58566

Files:
  lldb/include/lldb/Utility/ReproducerInstrumentation.h
  lldb/source/Utility/ReproducerInstrumentation.cpp

Index: lldb/source/Utility/ReproducerInstrumentation.cpp
===
--- lldb/source/Utility/ReproducerInstrumentation.cpp
+++ lldb/source/Utility/ReproducerInstrumentation.cpp
@@ -44,22 +44,38 @@
 
 bool Registry::Replay(llvm::StringRef buffer) {
   Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_API);
-
   Deserializer deserializer(buffer);
   while (deserializer.HasData(1)) {
 unsigned id = deserializer.Deserialize();
-LLDB_LOG(log, "Replaying function #{0}", id);
+#ifndef LLDB_REPRO_INSTR_TRACE
+LLDB_LOG(log, "Replaying {0}: {1}", id, GetSignature(id));
+#else
+(void)log;
+llvm::errs() << "Replaying " << id << ": " << GetSignature(id) << "\n";
+#endif
+assert(m_ids.count(id) != 0 && "Invalid id?");
 m_ids[id]->operator()(deserializer);
   }
 
   return true;
 }
 
-void Registry::DoRegister(uintptr_t RunID, std::unique_ptr replayer) {
+unsigned Registry::DoRegister(uintptr_t RunID,
+  std::unique_ptr replayer) {
   const unsigned id = m_replayers.size() + 1;
   assert(m_replayers.find(RunID) == m_replayers.end());
   m_replayers[RunID] = std::make_pair(std::move(replayer), id);
   m_ids[id] = m_replayers[RunID].first.get();
+  return id;
+}
+
+void Registry::RegisterSignature(unsigned id, llvm::StringRef result,
+ llvm::StringRef theclass,
+ llvm::StringRef method,
+ llvm::StringRef signature) {
+  m_signatures[id] = (result + (result.empty() ? "" : " ") + theclass +
+  "::" + method + signature)
+ .str();
 }
 
 unsigned Registry::GetID(uintptr_t addr) {
Index: lldb/include/lldb/Utility/ReproducerInstrumentation.h
===
--- lldb/include/lldb/Utility/ReproducerInstrumentation.h
+++ lldb/include/lldb/Utility/ReproducerInstrumentation.h
@@ -18,15 +18,37 @@
 
 #include 
 
+// Define LLDB_REPRO_INSTR_TRACE to trace to stderr instead of LLDB's log
+// infrastructure. This is useful when you need to see traces before the logger
+// is initialized or enabled.
+// #define LLDB_REPRO_INSTR_TRACE
+
 #define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)\
-  Register(&construct::doit)
+  {\
+unsigned id =  \
+Register(&construct::doit);\
+RegisterSignature(id, "", #Class, #Class, #Signature); \
+  }
+
 #define LLDB_REGISTER_METHOD(Result, Class, Method, Signature) \
-  Register(&invoke::method<&Class::Method>::doit)
+  {\
+unsigned id = Register(\
+&invoke::method<&Class::Method>::doit);\
+RegisterSignature(id, #Result, #Class, #Method, #Signature);   \
+  }
 #define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)   \
-  Register(&invoke::method_const<&Class::Method>::doit)
+  {\
+unsigned id = Register(\
+&invoke::method_const<&Class::Method>::doit); \
+RegisterSignature(id, #Result, #Class, #Method, #Signature);   \
+  }
 #define LLDB_REGISTER_STATIC_METHOD(Result, Class, Method, Signature)  \
-  Register(static_cast(&Class::Method))
+  {\
+unsigned id = Register(  \
+static_cast(&Class::Method)); \
+RegisterSignature(id, #Result, #Class, #Method, #Signature);   \
+  }
 
 #define LLDB_RECORD_CONSTRUCTOR(Class, Signature, ...) \
   LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), "{0}",   \
@@ -224,6 +246,9 @@
 
   /// Deserialize and interpret value as T.
   template  T Deserialize() {
+#ifdef LLDB_REPRO_INSTR_TRACE
+llvm::errs() << "Deserializing with " << LLVM_PRETTY_FUNCTION << "\n";
+#endif
 return Read(typename serializer_tag::type());
   }
 
@@ -376,14 +401,16 @@
   virtua