aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectProcess.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/CommandObjectProcess.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/CommandObjectProcess.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectProcess.cpp70
1 files changed, 27 insertions, 43 deletions
diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp
index 2f5f649..c76ae990 100644
--- a/lldb/source/Commands/CommandObjectProcess.cpp
+++ b/lldb/source/Commands/CommandObjectProcess.cpp
@@ -414,12 +414,6 @@ protected:
ModuleSP old_exec_module_sp = target->GetExecutableModule();
ArchSpec old_arch_spec = target->GetArchitecture();
- if (command.GetArgumentCount()) {
- result.AppendErrorWithFormat("Invalid arguments for '%s'.\nUsage: %s\n",
- m_cmd_name.c_str(), m_cmd_syntax.c_str());
- return false;
- }
-
StreamString stream;
ProcessSP process_sp;
const auto error = target->Attach(m_options.attach_info, &stream);
@@ -562,13 +556,6 @@ protected:
bool synchronous_execution = m_interpreter.GetSynchronous();
StateType state = process->GetState();
if (state == eStateStopped) {
- if (command.GetArgumentCount() != 0) {
- result.AppendErrorWithFormat(
- "The '%s' command does not take any arguments.\n",
- m_cmd_name.c_str());
- return false;
- }
-
if (m_options.m_ignore > 0) {
ThreadSP sel_thread_sp(GetDefaultThread()->shared_from_this());
if (sel_thread_sp) {
@@ -943,7 +930,10 @@ public:
CommandObjectProcessConnect(CommandInterpreter &interpreter)
: CommandObjectParsed(interpreter, "process connect",
"Connect to a remote debug service.",
- "process connect <remote-url>", 0) {}
+ "process connect <remote-url>", 0) {
+ CommandArgumentData connect_arg{eArgTypeConnectURL, eArgRepeatPlain};
+ m_arguments.push_back({connect_arg});
+ }
~CommandObjectProcessConnect() override = default;
@@ -1068,7 +1058,10 @@ public:
"process load <filename> [<filename> ...]",
eCommandRequiresProcess | eCommandTryTargetAPILock |
eCommandProcessMustBeLaunched |
- eCommandProcessMustBePaused) {}
+ eCommandProcessMustBePaused) {
+ CommandArgumentData file_arg{eArgTypePath, eArgRepeatPlus};
+ m_arguments.push_back({file_arg});
+ }
~CommandObjectProcessLoad() override = default;
@@ -1143,7 +1136,10 @@ public:
"returned by a previous call to \"process load\".",
"process unload <index>",
eCommandRequiresProcess | eCommandTryTargetAPILock |
- eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
+ eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
+ CommandArgumentData load_idx_arg{eArgTypeUnsignedInteger, eArgRepeatPlain};
+ m_arguments.push_back({load_idx_arg});
+ }
~CommandObjectProcessUnload() override = default;
@@ -1291,18 +1287,13 @@ protected:
return false;
}
- if (command.GetArgumentCount() == 0) {
- bool clear_thread_plans = true;
- Status error(process->Halt(clear_thread_plans));
- if (error.Success()) {
- result.SetStatus(eReturnStatusSuccessFinishResult);
- } else {
- result.AppendErrorWithFormat("Failed to halt process: %s\n",
- error.AsCString());
- }
+ bool clear_thread_plans = true;
+ Status error(process->Halt(clear_thread_plans));
+ if (error.Success()) {
+ result.SetStatus(eReturnStatusSuccessFinishResult);
} else {
- result.AppendErrorWithFormat("'%s' takes no arguments:\nUsage: %s\n",
- m_cmd_name.c_str(), m_cmd_syntax.c_str());
+ result.AppendErrorWithFormat("Failed to halt process: %s\n",
+ error.AsCString());
}
return result.Succeeded();
}
@@ -1330,17 +1321,12 @@ protected:
return false;
}
- if (command.GetArgumentCount() == 0) {
- Status error(process->Destroy(true));
- if (error.Success()) {
- result.SetStatus(eReturnStatusSuccessFinishResult);
- } else {
- result.AppendErrorWithFormat("Failed to kill process: %s\n",
- error.AsCString());
- }
+ Status error(process->Destroy(true));
+ if (error.Success()) {
+ result.SetStatus(eReturnStatusSuccessFinishResult);
} else {
- result.AppendErrorWithFormat("'%s' takes no arguments:\nUsage: %s\n",
- m_cmd_name.c_str(), m_cmd_syntax.c_str());
+ result.AppendErrorWithFormat("Failed to kill process: %s\n",
+ error.AsCString());
}
return result.Succeeded();
}
@@ -1372,7 +1358,10 @@ public:
"appropriate file type.",
"process save-core [-s corefile-style -p plugin-name] FILE",
eCommandRequiresProcess | eCommandTryTargetAPILock |
- eCommandProcessMustBeLaunched) {}
+ eCommandProcessMustBeLaunched) {
+ CommandArgumentData file_arg{eArgTypePath, eArgRepeatPlain};
+ m_arguments.push_back({file_arg});
+ }
~CommandObjectProcessSaveCore() override = default;
@@ -1519,11 +1508,6 @@ protected:
Stream &strm = result.GetOutputStream();
result.SetStatus(eReturnStatusSuccessFinishNoResult);
- if (command.GetArgumentCount()) {
- result.AppendError("'process status' takes no arguments");
- return result.Succeeded();
- }
-
// No need to check "process" for validity as eCommandRequiresProcess
// ensures it is valid
Process *process = m_exe_ctx.GetProcessPtr();