LLDB  mainline
SBReproducer.cpp
Go to the documentation of this file.
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 
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"
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"
27 #include "lldb/Version/Version.h"
28 
29 using namespace lldb;
30 using namespace lldb_private;
31 using namespace lldb_private::repro;
32 
34  : m_opaque_up(std::make_unique<ReplayOptions>()){}
35 
37  : m_opaque_up(std::make_unique<ReplayOptions>(*rhs.m_opaque_up)) {}
38 
40 
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 
49 void SBReplayOptions::SetVerify(bool verify) {
50  LLDB_INSTRUMENT_VA(this, verify) m_opaque_up->verify = verify;
51 }
52 
54  LLDB_INSTRUMENT_VA(this) return m_opaque_up->verify;
55 }
56 
58  LLDB_INSTRUMENT_VA(this, check)
59  m_opaque_up->check_version = check;
60 }
61 
63  LLDB_INSTRUMENT_VA(this)
64  return m_opaque_up->check_version;
65 }
66 
67 const char *SBReproducer::Capture() {
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 
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 
90 const char *SBReproducer::PassiveReplay(const char *path) {
91  LLDB_INSTRUMENT_VA(path)
92  return "Reproducer replay has been removed";
93 }
94 
95 const char *SBReproducer::Replay(const char *path) {
96  LLDB_INSTRUMENT_VA(path)
97  return "Reproducer replay has been removed";
98 }
99 
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 
105 const char *SBReproducer::Replay(const char *path,
106  const SBReplayOptions &options) {
107  LLDB_INSTRUMENT_VA(path, options)
108  return Replay(path);
109 }
110 
111 const char *SBReproducer::Finalize(const char *path) {
112  LLDB_INSTRUMENT_VA(path)
113  return "Reproducer finalize has been removed";
114 }
115 
118  auto &r = Reproducer::Instance();
119  if (auto generator = r.GetGenerator()) {
120  generator->Keep();
121  return true;
122  }
123  return false;
124 }
125 
128  auto &r = Reproducer::Instance();
129  if (auto generator = r.GetGenerator()) {
130  generator->SetAutoGenerate(b);
131  return true;
132  }
133  return false;
134 }
135 
136 const char *SBReproducer::GetPath() {
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 
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 }
lldb_private::toString
const char * toString(AppleArm64ExceptionClass EC)
Definition: AppleArm64ExceptionClass.h:38
Instrumentation.h
lldb::SBReplayOptions
Definition: SBReproducer.h:22
SBCommandInterpreterRunOptions.h
FileSystem.h
lldb::SBReproducer::Finalize
static const char * Finalize(const char *path)
Definition: SBReproducer.cpp:111
lldb::SBReplayOptions::GetCheckVersion
bool GetCheckVersion() const
Definition: SBReproducer.cpp:62
Reproducer.h
lldb::SBReproducer::PassiveReplay
static const char * PassiveReplay(const char *path)
Definition: SBReproducer.cpp:90
LLDB_INSTRUMENT
#define LLDB_INSTRUMENT()
Definition: Instrumentation.h:95
LLDB.h
lldb::SBReplayOptions::~SBReplayOptions
~SBReplayOptions()
lldb_private::repro::FileProvider
Definition: ReproducerProvider.h:94
lldb::SBReplayOptions::SetVerify
void SetVerify(bool verify)
Definition: SBReproducer.cpp:49
ReproducerProvider.h
lldb::SBReplayOptions::GetVerify
bool GetVerify() const
Definition: SBReproducer.cpp:53
lldb_private::FileSpec
Definition: FileSpec.h:56
SBData.h
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb::SBReproducer::Generate
static bool Generate()
Definition: SBReproducer.cpp:116
SBBlock.h
lldb::SBReplayOptions::operator=
SBReplayOptions & operator=(const SBReplayOptions &rhs)
Definition: SBReproducer.cpp:41
Version.h
SBFileSpec.h
lldb_private::ConstString
Definition: ConstString.h:40
SBAttachInfo.h
lldb::SBReplayOptions::SBReplayOptions
SBReplayOptions()
Definition: SBReproducer.cpp:33
SBDeclaration.h
SBDebugger.h
SBHostOS.h
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
SBAddress.h
lldb::SBReproducer::SetAutoGenerate
static bool SetAutoGenerate(bool b)
Definition: SBReproducer.cpp:126
lldb::SBReplayOptions::SetCheckVersion
void SetCheckVersion(bool check)
Definition: SBReproducer.cpp:57
lldb_private::repro
Definition: SBReproducer.h:15
lldb_private::ConstString::GetCString
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
lldb::SBReproducer::GetPath
static const char * GetPath()
Definition: SBReproducer.cpp:136
SBReproducer.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::SBReproducer::SetWorkingDirectory
static void SetWorkingDirectory(const char *path)
The working directory is set to the current working directory when the reproducers are initialized.
Definition: SBReproducer.cpp:145
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
SBCommandInterpreter.h
lldb_private::repro::ReplayOptions
Definition: Reproducer.h:223
fp
@ fp
Definition: CompactUnwindInfo.cpp:1248
lldb_private::repro::Reproducer::Instance
static Reproducer & Instance()
Definition: Reproducer.cpp:23
lldb::SBReproducer::Capture
static const char * Capture()
Definition: SBReproducer.cpp:67
lldb
Definition: SBAddress.h:15
lldb::SBReproducer::Replay
static const char * Replay(const char *path)
Definition: SBReproducer.cpp:95
lldb_private::repro::DirectoryProvider::SetDirectory
void SetDirectory(std::string directory)
Definition: ReproducerProvider.h:146
SBError.h
lldb_private::repro::WorkingDirectoryProvider
Provider for the current working directory.
Definition: ReproducerProvider.h:168
SBBreakpoint.h
lldb::SBReplayOptions::m_opaque_up
std::unique_ptr< lldb_private::repro::ReplayOptions > m_opaque_up
Definition: SBReproducer.h:37