1 //===-- SBReproducer.cpp ----------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "SBReproducerPrivate.h" 10 11 #include "SBReproducerPrivate.h" 12 #include "lldb/API/LLDB.h" 13 #include "lldb/API/SBAddress.h" 14 #include "lldb/API/SBAttachInfo.h" 15 #include "lldb/API/SBBlock.h" 16 #include "lldb/API/SBBreakpoint.h" 17 #include "lldb/API/SBCommandInterpreter.h" 18 #include "lldb/API/SBData.h" 19 #include "lldb/API/SBDebugger.h" 20 #include "lldb/API/SBDeclaration.h" 21 #include "lldb/API/SBError.h" 22 #include "lldb/API/SBFileSpec.h" 23 #include "lldb/API/SBHostOS.h" 24 #include "lldb/API/SBReproducer.h" 25 26 #include "lldb/Host/FileSystem.h" 27 28 using namespace lldb; 29 using namespace lldb_private; 30 using namespace lldb_private::repro; 31 32 SBRegistry::SBRegistry() { 33 Registry& R = *this; 34 35 RegisterMethods<SBAddress>(R); 36 RegisterMethods<SBAttachInfo>(R); 37 RegisterMethods<SBBlock>(R); 38 RegisterMethods<SBBreakpoint>(R); 39 RegisterMethods<SBBreakpointList>(R); 40 RegisterMethods<SBBreakpointLocation>(R); 41 RegisterMethods<SBBreakpointName>(R); 42 RegisterMethods<SBBroadcaster>(R); 43 RegisterMethods<SBCommandInterpreterRunOptions>(R); 44 RegisterMethods<SBCommandReturnObject>(R); 45 RegisterMethods<SBCommunication>(R); 46 RegisterMethods<SBCompileUnit>(R); 47 RegisterMethods<SBData>(R); 48 RegisterMethods<SBInputReader>(R); 49 RegisterMethods<SBDebugger>(R); 50 RegisterMethods<SBDeclaration>(R); 51 RegisterMethods<SBError>(R); 52 RegisterMethods<SBEvent>(R); 53 RegisterMethods<SBExecutionContext>(R); 54 RegisterMethods<SBExpressionOptions>(R); 55 RegisterMethods<SBFileSpec>(R); 56 RegisterMethods<SBFileSpecList>(R); 57 RegisterMethods<SBFrame>(R); 58 RegisterMethods<SBFunction>(R); 59 RegisterMethods<SBHostOS>(R); 60 RegisterMethods<SBInstruction>(R); 61 RegisterMethods<SBInstructionList>(R); 62 RegisterMethods<SBLanguageRuntime>(R); 63 RegisterMethods<SBLaunchInfo>(R); 64 RegisterMethods<SBLineEntry>(R); 65 RegisterMethods<SBListener>(R); 66 RegisterMethods<SBMemoryRegionInfo>(R); 67 RegisterMethods<SBMemoryRegionInfoList>(R); 68 RegisterMethods<SBModule>(R); 69 RegisterMethods<SBModuleSpec>(R); 70 RegisterMethods<SBPlatformConnectOptions>(R); 71 RegisterMethods<SBPlatformShellCommand>(R); 72 RegisterMethods<SBPlatform>(R); 73 RegisterMethods<SBProcess>(R); 74 RegisterMethods<SBProcessInfo>(R); 75 RegisterMethods<SBQueue>(R); 76 RegisterMethods<SBQueueItem>(R); 77 RegisterMethods<SBSection>(R); 78 RegisterMethods<SBSourceManager>(R); 79 RegisterMethods<SBStream>(R); 80 RegisterMethods<SBStringList>(R); 81 RegisterMethods<SBStructuredData>(R); 82 RegisterMethods<SBSymbol>(R); 83 RegisterMethods<SBSymbolContext>(R); 84 RegisterMethods<SBSymbolContextList>(R); 85 RegisterMethods<SBTarget>(R); 86 RegisterMethods<SBThread>(R); 87 RegisterMethods<SBThreadCollection>(R); 88 RegisterMethods<SBThreadPlan>(R); 89 RegisterMethods<SBTrace>(R); 90 RegisterMethods<SBTraceOptions>(R); 91 RegisterMethods<SBType>(R); 92 RegisterMethods<SBTypeCategory>(R); 93 RegisterMethods<SBTypeEnumMember>(R); 94 RegisterMethods<SBTypeFilter>(R); 95 RegisterMethods<SBTypeFormat>(R); 96 RegisterMethods<SBTypeNameSpecifier>(R); 97 RegisterMethods<SBTypeSummaryOptions>(R); 98 RegisterMethods<SBTypeSummary>(R); 99 RegisterMethods<SBTypeSynthetic>(R); 100 RegisterMethods<SBUnixSignals>(R); 101 RegisterMethods<SBValue>(R); 102 RegisterMethods<SBValueList>(R); 103 RegisterMethods<SBVariablesOptions>(R); 104 RegisterMethods<SBWatchpoint>(R); 105 } 106 107 const char *SBReproducer::Capture() { 108 static std::string error; 109 if (auto e = Reproducer::Initialize(ReproducerMode::Capture, llvm::None)) { 110 error = llvm::toString(std::move(e)); 111 return error.c_str(); 112 } 113 return nullptr; 114 } 115 116 const char *SBReproducer::Capture(const char *path) { 117 static std::string error; 118 if (auto e = 119 Reproducer::Initialize(ReproducerMode::Capture, FileSpec(path))) { 120 error = llvm::toString(std::move(e)); 121 return error.c_str(); 122 } 123 return nullptr; 124 } 125 126 const char *SBReproducer::Replay(const char *path) { 127 static std::string error; 128 if (auto e = Reproducer::Initialize(ReproducerMode::Replay, FileSpec(path))) { 129 error = llvm::toString(std::move(e)); 130 return error.c_str(); 131 } 132 133 repro::Loader *loader = repro::Reproducer::Instance().GetLoader(); 134 if (!loader) { 135 error = "unable to get replay loader."; 136 return error.c_str(); 137 } 138 139 FileSpec file = loader->GetFile<SBProvider::Info>(); 140 if (!file) { 141 error = "unable to get replay data from reproducer."; 142 return error.c_str(); 143 } 144 145 SBRegistry registry; 146 registry.Replay(file); 147 148 return nullptr; 149 } 150 151 char lldb_private::repro::SBProvider::ID = 0; 152 const char *SBProvider::Info::name = "sbapi"; 153 const char *SBProvider::Info::file = "sbapi.bin"; 154