1 //===-- SBReproducerPrivate.h -----------------------------------*- C++ -*-===// 2 // 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLDB_API_SBREPRODUCER_PRIVATE_H 11 #define LLDB_API_SBREPRODUCER_PRIVATE_H 12 13 #include "lldb/API/SBReproducer.h" 14 15 #include "lldb/Utility/FileSpec.h" 16 #include "lldb/Utility/Log.h" 17 #include "lldb/Utility/Reproducer.h" 18 #include "lldb/Utility/ReproducerInstrumentation.h" 19 20 #include "llvm/ADT/DenseMap.h" 21 22 #define LLDB_GET_INSTRUMENTATION_DATA() \ 23 lldb_private::repro::GetInstrumentationData() 24 25 namespace lldb_private { 26 namespace repro { 27 28 class SBRegistry : public Registry { 29 public: 30 SBRegistry(); 31 }; 32 33 class SBProvider : public Provider<SBProvider> { 34 public: 35 struct Info { 36 static const char *name; 37 static const char *file; 38 }; 39 SBProvider(const FileSpec & directory)40 SBProvider(const FileSpec &directory) 41 : Provider(directory), 42 m_stream(directory.CopyByAppendingPathComponent("sbapi.bin").GetPath(), 43 m_ec, llvm::sys::fs::OpenFlags::OF_None), 44 m_serializer(m_stream) {} 45 GetSerializer()46 Serializer &GetSerializer() { return m_serializer; } GetRegistry()47 Registry &GetRegistry() { return m_registry; } 48 49 static char ID; 50 51 private: 52 std::error_code m_ec; 53 llvm::raw_fd_ostream m_stream; 54 Serializer m_serializer; 55 SBRegistry m_registry; 56 }; 57 GetInstrumentationData()58inline InstrumentationData GetInstrumentationData() { 59 if (!lldb_private::repro::Reproducer::Initialized()) 60 return {}; 61 62 if (auto *g = lldb_private::repro::Reproducer::Instance().GetGenerator()) { 63 auto &p = g->GetOrCreate<SBProvider>(); 64 return {p.GetSerializer(), p.GetRegistry()}; 65 } 66 67 return {}; 68 } 69 70 template <typename T> void RegisterMethods(Registry &R); 71 72 } // namespace repro 73 } // namespace lldb_private 74 75 #endif 76