1 //===-- SBReproducer.cpp ----------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "SBReproducerPrivate.h"
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 #include "lldb/Host/FileSystem.h"
26 #include "lldb/lldb-private.h"
29 using namespace lldb_private
;
30 using namespace lldb_private::repro
;
32 SBRegistry::SBRegistry() {
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
<SBFile
>(R
);
56 RegisterMethods
<SBFileSpec
>(R
);
57 RegisterMethods
<SBFileSpecList
>(R
);
58 RegisterMethods
<SBFrame
>(R
);
59 RegisterMethods
<SBFunction
>(R
);
60 RegisterMethods
<SBHostOS
>(R
);
61 RegisterMethods
<SBInstruction
>(R
);
62 RegisterMethods
<SBInstructionList
>(R
);
63 RegisterMethods
<SBLanguageRuntime
>(R
);
64 RegisterMethods
<SBLaunchInfo
>(R
);
65 RegisterMethods
<SBLineEntry
>(R
);
66 RegisterMethods
<SBListener
>(R
);
67 RegisterMethods
<SBMemoryRegionInfo
>(R
);
68 RegisterMethods
<SBMemoryRegionInfoList
>(R
);
69 RegisterMethods
<SBModule
>(R
);
70 RegisterMethods
<SBModuleSpec
>(R
);
71 RegisterMethods
<SBPlatformConnectOptions
>(R
);
72 RegisterMethods
<SBPlatformShellCommand
>(R
);
73 RegisterMethods
<SBPlatform
>(R
);
74 RegisterMethods
<SBProcess
>(R
);
75 RegisterMethods
<SBProcessInfo
>(R
);
76 RegisterMethods
<SBQueue
>(R
);
77 RegisterMethods
<SBQueueItem
>(R
);
78 RegisterMethods
<SBSection
>(R
);
79 RegisterMethods
<SBSourceManager
>(R
);
80 RegisterMethods
<SBStream
>(R
);
81 RegisterMethods
<SBStringList
>(R
);
82 RegisterMethods
<SBStructuredData
>(R
);
83 RegisterMethods
<SBSymbol
>(R
);
84 RegisterMethods
<SBSymbolContext
>(R
);
85 RegisterMethods
<SBSymbolContextList
>(R
);
86 RegisterMethods
<SBTarget
>(R
);
87 RegisterMethods
<SBThread
>(R
);
88 RegisterMethods
<SBThreadCollection
>(R
);
89 RegisterMethods
<SBThreadPlan
>(R
);
90 RegisterMethods
<SBTrace
>(R
);
91 RegisterMethods
<SBTraceOptions
>(R
);
92 RegisterMethods
<SBType
>(R
);
93 RegisterMethods
<SBTypeCategory
>(R
);
94 RegisterMethods
<SBTypeEnumMember
>(R
);
95 RegisterMethods
<SBTypeFilter
>(R
);
96 RegisterMethods
<SBTypeFormat
>(R
);
97 RegisterMethods
<SBTypeNameSpecifier
>(R
);
98 RegisterMethods
<SBTypeSummaryOptions
>(R
);
99 RegisterMethods
<SBTypeSummary
>(R
);
100 RegisterMethods
<SBTypeSynthetic
>(R
);
101 RegisterMethods
<SBUnixSignals
>(R
);
102 RegisterMethods
<SBValue
>(R
);
103 RegisterMethods
<SBValueList
>(R
);
104 RegisterMethods
<SBVariablesOptions
>(R
);
105 RegisterMethods
<SBWatchpoint
>(R
);
108 const char *SBReproducer::Capture() {
109 static std::string error
;
110 if (auto e
= Reproducer::Initialize(ReproducerMode::Capture
, llvm::None
)) {
111 error
= llvm::toString(std::move(e
));
112 return error
.c_str();
117 const char *SBReproducer::Capture(const char *path
) {
118 static std::string error
;
120 Reproducer::Initialize(ReproducerMode::Capture
, FileSpec(path
))) {
121 error
= llvm::toString(std::move(e
));
122 return error
.c_str();
127 const char *SBReproducer::Replay(const char *path
) {
128 return SBReproducer::Replay(path
, false);
131 const char *SBReproducer::Replay(const char *path
, bool skip_version_check
) {
132 static std::string error
;
133 if (auto e
= Reproducer::Initialize(ReproducerMode::Replay
, FileSpec(path
))) {
134 error
= llvm::toString(std::move(e
));
135 return error
.c_str();
138 repro::Loader
*loader
= repro::Reproducer::Instance().GetLoader();
140 error
= "unable to get replay loader.";
141 return error
.c_str();
144 if (!skip_version_check
) {
145 llvm::Expected
<std::string
> version
= loader
->LoadBuffer
<VersionProvider
>();
147 error
= llvm::toString(version
.takeError());
148 return error
.c_str();
150 if (lldb_private::GetVersion() != llvm::StringRef(*version
).rtrim()) {
151 error
= "reproducer capture and replay version don't match:\n";
152 error
.append("reproducer captured with:\n");
153 error
.append(*version
);
154 error
.append("reproducer replayed with:\n");
155 error
.append(lldb_private::GetVersion());
156 return error
.c_str();
160 FileSpec file
= loader
->GetFile
<SBProvider::Info
>();
162 error
= "unable to get replay data from reproducer.";
163 return error
.c_str();
167 registry
.Replay(file
);
172 bool SBReproducer::Generate() {
173 auto &r
= Reproducer::Instance();
174 if (auto generator
= r
.GetGenerator()) {
181 bool SBReproducer::SetAutoGenerate(bool b
) {
182 auto &r
= Reproducer::Instance();
183 if (auto generator
= r
.GetGenerator()) {
184 generator
->SetAutoGenerate(b
);
190 const char *SBReproducer::GetPath() {
191 static std::string path
;
192 auto &r
= Reproducer::Instance();
193 path
= r
.GetReproducerPath().GetCString();
197 char lldb_private::repro::SBProvider::ID
= 0;
198 const char *SBProvider::Info::name
= "sbapi";
199 const char *SBProvider::Info::file
= "sbapi.bin";