aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectPlatform.cpp
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2022-06-23 09:33:40 -0700
committerJim Ingham <jingham@apple.com>2022-06-27 15:14:41 -0700
commitc1b07d617705dfdb3aabbdda51c1a40d99f7cc1a (patch)
treeed7886491e1a97d19af06525fca43987a3dfb0a9 /lldb/source/Commands/CommandObjectPlatform.cpp
parent6824eee94203b16de7633050367505c2ad10c56a (diff)
downloadllvm-c1b07d617705dfdb3aabbdda51c1a40d99f7cc1a.zip
llvm-c1b07d617705dfdb3aabbdda51c1a40d99f7cc1a.tar.gz
llvm-c1b07d617705dfdb3aabbdda51c1a40d99f7cc1a.tar.bz2
Have CommandObjectParsed check for "commands that take no arguments".
This is currently being done in an ad hoc way, and so for some commands it isn't being checked. We have the info to make this check, since commands are supposed to add their arguments to the m_arguments field of the CommandObject. This change uses that info to check whether the command received arguments in error. A handful of commands weren't defining their argument types, I also had to fix them. And a bunch of commands were checking for arguments by hand, so I removed those checks in favor of the CommandObject one. That also meant I had to change some tests that were checking for the ad hoc error outputs. Differential Revision: https://reviews.llvm.org/D128453
Diffstat (limited to 'lldb/source/Commands/CommandObjectPlatform.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectPlatform.cpp187
1 files changed, 108 insertions, 79 deletions
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index 774ef6c..42b19db 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -150,6 +150,8 @@ public:
{
m_option_group.Append(&m_platform_options, LLDB_OPT_SET_ALL, 1);
m_option_group.Finalize();
+ CommandArgumentData platform_arg{eArgTypePlatform, eArgRepeatPlain};
+ m_arguments.push_back({platform_arg});
}
~CommandObjectPlatformSelect() override = default;
@@ -271,7 +273,10 @@ public:
: CommandObjectParsed(
interpreter, "platform connect",
"Select the current platform by providing a connection URL.",
- "platform connect <connect-url>", 0) {}
+ "platform connect <connect-url>", 0) {
+ CommandArgumentData platform_arg{eArgTypeConnectURL, eArgRepeatPlain};
+ m_arguments.push_back({platform_arg});
+ }
~CommandObjectPlatformConnect() override = default;
@@ -415,7 +420,10 @@ public:
CommandObjectPlatformMkDir(CommandInterpreter &interpreter)
: CommandObjectParsed(interpreter, "platform mkdir",
"Make a new directory on the remote end.", nullptr,
- 0) {}
+ 0) {
+ CommandArgumentData thread_arg{eArgTypePath, eArgRepeatPlain};
+ m_arguments.push_back({thread_arg});
+ }
~CommandObjectPlatformMkDir() override = default;
@@ -461,7 +469,10 @@ class CommandObjectPlatformFOpen : public CommandObjectParsed {
public:
CommandObjectPlatformFOpen(CommandInterpreter &interpreter)
: CommandObjectParsed(interpreter, "platform file open",
- "Open a file on the remote end.", nullptr, 0) {}
+ "Open a file on the remote end.", nullptr, 0) {
+ CommandArgumentData path_arg{eArgTypePath, eArgRepeatPlain};
+ m_arguments.push_back({path_arg});
+ }
~CommandObjectPlatformFOpen() override = default;
@@ -521,7 +532,10 @@ class CommandObjectPlatformFClose : public CommandObjectParsed {
public:
CommandObjectPlatformFClose(CommandInterpreter &interpreter)
: CommandObjectParsed(interpreter, "platform file close",
- "Close a file on the remote end.", nullptr, 0) {}
+ "Close a file on the remote end.", nullptr, 0) {
+ CommandArgumentData path_arg{eArgTypeUnsignedInteger, eArgRepeatPlain};
+ m_arguments.push_back({path_arg});
+ }
~CommandObjectPlatformFClose() override = default;
@@ -562,7 +576,10 @@ public:
CommandObjectPlatformFRead(CommandInterpreter &interpreter)
: CommandObjectParsed(interpreter, "platform file read",
"Read data from a file on the remote end.", nullptr,
- 0) {}
+ 0) {
+ CommandArgumentData path_arg{eArgTypeUnsignedInteger, eArgRepeatPlain};
+ m_arguments.push_back({path_arg});
+ }
~CommandObjectPlatformFRead() override = default;
@@ -655,7 +672,10 @@ public:
CommandObjectPlatformFWrite(CommandInterpreter &interpreter)
: CommandObjectParsed(interpreter, "platform file write",
"Write data to a file on the remote end.", nullptr,
- 0) {}
+ 0) {
+ CommandArgumentData path_arg{eArgTypeUnsignedInteger, eArgRepeatPlain};
+ m_arguments.push_back({path_arg});
+ }
~CommandObjectPlatformFWrite() override = default;
@@ -1070,6 +1090,10 @@ public:
Relative source file paths are resolved against lldb's local working directory.
Omitting the destination places the file in the platform working directory.)");
+ CommandArgumentData source_arg{eArgTypePath, eArgRepeatPlain};
+ CommandArgumentData path_arg{eArgTypePath, eArgRepeatOptional};
+ m_arguments.push_back({source_arg});
+ m_arguments.push_back({path_arg});
}
~CommandObjectPlatformPutFile() override = default;
@@ -1121,6 +1145,8 @@ public:
eCommandRequiresTarget | eCommandTryTargetAPILock) {
m_all_options.Append(&m_options);
m_all_options.Finalize();
+ CommandArgumentData run_arg_arg{eArgTypeRunArgs, eArgRepeatStar};
+ m_arguments.push_back({run_arg_arg});
}
~CommandObjectPlatformProcessLaunch() override = default;
@@ -1229,83 +1255,78 @@ protected:
if (platform_sp) {
Status error;
- if (args.GetArgumentCount() == 0) {
- if (platform_sp) {
- Stream &ostrm = result.GetOutputStream();
-
- lldb::pid_t pid =
- m_options.match_info.GetProcessInfo().GetProcessID();
- if (pid != LLDB_INVALID_PROCESS_ID) {
- ProcessInstanceInfo proc_info;
- if (platform_sp->GetProcessInfo(pid, proc_info)) {
- ProcessInstanceInfo::DumpTableHeader(ostrm, m_options.show_args,
- m_options.verbose);
- proc_info.DumpAsTableRow(ostrm, platform_sp->GetUserIDResolver(),
- m_options.show_args, m_options.verbose);
- result.SetStatus(eReturnStatusSuccessFinishResult);
- } else {
- result.AppendErrorWithFormat(
- "no process found with pid = %" PRIu64 "\n", pid);
- }
+ if (platform_sp) {
+ Stream &ostrm = result.GetOutputStream();
+
+ lldb::pid_t pid = m_options.match_info.GetProcessInfo().GetProcessID();
+ if (pid != LLDB_INVALID_PROCESS_ID) {
+ ProcessInstanceInfo proc_info;
+ if (platform_sp->GetProcessInfo(pid, proc_info)) {
+ ProcessInstanceInfo::DumpTableHeader(ostrm, m_options.show_args,
+ m_options.verbose);
+ proc_info.DumpAsTableRow(ostrm, platform_sp->GetUserIDResolver(),
+ m_options.show_args, m_options.verbose);
+ result.SetStatus(eReturnStatusSuccessFinishResult);
} else {
- ProcessInstanceInfoList proc_infos;
- const uint32_t matches =
- platform_sp->FindProcesses(m_options.match_info, proc_infos);
- const char *match_desc = nullptr;
- const char *match_name =
- m_options.match_info.GetProcessInfo().GetName();
- if (match_name && match_name[0]) {
- switch (m_options.match_info.GetNameMatchType()) {
- case NameMatch::Ignore:
- break;
- case NameMatch::Equals:
- match_desc = "matched";
- break;
- case NameMatch::Contains:
- match_desc = "contained";
- break;
- case NameMatch::StartsWith:
- match_desc = "started with";
- break;
- case NameMatch::EndsWith:
- match_desc = "ended with";
- break;
- case NameMatch::RegularExpression:
- match_desc = "matched the regular expression";
- break;
- }
+ result.AppendErrorWithFormat(
+ "no process found with pid = %" PRIu64 "\n", pid);
+ }
+ } else {
+ ProcessInstanceInfoList proc_infos;
+ const uint32_t matches =
+ platform_sp->FindProcesses(m_options.match_info, proc_infos);
+ const char *match_desc = nullptr;
+ const char *match_name =
+ m_options.match_info.GetProcessInfo().GetName();
+ if (match_name && match_name[0]) {
+ switch (m_options.match_info.GetNameMatchType()) {
+ case NameMatch::Ignore:
+ break;
+ case NameMatch::Equals:
+ match_desc = "matched";
+ break;
+ case NameMatch::Contains:
+ match_desc = "contained";
+ break;
+ case NameMatch::StartsWith:
+ match_desc = "started with";
+ break;
+ case NameMatch::EndsWith:
+ match_desc = "ended with";
+ break;
+ case NameMatch::RegularExpression:
+ match_desc = "matched the regular expression";
+ break;
}
+ }
- if (matches == 0) {
- if (match_desc)
- result.AppendErrorWithFormatv(
- "no processes were found that {0} \"{1}\" on the \"{2}\" "
- "platform\n",
- match_desc, match_name, platform_sp->GetName());
- else
- result.AppendErrorWithFormatv(
- "no processes were found on the \"{0}\" platform\n",
- platform_sp->GetName());
- } else {
- result.AppendMessageWithFormatv(
- "{0} matching process{1} found on \"{2}\"", matches,
- matches > 1 ? "es were" : " was", platform_sp->GetName());
- if (match_desc)
- result.AppendMessageWithFormat(" whose name %s \"%s\"",
- match_desc, match_name);
- result.AppendMessageWithFormat("\n");
- ProcessInstanceInfo::DumpTableHeader(ostrm, m_options.show_args,
- m_options.verbose);
- for (uint32_t i = 0; i < matches; ++i) {
- proc_infos[i].DumpAsTableRow(
- ostrm, platform_sp->GetUserIDResolver(),
- m_options.show_args, m_options.verbose);
- }
+ if (matches == 0) {
+ if (match_desc)
+ result.AppendErrorWithFormatv(
+ "no processes were found that {0} \"{1}\" on the \"{2}\" "
+ "platform\n",
+ match_desc, match_name, platform_sp->GetName());
+ else
+ result.AppendErrorWithFormatv(
+ "no processes were found on the \"{0}\" platform\n",
+ platform_sp->GetName());
+ } else {
+ result.AppendMessageWithFormatv(
+ "{0} matching process{1} found on \"{2}\"", matches,
+ matches > 1 ? "es were" : " was", platform_sp->GetName());
+ if (match_desc)
+ result.AppendMessageWithFormat(" whose name %s \"%s\"",
+ match_desc, match_name);
+ result.AppendMessageWithFormat("\n");
+ ProcessInstanceInfo::DumpTableHeader(ostrm, m_options.show_args,
+ m_options.verbose);
+ for (uint32_t i = 0; i < matches; ++i) {
+ proc_infos[i].DumpAsTableRow(
+ ostrm, platform_sp->GetUserIDResolver(), m_options.show_args,
+ m_options.verbose);
}
}
}
- } else {
- result.AppendError("invalid args: process list takes only options\n");
}
} else {
result.AppendError("no platform is selected\n");
@@ -1737,7 +1758,10 @@ public:
CommandObjectPlatformShell(CommandInterpreter &interpreter)
: CommandObjectRaw(interpreter, "platform shell",
"Run a shell command on the current platform.",
- "platform shell <shell-command>", 0) {}
+ "platform shell <shell-command>", 0) {
+ CommandArgumentData thread_arg{eArgTypeNone, eArgRepeatStar};
+ m_arguments.push_back({thread_arg});
+ }
~CommandObjectPlatformShell() override = default;
@@ -1824,7 +1848,12 @@ public:
: CommandObjectParsed(
interpreter, "platform target-install",
"Install a target (bundle or executable file) to the remote end.",
- "platform target-install <local-thing> <remote-sandbox>", 0) {}
+ "platform target-install <local-thing> <remote-sandbox>", 0) {
+ CommandArgumentData local_arg{eArgTypePath, eArgRepeatPlain};
+ CommandArgumentData remote_arg{eArgTypePath, eArgRepeatPlain};
+ m_arguments.push_back({local_arg});
+ m_arguments.push_back({remote_arg});
+ }
~CommandObjectPlatformInstall() override = default;