aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectPlatform.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/CommandObjectPlatform.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/CommandObjectPlatform.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectPlatform.cpp102
1 files changed, 40 insertions, 62 deletions
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index 54115b5..790f1db 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -169,7 +169,7 @@ public:
Options *GetOptions() override { return &m_option_group; }
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
if (args.GetArgumentCount() == 1) {
const char *platform_name = args.GetArgumentAtIndex(0);
if (platform_name && platform_name[0]) {
@@ -194,7 +194,6 @@ protected:
result.AppendError(
"platform create takes a platform name as an argument\n");
}
- return result.Succeeded();
}
OptionGroupOptions m_option_group;
@@ -212,7 +211,7 @@ public:
~CommandObjectPlatformList() override = default;
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
Stream &ostrm = result.GetOutputStream();
ostrm.Printf("Available platforms:\n");
@@ -235,7 +234,6 @@ protected:
result.AppendError("no platforms are available\n");
} else
result.SetStatus(eReturnStatusSuccessFinishResult);
- return result.Succeeded();
}
};
@@ -250,7 +248,7 @@ public:
~CommandObjectPlatformStatus() override = default;
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
Stream &ostrm = result.GetOutputStream();
Target *target = GetDebugger().GetSelectedTarget().get();
@@ -267,7 +265,6 @@ protected:
} else {
result.AppendError("no platform is currently selected\n");
}
- return result.Succeeded();
}
};
@@ -286,7 +283,7 @@ public:
~CommandObjectPlatformConnect() override = default;
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
Stream &ostrm = result.GetOutputStream();
PlatformSP platform_sp(
@@ -307,7 +304,6 @@ protected:
} else {
result.AppendError("no platform is currently selected\n");
}
- return result.Succeeded();
}
Options *GetOptions() override {
@@ -334,7 +330,7 @@ public:
~CommandObjectPlatformDisconnect() override = default;
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
PlatformSP platform_sp(
GetDebugger().GetPlatformList().GetSelectedPlatform());
if (platform_sp) {
@@ -374,7 +370,6 @@ protected:
} else {
result.AppendError("no platform is currently selected");
}
- return result.Succeeded();
}
};
@@ -394,7 +389,7 @@ public:
~CommandObjectPlatformSettings() override = default;
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
PlatformSP platform_sp(
GetDebugger().GetPlatformList().GetSelectedPlatform());
if (platform_sp) {
@@ -404,7 +399,6 @@ protected:
} else {
result.AppendError("no platform is currently selected");
}
- return result.Succeeded();
}
Options *GetOptions() override {
@@ -430,7 +424,7 @@ public:
~CommandObjectPlatformMkDir() override = default;
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
PlatformSP platform_sp(
GetDebugger().GetPlatformList().GetSelectedPlatform());
if (platform_sp) {
@@ -453,7 +447,6 @@ public:
} else {
result.AppendError("no platform currently selected\n");
}
- return result.Succeeded();
}
Options *GetOptions() override {
@@ -489,7 +482,7 @@ public:
nullptr);
}
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
PlatformSP platform_sp(
GetDebugger().GetPlatformList().GetSelectedPlatform());
if (platform_sp) {
@@ -517,7 +510,6 @@ public:
} else {
result.AppendError("no platform currently selected\n");
}
- return result.Succeeded();
}
Options *GetOptions() override {
@@ -544,7 +536,7 @@ public:
~CommandObjectPlatformFClose() override = default;
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
PlatformSP platform_sp(
GetDebugger().GetPlatformList().GetSelectedPlatform());
if (platform_sp) {
@@ -554,7 +546,7 @@ public:
if (!llvm::to_integer(cmd_line, fd)) {
result.AppendErrorWithFormatv("'{0}' is not a valid file descriptor.\n",
cmd_line);
- return result.Succeeded();
+ return;
}
Status error;
bool success = platform_sp->CloseFile(fd, error);
@@ -567,7 +559,6 @@ public:
} else {
result.AppendError("no platform currently selected\n");
}
- return result.Succeeded();
}
};
@@ -588,7 +579,7 @@ public:
~CommandObjectPlatformFRead() override = default;
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
PlatformSP platform_sp(
GetDebugger().GetPlatformList().GetSelectedPlatform());
if (platform_sp) {
@@ -598,7 +589,7 @@ public:
if (!llvm::to_integer(cmd_line, fd)) {
result.AppendErrorWithFormatv("'{0}' is not a valid file descriptor.\n",
cmd_line);
- return result.Succeeded();
+ return;
}
std::string buffer(m_options.m_count, 0);
Status error;
@@ -614,7 +605,6 @@ public:
} else {
result.AppendError("no platform currently selected\n");
}
- return result.Succeeded();
}
Options *GetOptions() override { return &m_options; }
@@ -684,7 +674,7 @@ public:
~CommandObjectPlatformFWrite() override = default;
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
PlatformSP platform_sp(
GetDebugger().GetPlatformList().GetSelectedPlatform());
if (platform_sp) {
@@ -695,7 +685,7 @@ public:
if (!llvm::to_integer(cmd_line, fd)) {
result.AppendErrorWithFormatv("'{0}' is not a valid file descriptor.",
cmd_line);
- return result.Succeeded();
+ return;
}
uint64_t retcode =
platform_sp->WriteFile(fd, m_options.m_offset, &m_options.m_data[0],
@@ -709,7 +699,6 @@ public:
} else {
result.AppendError("no platform currently selected\n");
}
- return result.Succeeded();
}
Options *GetOptions() override { return &m_options; }
@@ -839,12 +828,12 @@ public:
GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
}
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
// If the number of arguments is incorrect, issue an error message.
if (args.GetArgumentCount() != 2) {
result.AppendError("required arguments missing; specify both the "
"source and destination file paths");
- return false;
+ return;
}
PlatformSP platform_sp(
@@ -866,7 +855,6 @@ public:
} else {
result.AppendError("no platform currently selected\n");
}
- return result.Succeeded();
}
};
@@ -911,12 +899,12 @@ public:
nullptr);
}
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
// If the number of arguments is incorrect, issue an error message.
if (args.GetArgumentCount() != 1) {
result.AppendError("required argument missing; specify the source file "
"path as the only argument");
- return false;
+ return;
}
PlatformSP platform_sp(
@@ -937,7 +925,6 @@ public:
} else {
result.AppendError("no platform currently selected\n");
}
- return result.Succeeded();
}
};
@@ -982,12 +969,12 @@ public:
nullptr);
}
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
// If the number of arguments is incorrect, issue an error message.
if (args.GetArgumentCount() != 1) {
result.AppendError("required argument missing; specify the source file "
"path as the only argument");
- return false;
+ return;
}
PlatformSP platform_sp(
@@ -1007,7 +994,6 @@ public:
} else {
result.AppendError("no platform currently selected\n");
}
- return result.Succeeded();
}
};
@@ -1052,12 +1038,12 @@ public:
nullptr);
}
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
// If the number of arguments is incorrect, issue an error message.
if (args.GetArgumentCount() != 1) {
result.AppendError("required argument missing; specify the source file "
"path as the only argument");
- return false;
+ return;
}
PlatformSP platform_sp(
@@ -1072,7 +1058,6 @@ public:
} else {
result.AppendError("no platform currently selected\n");
}
- return result.Succeeded();
}
};
@@ -1114,7 +1099,7 @@ public:
nullptr);
}
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
const char *src = args.GetArgumentAtIndex(0);
const char *dst = args.GetArgumentAtIndex(1);
@@ -1134,7 +1119,6 @@ public:
} else {
result.AppendError("no platform currently selected\n");
}
- return result.Succeeded();
}
};
@@ -1160,7 +1144,7 @@ public:
Options *GetOptions() override { return &m_all_options; }
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
Target *target = GetDebugger().GetSelectedTarget().get();
PlatformSP platform_sp;
if (target) {
@@ -1220,10 +1204,10 @@ protected:
if (!process_sp && error.Success()) {
result.AppendError("failed to launch or debug process");
- return false;
+ return;
} else if (!error.Success()) {
result.AppendError(error.AsCString());
- return false;
+ return;
}
const bool synchronous_execution =
@@ -1242,7 +1226,7 @@ protected:
if (rebroadcast_first_stop) {
assert(first_stop_event_sp);
process_sp->BroadcastEvent(first_stop_event_sp);
- return true;
+ return;
}
switch (state) {
@@ -1272,18 +1256,17 @@ protected:
if (process_sp && process_sp->IsAlive()) {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
- return true;
+ return;
}
} else {
result.AppendError("'platform process launch' uses the current target "
"file and arguments, or the executable and its "
"arguments can be specified in this command");
- return false;
+ return;
}
} else {
result.AppendError("no platform is selected\n");
}
- return result.Succeeded();
}
CommandOptionsProcessLaunch m_options;
@@ -1310,7 +1293,7 @@ public:
Options *GetOptions() override { return &m_options; }
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
Target *target = GetDebugger().GetSelectedTarget().get();
PlatformSP platform_sp;
if (target) {
@@ -1398,7 +1381,6 @@ protected:
} else {
result.AppendError("no platform is selected\n");
}
- return result.Succeeded();
}
class CommandOptions : public Options {
@@ -1578,7 +1560,7 @@ public:
}
protected:
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
Target *target = GetDebugger().GetSelectedTarget().get();
PlatformSP platform_sp;
if (target) {
@@ -1627,7 +1609,6 @@ protected:
} else {
result.AppendError("no platform is currently selected");
}
- return result.Succeeded();
}
};
@@ -1649,7 +1630,7 @@ public:
~CommandObjectPlatformProcessAttach() override = default;
- bool DoExecute(Args &command, CommandReturnObject &result) override {
+ void DoExecute(Args &command, CommandReturnObject &result) override {
PlatformSP platform_sp(
GetDebugger().GetPlatformList().GetSelectedPlatform());
if (platform_sp) {
@@ -1673,7 +1654,6 @@ public:
} else {
result.AppendError("no platform is currently selected");
}
- return result.Succeeded();
}
Options *GetOptions() override { return &m_all_options; }
@@ -1788,7 +1768,7 @@ public:
Options *GetOptions() override { return &m_options; }
- bool DoExecute(llvm::StringRef raw_command_line,
+ void DoExecute(llvm::StringRef raw_command_line,
CommandReturnObject &result) override {
ExecutionContext exe_ctx = GetCommandInterpreter().GetExecutionContext();
m_options.NotifyOptionParsingStarting(&exe_ctx);
@@ -1796,7 +1776,7 @@ public:
// Print out an usage syntax on an empty command line.
if (raw_command_line.empty()) {
result.GetOutputStream().Printf("%s\n", this->GetSyntax().str().c_str());
- return true;
+ return;
}
const bool is_alias = !raw_command_line.contains("platform");
@@ -1804,12 +1784,12 @@ public:
if (args.HasArgs())
if (!ParseOptions(args.GetArgs(), result))
- return false;
+ return;
if (args.GetRawPart().empty()) {
result.GetOutputStream().Printf("%s <shell-command>\n",
is_alias ? "shell" : "platform shell");
- return false;
+ return;
}
llvm::StringRef cmd = args.GetRawPart();
@@ -1856,7 +1836,6 @@ public:
} else {
result.SetStatus(eReturnStatusSuccessFinishResult);
}
- return true;
}
CommandOptions m_options;
@@ -1887,10 +1866,10 @@ public:
GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
}
- bool DoExecute(Args &args, CommandReturnObject &result) override {
+ void DoExecute(Args &args, CommandReturnObject &result) override {
if (args.GetArgumentCount() != 2) {
result.AppendError("platform target-install takes two arguments");
- return false;
+ return;
}
// TODO: move the bulk of this code over to the platform itself
FileSpec src(args.GetArgumentAtIndex(0));
@@ -1898,13 +1877,13 @@ public:
FileSpec dst(args.GetArgumentAtIndex(1));
if (!FileSystem::Instance().Exists(src)) {
result.AppendError("source location does not exist or is not accessible");
- return false;
+ return;
}
PlatformSP platform_sp(
GetDebugger().GetPlatformList().GetSelectedPlatform());
if (!platform_sp) {
result.AppendError("no platform currently selected");
- return false;
+ return;
}
Status error = platform_sp->Install(src, dst);
@@ -1913,7 +1892,6 @@ public:
} else {
result.AppendErrorWithFormat("install failed: %s", error.AsCString());
}
- return result.Succeeded();
}
};