diff options
author | Jim Ingham <jingham@apple.com> | 2022-06-23 09:33:40 -0700 |
---|---|---|
committer | Jim Ingham <jingham@apple.com> | 2022-06-27 15:14:41 -0700 |
commit | c1b07d617705dfdb3aabbdda51c1a40d99f7cc1a (patch) | |
tree | ed7886491e1a97d19af06525fca43987a3dfb0a9 /lldb/source/Commands/CommandObjectTarget.cpp | |
parent | 6824eee94203b16de7633050367505c2ad10c56a (diff) | |
download | llvm-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/CommandObjectTarget.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectTarget.cpp | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index 23ebbdb..2b71f1b 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -487,18 +487,14 @@ public: protected: bool DoExecute(Args &args, CommandReturnObject &result) override { - if (args.GetArgumentCount() == 0) { - Stream &strm = result.GetOutputStream(); + Stream &strm = result.GetOutputStream(); - bool show_stopped_process_status = false; - if (DumpTargetList(GetDebugger().GetTargetList(), - show_stopped_process_status, strm) == 0) { - strm.PutCString("No targets.\n"); - } - result.SetStatus(eReturnStatusSuccessFinishResult); - } else { - result.AppendError("the 'target list' command takes no arguments\n"); + bool show_stopped_process_status = false; + if (DumpTargetList(GetDebugger().GetTargetList(), + show_stopped_process_status, strm) == 0) { + strm.PutCString("No targets.\n"); } + result.SetStatus(eReturnStatusSuccessFinishResult); return result.Succeeded(); } }; @@ -511,6 +507,8 @@ public: : CommandObjectParsed( interpreter, "target select", "Select a target as the current target by target index.", nullptr) { + CommandArgumentData target_arg{eArgTypeTargetID, eArgRepeatPlain}; + m_arguments.push_back({target_arg}); } ~CommandObjectTargetSelect() override = default; @@ -575,6 +573,8 @@ public: m_option_group.Append(&m_all_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); m_option_group.Append(&m_cleanup_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); m_option_group.Finalize(); + CommandArgumentData target_arg{eArgTypeTargetID, eArgRepeatStar}; + m_arguments.push_back({target_arg}); } ~CommandObjectTargetDelete() override = default; @@ -1230,10 +1230,6 @@ public: protected: bool DoExecute(Args &command, CommandReturnObject &result) override { Target *target = &GetSelectedTarget(); - if (command.GetArgumentCount() != 0) { - result.AppendError("list takes no arguments\n"); - return result.Succeeded(); - } target->GetImageSearchPathList().Dump(&result.GetOutputStream()); result.SetStatus(eReturnStatusSuccessFinishResult); @@ -2454,6 +2450,8 @@ public: LLDB_OPT_SET_1); m_option_group.Append(&m_symbol_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); m_option_group.Finalize(); + CommandArgumentData module_arg{eArgTypePath, eArgRepeatStar}; + m_arguments.push_back({module_arg}); } ~CommandObjectTargetModulesAdd() override = default; @@ -4019,6 +4017,8 @@ public: m_option_group.Append(&m_current_stack_option, LLDB_OPT_SET_2, LLDB_OPT_SET_2); m_option_group.Finalize(); + CommandArgumentData module_arg{eArgTypeShlibName, eArgRepeatPlain}; + m_arguments.push_back({module_arg}); } ~CommandObjectTargetSymbolsAdd() override = default; @@ -4867,7 +4867,10 @@ public: CommandObjectTargetStopHookDelete(CommandInterpreter &interpreter) : CommandObjectParsed(interpreter, "target stop-hook delete", "Delete a stop-hook.", - "target stop-hook delete [<idx>]") {} + "target stop-hook delete [<idx>]") { + CommandArgumentData hook_arg{eArgTypeStopHookID, eArgRepeatStar}; + m_arguments.push_back({hook_arg}); + } ~CommandObjectTargetStopHookDelete() override = default; @@ -4921,6 +4924,8 @@ public: bool enable, const char *name, const char *help, const char *syntax) : CommandObjectParsed(interpreter, name, help, syntax), m_enable(enable) { + CommandArgumentData hook_arg{eArgTypeStopHookID, eArgRepeatStar}; + m_arguments.push_back({hook_arg}); } ~CommandObjectTargetStopHookEnableDisable() override = default; @@ -4976,8 +4981,7 @@ class CommandObjectTargetStopHookList : public CommandObjectParsed { public: CommandObjectTargetStopHookList(CommandInterpreter &interpreter) : CommandObjectParsed(interpreter, "target stop-hook list", - "List all stop-hooks.", - "target stop-hook list [<type>]") {} + "List all stop-hooks.", "target stop-hook list") {} ~CommandObjectTargetStopHookList() override = default; @@ -5049,11 +5053,6 @@ public: protected: bool DoExecute(Args &command, CommandReturnObject &result) override { - if (!command.empty()) { - result.AppendError("target dump typesystem doesn't take arguments."); - return result.Succeeded(); - } - // Go over every scratch TypeSystem and dump to the command output. for (TypeSystem *ts : GetSelectedTarget().GetScratchTypeSystems()) ts->Dump(result.GetOutputStream().AsRawOstream()); |