1 //===-- CommandObjectReproducer.cpp -----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "CommandObjectReproducer.h"
12 #include "lldb/Utility/Reproducer.h"
14 #include "lldb/Interpreter/CommandInterpreter.h"
15 #include "lldb/Interpreter/CommandReturnObject.h"
16 #include "lldb/Interpreter/OptionArgParser.h"
17 #include "lldb/Interpreter/OptionGroupBoolean.h"
20 using namespace lldb_private;
22 class CommandObjectReproducerGenerate : public CommandObjectParsed {
24 CommandObjectReproducerGenerate(CommandInterpreter &interpreter)
25 : CommandObjectParsed(interpreter, "reproducer generate",
26 "Generate reproducer on disk.", nullptr) {}
28 ~CommandObjectReproducerGenerate() override = default;
31 bool DoExecute(Args &command, CommandReturnObject &result) override {
32 if (!command.empty()) {
33 result.AppendErrorWithFormat("'%s' takes no arguments",
38 auto &r = repro::Reproducer::Instance();
39 if (auto generator = r.GetGenerator()) {
42 result.AppendErrorWithFormat("Unable to get the reproducer generator");
46 result.GetOutputStream()
47 << "Reproducer written to '" << r.GetReproducerPath() << "'\n";
49 result.SetStatus(eReturnStatusSuccessFinishResult);
50 return result.Succeeded();
54 class CommandObjectReproducerStatus : public CommandObjectParsed {
56 CommandObjectReproducerStatus(CommandInterpreter &interpreter)
57 : CommandObjectParsed(interpreter, "reproducer status",
58 "Show the current reproducer status.", nullptr) {}
60 ~CommandObjectReproducerStatus() override = default;
63 bool DoExecute(Args &command, CommandReturnObject &result) override {
64 if (!command.empty()) {
65 result.AppendErrorWithFormat("'%s' takes no arguments",
70 auto &r = repro::Reproducer::Instance();
71 if (auto generator = r.GetGenerator()) {
72 result.GetOutputStream() << "Reproducer is in capture mode.\n";
73 } else if (auto generator = r.GetLoader()) {
74 result.GetOutputStream() << "Reproducer is in replay mode.\n";
77 result.GetOutputStream() << "Reproducer is off.\n";
80 result.SetStatus(eReturnStatusSuccessFinishResult);
81 return result.Succeeded();
85 CommandObjectReproducer::CommandObjectReproducer(
86 CommandInterpreter &interpreter)
87 : CommandObjectMultiword(interpreter, "reproducer",
88 "Commands controlling LLDB reproducers.",
89 "log <subcommand> [<command-options>]") {
92 CommandObjectSP(new CommandObjectReproducerGenerate(interpreter)));
93 LoadSubCommand("status", CommandObjectSP(
94 new CommandObjectReproducerStatus(interpreter)));
97 CommandObjectReproducer::~CommandObjectReproducer() = default;