11
11
12
12
#include " lldb/Utility/FileCollector.h"
13
13
#include " lldb/Utility/FileSpec.h"
14
-
15
14
#include " llvm/ADT/DenseMap.h"
16
15
#include " llvm/Support/Error.h"
17
16
#include " llvm/Support/YAMLTraits.h"
@@ -130,6 +129,27 @@ class VersionProvider : public Provider<VersionProvider> {
130
129
static char ID;
131
130
};
132
131
132
+ // / Provider for the LLDB current working directroy.
133
+ // /
134
+ // / When the reproducer is kept, it writes lldb's current working directory to
135
+ // / a file named cwd.txt in the reproducer root.
136
+ class WorkingDirectoryProvider : public Provider <WorkingDirectoryProvider> {
137
+ public:
138
+ WorkingDirectoryProvider (const FileSpec &directory) : Provider(directory) {
139
+ llvm::SmallString<128 > cwd;
140
+ if (std::error_code EC = llvm::sys::fs::current_path (cwd))
141
+ return ;
142
+ m_cwd = cwd.str ();
143
+ }
144
+ struct Info {
145
+ static const char *name;
146
+ static const char *file;
147
+ };
148
+ void Keep () override ;
149
+ std::string m_cwd;
150
+ static char ID;
151
+ };
152
+
133
153
class DataRecorder {
134
154
public:
135
155
DataRecorder (const FileSpec &filename, std::error_code &ec)
@@ -181,12 +201,39 @@ class CommandProvider : public Provider<CommandProvider> {
181
201
std::vector<std::unique_ptr<DataRecorder>> m_data_recorders;
182
202
};
183
203
204
+ class ProcessGDBRemoteProvider
205
+ : public repro::Provider<ProcessGDBRemoteProvider> {
206
+ public:
207
+ struct Info {
208
+ static const char *name;
209
+ static const char *file;
210
+ };
211
+
212
+ ProcessGDBRemoteProvider (const FileSpec &directory) : Provider(directory) {}
213
+
214
+ llvm::raw_ostream *GetHistoryStream ();
215
+
216
+ void SetCallback (std::function<void ()> callback) {
217
+ m_callback = std::move (callback);
218
+ }
219
+
220
+ void Keep () override { m_callback (); }
221
+ void Discard () override { m_callback (); }
222
+
223
+ static char ID;
224
+
225
+ private:
226
+ std::function<void ()> m_callback;
227
+ std::unique_ptr<llvm::raw_fd_ostream> m_stream_up;
228
+ };
229
+
184
230
// / The generator is responsible for the logic needed to generate a
185
231
// / reproducer. For doing so it relies on providers, who serialize data that
186
232
// / is necessary for reproducing a failure.
187
233
class Generator final {
234
+
188
235
public:
189
- Generator (const FileSpec & root);
236
+ Generator (FileSpec root);
190
237
~Generator ();
191
238
192
239
// / Method to indicate we want to keep the reproducer. If reproducer
@@ -243,7 +290,7 @@ class Generator final {
243
290
244
291
class Loader final {
245
292
public:
246
- Loader (const FileSpec & root);
293
+ Loader (FileSpec root);
247
294
248
295
template <typename T> FileSpec GetFile () {
249
296
if (!HasFile (T::file))
@@ -252,6 +299,15 @@ class Loader final {
252
299
return GetRoot ().CopyByAppendingPathComponent (T::file);
253
300
}
254
301
302
+ template <typename T> llvm::Expected<std::string> LoadBuffer () {
303
+ FileSpec file = GetFile<typename T::Info>();
304
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer =
305
+ llvm::vfs::getRealFileSystem ()->getBufferForFile (file.GetPath ());
306
+ if (!buffer)
307
+ return llvm::errorCodeToError (buffer.getError ());
308
+ return (*buffer)->getBuffer ().str ();
309
+ }
310
+
255
311
llvm::Error LoadIndex ();
256
312
257
313
const FileSpec &GetRoot () const { return m_root; }
@@ -284,6 +340,9 @@ class Reproducer {
284
340
285
341
FileSpec GetReproducerPath () const ;
286
342
343
+ bool IsCapturing () { return static_cast <bool >(m_generator); };
344
+ bool IsReplaying () { return static_cast <bool >(m_loader); };
345
+
287
346
protected:
288
347
llvm::Error SetCapture (llvm::Optional<FileSpec> root);
289
348
llvm::Error SetReplay (llvm::Optional<FileSpec> root);
@@ -297,6 +356,19 @@ class Reproducer {
297
356
mutable std::mutex m_mutex;
298
357
};
299
358
359
+ // / Helper class for replaying commands through the reproducer.
360
+ class CommandLoader {
361
+ public:
362
+ CommandLoader (std::vector<std::string> files) : m_files(files) {}
363
+
364
+ static std::unique_ptr<CommandLoader> Create (Loader *loader);
365
+ llvm::Optional<std::string> GetNextFile ();
366
+
367
+ private:
368
+ std::vector<std::string> m_files;
369
+ unsigned m_index = 0 ;
370
+ };
371
+
300
372
} // namespace repro
301
373
} // namespace lldb_private
302
374
0 commit comments