aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectLog.cpp
diff options
context:
space:
mode:
authorPete Lawrence <plawrence@apple.com>2023-10-30 10:21:00 -1000
committerGitHub <noreply@github.com>2023-10-30 13:21:00 -0700
commit92d8a28cc665d73d9d679b8c014dd04f95d1df18 (patch)
tree19b3a218ad57e05a911da01c0f4f80ca3c0a4bd4 /lldb/source/Commands/CommandObjectLog.cpp
parent2446439f51cf0d2dfb11c823436a930de7a4b8a2 (diff)
downloadllvm-92d8a28cc665d73d9d679b8c014dd04f95d1df18.zip
llvm-92d8a28cc665d73d9d679b8c014dd04f95d1df18.tar.gz
llvm-92d8a28cc665d73d9d679b8c014dd04f95d1df18.tar.bz2
[lldb] Part 2 of 2 - Refactor `CommandObject::DoExecute(...)` return `void` (not `bool`) (#69991)
[lldb] Part 2 of 2 - Refactor `CommandObject::DoExecute(...)` to return `void` instead of ~~`bool`~~ Justifications: - The code doesn't ultimately apply the `true`/`false` return values. - The methods already pass around a `CommandReturnObject`, typically with a `result` parameter. - Each command return object already contains: - A more precise status - The error code(s) that apply to that status Part 1 refactors the `CommandObject::Execute(...)` method. - See [https://github.com/llvm/llvm-project/pull/69989](https://github.com/llvm/llvm-project/pull/69989) rdar://117378957
Diffstat (limited to 'lldb/source/Commands/CommandObjectLog.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectLog.cpp42
1 files changed, 16 insertions, 26 deletions
diff --git a/lldb/source/Commands/CommandObjectLog.cpp b/lldb/source/Commands/CommandObjectLog.cpp
index 5dd6f89..6bfbf98 100644
--- a/lldb/source/Commands/CommandObjectLog.cpp
+++ b/lldb/source/Commands/CommandObjectLog.cpp
@@ -162,19 +162,19 @@ public:
}
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
if (args.GetArgumentCount() < 2) {
result.AppendErrorWithFormat(
"%s takes a log channel and one or more log types.\n",
m_cmd_name.c_str());
- return false;
+ return;
}
if (m_options.handler == eLogHandlerCircular &&
m_options.buffer_size.GetCurrentValue() == 0) {
result.AppendError(
"the circular buffer handler requires a non-zero buffer size.\n");
- return false;
+ return;
}
if ((m_options.handler != eLogHandlerCircular &&
@@ -182,13 +182,13 @@ protected:
m_options.buffer_size.GetCurrentValue() != 0) {
result.AppendError("a buffer size can only be specified for the circular "
"and stream buffer handler.\n");
- return false;
+ return;
}
if (m_options.handler != eLogHandlerStream && m_options.log_file) {
result.AppendError(
"a file name can only be specified for the stream handler.\n");
- return false;
+ return;
}
// Store into a std::string since we're about to shift the channel off.
@@ -212,7 +212,6 @@ protected:
result.SetStatus(eReturnStatusSuccessFinishNoResult);
else
result.SetStatus(eReturnStatusFailed);
- return result.Succeeded();
}
CommandOptions m_options;
@@ -257,12 +256,12 @@ public:
}
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
if (args.empty()) {
result.AppendErrorWithFormat(
"%s takes a log channel and one or more log types.\n",
m_cmd_name.c_str());
- return false;
+ return;
}
const std::string channel = std::string(args[0].ref());
@@ -278,7 +277,6 @@ protected:
result.SetStatus(eReturnStatusSuccessFinishNoResult);
result.GetErrorStream() << error_stream.str();
}
- return result.Succeeded();
}
};
@@ -315,7 +313,7 @@ public:
}
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
std::string output;
llvm::raw_string_ostream output_stream(output);
if (args.empty()) {
@@ -330,7 +328,6 @@ protected:
result.SetStatus(eReturnStatusSuccessFinishResult);
}
result.GetOutputStream() << output_stream.str();
- return result.Succeeded();
}
};
class CommandObjectLogDump : public CommandObjectParsed {
@@ -398,12 +395,12 @@ public:
}
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
if (args.empty()) {
result.AppendErrorWithFormat(
"%s takes a log channel and one or more log types.\n",
m_cmd_name.c_str());
- return false;
+ return;
}
std::unique_ptr<llvm::raw_ostream> stream_up;
@@ -417,7 +414,7 @@ protected:
result.AppendErrorWithFormat("Unable to open log file '%s': %s",
m_options.log_file.GetPath().c_str(),
llvm::toString(file.takeError()).c_str());
- return false;
+ return;
}
stream_up = std::make_unique<llvm::raw_fd_ostream>(
(*file)->GetDescriptor(), /*shouldClose=*/true);
@@ -435,8 +432,6 @@ protected:
result.SetStatus(eReturnStatusFailed);
result.GetErrorStream() << error_stream.str();
}
-
- return result.Succeeded();
}
CommandOptions m_options;
@@ -467,7 +462,7 @@ public:
~CommandObjectLogTimerEnable() override = default;
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
result.SetStatus(eReturnStatusFailed);
if (args.GetArgumentCount() == 0) {
@@ -488,7 +483,6 @@ protected:
result.AppendError("Missing subcommand");
result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str());
}
- return result.Succeeded();
}
};
@@ -503,7 +497,7 @@ public:
~CommandObjectLogTimerDisable() override = default;
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
Timer::DumpCategoryTimes(result.GetOutputStream());
Timer::SetDisplayDepth(0);
result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -512,7 +506,6 @@ protected:
result.AppendError("Missing subcommand");
result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str());
}
- return result.Succeeded();
}
};
@@ -526,7 +519,7 @@ public:
~CommandObjectLogTimerDump() override = default;
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
Timer::DumpCategoryTimes(result.GetOutputStream());
result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -534,7 +527,6 @@ protected:
result.AppendError("Missing subcommand");
result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str());
}
- return result.Succeeded();
}
};
@@ -549,7 +541,7 @@ public:
~CommandObjectLogTimerReset() override = default;
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
Timer::ResetCategoryTimes();
result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -557,7 +549,6 @@ protected:
result.AppendError("Missing subcommand");
result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str());
}
- return result.Succeeded();
}
};
@@ -593,7 +584,7 @@ public:
}
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
result.SetStatus(eReturnStatusFailed);
if (args.GetArgumentCount() == 1) {
@@ -612,7 +603,6 @@ protected:
result.AppendError("Missing subcommand");
result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str());
}
- return result.Succeeded();
}
};