1 //===-- SBReproducer.cpp --------------------------------------------------===//
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 "lldb/API/SBReproducer.h"
10 #include "lldb/API/LLDB.h"
11 #include "lldb/API/SBAddress.h"
12 #include "lldb/API/SBAttachInfo.h"
13 #include "lldb/API/SBBlock.h"
14 #include "lldb/API/SBBreakpoint.h"
15 #include "lldb/API/SBCommandInterpreter.h"
16 #include "lldb/API/SBCommandInterpreterRunOptions.h"
17 #include "lldb/API/SBData.h"
18 #include "lldb/API/SBDebugger.h"
19 #include "lldb/API/SBDeclaration.h"
20 #include "lldb/API/SBError.h"
21 #include "lldb/API/SBFileSpec.h"
22 #include "lldb/API/SBHostOS.h"
23 #include "lldb/Host/FileSystem.h"
24 #include "lldb/Utility/Instrumentation.h"
25 #include "lldb/Utility/Reproducer.h"
26 #include "lldb/Utility/ReproducerProvider.h"
27 #include "lldb/Version/Version.h"
28
29 using namespace lldb;
30 using namespace lldb_private;
31 using namespace lldb_private::repro;
32
SBReplayOptions()33 SBReplayOptions::SBReplayOptions()
34 : m_opaque_up(std::make_unique<ReplayOptions>()){}
35
SBReplayOptions(const SBReplayOptions & rhs)36 SBReplayOptions::SBReplayOptions(const SBReplayOptions &rhs)
37 : m_opaque_up(std::make_unique<ReplayOptions>(*rhs.m_opaque_up)) {}
38
39 SBReplayOptions::~SBReplayOptions() = default;
40
operator =(const SBReplayOptions & rhs)41 SBReplayOptions &SBReplayOptions::operator=(const SBReplayOptions &rhs) {
42 LLDB_INSTRUMENT_VA(this, rhs)
43 if (this == &rhs)
44 return *this;
45 *m_opaque_up = *rhs.m_opaque_up;
46 return *this;
47 }
48
SetVerify(bool verify)49 void SBReplayOptions::SetVerify(bool verify) {
50 LLDB_INSTRUMENT_VA(this, verify) m_opaque_up->verify = verify;
51 }
52
GetVerify() const53 bool SBReplayOptions::GetVerify() const {
54 LLDB_INSTRUMENT_VA(this) return m_opaque_up->verify;
55 }
56
SetCheckVersion(bool check)57 void SBReplayOptions::SetCheckVersion(bool check) {
58 LLDB_INSTRUMENT_VA(this, check)
59 m_opaque_up->check_version = check;
60 }
61
GetCheckVersion() const62 bool SBReplayOptions::GetCheckVersion() const {
63 LLDB_INSTRUMENT_VA(this)
64 return m_opaque_up->check_version;
65 }
66
Capture()67 const char *SBReproducer::Capture() {
68 LLDB_INSTRUMENT()
69 static std::string error;
70 if (auto e = Reproducer::Initialize(ReproducerMode::Capture, llvm::None)) {
71 error = llvm::toString(std::move(e));
72 return error.c_str();
73 }
74
75 return nullptr;
76 }
77
Capture(const char * path)78 const char *SBReproducer::Capture(const char *path) {
79 LLDB_INSTRUMENT_VA(path)
80 static std::string error;
81 if (auto e =
82 Reproducer::Initialize(ReproducerMode::Capture, FileSpec(path))) {
83 error = llvm::toString(std::move(e));
84 return error.c_str();
85 }
86
87 return nullptr;
88 }
89
PassiveReplay(const char * path)90 const char *SBReproducer::PassiveReplay(const char *path) {
91 LLDB_INSTRUMENT_VA(path)
92 return "Reproducer replay has been removed";
93 }
94
Replay(const char * path)95 const char *SBReproducer::Replay(const char *path) {
96 LLDB_INSTRUMENT_VA(path)
97 return "Reproducer replay has been removed";
98 }
99
Replay(const char * path,bool skip_version_check)100 const char *SBReproducer::Replay(const char *path, bool skip_version_check) {
101 LLDB_INSTRUMENT_VA(path, skip_version_check)
102 return Replay(path);
103 }
104
Replay(const char * path,const SBReplayOptions & options)105 const char *SBReproducer::Replay(const char *path,
106 const SBReplayOptions &options) {
107 LLDB_INSTRUMENT_VA(path, options)
108 return Replay(path);
109 }
110
Finalize(const char * path)111 const char *SBReproducer::Finalize(const char *path) {
112 LLDB_INSTRUMENT_VA(path)
113 return "Reproducer finalize has been removed";
114 }
115
Generate()116 bool SBReproducer::Generate() {
117 LLDB_INSTRUMENT()
118 auto &r = Reproducer::Instance();
119 if (auto generator = r.GetGenerator()) {
120 generator->Keep();
121 return true;
122 }
123 return false;
124 }
125
SetAutoGenerate(bool b)126 bool SBReproducer::SetAutoGenerate(bool b) {
127 LLDB_INSTRUMENT_VA(b)
128 auto &r = Reproducer::Instance();
129 if (auto generator = r.GetGenerator()) {
130 generator->SetAutoGenerate(b);
131 return true;
132 }
133 return false;
134 }
135
GetPath()136 const char *SBReproducer::GetPath() {
137 LLDB_INSTRUMENT()
138 ConstString path;
139 auto &r = Reproducer::Instance();
140 if (FileSpec reproducer_path = Reproducer::Instance().GetReproducerPath())
141 path = ConstString(r.GetReproducerPath().GetCString());
142 return path.GetCString();
143 }
144
SetWorkingDirectory(const char * path)145 void SBReproducer::SetWorkingDirectory(const char *path) {
146 LLDB_INSTRUMENT_VA(path)
147 if (auto *g = lldb_private::repro::Reproducer::Instance().GetGenerator()) {
148 auto &wp = g->GetOrCreate<repro::WorkingDirectoryProvider>();
149 wp.SetDirectory(path);
150 auto &fp = g->GetOrCreate<repro::FileProvider>();
151 fp.RecordInterestingDirectory(wp.GetDirectory());
152 }
153 }
154