summaryrefslogtreecommitdiff
path: root/source/Commands/CommandObjectCommands.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Commands/CommandObjectCommands.cpp')
-rw-r--r--source/Commands/CommandObjectCommands.cpp113
1 files changed, 43 insertions, 70 deletions
diff --git a/source/Commands/CommandObjectCommands.cpp b/source/Commands/CommandObjectCommands.cpp
index 01e1c4269bba..4092e76be6ac 100644
--- a/source/Commands/CommandObjectCommands.cpp
+++ b/source/Commands/CommandObjectCommands.cpp
@@ -1,9 +1,8 @@
//===-- CommandObjectCommands.cpp -------------------------------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -30,9 +29,7 @@
using namespace lldb;
using namespace lldb_private;
-//-------------------------------------------------------------------------
// CommandObjectCommandsSource
-//-------------------------------------------------------------------------
static constexpr OptionDefinition g_history_options[] = {
// clang-format off
@@ -189,9 +186,7 @@ protected:
CommandOptions m_options;
};
-//-------------------------------------------------------------------------
// CommandObjectCommandsSource
-//-------------------------------------------------------------------------
static constexpr OptionDefinition g_source_options[] = {
// clang-format off
@@ -314,14 +309,20 @@ protected:
m_options.m_stop_on_continue.OptionWasSet()) {
// Use user set settings
CommandInterpreterRunOptions options;
- options.SetStopOnContinue(m_options.m_stop_on_continue.GetCurrentValue());
- options.SetStopOnError(m_options.m_stop_on_error.GetCurrentValue());
+
+ if (m_options.m_stop_on_continue.OptionWasSet())
+ options.SetStopOnContinue(
+ m_options.m_stop_on_continue.GetCurrentValue());
+
+ if (m_options.m_stop_on_error.OptionWasSet())
+ options.SetStopOnError(m_options.m_stop_on_error.GetCurrentValue());
// Individual silent setting is override for global command echo settings.
if (m_options.m_silent_run.GetCurrentValue()) {
options.SetSilent(true);
} else {
options.SetPrintResults(true);
+ options.SetPrintErrors(true);
options.SetEchoCommands(m_interpreter.GetEchoCommands());
options.SetEchoCommentCommands(m_interpreter.GetEchoCommentCommands());
}
@@ -340,9 +341,7 @@ protected:
};
#pragma mark CommandObjectCommandsAlias
-//-------------------------------------------------------------------------
// CommandObjectCommandsAlias
-//-------------------------------------------------------------------------
static constexpr OptionDefinition g_alias_options[] = {
// clang-format off
@@ -766,9 +765,7 @@ protected:
};
#pragma mark CommandObjectCommandsUnalias
-//-------------------------------------------------------------------------
// CommandObjectCommandsUnalias
-//-------------------------------------------------------------------------
class CommandObjectCommandsUnalias : public CommandObjectParsed {
public:
@@ -849,9 +846,7 @@ protected:
};
#pragma mark CommandObjectCommandsDelete
-//-------------------------------------------------------------------------
// CommandObjectCommandsDelete
-//-------------------------------------------------------------------------
class CommandObjectCommandsDelete : public CommandObjectParsed {
public:
@@ -891,11 +886,11 @@ protected:
auto command_name = args[0].ref;
if (!m_interpreter.CommandExists(command_name)) {
StreamString error_msg_stream;
- const bool generate_apropos = true;
+ const bool generate_upropos = true;
const bool generate_type_lookup = false;
CommandObjectHelp::GenerateAdditionalHelpAvenuesMessage(
&error_msg_stream, command_name, llvm::StringRef(), llvm::StringRef(),
- generate_apropos, generate_type_lookup);
+ generate_upropos, generate_type_lookup);
result.AppendError(error_msg_stream.GetString());
result.SetStatus(eReturnStatusFailed);
return false;
@@ -914,9 +909,7 @@ protected:
}
};
-//-------------------------------------------------------------------------
// CommandObjectCommandsAddRegex
-//-------------------------------------------------------------------------
static constexpr OptionDefinition g_regex_options[] = {
// clang-format off
@@ -976,10 +969,10 @@ a number follows 'f':"
~CommandObjectCommandsAddRegex() override = default;
protected:
- void IOHandlerActivated(IOHandler &io_handler) override {
+ void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
StreamFileSP output_sp(io_handler.GetOutputStreamFile());
- if (output_sp) {
- output_sp->PutCString("Enter one of more sed substitution commands in "
+ if (output_sp && interactive) {
+ output_sp->PutCString("Enter one or more sed substitution commands in "
"the form: 's/<regex>/<subst>/'.\nTerminate the "
"substitution list with an empty line.\n");
output_sp->Flush();
@@ -989,7 +982,7 @@ protected:
void IOHandlerInputComplete(IOHandler &io_handler,
std::string &data) override {
io_handler.SetIsDone(true);
- if (m_regex_cmd_ap) {
+ if (m_regex_cmd_up) {
StringList lines;
if (lines.SplitIntoLines(data)) {
const size_t num_lines = lines.GetSize();
@@ -998,18 +991,15 @@ protected:
llvm::StringRef bytes_strref(lines[i]);
Status error = AppendRegexSubstitution(bytes_strref, check_only);
if (error.Fail()) {
- if (!m_interpreter.GetDebugger()
- .GetCommandInterpreter()
- .GetBatchCommandMode()) {
- StreamSP out_stream =
- m_interpreter.GetDebugger().GetAsyncOutputStream();
+ if (!GetDebugger().GetCommandInterpreter().GetBatchCommandMode()) {
+ StreamSP out_stream = GetDebugger().GetAsyncOutputStream();
out_stream->Printf("error: %s\n", error.AsCString());
}
}
}
}
- if (m_regex_cmd_ap->HasRegexEntries()) {
- CommandObjectSP cmd_sp(m_regex_cmd_ap.release());
+ if (m_regex_cmd_up->HasRegexEntries()) {
+ CommandObjectSP cmd_sp(m_regex_cmd_up.release());
m_interpreter.AddCommand(cmd_sp->GetCommandName(), cmd_sp, true);
}
}
@@ -1026,12 +1016,12 @@ protected:
Status error;
auto name = command[0].ref;
- m_regex_cmd_ap = llvm::make_unique<CommandObjectRegexCommand>(
+ m_regex_cmd_up = llvm::make_unique<CommandObjectRegexCommand>(
m_interpreter, name, m_options.GetHelp(), m_options.GetSyntax(), 10, 0,
true);
if (argc == 1) {
- Debugger &debugger = m_interpreter.GetDebugger();
+ Debugger &debugger = GetDebugger();
bool color_prompt = debugger.GetUseColor();
const bool multiple_lines = true; // Get multiple lines
IOHandlerSP io_handler_sp(new IOHandlerEditline(
@@ -1041,7 +1031,7 @@ protected:
llvm::StringRef(), // Continuation prompt
multiple_lines, color_prompt,
0, // Don't show line numbers
- *this));
+ *this, nullptr));
if (io_handler_sp) {
debugger.PushIOHandler(io_handler_sp);
@@ -1071,7 +1061,7 @@ protected:
bool check_only) {
Status error;
- if (!m_regex_cmd_ap) {
+ if (!m_regex_cmd_up) {
error.SetErrorStringWithFormat(
"invalid regular expression command object for: '%.*s'",
(int)regex_sed.size(), regex_sed.data());
@@ -1157,22 +1147,22 @@ protected:
std::string subst(regex_sed.substr(second_separator_char_pos + 1,
third_separator_char_pos -
second_separator_char_pos - 1));
- m_regex_cmd_ap->AddRegexCommand(regex.c_str(), subst.c_str());
+ m_regex_cmd_up->AddRegexCommand(regex.c_str(), subst.c_str());
}
return error;
}
void AddRegexCommandToInterpreter() {
- if (m_regex_cmd_ap) {
- if (m_regex_cmd_ap->HasRegexEntries()) {
- CommandObjectSP cmd_sp(m_regex_cmd_ap.release());
+ if (m_regex_cmd_up) {
+ if (m_regex_cmd_up->HasRegexEntries()) {
+ CommandObjectSP cmd_sp(m_regex_cmd_up.release());
m_interpreter.AddCommand(cmd_sp->GetCommandName(), cmd_sp, true);
}
}
}
private:
- std::unique_ptr<CommandObjectRegexCommand> m_regex_cmd_ap;
+ std::unique_ptr<CommandObjectRegexCommand> m_regex_cmd_up;
class CommandOptions : public Options {
public:
@@ -1259,7 +1249,7 @@ public:
if (m_fetched_help_long)
return CommandObjectRaw::GetHelpLong();
- ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter();
if (!scripter)
return CommandObjectRaw::GetHelpLong();
@@ -1274,7 +1264,7 @@ public:
protected:
bool DoExecute(llvm::StringRef raw_command_line,
CommandReturnObject &result) override {
- ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter();
Status error;
@@ -1317,7 +1307,7 @@ public:
StreamString stream;
stream.Printf("For more information run 'help %s'", name.c_str());
SetHelp(stream.GetString());
- if (ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter())
+ if (ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter())
GetFlags().Set(scripter->GetFlagsForCommandObject(cmd_obj_sp));
}
@@ -1332,7 +1322,7 @@ public:
llvm::StringRef GetHelp() override {
if (m_fetched_help_short)
return CommandObjectRaw::GetHelp();
- ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter();
if (!scripter)
return CommandObjectRaw::GetHelp();
std::string docstring;
@@ -1348,7 +1338,7 @@ public:
if (m_fetched_help_long)
return CommandObjectRaw::GetHelpLong();
- ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter();
if (!scripter)
return CommandObjectRaw::GetHelpLong();
@@ -1363,7 +1353,7 @@ public:
protected:
bool DoExecute(llvm::StringRef raw_command_line,
CommandReturnObject &result) override {
- ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter();
Status error;
@@ -1394,9 +1384,7 @@ private:
bool m_fetched_help_long : 1;
};
-//-------------------------------------------------------------------------
// CommandObjectCommandsScriptImport
-//-------------------------------------------------------------------------
static constexpr OptionDefinition g_script_import_options[] = {
// clang-format off
@@ -1477,8 +1465,7 @@ protected:
};
bool DoExecute(Args &command, CommandReturnObject &result) override {
- if (m_interpreter.GetDebugger().GetScriptLanguage() !=
- lldb::eScriptLanguagePython) {
+ if (GetDebugger().GetScriptLanguage() != lldb::eScriptLanguagePython) {
result.AppendError("only scripting language supported for module "
"importing is currently Python");
result.SetStatus(eReturnStatusFailed);
@@ -1504,7 +1491,7 @@ protected:
// won't stomp on each other (wrt to execution contents, options, and
// more)
m_exe_ctx.Clear();
- if (m_interpreter.GetScriptInterpreter()->LoadScriptingModule(
+ if (GetDebugger().GetScriptInterpreter()->LoadScriptingModule(
entry.c_str(), m_options.m_allow_reload, init_session, error)) {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
} else {
@@ -1520,9 +1507,7 @@ protected:
CommandOptions m_options;
};
-//-------------------------------------------------------------------------
// CommandObjectCommandsScriptAdd
-//-------------------------------------------------------------------------
static constexpr OptionEnumValueElement g_script_synchro_type[] = {
{eScriptedCommandSynchronicitySynchronous, "synchronous",
"Run synchronous"},
@@ -1635,9 +1620,9 @@ protected:
ScriptedCommandSynchronicity m_synchronicity;
};
- void IOHandlerActivated(IOHandler &io_handler) override {
+ void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
StreamFileSP output_sp(io_handler.GetOutputStreamFile());
- if (output_sp) {
+ if (output_sp && interactive) {
output_sp->PutCString(g_python_command_instructions);
output_sp->Flush();
}
@@ -1647,7 +1632,7 @@ protected:
std::string &data) override {
StreamFileSP error_sp = io_handler.GetErrorStreamFile();
- ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
if (interpreter) {
StringList lines;
@@ -1693,8 +1678,7 @@ protected:
protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
- if (m_interpreter.GetDebugger().GetScriptLanguage() !=
- lldb::eScriptLanguagePython) {
+ if (GetDebugger().GetScriptLanguage() != lldb::eScriptLanguagePython) {
result.AppendError("only scripting language supported for scripted "
"commands is currently Python");
result.SetStatus(eReturnStatusFailed);
@@ -1732,8 +1716,7 @@ protected:
}
}
} else {
- ScriptInterpreter *interpreter =
- GetCommandInterpreter().GetScriptInterpreter();
+ ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
if (!interpreter) {
result.AppendError("cannot find ScriptInterpreter");
result.SetStatus(eReturnStatusFailed);
@@ -1767,9 +1750,7 @@ protected:
ScriptedCommandSynchronicity m_synchronicity;
};
-//-------------------------------------------------------------------------
// CommandObjectCommandsScriptList
-//-------------------------------------------------------------------------
class CommandObjectCommandsScriptList : public CommandObjectParsed {
public:
@@ -1788,9 +1769,7 @@ public:
}
};
-//-------------------------------------------------------------------------
// CommandObjectCommandsScriptClear
-//-------------------------------------------------------------------------
class CommandObjectCommandsScriptClear : public CommandObjectParsed {
public:
@@ -1810,9 +1789,7 @@ protected:
}
};
-//-------------------------------------------------------------------------
// CommandObjectCommandsScriptDelete
-//-------------------------------------------------------------------------
class CommandObjectCommandsScriptDelete : public CommandObjectParsed {
public:
@@ -1862,9 +1839,7 @@ protected:
#pragma mark CommandObjectMultiwordCommandsScript
-//-------------------------------------------------------------------------
// CommandObjectMultiwordCommandsScript
-//-------------------------------------------------------------------------
class CommandObjectMultiwordCommandsScript : public CommandObjectMultiword {
public:
@@ -1894,9 +1869,7 @@ public:
#pragma mark CommandObjectMultiwordCommands
-//-------------------------------------------------------------------------
// CommandObjectMultiwordCommands
-//-------------------------------------------------------------------------
CommandObjectMultiwordCommands::CommandObjectMultiwordCommands(
CommandInterpreter &interpreter)