| Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 1 | //===-- CommandObjectReproducer.cpp -----------------------------*- C++ -*-===// |
| 2 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
| Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "CommandObjectReproducer.h" |
| 10 | |
| 11 | #include "lldb/Utility/Reproducer.h" |
| 12 | |
| Jonas Devlieghere | df14b94 | 2018-11-15 01:05:40 +0000 | [diff] [blame] | 13 | #include "lldb/Interpreter/CommandInterpreter.h" |
| Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 14 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 15 | #include "lldb/Interpreter/OptionArgParser.h" |
| 16 | #include "lldb/Interpreter/OptionGroupBoolean.h" |
| 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
| Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 21 | class CommandObjectReproducerGenerate : public CommandObjectParsed { |
| 22 | public: |
| 23 | CommandObjectReproducerGenerate(CommandInterpreter &interpreter) |
| Jonas Devlieghere | 973d66e | 2019-05-03 00:10:31 +0000 | [diff] [blame^] | 24 | : CommandObjectParsed( |
| 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) {} |
| Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 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(); |
| Jonas Devlieghere | 2dca653 | 2019-02-27 17:47:06 +0000 | [diff] [blame] | 44 | } else if (r.GetLoader()) { |
| 45 | // Make this operation a NOP in replay mode. |
| 46 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 47 | return result.Succeeded(); |
| Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 48 | } else { |
| 49 | result.AppendErrorWithFormat("Unable to get the reproducer generator"); |
| Jonas Devlieghere | 2dca653 | 2019-02-27 17:47:06 +0000 | [diff] [blame] | 50 | result.SetStatus(eReturnStatusFailed); |
| Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 51 | return false; |
| 52 | } |
| 53 | |
| 54 | result.GetOutputStream() |
| 55 | << "Reproducer written to '" << r.GetReproducerPath() << "'\n"; |
| Jonas Devlieghere | 1c5250a | 2019-04-02 18:23:16 +0000 | [diff] [blame] | 56 | result.GetOutputStream() |
| 57 | << "Please have a look at the directory to assess if you're willing to " |
| 58 | "share the contained information.\n"; |
| Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 59 | |
| 60 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 61 | return result.Succeeded(); |
| 62 | } |
| 63 | }; |
| 64 | |
| Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 65 | class CommandObjectReproducerStatus : public CommandObjectParsed { |
| Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 66 | public: |
| Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 67 | CommandObjectReproducerStatus(CommandInterpreter &interpreter) |
| Jonas Devlieghere | 973d66e | 2019-05-03 00:10:31 +0000 | [diff] [blame^] | 68 | : CommandObjectParsed( |
| 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) {} |
| Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 76 | |
| Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 77 | ~CommandObjectReproducerStatus() override = default; |
| Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 78 | |
| 79 | protected: |
| 80 | bool DoExecute(Args &command, CommandReturnObject &result) override { |
| Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 81 | if (!command.empty()) { |
| 82 | result.AppendErrorWithFormat("'%s' takes no arguments", |
| 83 | m_cmd_name.c_str()); |
| Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 84 | return false; |
| 85 | } |
| 86 | |
| 87 | auto &r = repro::Reproducer::Instance(); |
| Zachary Turner | 52f8f34 | 2019-01-29 22:55:21 +0000 | [diff] [blame] | 88 | if (r.GetGenerator()) { |
| Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 89 | result.GetOutputStream() << "Reproducer is in capture mode.\n"; |
| Zachary Turner | 52f8f34 | 2019-01-29 22:55:21 +0000 | [diff] [blame] | 90 | } else if (r.GetLoader()) { |
| Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 91 | result.GetOutputStream() << "Reproducer is in replay mode.\n"; |
| 92 | } else { |
| Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 93 | result.GetOutputStream() << "Reproducer is off.\n"; |
| Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 96 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 97 | return result.Succeeded(); |
| 98 | } |
| 99 | }; |
| 100 | |
| Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 101 | CommandObjectReproducer::CommandObjectReproducer( |
| 102 | CommandInterpreter &interpreter) |
| Jonas Devlieghere | 973d66e | 2019-05-03 00:10:31 +0000 | [diff] [blame^] | 103 | : CommandObjectMultiword( |
| 104 | interpreter, "reproducer", |
| 105 | "Commands to inspect and manipulate the reproducer functionality.", |
| 106 | "log <subcommand> [<command-options>]") { |
| Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 107 | LoadSubCommand( |
| 108 | "generate", |
| 109 | CommandObjectSP(new CommandObjectReproducerGenerate(interpreter))); |
| Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 110 | LoadSubCommand("status", CommandObjectSP( |
| 111 | new CommandObjectReproducerStatus(interpreter))); |
| Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | CommandObjectReproducer::~CommandObjectReproducer() = default; |