Skip to content

Commit 33e3b07

Browse files
committed
[lldb] Include thread id in the reproducer trace (NFC)
Include the current thread ID in the reproducer trace during capture/recording.
1 parent 6e614b0 commit 33e3b07

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

lldb/include/lldb/Utility/ReproducerInstrumentation.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/Support/ErrorHandling.h"
1818

1919
#include <map>
20+
#include <thread>
2021
#include <type_traits>
2122

2223
template <typename T,
@@ -78,6 +79,13 @@ template <typename... Ts> inline std::string stringify_args(const Ts &... ts) {
7879
// is initialized or enabled.
7980
// #define LLDB_REPRO_INSTR_TRACE
8081

82+
#ifdef LLDB_REPRO_INSTR_TRACE
83+
inline llvm::raw_ostream &this_thread_id() {
84+
size_t tid = std::hash<std::thread::id>{}(std::this_thread::get_id());
85+
return llvm::errs().write_hex(tid) << " :: ";
86+
}
87+
#endif
88+
8189
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature) \
8290
R.Register<Class * Signature>(&construct<Class Signature>::record, "", \
8391
#Class, #Class, #Signature)
@@ -600,8 +608,8 @@ class Serializer {
600608
/// objects (in which case we serialize their index).
601609
template <typename T> void Serialize(T *t) {
602610
#ifdef LLDB_REPRO_INSTR_TRACE
603-
llvm::errs() << "Serializing with " << LLVM_PRETTY_FUNCTION << " -> "
604-
<< stringify_args(t) << "\n";
611+
this_thread_id() << "Serializing with " << LLVM_PRETTY_FUNCTION << " -> "
612+
<< stringify_args(t) << "\n";
605613
#endif
606614
if (std::is_fundamental<T>::value) {
607615
Serialize(*t);
@@ -616,8 +624,8 @@ class Serializer {
616624
/// to objects (in which case we serialize their index).
617625
template <typename T> void Serialize(T &t) {
618626
#ifdef LLDB_REPRO_INSTR_TRACE
619-
llvm::errs() << "Serializing with " << LLVM_PRETTY_FUNCTION << " -> "
620-
<< stringify_args(t) << "\n";
627+
this_thread_id() << "Serializing with " << LLVM_PRETTY_FUNCTION << " -> "
628+
<< stringify_args(t) << "\n";
621629
#endif
622630
if (is_trivially_serializable<T>::value) {
623631
m_stream.write(reinterpret_cast<const char *>(&t), sizeof(T));
@@ -637,8 +645,8 @@ class Serializer {
637645

638646
void Serialize(const char *t) {
639647
#ifdef LLDB_REPRO_INSTR_TRACE
640-
llvm::errs() << "Serializing with " << LLVM_PRETTY_FUNCTION << " -> "
641-
<< stringify_args(t) << "\n";
648+
this_thread_id() << "Serializing with " << LLVM_PRETTY_FUNCTION << " -> "
649+
<< stringify_args(t) << "\n";
642650
#endif
643651
const size_t size = t ? strlen(t) : std::numeric_limits<size_t>::max();
644652
Serialize(size);
@@ -842,8 +850,8 @@ class Recorder {
842850

843851
#ifdef LLDB_REPRO_INSTR_TRACE
844852
void Log(unsigned id) {
845-
llvm::errs() << "Recording " << id << ": " << m_pretty_func << " ("
846-
<< m_pretty_args << ")\n";
853+
this_thread_id() << "Recording " << id << ": " << m_pretty_func << " ("
854+
<< m_pretty_args << ")\n";
847855
}
848856
#endif
849857

0 commit comments

Comments
 (0)