aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectSettings.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/CommandObjectSettings.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/CommandObjectSettings.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectSettings.cpp91
1 files changed, 32 insertions, 59 deletions
diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp
index 7069cb1..5fb7dcc 100644
--- a/lldb/source/Commands/CommandObjectSettings.cpp
+++ b/lldb/source/Commands/CommandObjectSettings.cpp
@@ -169,27 +169,27 @@ insert-before or insert-after.");
}
protected:
- bool DoExecute(llvm::StringRef command,
+ void DoExecute(llvm::StringRef command,
CommandReturnObject &result) override {
Args cmd_args(command);
// Process possible options.
if (!ParseOptions(cmd_args, result))
- return false;
+ return;
const size_t min_argc = m_options.m_force ? 1 : 2;
const size_t argc = cmd_args.GetArgumentCount();
if ((argc < min_argc) && (!m_options.m_global)) {
result.AppendError("'settings set' takes more arguments");
- return false;
+ return;
}
const char *var_name = cmd_args.GetArgumentAtIndex(0);
if ((var_name == nullptr) || (var_name[0] == '\0')) {
result.AppendError(
"'settings set' command requires a valid variable name");
- return false;
+ return;
}
// A missing value corresponds to clearing the setting when "force" is
@@ -199,9 +199,8 @@ protected:
&m_exe_ctx, eVarSetOperationClear, var_name, llvm::StringRef()));
if (error.Fail()) {
result.AppendError(error.AsCString());
- return false;
}
- return result.Succeeded();
+ return;
}
// Split the raw command into var_name and value pair.
@@ -227,11 +226,10 @@ protected:
if (error.Fail() && !m_options.m_exists) {
result.AppendError(error.AsCString());
- return false;
+ return;
}
result.SetStatus(eReturnStatusSuccessFinishResult);
- return result.Succeeded();
}
private:
@@ -273,7 +271,7 @@ public:
}
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
result.SetStatus(eReturnStatusSuccessFinishResult);
if (!args.empty()) {
@@ -291,8 +289,6 @@ protected:
GetDebugger().DumpAllPropertyValues(&m_exe_ctx, result.GetOutputStream(),
OptionValue::eDumpGroupValue);
}
-
- return result.Succeeded();
}
};
@@ -368,7 +364,7 @@ public:
};
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
FileSpec file_spec(m_options.m_filename);
FileSystem::Instance().Resolve(file_spec);
std::string path(file_spec.GetPath());
@@ -383,7 +379,7 @@ protected:
if (!out_file.GetFile().IsValid()) {
result.AppendErrorWithFormat("%s: unable to write to file", path.c_str());
- return false;
+ return;
}
// Exporting should not be context sensitive.
@@ -392,7 +388,7 @@ protected:
if (args.empty()) {
GetDebugger().DumpAllPropertyValues(&clean_ctx, out_file,
OptionValue::eDumpGroupExport);
- return result.Succeeded();
+ return;
}
for (const auto &arg : args) {
@@ -402,8 +398,6 @@ protected:
result.AppendError(error.AsCString());
}
}
-
- return result.Succeeded();
}
private:
@@ -461,7 +455,7 @@ public:
};
protected:
- bool DoExecute(Args &command, CommandReturnObject &result) override {
+ void DoExecute(Args &command, CommandReturnObject &result) override {
FileSpec file(m_options.m_filename);
FileSystem::Instance().Resolve(file);
CommandInterpreterRunOptions options;
@@ -471,7 +465,6 @@ protected:
options.SetPrintErrors(true);
options.SetStopOnError(false);
m_interpreter.HandleCommandsFromFile(file, options, result);
- return result.Succeeded();
}
private:
@@ -517,7 +510,7 @@ public:
}
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
result.SetStatus(eReturnStatusSuccessFinishResult);
const size_t argc = args.GetArgumentCount();
@@ -543,8 +536,6 @@ protected:
GetDebugger().DumpAllDescriptions(m_interpreter,
result.GetOutputStream());
}
-
- return result.Succeeded();
}
};
@@ -601,7 +592,7 @@ public:
}
protected:
- bool DoExecute(llvm::StringRef command,
+ void DoExecute(llvm::StringRef command,
CommandReturnObject &result) override {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
@@ -609,7 +600,7 @@ protected:
// Process possible options.
if (!ParseOptions(cmd_args, result))
- return false;
+ return;
const size_t argc = cmd_args.GetArgumentCount();
if (argc == 0) {
@@ -617,14 +608,14 @@ protected:
"or an array followed by one or more indexes, or a "
"dictionary followed by one or more key names to "
"remove");
- return false;
+ return;
}
const char *var_name = cmd_args.GetArgumentAtIndex(0);
if ((var_name == nullptr) || (var_name[0] == '\0')) {
result.AppendError(
"'settings remove' command requires a valid variable name");
- return false;
+ return;
}
// Split the raw command into var_name and value pair.
@@ -635,10 +626,7 @@ protected:
&m_exe_ctx, eVarSetOperationRemove, var_name, var_value));
if (error.Fail()) {
result.AppendError(error.AsCString());
- return false;
}
-
- return result.Succeeded();
}
};
@@ -709,7 +697,7 @@ public:
}
protected:
- bool DoExecute(llvm::StringRef command,
+ void DoExecute(llvm::StringRef command,
CommandReturnObject &result) override {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
@@ -718,7 +706,7 @@ protected:
if ((var_name == nullptr) || (var_name[0] == '\0')) {
result.AppendError("'settings replace' command requires a valid variable "
"name; No value supplied");
- return false;
+ return;
}
// Split the raw command into var_name, index_value, and value triple.
@@ -729,12 +717,9 @@ protected:
&m_exe_ctx, eVarSetOperationReplace, var_name, var_value));
if (error.Fail()) {
result.AppendError(error.AsCString());
- return false;
} else {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
-
- return result.Succeeded();
}
};
@@ -801,7 +786,7 @@ public:
}
protected:
- bool DoExecute(llvm::StringRef command,
+ void DoExecute(llvm::StringRef command,
CommandReturnObject &result) override {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
@@ -810,14 +795,14 @@ protected:
if (argc < 3) {
result.AppendError("'settings insert-before' takes more arguments");
- return false;
+ return;
}
const char *var_name = cmd_args.GetArgumentAtIndex(0);
if ((var_name == nullptr) || (var_name[0] == '\0')) {
result.AppendError("'settings insert-before' command requires a valid "
"variable name; No value supplied");
- return false;
+ return;
}
// Split the raw command into var_name, index_value, and value triple.
@@ -828,10 +813,7 @@ protected:
&m_exe_ctx, eVarSetOperationInsertBefore, var_name, var_value));
if (error.Fail()) {
result.AppendError(error.AsCString());
- return false;
}
-
- return result.Succeeded();
}
};
@@ -897,7 +879,7 @@ public:
}
protected:
- bool DoExecute(llvm::StringRef command,
+ void DoExecute(llvm::StringRef command,
CommandReturnObject &result) override {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
@@ -906,14 +888,14 @@ protected:
if (argc < 3) {
result.AppendError("'settings insert-after' takes more arguments");
- return false;
+ return;
}
const char *var_name = cmd_args.GetArgumentAtIndex(0);
if ((var_name == nullptr) || (var_name[0] == '\0')) {
result.AppendError("'settings insert-after' command requires a valid "
"variable name; No value supplied");
- return false;
+ return;
}
// Split the raw command into var_name, index_value, and value triple.
@@ -924,10 +906,7 @@ protected:
&m_exe_ctx, eVarSetOperationInsertAfter, var_name, var_value));
if (error.Fail()) {
result.AppendError(error.AsCString());
- return false;
}
-
- return result.Succeeded();
}
};
@@ -982,7 +961,7 @@ public:
}
protected:
- bool DoExecute(llvm::StringRef command,
+ void DoExecute(llvm::StringRef command,
CommandReturnObject &result) override {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
Args cmd_args(command);
@@ -990,14 +969,14 @@ protected:
if (argc < 2) {
result.AppendError("'settings append' takes more arguments");
- return false;
+ return;
}
const char *var_name = cmd_args.GetArgumentAtIndex(0);
if ((var_name == nullptr) || (var_name[0] == '\0')) {
result.AppendError("'settings append' command requires a valid variable "
"name; No value supplied");
- return false;
+ return;
}
// Do not perform cmd_args.Shift() since StringRef is manipulating the raw
@@ -1011,10 +990,7 @@ protected:
&m_exe_ctx, eVarSetOperationAppend, var_name, var_value));
if (error.Fail()) {
result.AppendError(error.AsCString());
- return false;
}
-
- return result.Succeeded();
}
};
@@ -1089,39 +1065,36 @@ public:
};
protected:
- bool DoExecute(Args &command, CommandReturnObject &result) override {
+ void DoExecute(Args &command, CommandReturnObject &result) override {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
const size_t argc = command.GetArgumentCount();
if (m_options.m_clear_all) {
if (argc != 0) {
result.AppendError("'settings clear --all' doesn't take any arguments");
- return false;
+ return;
}
GetDebugger().GetValueProperties()->Clear();
- return result.Succeeded();
+ return;
}
if (argc != 1) {
result.AppendError("'settings clear' takes exactly one argument");
- return false;
+ return;
}
const char *var_name = command.GetArgumentAtIndex(0);
if ((var_name == nullptr) || (var_name[0] == '\0')) {
result.AppendError("'settings clear' command requires a valid variable "
"name; No value supplied");
- return false;
+ return;
}
Status error(GetDebugger().SetPropertyValue(
&m_exe_ctx, eVarSetOperationClear, var_name, llvm::StringRef()));
if (error.Fail()) {
result.AppendError(error.AsCString());
- return false;
}
-
- return result.Succeeded();
}
private: