LLDB  mainline
CommandObjectReproducer.cpp
Go to the documentation of this file.
1 //===-- CommandObjectReproducer.cpp -----------------------------*- C++ -*-===//
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 
12 
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 
22 public:
25  interpreter, "reproducer generate",
26  "Generate reproducer on disk. When the debugger is in capture "
27  "mode, this command will output the reproducer to a directory on "
28  "disk. In replay mode this command in a no-op.",
29  nullptr) {}
30 
31  ~CommandObjectReproducerGenerate() override = default;
32 
33 protected:
34  bool DoExecute(Args &command, CommandReturnObject &result) override {
35  if (!command.empty()) {
36  result.AppendErrorWithFormat("'%s' takes no arguments",
37  m_cmd_name.c_str());
38  return false;
39  }
40 
41  auto &r = repro::Reproducer::Instance();
42  if (auto generator = r.GetGenerator()) {
43  generator->Keep();
44  } else if (r.GetLoader()) {
45  // Make this operation a NOP in replay mode.
47  return result.Succeeded();
48  } else {
49  result.AppendErrorWithFormat("Unable to get the reproducer generator");
51  return false;
52  }
53 
54  result.GetOutputStream()
55  << "Reproducer written to '" << r.GetReproducerPath() << "'\n";
56  result.GetOutputStream()
57  << "Please have a look at the directory to assess if you're willing to "
58  "share the contained information.\n";
59 
61  return result.Succeeded();
62  }
63 };
64 
66 public:
69  interpreter, "reproducer status",
70  "Show the current reproducer status. In capture mode the debugger "
71  "is collecting all the information it needs to create a "
72  "reproducer. In replay mode the reproducer is replaying a "
73  "reproducer. When the reproducers are off, no data is collected "
74  "and no reproducer can be generated.",
75  nullptr) {}
76 
77  ~CommandObjectReproducerStatus() override = default;
78 
79 protected:
80  bool DoExecute(Args &command, CommandReturnObject &result) override {
81  if (!command.empty()) {
82  result.AppendErrorWithFormat("'%s' takes no arguments",
83  m_cmd_name.c_str());
84  return false;
85  }
86 
87  auto &r = repro::Reproducer::Instance();
88  if (r.GetGenerator()) {
89  result.GetOutputStream() << "Reproducer is in capture mode.\n";
90  } else if (r.GetLoader()) {
91  result.GetOutputStream() << "Reproducer is in replay mode.\n";
92  } else {
93  result.GetOutputStream() << "Reproducer is off.\n";
94  }
95 
97  return result.Succeeded();
98  }
99 };
100 
101 CommandObjectReproducer::CommandObjectReproducer(
102  CommandInterpreter &interpreter)
104  interpreter, "reproducer",
105  "Commands to inspect and manipulate the reproducer functionality.",
106  "log <subcommand> [<command-options>]") {
108  "generate",
109  CommandObjectSP(new CommandObjectReproducerGenerate(interpreter)));
110  LoadSubCommand("status", CommandObjectSP(
111  new CommandObjectReproducerStatus(interpreter)));
112 }
113 
A command line argument class.
Definition: Args.h:32
bool empty() const
Definition: Args.h:113
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
bool DoExecute(Args &command, CommandReturnObject &result) override
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
bool DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectReproducerGenerate(CommandInterpreter &interpreter)
Definition: SBAddress.h:15
CommandObjectReproducerStatus(CommandInterpreter &interpreter)
void SetStatus(lldb::ReturnStatus status)