18
18
19
19
#include < map>
20
20
21
+ // Define LLDB_REPRO_INSTR_TRACE to trace to stderr instead of LLDB's log
22
+ // infrastructure. This is useful when you need to see traces before the logger
23
+ // is initialized or enabled.
24
+ #define LLDB_REPRO_INSTR_TRACE
25
+
21
26
#define LLDB_REGISTER_CONSTRUCTOR (Class, Signature ) \
22
- Register<Class * Signature>(&construct<Class Signature>::doit)
27
+ Register<Class * Signature>(&construct<Class Signature>::doit, " " , #Class, \
28
+ #Class, #Signature)
23
29
#define LLDB_REGISTER_METHOD (Result, Class, Method, Signature ) \
24
- Register (&invoke<Result(Class::*) Signature>::method<&Class::Method>::doit)
30
+ Register (&invoke<Result(Class::*) Signature>::method<&Class::Method>::doit, \
31
+ #Result, #Class, #Method, #Signature)
25
32
#define LLDB_REGISTER_METHOD_CONST (Result, Class, Method, Signature ) \
26
33
Register (&invoke<Result(Class::*) \
27
- Signature const >::method_const<&Class::Method>::doit)
34
+ Signature const >::method_const<&Class::Method>::doit, \
35
+ #Result, #Class, #Method, #Signature)
28
36
#define LLDB_REGISTER_STATIC_METHOD (Result, Class, Method, Signature ) \
29
- Register<Result Signature>(static_cast <Result(*) Signature>(&Class::Method))
37
+ Register<Result Signature>(static_cast <Result(*) Signature>(&Class::Method), \
38
+ #Result, #Class, #Method, #Signature)
30
39
31
40
#define LLDB_RECORD_CONSTRUCTOR (Class, Signature, ...) \
32
41
LLDB_LOG (GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), "{0 }" , \
@@ -224,6 +233,9 @@ class Deserializer {
224
233
225
234
/// Deserialize and interpret value as T.
226
235
template <typename T> T Deserialize() {
236
+ #ifdef LLDB_REPRO_INSTR_TRACE
237
+ llvm::errs() << " Deserializing with " << LLVM_PRETTY_FUNCTION << " \n" ;
238
+ #endif
227
239
return Read<T>(typename serializer_tag<T>::type());
228
240
}
229
241
@@ -371,19 +383,41 @@ struct DefaultReplayer<void(Args...)> : public Replayer {
371
383
/// IDs can be serialized and deserialized to replay a function. Functions need
372
384
/// to be registered with the registry for this to work.
373
385
class Registry {
386
+ private:
387
+ struct SignatureStr {
388
+ SignatureStr(llvm::StringRef result = {}, llvm::StringRef scope = {},
389
+ llvm::StringRef name = {}, llvm::StringRef args = {})
390
+ : result(result), scope(scope), name(name), args(args) {}
391
+
392
+ std::string ToString() const;
393
+
394
+ llvm::StringRef result;
395
+ llvm::StringRef scope;
396
+ llvm::StringRef name;
397
+ llvm::StringRef args;
398
+ };
399
+
374
400
public:
375
401
Registry() = default;
376
402
virtual ~Registry() = default;
377
403
378
404
/// Register a default replayer for a function.
379
- template <typename Signature> void Register(Signature *f) {
380
- DoRegister(uintptr_t(f), llvm::make_unique<DefaultReplayer<Signature>>(f));
405
+ template <typename Signature>
406
+ void Register(Signature *f, llvm::StringRef result = {},
407
+ llvm::StringRef scope = {}, llvm::StringRef name = {},
408
+ llvm::StringRef args = {}) {
409
+ DoRegister(uintptr_t(f), llvm::make_unique<DefaultReplayer<Signature>>(f),
410
+ SignatureStr(result, scope, name, args));
381
411
}
382
412
383
413
/// Register a replayer that invokes a custom function with the same
384
414
/// signature as the replayed function.
385
- template <typename Signature> void Register(Signature *f, Signature *g) {
386
- DoRegister(uintptr_t(f), llvm::make_unique<DefaultReplayer<Signature>>(g));
415
+ template <typename Signature>
416
+ void Register(Signature *f, Signature *g, llvm::StringRef result = {},
417
+ llvm::StringRef scope = {}, llvm::StringRef name = {},
418
+ llvm::StringRef args = {}) {
419
+ DoRegister(uintptr_t(f), llvm::make_unique<DefaultReplayer<Signature>>(g),
420
+ SignatureStr(result, scope, name, args));
387
421
}
388
422
389
423
/// Replay functions from a file.
@@ -397,15 +431,19 @@ class Registry {
397
431
398
432
protected:
399
433
/// Register the given replayer for a function (and the ID mapping).
400
- void DoRegister(uintptr_t RunID, std::unique_ptr<Replayer> replayer);
434
+ void DoRegister(uintptr_t RunID, std::unique_ptr<Replayer> replayer,
435
+ SignatureStr signature);
401
436
402
437
private:
438
+ std::string GetSignature(unsigned id);
439
+ Replayer *GetReplayer(unsigned id);
440
+
403
441
/// Mapping of function addresses to replayers and their ID.
404
442
std::map<uintptr_t, std::pair<std::unique_ptr<Replayer>, unsigned>>
405
443
m_replayers;
406
444
407
445
/// Mapping of IDs to replayer instances.
408
- std::map<unsigned, Replayer *> m_ids;
446
+ std::map<unsigned, std::pair< Replayer *, SignatureStr> > m_ids;
409
447
};
410
448
411
449
/// To be used as the " Runtime ID" of a constructor. It also invokes the
@@ -551,8 +589,12 @@ class Recorder {
551
589
552
590
unsigned id = m_registry.GetID(uintptr_t(f));
553
591
554
- LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), " Recording ({0 }) ' {1}' " ,
592
+ #ifndef LLDB_REPRO_INSTR_TRACE
593
+ LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), " Recording {0 }: {1 }" ,
555
594
id, m_pretty_func);
595
+ #else
596
+ llvm::errs() << " Recording " << id << " : " << m_pretty_func << " \n" ;
597
+ #endif
556
598
557
599
m_serializer.SerializeAll(id);
558
600
m_serializer.SerializeAll(args...);
@@ -574,8 +616,12 @@ class Recorder {
574
616
575
617
unsigned id = m_registry.GetID(uintptr_t(f));
576
618
577
- LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), " Recording ({0 }) ' {1}' " ,
619
+ #ifndef LLDB_REPRO_INSTR_TRACE
620
+ LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), " Recording {0 }: {1 }" ,
578
621
id, m_pretty_func);
622
+ #else
623
+ llvm::errs() << " Recording " << id << " : " << m_pretty_func << " \n" ;
624
+ #endif
579
625
580
626
m_serializer.SerializeAll(id);
581
627
m_serializer.SerializeAll(args...);
0 commit comments