aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectCommands.cpp
diff options
context:
space:
mode:
authorMed Ismail Bennani <medismail.bennani@gmail.com>2020-07-22 13:07:12 +0200
committerMed Ismail Bennani <medismail.bennani@gmail.com>2020-07-23 13:05:45 +0200
commit85fbb08fa2ac5195dc7a2f13eea7de1471da2a21 (patch)
tree13ba8b1a3e99f80ea80bc5c88c0cfb12e78b27d8 /lldb/source/Commands/CommandObjectCommands.cpp
parentf758d72eb852e3cb21acbf9ab8e5464adc689367 (diff)
downloadllvm-85fbb08fa2ac5195dc7a2f13eea7de1471da2a21.zip
llvm-85fbb08fa2ac5195dc7a2f13eea7de1471da2a21.tar.gz
llvm-85fbb08fa2ac5195dc7a2f13eea7de1471da2a21.tar.bz2
[lldb/interpreter] Move the history subcommand to session (NFCI)
This patch moves the `history` subcommand from the `command` to `session` command. I think it makes more sense to have it there because as the `command` usage suggests, it should be used to manage custom LLDB commands. However, `history` is essentially tied to a debugging session and holds all the commands (not specifically custom ones). This also makes it more discoverable by adding an alias for it (mimicking the shell builtin). Differential Revision: https://reviews.llvm.org/D84307 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
Diffstat (limited to 'lldb/source/Commands/CommandObjectCommands.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectCommands.cpp151
1 files changed, 0 insertions, 151 deletions
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp
index d77e69c..255fbe5 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -30,155 +30,6 @@ using namespace lldb_private;
// CommandObjectCommandsSource
-#define LLDB_OPTIONS_history
-#include "CommandOptions.inc"
-
-class CommandObjectCommandsHistory : public CommandObjectParsed {
-public:
- CommandObjectCommandsHistory(CommandInterpreter &interpreter)
- : CommandObjectParsed(interpreter, "command history",
- "Dump the history of commands in this session.\n"
- "Commands in the history list can be run again "
- "using \"!<INDEX>\". \"!-<OFFSET>\" will re-run "
- "the command that is <OFFSET> commands from the end"
- " of the list (counting the current command).",
- nullptr),
- m_options() {}
-
- ~CommandObjectCommandsHistory() override = default;
-
- Options *GetOptions() override { return &m_options; }
-
-protected:
- class CommandOptions : public Options {
- public:
- CommandOptions()
- : Options(), m_start_idx(0), m_stop_idx(0), m_count(0), m_clear(false) {
- }
-
- ~CommandOptions() override = default;
-
- Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
- ExecutionContext *execution_context) override {
- Status error;
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option) {
- case 'c':
- error = m_count.SetValueFromString(option_arg, eVarSetOperationAssign);
- break;
- case 's':
- if (option_arg == "end") {
- m_start_idx.SetCurrentValue(UINT64_MAX);
- m_start_idx.SetOptionWasSet();
- } else
- error = m_start_idx.SetValueFromString(option_arg,
- eVarSetOperationAssign);
- break;
- case 'e':
- error =
- m_stop_idx.SetValueFromString(option_arg, eVarSetOperationAssign);
- break;
- case 'C':
- m_clear.SetCurrentValue(true);
- m_clear.SetOptionWasSet();
- break;
- default:
- llvm_unreachable("Unimplemented option");
- }
-
- return error;
- }
-
- void OptionParsingStarting(ExecutionContext *execution_context) override {
- m_start_idx.Clear();
- m_stop_idx.Clear();
- m_count.Clear();
- m_clear.Clear();
- }
-
- llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
- return llvm::makeArrayRef(g_history_options);
- }
-
- // Instance variables to hold the values for command options.
-
- OptionValueUInt64 m_start_idx;
- OptionValueUInt64 m_stop_idx;
- OptionValueUInt64 m_count;
- OptionValueBoolean m_clear;
- };
-
- bool DoExecute(Args &command, CommandReturnObject &result) override {
- if (m_options.m_clear.GetCurrentValue() &&
- m_options.m_clear.OptionWasSet()) {
- m_interpreter.GetCommandHistory().Clear();
- result.SetStatus(lldb::eReturnStatusSuccessFinishNoResult);
- } else {
- if (m_options.m_start_idx.OptionWasSet() &&
- m_options.m_stop_idx.OptionWasSet() &&
- m_options.m_count.OptionWasSet()) {
- result.AppendError("--count, --start-index and --end-index cannot be "
- "all specified in the same invocation");
- result.SetStatus(lldb::eReturnStatusFailed);
- } else {
- std::pair<bool, uint64_t> start_idx(
- m_options.m_start_idx.OptionWasSet(),
- m_options.m_start_idx.GetCurrentValue());
- std::pair<bool, uint64_t> stop_idx(
- m_options.m_stop_idx.OptionWasSet(),
- m_options.m_stop_idx.GetCurrentValue());
- std::pair<bool, uint64_t> count(m_options.m_count.OptionWasSet(),
- m_options.m_count.GetCurrentValue());
-
- const CommandHistory &history(m_interpreter.GetCommandHistory());
-
- if (start_idx.first && start_idx.second == UINT64_MAX) {
- if (count.first) {
- start_idx.second = history.GetSize() - count.second;
- stop_idx.second = history.GetSize() - 1;
- } else if (stop_idx.first) {
- start_idx.second = stop_idx.second;
- stop_idx.second = history.GetSize() - 1;
- } else {
- start_idx.second = 0;
- stop_idx.second = history.GetSize() - 1;
- }
- } else {
- if (!start_idx.first && !stop_idx.first && !count.first) {
- start_idx.second = 0;
- stop_idx.second = history.GetSize() - 1;
- } else if (start_idx.first) {
- if (count.first) {
- stop_idx.second = start_idx.second + count.second - 1;
- } else if (!stop_idx.first) {
- stop_idx.second = history.GetSize() - 1;
- }
- } else if (stop_idx.first) {
- if (count.first) {
- if (stop_idx.second >= count.second)
- start_idx.second = stop_idx.second - count.second + 1;
- else
- start_idx.second = 0;
- }
- } else /* if (count.first) */
- {
- start_idx.second = 0;
- stop_idx.second = count.second - 1;
- }
- }
- history.Dump(result.GetOutputStream(), start_idx.second,
- stop_idx.second);
- }
- }
- return result.Succeeded();
- }
-
- CommandOptions m_options;
-};
-
-// CommandObjectCommandsSource
-
#define LLDB_OPTIONS_source
#include "CommandOptions.inc"
@@ -1850,8 +1701,6 @@ CommandObjectMultiwordCommands::CommandObjectMultiwordCommands(
CommandObjectSP(new CommandObjectCommandsDelete(interpreter)));
LoadSubCommand(
"regex", CommandObjectSP(new CommandObjectCommandsAddRegex(interpreter)));
- LoadSubCommand("history", CommandObjectSP(
- new CommandObjectCommandsHistory(interpreter)));
LoadSubCommand(
"script",
CommandObjectSP(new CommandObjectMultiwordCommandsScript(interpreter)));