aboutsummaryrefslogtreecommitdiffstats
path: root/source/Commands/CommandObjectCommands.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Commands/CommandObjectCommands.cpp')
-rw-r--r--source/Commands/CommandObjectCommands.cpp164
1 files changed, 70 insertions, 94 deletions
diff --git a/source/Commands/CommandObjectCommands.cpp b/source/Commands/CommandObjectCommands.cpp
index 4092e76be6ac..259affbe6e0a 100644
--- a/source/Commands/CommandObjectCommands.cpp
+++ b/source/Commands/CommandObjectCommands.cpp
@@ -31,14 +31,8 @@ using namespace lldb_private;
// CommandObjectCommandsSource
-static constexpr OptionDefinition g_history_options[] = {
- // clang-format off
- { LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeUnsignedInteger, "How many history commands to print." },
- { LLDB_OPT_SET_1, false, "start-index", 's', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeUnsignedInteger, "Index at which to start printing history commands (or end to mean tail mode)." },
- { LLDB_OPT_SET_1, false, "end-index", 'e', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeUnsignedInteger, "Index at which to stop printing history commands." },
- { LLDB_OPT_SET_2, false, "clear", 'C', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeBoolean, "Clears the current command history." },
- // clang-format on
-};
+#define LLDB_OPTIONS_history
+#include "CommandOptions.inc"
class CommandObjectCommandsHistory : public CommandObjectParsed {
public:
@@ -91,9 +85,7 @@ protected:
m_clear.SetOptionWasSet();
break;
default:
- error.SetErrorStringWithFormat("unrecognized option '%c'",
- short_option);
- break;
+ llvm_unreachable("Unimplemented option");
}
return error;
@@ -188,13 +180,8 @@ protected:
// CommandObjectCommandsSource
-static constexpr OptionDefinition g_source_options[] = {
- // clang-format off
- { LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, "If true, stop executing commands on error." },
- { LLDB_OPT_SET_ALL, false, "stop-on-continue", 'c', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, "If true, stop executing commands on continue." },
- { LLDB_OPT_SET_ALL, false, "silent-run", 's', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, "If true don't echo commands while executing." },
- // clang-format on
-};
+#define LLDB_OPTIONS_source
+#include "CommandOptions.inc"
class CommandObjectCommandsSource : public CommandObjectParsed {
public:
@@ -226,13 +213,12 @@ public:
return "";
}
- int HandleArgumentCompletion(
- CompletionRequest &request,
- OptionElementVector &opt_element_vector) override {
+ void
+ HandleArgumentCompletion(CompletionRequest &request,
+ OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
- return request.GetNumberOfMatches();
}
Options *GetOptions() override { return &m_options; }
@@ -265,9 +251,7 @@ protected:
break;
default:
- error.SetErrorStringWithFormat("unrecognized option '%c'",
- short_option);
- break;
+ llvm_unreachable("Unimplemented option");
}
return error;
@@ -299,7 +283,7 @@ protected:
return false;
}
- FileSpec cmd_file(command[0].ref);
+ FileSpec cmd_file(command[0].ref());
FileSystem::Instance().Resolve(cmd_file);
ExecutionContext *exe_ctx = nullptr; // Just use the default context.
@@ -343,12 +327,8 @@ protected:
#pragma mark CommandObjectCommandsAlias
// CommandObjectCommandsAlias
-static constexpr OptionDefinition g_alias_options[] = {
- // clang-format off
- { LLDB_OPT_SET_ALL, false, "help", 'h', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeHelpText, "Help text for this command" },
- { LLDB_OPT_SET_ALL, false, "long-help", 'H', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeHelpText, "Long help text for this command" },
- // clang-format on
-};
+#define LLDB_OPTIONS_alias
+#include "CommandOptions.inc"
static const char *g_python_command_instructions =
"Enter your Python command(s). Type 'DONE' to end.\n"
@@ -386,9 +366,7 @@ protected:
break;
default:
- error.SetErrorStringWithFormat("invalid short option character '%c'",
- short_option);
- break;
+ llvm_unreachable("Unimplemented option");
}
return error;
@@ -568,7 +546,7 @@ protected:
// Get the alias command.
- auto alias_command = args[0].ref;
+ auto alias_command = args[0].ref();
if (alias_command.startswith("-")) {
result.AppendError("aliases starting with a dash are not supported");
if (alias_command == "--help" || alias_command == "--long-help") {
@@ -675,8 +653,8 @@ protected:
}
// Save these in std::strings since we're going to shift them off.
- const std::string alias_command(args[0].ref);
- const std::string actual_command(args[1].ref);
+ const std::string alias_command(args[0].ref());
+ const std::string actual_command(args[1].ref());
args.Shift(); // Shift the alias command word off the argument vector.
args.Shift(); // Shift the old command word off the argument vector.
@@ -708,7 +686,7 @@ protected:
OptionArgVectorSP(new OptionArgVector);
while (cmd_obj->IsMultiwordObject() && !args.empty()) {
- auto sub_command = args[0].ref;
+ auto sub_command = args[0].ref();
assert(!sub_command.empty());
subcommand_obj_sp = cmd_obj->GetSubcommandSP(sub_command);
if (!subcommand_obj_sp) {
@@ -802,7 +780,7 @@ protected:
return false;
}
- auto command_name = args[0].ref;
+ auto command_name = args[0].ref();
cmd_obj = m_interpreter.GetCommandObject(command_name);
if (!cmd_obj) {
result.AppendErrorWithFormat(
@@ -881,9 +859,10 @@ protected:
"defined regular expression command names",
GetCommandName().str().c_str());
result.SetStatus(eReturnStatusFailed);
+ return false;
}
- auto command_name = args[0].ref;
+ auto command_name = args[0].ref();
if (!m_interpreter.CommandExists(command_name)) {
StreamString error_msg_stream;
const bool generate_upropos = true;
@@ -911,12 +890,8 @@ protected:
// CommandObjectCommandsAddRegex
-static constexpr OptionDefinition g_regex_options[] = {
- // clang-format off
- { LLDB_OPT_SET_1, false, "help" , 'h', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeNone, "The help text to display for this command." },
- { LLDB_OPT_SET_1, false, "syntax", 's', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeNone, "A syntax string showing the typical usage syntax." },
- // clang-format on
-};
+#define LLDB_OPTIONS_regex
+#include "CommandOptions.inc"
#pragma mark CommandObjectCommandsAddRegex
@@ -970,7 +945,7 @@ a number follows 'f':"
protected:
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
if (output_sp && interactive) {
output_sp->PutCString("Enter one or more sed substitution commands in "
"the form: 's/<regex>/<subst>/'.\nTerminate the "
@@ -985,11 +960,9 @@ protected:
if (m_regex_cmd_up) {
StringList lines;
if (lines.SplitIntoLines(data)) {
- const size_t num_lines = lines.GetSize();
bool check_only = false;
- for (size_t i = 0; i < num_lines; ++i) {
- llvm::StringRef bytes_strref(lines[i]);
- Status error = AppendRegexSubstitution(bytes_strref, check_only);
+ for (const std::string &line : lines) {
+ Status error = AppendRegexSubstitution(line, check_only);
if (error.Fail()) {
if (!GetDebugger().GetCommandInterpreter().GetBatchCommandMode()) {
StreamSP out_stream = GetDebugger().GetAsyncOutputStream();
@@ -1015,8 +988,8 @@ protected:
}
Status error;
- auto name = command[0].ref;
- m_regex_cmd_up = llvm::make_unique<CommandObjectRegexCommand>(
+ auto name = command[0].ref();
+ m_regex_cmd_up = std::make_unique<CommandObjectRegexCommand>(
m_interpreter, name, m_options.GetHelp(), m_options.GetSyntax(), 10, 0,
true);
@@ -1040,7 +1013,7 @@ protected:
} else {
for (auto &entry : command.entries().drop_front()) {
bool check_only = false;
- error = AppendRegexSubstitution(entry.ref, check_only);
+ error = AppendRegexSubstitution(entry.ref(), check_only);
if (error.Fail())
break;
}
@@ -1183,9 +1156,7 @@ private:
m_syntax.assign(option_arg);
break;
default:
- error.SetErrorStringWithFormat("unrecognized option '%c'",
- short_option);
- break;
+ llvm_unreachable("Unimplemented option");
}
return error;
@@ -1315,8 +1286,6 @@ public:
bool IsRemovable() const override { return true; }
- StructuredData::GenericSP GetImplementingObject() { return m_cmd_obj_sp; }
-
ScriptedCommandSynchronicity GetSynchronicity() { return m_synchro; }
llvm::StringRef GetHelp() override {
@@ -1385,12 +1354,8 @@ private:
};
// CommandObjectCommandsScriptImport
-
-static constexpr OptionDefinition g_script_import_options[] = {
- // clang-format off
- { LLDB_OPT_SET_1, false, "allow-reload", 'r', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Allow the script to be loaded even if it was already loaded before. This argument exists for backwards compatibility, but reloading is always allowed, whether you specify it or not." },
- // clang-format on
-};
+#define LLDB_OPTIONS_script_import
+#include "CommandOptions.inc"
class CommandObjectCommandsScriptImport : public CommandObjectParsed {
public:
@@ -1415,13 +1380,12 @@ public:
~CommandObjectCommandsScriptImport() override = default;
- int HandleArgumentCompletion(
- CompletionRequest &request,
- OptionElementVector &opt_element_vector) override {
+ void
+ HandleArgumentCompletion(CompletionRequest &request,
+ OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
- return request.GetNumberOfMatches();
}
Options *GetOptions() override { return &m_options; }
@@ -1443,9 +1407,7 @@ protected:
m_allow_reload = true;
break;
default:
- error.SetErrorStringWithFormat("unrecognized option '%c'",
- short_option);
- break;
+ llvm_unreachable("Unimplemented option");
}
return error;
@@ -1509,25 +1471,29 @@ protected:
// CommandObjectCommandsScriptAdd
static constexpr OptionEnumValueElement g_script_synchro_type[] = {
- {eScriptedCommandSynchronicitySynchronous, "synchronous",
- "Run synchronous"},
- {eScriptedCommandSynchronicityAsynchronous, "asynchronous",
- "Run asynchronous"},
- {eScriptedCommandSynchronicityCurrentValue, "current",
- "Do not alter current setting"} };
+ {
+ eScriptedCommandSynchronicitySynchronous,
+ "synchronous",
+ "Run synchronous",
+ },
+ {
+ eScriptedCommandSynchronicityAsynchronous,
+ "asynchronous",
+ "Run asynchronous",
+ },
+ {
+ eScriptedCommandSynchronicityCurrentValue,
+ "current",
+ "Do not alter current setting",
+ },
+};
static constexpr OptionEnumValues ScriptSynchroType() {
return OptionEnumValues(g_script_synchro_type);
}
-static constexpr OptionDefinition g_script_add_options[] = {
- // clang-format off
- { LLDB_OPT_SET_1, false, "function", 'f', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypePythonFunction, "Name of the Python function to bind to this command name." },
- { LLDB_OPT_SET_2, false, "class", 'c', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypePythonClass, "Name of the Python class to bind to this command name." },
- { LLDB_OPT_SET_1, false, "help" , 'h', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeHelpText, "The help text to display for this command." },
- { LLDB_OPT_SET_ALL, false, "synchronicity", 's', OptionParser::eRequiredArgument, nullptr, ScriptSynchroType(), 0, eArgTypeScriptedCommandSynchronicity, "Set the synchronicity of this command's executions with regard to LLDB event system." },
- // clang-format on
-};
+#define LLDB_OPTIONS_script_add
+#include "CommandOptions.inc"
class CommandObjectCommandsScriptAdd : public CommandObjectParsed,
public IOHandlerDelegateMultiline {
@@ -1593,9 +1559,7 @@ protected:
option_arg.str().c_str());
break;
default:
- error.SetErrorStringWithFormat("unrecognized option '%c'",
- short_option);
- break;
+ llvm_unreachable("Unimplemented option");
}
return error;
@@ -1621,7 +1585,7 @@ protected:
};
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
if (output_sp && interactive) {
output_sp->PutCString(g_python_command_instructions);
output_sp->Flush();
@@ -1630,7 +1594,7 @@ protected:
void IOHandlerInputComplete(IOHandler &io_handler,
std::string &data) override {
- StreamFileSP error_sp = io_handler.GetErrorStreamFile();
+ StreamFileSP error_sp = io_handler.GetErrorStreamFileSP();
ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
if (interpreter) {
@@ -1692,7 +1656,7 @@ protected:
}
// Store the options in case we get multi-line input
- m_cmd_name = command[0].ref;
+ m_cmd_name = command[0].ref();
m_short_help.assign(m_options.m_short_help);
m_synchronicity = m_options.m_synchronicity;
@@ -1761,6 +1725,12 @@ public:
~CommandObjectCommandsScriptList() override = default;
bool DoExecute(Args &command, CommandReturnObject &result) override {
+ if (command.GetArgumentCount() != 0) {
+ result.AppendError("'command script list' doesn't take any arguments");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
m_interpreter.GetHelp(result, CommandInterpreter::eCommandTypesUserDef);
result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -1781,6 +1751,12 @@ public:
protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
+ if (command.GetArgumentCount() != 0) {
+ result.AppendError("'command script clear' doesn't take any arguments");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
m_interpreter.RemoveAllUser();
result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -1822,7 +1798,7 @@ protected:
return false;
}
- auto cmd_name = command[0].ref;
+ auto cmd_name = command[0].ref();
if (cmd_name.empty() || !m_interpreter.HasUserCommands() ||
!m_interpreter.UserCommandExists(cmd_name)) {