aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectCommands.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Commands/CommandObjectCommands.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectCommands.cpp69
1 files changed, 16 insertions, 53 deletions
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp
index 3b3cdde6ab9a..9a8b81c007ad 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -128,21 +128,17 @@ protected:
result.AppendErrorWithFormat(
"'%s' takes exactly one executable filename argument.\n",
GetCommandName().str().c_str());
- result.SetStatus(eReturnStatusFailed);
return false;
}
FileSpec cmd_file(command[0].ref());
FileSystem::Instance().Resolve(cmd_file);
- ExecutionContext *exe_ctx = nullptr; // Just use the default context.
+ CommandInterpreterRunOptions options;
// If any options were set, then use them
if (m_options.m_stop_on_error.OptionWasSet() ||
m_options.m_silent_run.OptionWasSet() ||
m_options.m_stop_on_continue.OptionWasSet()) {
- // Use user set settings
- CommandInterpreterRunOptions options;
-
if (m_options.m_stop_on_continue.OptionWasSet())
options.SetStopOnContinue(
m_options.m_stop_on_continue.GetCurrentValue());
@@ -159,14 +155,9 @@ protected:
options.SetEchoCommands(m_interpreter.GetEchoCommands());
options.SetEchoCommentCommands(m_interpreter.GetEchoCommentCommands());
}
-
- m_interpreter.HandleCommandsFromFile(cmd_file, exe_ctx, options, result);
- } else {
- // No options were set, inherit any settings from nested "command source"
- // commands, or set to sane default settings...
- CommandInterpreterRunOptions options;
- m_interpreter.HandleCommandsFromFile(cmd_file, exe_ctx, options, result);
}
+
+ m_interpreter.HandleCommandsFromFile(cmd_file, options, result);
return result.Succeeded();
}
@@ -388,7 +379,6 @@ protected:
if (args.GetArgumentCount() < 2) {
result.AppendError("'command alias' requires at least two arguments");
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -401,7 +391,6 @@ protected:
result.AppendWarning("if trying to pass options to 'command alias' add "
"a -- at the end of the options");
}
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -415,7 +404,6 @@ protected:
raw_command_string = raw_command_string.substr(pos);
} else {
result.AppendError("Error parsing command string. No alias created.");
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -424,7 +412,6 @@ protected:
result.AppendErrorWithFormat(
"'%s' is a permanent debugger command and cannot be redefined.\n",
args[0].c_str());
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -440,7 +427,6 @@ protected:
"'%s' does not begin with a valid command."
" No alias created.",
original_raw_command_string.str().c_str());
- result.SetStatus(eReturnStatusFailed);
return false;
} else if (!cmd_obj->WantsRawCommandString()) {
// Note that args was initialized with the original command, and has not
@@ -480,12 +466,10 @@ protected:
result.SetStatus(eReturnStatusSuccessFinishNoResult);
} else {
result.AppendError("Unable to create requested alias.\n");
- result.SetStatus(eReturnStatusFailed);
}
} else {
result.AppendError("Unable to create requested alias.\n");
- result.SetStatus(eReturnStatusFailed);
}
return result.Succeeded();
@@ -496,7 +480,6 @@ protected:
if (argc < 2) {
result.AppendError("'command alias' requires at least two arguments");
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -514,7 +497,6 @@ protected:
result.AppendErrorWithFormat(
"'%s' is a permanent debugger command and cannot be redefined.\n",
alias_command.c_str());
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -525,7 +507,6 @@ protected:
if (!command_obj_sp) {
result.AppendErrorWithFormat("'%s' is not an existing command.\n",
actual_command.c_str());
- result.SetStatus(eReturnStatusFailed);
return false;
}
CommandObject *cmd_obj = command_obj_sp.get();
@@ -542,7 +523,6 @@ protected:
"'%s' is not a valid sub-command of '%s'. "
"Unable to create alias.\n",
args[0].c_str(), actual_command.c_str());
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -581,7 +561,6 @@ protected:
result.SetStatus(eReturnStatusSuccessFinishNoResult);
} else {
result.AppendError("Unable to create requested alias.\n");
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -634,7 +613,6 @@ protected:
if (args.empty()) {
result.AppendError("must call 'unalias' with a valid alias");
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -645,7 +623,6 @@ protected:
"'%s' is not a known command.\nTry 'help' to see a "
"current list of commands.\n",
args[0].c_str());
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -660,7 +637,6 @@ protected:
"'%s' is a permanent debugger command and cannot be removed.\n",
args[0].c_str());
}
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -672,7 +648,6 @@ protected:
else
result.AppendErrorWithFormat("'%s' is not an existing alias.\n",
args[0].c_str());
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -728,7 +703,6 @@ protected:
result.AppendErrorWithFormat("must call '%s' with one or more valid user "
"defined regular expression command names",
GetCommandName().str().c_str());
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -741,7 +715,6 @@ protected:
&error_msg_stream, command_name, llvm::StringRef(), llvm::StringRef(),
generate_upropos, generate_type_lookup);
result.AppendError(error_msg_stream.GetString());
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -749,7 +722,6 @@ protected:
result.AppendErrorWithFormat(
"'%s' is a permanent debugger command and cannot be removed.\n",
args[0].c_str());
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -854,7 +826,6 @@ protected:
if (argc == 0) {
result.AppendError("usage: 'command regex <command-name> "
"[s/<regex1>/<subst1>/ s/<regex2>/<subst2>/ ...]'\n");
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -895,7 +866,6 @@ protected:
}
if (error.Fail()) {
result.AppendError(error.AsCString());
- result.SetStatus(eReturnStatusFailed);
}
return result.Succeeded();
@@ -1111,7 +1081,6 @@ protected:
m_function_name.c_str(), raw_command_line, m_synchro,
result, error, m_exe_ctx)) {
result.AppendError(error.AsCString());
- result.SetStatus(eReturnStatusFailed);
} else {
// Don't change the status if the command already set it...
if (result.GetStatus() == eReturnStatusInvalid) {
@@ -1197,7 +1166,6 @@ protected:
!scripter->RunScriptBasedCommand(m_cmd_obj_sp, raw_command_line,
m_synchro, result, error, m_exe_ctx)) {
result.AppendError(error.AsCString());
- result.SetStatus(eReturnStatusFailed);
} else {
// Don't change the status if the command already set it...
if (result.GetStatus() == eReturnStatusInvalid) {
@@ -1274,6 +1242,9 @@ protected:
case 'c':
relative_to_command_file = true;
break;
+ case 's':
+ silent = true;
+ break;
default:
llvm_unreachable("Unimplemented option");
}
@@ -1289,12 +1260,12 @@ protected:
return llvm::makeArrayRef(g_script_import_options);
}
bool relative_to_command_file = false;
+ bool silent = false;
};
bool DoExecute(Args &command, CommandReturnObject &result) override {
if (command.empty()) {
result.AppendError("command script import needs one or more arguments");
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -1304,7 +1275,6 @@ protected:
if (!source_dir) {
result.AppendError("command script import -c can only be specified "
"from a command file");
- result.SetStatus(eReturnStatusFailed);
return false;
}
}
@@ -1312,7 +1282,10 @@ protected:
for (auto &entry : command.entries()) {
Status error;
- const bool init_session = true;
+ LoadScriptOptions options;
+ options.SetInitSession(true);
+ options.SetSilent(m_options.silent);
+
// FIXME: this is necessary because CommandObject::CheckRequirements()
// assumes that commands won't ever be recursively invoked, but it's
// actually possible to craft a Python script that does other "command
@@ -1323,12 +1296,12 @@ protected:
// more)
m_exe_ctx.Clear();
if (GetDebugger().GetScriptInterpreter()->LoadScriptingModule(
- entry.c_str(), init_session, error, nullptr, source_dir)) {
+ entry.c_str(), options, error, /*module_sp=*/nullptr,
+ source_dir)) {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
} else {
result.AppendErrorWithFormat("module importing failed: %s",
error.AsCString());
- result.SetStatus(eReturnStatusFailed);
}
}
@@ -1395,8 +1368,7 @@ protected:
class CommandOptions : public Options {
public:
CommandOptions()
- : Options(), m_class_name(), m_funct_name(), m_short_help(),
- m_synchronicity(eScriptedCommandSynchronicitySynchronous) {}
+ : Options(), m_class_name(), m_funct_name(), m_short_help() {}
~CommandOptions() override = default;
@@ -1450,7 +1422,8 @@ protected:
std::string m_class_name;
std::string m_funct_name;
std::string m_short_help;
- ScriptedCommandSynchronicity m_synchronicity;
+ ScriptedCommandSynchronicity m_synchronicity =
+ eScriptedCommandSynchronicitySynchronous;
};
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
@@ -1513,13 +1486,11 @@ protected:
if (GetDebugger().GetScriptLanguage() != lldb::eScriptLanguagePython) {
result.AppendError("only scripting language supported for scripted "
"commands is currently Python");
- result.SetStatus(eReturnStatusFailed);
return false;
}
if (command.GetArgumentCount() != 1) {
result.AppendError("'command script add' requires one argument");
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -1541,14 +1512,12 @@ protected:
result.SetStatus(eReturnStatusSuccessFinishNoResult);
} else {
result.AppendError("cannot add command");
- result.SetStatus(eReturnStatusFailed);
}
}
} else {
ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
if (!interpreter) {
result.AppendError("cannot find ScriptInterpreter");
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -1556,7 +1525,6 @@ protected:
m_options.m_class_name.c_str());
if (!cmd_obj_sp) {
result.AppendError("cannot create helper object");
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -1566,7 +1534,6 @@ protected:
result.SetStatus(eReturnStatusSuccessFinishNoResult);
} else {
result.AppendError("cannot add command");
- result.SetStatus(eReturnStatusFailed);
}
}
@@ -1592,7 +1559,6 @@ public:
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;
}
@@ -1618,7 +1584,6 @@ 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;
}
@@ -1669,7 +1634,6 @@ protected:
if (command.GetArgumentCount() != 1) {
result.AppendError("'command script delete' requires one argument");
- result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -1678,7 +1642,6 @@ protected:
if (cmd_name.empty() || !m_interpreter.HasUserCommands() ||
!m_interpreter.UserCommandExists(cmd_name)) {
result.AppendErrorWithFormat("command %s not found", command[0].c_str());
- result.SetStatus(eReturnStatusFailed);
return false;
}