aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectLog.cpp
diff options
context:
space:
mode:
authorShu Anzai <shu.anzai@gmail.com>2020-04-09 08:11:55 +0200
committerRaphael Isemann <teemperor@gmail.com>2020-04-09 08:58:52 +0200
commit1d3b7370c466eba4bf22dce4a51f885f76698053 (patch)
treec38e9b328e150b73838fe586c29d78df8b9e4944 /lldb/source/Commands/CommandObjectLog.cpp
parentc7ff5b38f27f812dcd6e2e8732208a39232dc284 (diff)
downloadllvm-1d3b7370c466eba4bf22dce4a51f885f76698053.zip
llvm-1d3b7370c466eba4bf22dce4a51f885f76698053.tar.gz
llvm-1d3b7370c466eba4bf22dce4a51f885f76698053.tar.bz2
[lldb] Fixing the bug that the "log timer" has no tab completion
I fixed the bug that the "log timer" has no tab command. Original code has the only CommandObjectLogTimer class, but it is not sufficient. Thus I divided the content of CommandObjectLog class into CommandObjectLogEnable class, CommandObjectLogDisable class, CommandObjectLogDump class, CommandObjectLogReset class, CommandObjectLogIncrement class. Reviewed by: teemperor Differential Revision: https://reviews.llvm.org/D76906
Diffstat (limited to 'lldb/source/Commands/CommandObjectLog.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectLog.cpp221
1 files changed, 177 insertions, 44 deletions
diff --git a/lldb/source/Commands/CommandObjectLog.cpp b/lldb/source/Commands/CommandObjectLog.cpp
index 233831f..4016b07 100644
--- a/lldb/source/Commands/CommandObjectLog.cpp
+++ b/lldb/source/Commands/CommandObjectLog.cpp
@@ -298,61 +298,170 @@ protected:
}
};
-class CommandObjectLogTimer : public CommandObjectParsed {
+class CommandObjectLogTimerEnable : public CommandObjectParsed {
public:
// Constructors and Destructors
- CommandObjectLogTimer(CommandInterpreter &interpreter)
- : CommandObjectParsed(interpreter, "log timers",
- "Enable, disable, dump, and reset LLDB internal "
- "performance timers.",
- "log timers < enable <depth> | disable | dump | "
- "increment <bool> | reset >") {}
+ CommandObjectLogTimerEnable(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "log timers enable",
+ "enable LLDB internal performance timers",
+ "log timers enable <depth>") {
+ CommandArgumentEntry arg;
+ CommandArgumentData depth_arg;
- ~CommandObjectLogTimer() override = default;
+ // Define the first (and only) variant of this arg.
+ depth_arg.arg_type = eArgTypeCount;
+ depth_arg.arg_repetition = eArgRepeatOptional;
+
+ // There is only one variant this argument could be; put it into the
+ // argument entry.
+ arg.push_back(depth_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back(arg);
+ }
+
+ ~CommandObjectLogTimerEnable() override = default;
+
+protected:
+ bool DoExecute(Args &args, CommandReturnObject &result) override {
+ result.SetStatus(eReturnStatusFailed);
+
+ if (args.GetArgumentCount() == 0) {
+ Timer::SetDisplayDepth(UINT32_MAX);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ } else if (args.GetArgumentCount() == 1) {
+ uint32_t depth;
+ if (args[0].ref().consumeInteger(0, depth)) {
+ result.AppendError(
+ "Could not convert enable depth to an unsigned integer.");
+ } else {
+ Timer::SetDisplayDepth(depth);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ }
+ }
+
+ if (!result.Succeeded()) {
+ result.AppendError("Missing subcommand");
+ result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str());
+ }
+ return result.Succeeded();
+ }
+};
+
+class CommandObjectLogTimerDisable : public CommandObjectParsed {
+public:
+ // Constructors and Destructors
+ CommandObjectLogTimerDisable(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "log timers disable",
+ "disable LLDB internal performance timers",
+ nullptr) {}
+
+ ~CommandObjectLogTimerDisable() override = default;
+
+protected:
+ bool DoExecute(Args &args, CommandReturnObject &result) override {
+ Timer::DumpCategoryTimes(&result.GetOutputStream());
+ Timer::SetDisplayDepth(0);
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+
+ if (!result.Succeeded()) {
+ result.AppendError("Missing subcommand");
+ result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str());
+ }
+ return result.Succeeded();
+ }
+};
+
+class CommandObjectLogTimerDump : public CommandObjectParsed {
+public:
+ // Constructors and Destructors
+ CommandObjectLogTimerDump(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "log timers dump",
+ "dump LLDB internal performance timers", nullptr) {}
+
+ ~CommandObjectLogTimerDump() override = default;
+
+protected:
+ bool DoExecute(Args &args, CommandReturnObject &result) override {
+ Timer::DumpCategoryTimes(&result.GetOutputStream());
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+
+ if (!result.Succeeded()) {
+ result.AppendError("Missing subcommand");
+ result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str());
+ }
+ return result.Succeeded();
+ }
+};
+
+class CommandObjectLogTimerReset : public CommandObjectParsed {
+public:
+ // Constructors and Destructors
+ CommandObjectLogTimerReset(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "log timers reset",
+ "reset LLDB internal performance timers", nullptr) {
+ }
+
+ ~CommandObjectLogTimerReset() override = default;
+
+protected:
+ bool DoExecute(Args &args, CommandReturnObject &result) override {
+ Timer::ResetCategoryTimes();
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+
+ if (!result.Succeeded()) {
+ result.AppendError("Missing subcommand");
+ result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str());
+ }
+ return result.Succeeded();
+ }
+};
+
+class CommandObjectLogTimerIncrement : public CommandObjectParsed {
+public:
+ // Constructors and Destructors
+ CommandObjectLogTimerIncrement(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "log timers increment",
+ "increment LLDB internal performance timers",
+ "log timers increment <bool>") {
+ CommandArgumentEntry arg;
+ CommandArgumentData bool_arg;
+
+ // Define the first (and only) variant of this arg.
+ bool_arg.arg_type = eArgTypeBoolean;
+ bool_arg.arg_repetition = eArgRepeatPlain;
+
+ // There is only one variant this argument could be; put it into the
+ // argument entry.
+ arg.push_back(bool_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back(arg);
+ }
+
+ ~CommandObjectLogTimerIncrement() override = default;
+
+ void
+ HandleArgumentCompletion(CompletionRequest &request,
+ OptionElementVector &opt_element_vector) override {
+ request.TryCompleteCurrentArg("true");
+ request.TryCompleteCurrentArg("false");
+ }
protected:
bool DoExecute(Args &args, CommandReturnObject &result) override {
result.SetStatus(eReturnStatusFailed);
if (args.GetArgumentCount() == 1) {
- auto sub_command = args[0].ref();
+ bool success;
+ bool increment =
+ OptionArgParser::ToBoolean(args[0].ref(), false, &success);
- if (sub_command.equals_lower("enable")) {
- Timer::SetDisplayDepth(UINT32_MAX);
+ if (success) {
+ Timer::SetQuiet(!increment);
result.SetStatus(eReturnStatusSuccessFinishNoResult);
- } else if (sub_command.equals_lower("disable")) {
- Timer::DumpCategoryTimes(&result.GetOutputStream());
- Timer::SetDisplayDepth(0);
- result.SetStatus(eReturnStatusSuccessFinishResult);
- } else if (sub_command.equals_lower("dump")) {
- Timer::DumpCategoryTimes(&result.GetOutputStream());
- result.SetStatus(eReturnStatusSuccessFinishResult);
- } else if (sub_command.equals_lower("reset")) {
- Timer::ResetCategoryTimes();
- result.SetStatus(eReturnStatusSuccessFinishResult);
- }
- } else if (args.GetArgumentCount() == 2) {
- auto sub_command = args[0].ref();
- auto param = args[1].ref();
-
- if (sub_command.equals_lower("enable")) {
- uint32_t depth;
- if (param.consumeInteger(0, depth)) {
- result.AppendError(
- "Could not convert enable depth to an unsigned integer.");
- } else {
- Timer::SetDisplayDepth(depth);
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- }
- } else if (sub_command.equals_lower("increment")) {
- bool success;
- bool increment = OptionArgParser::ToBoolean(param, false, &success);
- if (success) {
- Timer::SetQuiet(!increment);
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- } else
- result.AppendError("Could not convert increment value to boolean.");
- }
+ } else
+ result.AppendError("Could not convert increment value to boolean.");
}
if (!result.Succeeded()) {
@@ -363,6 +472,30 @@ protected:
}
};
+class CommandObjectLogTimer : public CommandObjectMultiword {
+public:
+ CommandObjectLogTimer(CommandInterpreter &interpreter)
+ : CommandObjectMultiword(interpreter, "log timers",
+ "Enable, disable, dump, and reset LLDB internal "
+ "performance timers.",
+ "log timers < enable <depth> | disable | dump | "
+ "increment <bool> | reset >") {
+ LoadSubCommand("enable", CommandObjectSP(
+ new CommandObjectLogTimerEnable(interpreter)));
+ LoadSubCommand("disable", CommandObjectSP(new CommandObjectLogTimerDisable(
+ interpreter)));
+ LoadSubCommand("dump",
+ CommandObjectSP(new CommandObjectLogTimerDump(interpreter)));
+ LoadSubCommand(
+ "reset", CommandObjectSP(new CommandObjectLogTimerReset(interpreter)));
+ LoadSubCommand(
+ "increment",
+ CommandObjectSP(new CommandObjectLogTimerIncrement(interpreter)));
+ }
+
+ ~CommandObjectLogTimer() override = default;
+};
+
CommandObjectLog::CommandObjectLog(CommandInterpreter &interpreter)
: CommandObjectMultiword(interpreter, "log",
"Commands controlling LLDB internal logging.",