[Reproducers] Change how reproducers are initialized.
This patch changes the way the reproducer is initialized. Rather than
making changes at run time we now do everything at initialization time.
To make this happen we had to introduce initializer options and their SB
variant. This allows us to tell the initializer that we're running in
reproducer capture/replay mode.
Because of this change we also had to alter our testing strategy. We
cannot reinitialize LLDB when using the dotest infrastructure. Instead
we use lit and invoke two instances of the driver.
Another consequence is that we can no longer enable capture or replay
through commands. This was bound to go away form the beginning, but I
had something in mind where you could enable/disable specific providers.
However this seems like it adds very little value right now so the
corresponding commands were removed.
Finally this change also means you now have to control this through the
driver, for which I replaced --reproducer with --capture and --replay to
differentiate between the two modes.
Differential revision: https://reviews.llvm.org/D55038
llvm-svn: 348152
diff --git a/lldb/source/Commands/CommandObjectReproducer.cpp b/lldb/source/Commands/CommandObjectReproducer.cpp
index 03a3e23..f393f17 100644
--- a/lldb/source/Commands/CommandObjectReproducer.cpp
+++ b/lldb/source/Commands/CommandObjectReproducer.cpp
@@ -19,65 +19,6 @@
using namespace lldb;
using namespace lldb_private;
-static void AppendErrorToResult(llvm::Error e, CommandReturnObject &result) {
- std::string error_str = llvm::toString(std::move(e));
- result.AppendErrorWithFormat("%s", error_str.c_str());
-}
-
-class CommandObjectReproducerCaptureEnable : public CommandObjectParsed {
-public:
- CommandObjectReproducerCaptureEnable(CommandInterpreter &interpreter)
- : CommandObjectParsed(interpreter, "reproducer capture enable",
- "Enable gathering information for reproducer",
- nullptr) {}
-
- ~CommandObjectReproducerCaptureEnable() override = default;
-
-protected:
- bool DoExecute(Args &command, CommandReturnObject &result) override {
- if (!command.empty()) {
- result.AppendErrorWithFormat("'%s' takes no arguments",
- m_cmd_name.c_str());
- return false;
- }
-
- if (auto e = m_interpreter.GetDebugger().SetReproducerCapture(true)) {
- AppendErrorToResult(std::move(e), result);
- return false;
- }
-
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- return result.Succeeded();
- }
-};
-
-class CommandObjectReproducerCaptureDisable : public CommandObjectParsed {
-public:
- CommandObjectReproducerCaptureDisable(CommandInterpreter &interpreter)
- : CommandObjectParsed(interpreter, "reproducer capture enable",
- "Disable gathering information for reproducer",
- nullptr) {}
-
- ~CommandObjectReproducerCaptureDisable() override = default;
-
-protected:
- bool DoExecute(Args &command, CommandReturnObject &result) override {
- if (!command.empty()) {
- result.AppendErrorWithFormat("'%s' takes no arguments",
- m_cmd_name.c_str());
- return false;
- }
-
- if (auto e = m_interpreter.GetDebugger().SetReproducerCapture(false)) {
- AppendErrorToResult(std::move(e), result);
- return false;
- }
-
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- return result.Succeeded();
- }
-};
-
class CommandObjectReproducerGenerate : public CommandObjectParsed {
public:
CommandObjectReproducerGenerate(CommandInterpreter &interpreter)
@@ -110,82 +51,47 @@
}
};
-class CommandObjectReproducerReplay : public CommandObjectParsed {
+class CommandObjectReproducerStatus : public CommandObjectParsed {
public:
- CommandObjectReproducerReplay(CommandInterpreter &interpreter)
- : CommandObjectParsed(interpreter, "reproducer replay",
- "Replay a reproducer.", nullptr) {
- CommandArgumentEntry arg1;
- CommandArgumentData path_arg;
+ CommandObjectReproducerStatus(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "reproducer status",
+ "Show the current reproducer status.", nullptr) {}
- // Define the first (and only) variant of this arg.
- path_arg.arg_type = eArgTypePath;
- path_arg.arg_repetition = eArgRepeatPlain;
-
- // There is only one variant this argument could be; put it into the
- // argument entry.
- arg1.push_back(path_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back(arg1);
- }
-
- ~CommandObjectReproducerReplay() override = default;
+ ~CommandObjectReproducerStatus() override = default;
protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
- if (command.empty()) {
- result.AppendErrorWithFormat(
- "'%s' takes a single argument: the reproducer path",
- m_cmd_name.c_str());
+ if (!command.empty()) {
+ result.AppendErrorWithFormat("'%s' takes no arguments",
+ m_cmd_name.c_str());
return false;
}
auto &r = repro::Reproducer::Instance();
+ if (auto generator = r.GetGenerator()) {
+ result.GetOutputStream() << "Reproducer is in capture mode.\n";
+ } else if (auto generator = r.GetLoader()) {
+ result.GetOutputStream() << "Reproducer is in replay mode.\n";
+ } else {
- const char *repro_path = command.GetArgumentAtIndex(0);
- if (auto e = r.SetReplay(FileSpec(repro_path))) {
- std::string error_str = llvm::toString(std::move(e));
- result.AppendErrorWithFormat("%s", error_str.c_str());
- return false;
+ result.GetOutputStream() << "Reproducer is off.\n";
}
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ result.SetStatus(eReturnStatusSuccessFinishResult);
return result.Succeeded();
}
};
-class CommandObjectReproducerCapture : public CommandObjectMultiword {
-private:
-public:
- CommandObjectReproducerCapture(CommandInterpreter &interpreter)
- : CommandObjectMultiword(
- interpreter, "reproducer capture",
- "Manage gathering of information needed to generate a reproducer.",
- NULL) {
- LoadSubCommand(
- "enable",
- CommandObjectSP(new CommandObjectReproducerCaptureEnable(interpreter)));
- LoadSubCommand("disable",
- CommandObjectSP(
- new CommandObjectReproducerCaptureDisable(interpreter)));
- }
-
- ~CommandObjectReproducerCapture() {}
-};
-
CommandObjectReproducer::CommandObjectReproducer(
CommandInterpreter &interpreter)
: CommandObjectMultiword(interpreter, "reproducer",
"Commands controlling LLDB reproducers.",
"log <subcommand> [<command-options>]") {
- LoadSubCommand("capture", CommandObjectSP(new CommandObjectReproducerCapture(
- interpreter)));
LoadSubCommand(
"generate",
CommandObjectSP(new CommandObjectReproducerGenerate(interpreter)));
- LoadSubCommand("replay", CommandObjectSP(
- new CommandObjectReproducerReplay(interpreter)));
+ LoadSubCommand("status", CommandObjectSP(
+ new CommandObjectReproducerStatus(interpreter)));
}
CommandObjectReproducer::~CommandObjectReproducer() = default;