[Lldb-commits] [lldb] r360216 - Propagate command interpreter errors from lldlbinit
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Tue May 7 18:23:47 PDT 2019
Author: jdevlieghere
Date: Tue May 7 18:23:47 2019
New Revision: 360216
URL: http://llvm.org/viewvc/llvm-project?rev=360216&view=rev
Log:
Propagate command interpreter errors from lldlbinit
This patch ensures that we propagate errors coming from the lldbinit
file trough the command/script interpreter. Before, if you did something
like command script import syntax_error.py, and the python file
contained a syntax error, lldb wouldn't tell you about it. This changes
with the current patch: errors are now propagated by default.
PS: Jim authored this change and I added testing.
Differential revision: https://reviews.llvm.org/D61579
Added:
lldb/trunk/lit/Driver/Inputs/syntax_error.py
Modified:
lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
lldb/trunk/lit/Driver/Inputs/.lldbinit
lldb/trunk/lit/Driver/LocalLLDBInit.test
lldb/trunk/source/Breakpoint/BreakpointOptions.cpp
lldb/trunk/source/Commands/CommandObjectBugreport.cpp
lldb/trunk/source/Commands/CommandObjectCommands.cpp
lldb/trunk/source/Commands/CommandObjectSettings.cpp
lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp
lldb/trunk/source/Interpreter/CommandInterpreter.cpp
lldb/trunk/source/Target/Target.cpp
Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=360216&r1=360215&r2=360216&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Tue May 7 18:23:47 2019
@@ -53,19 +53,23 @@ public:
/// \b false, print no ouput in this case. This setting has an effect only
/// if \param echo_commands is \b true.
/// \param[in] print_results
- /// If \b true print the results of the command after executing it. If
- /// \b false, execute silently.
+ /// If \b true and the command succeeds, print the results of the command
+ /// after executing it. If \b false, execute silently.
+ /// \param[in] print_errors
+ /// If \b true and the command fails, print the results of the command
+ /// after executing it. If \b false, execute silently.
/// \param[in] add_to_history
/// If \b true add the commands to the command history. If \b false, don't
/// add them.
CommandInterpreterRunOptions(LazyBool stop_on_continue,
LazyBool stop_on_error, LazyBool stop_on_crash,
LazyBool echo_commands, LazyBool echo_comments,
- LazyBool print_results, LazyBool add_to_history)
+ LazyBool print_results, LazyBool print_errors,
+ LazyBool add_to_history)
: m_stop_on_continue(stop_on_continue), m_stop_on_error(stop_on_error),
m_stop_on_crash(stop_on_crash), m_echo_commands(echo_commands),
m_echo_comment_commands(echo_comments), m_print_results(print_results),
- m_add_to_history(add_to_history) {}
+ m_print_errors(print_errors), m_add_to_history(add_to_history) {}
CommandInterpreterRunOptions()
: m_stop_on_continue(eLazyBoolCalculate),
@@ -73,13 +77,14 @@ public:
m_stop_on_crash(eLazyBoolCalculate),
m_echo_commands(eLazyBoolCalculate),
m_echo_comment_commands(eLazyBoolCalculate),
- m_print_results(eLazyBoolCalculate),
+ m_print_results(eLazyBoolCalculate), m_print_errors(eLazyBoolCalculate),
m_add_to_history(eLazyBoolCalculate) {}
void SetSilent(bool silent) {
LazyBool value = silent ? eLazyBoolNo : eLazyBoolYes;
m_print_results = value;
+ m_print_errors = value;
m_echo_commands = value;
m_echo_comment_commands = value;
m_add_to_history = value;
@@ -127,6 +132,12 @@ public:
m_print_results = print_results ? eLazyBoolYes : eLazyBoolNo;
}
+ bool GetPrintErrors() const { return DefaultToYes(m_print_errors); }
+
+ void SetPrintErrors(bool print_errors) {
+ m_print_errors = print_errors ? eLazyBoolYes : eLazyBoolNo;
+ }
+
bool GetAddToHistory() const { return DefaultToYes(m_add_to_history); }
void SetAddToHistory(bool add_to_history) {
@@ -139,6 +150,7 @@ public:
LazyBool m_echo_commands;
LazyBool m_echo_comment_commands;
LazyBool m_print_results;
+ LazyBool m_print_errors;
LazyBool m_add_to_history;
private:
Modified: lldb/trunk/lit/Driver/Inputs/.lldbinit
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Driver/Inputs/.lldbinit?rev=360216&r1=360215&r2=360216&view=diff
==============================================================================
--- lldb/trunk/lit/Driver/Inputs/.lldbinit (original)
+++ lldb/trunk/lit/Driver/Inputs/.lldbinit Tue May 7 18:23:47 2019
@@ -1 +1,2 @@
settings set -f frame-format "bogus"
+command script import syntax_error.py
Added: lldb/trunk/lit/Driver/Inputs/syntax_error.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Driver/Inputs/syntax_error.py?rev=360216&view=auto
==============================================================================
--- lldb/trunk/lit/Driver/Inputs/syntax_error.py (added)
+++ lldb/trunk/lit/Driver/Inputs/syntax_error.py Tue May 7 18:23:47 2019
@@ -0,0 +1 @@
+prlnt("foo")
Modified: lldb/trunk/lit/Driver/LocalLLDBInit.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Driver/LocalLLDBInit.test?rev=360216&r1=360215&r2=360216&view=diff
==============================================================================
--- lldb/trunk/lit/Driver/LocalLLDBInit.test (original)
+++ lldb/trunk/lit/Driver/LocalLLDBInit.test Tue May 7 18:23:47 2019
@@ -1,6 +1,7 @@
# RUN: mkdir -p %t.root
# RUN: mkdir -p %t.home
# RUN: cp %S/Inputs/.lldbinit %t.root
+# RUN: cp %S/Inputs/syntax_error.py %t.root
# RUN: cd %t.root
# RUN: env HOME=%t.home %lldb-init -o 'settings show frame-format' 2>&1 | FileCheck %s --check-prefix=WARNINIT --check-prefix=CHECK
# RUN: env HOME=%t.home %lldb-init -local-lldbinit -o 'settings show frame-format' 2>&1 | FileCheck %s --check-prefix=ALLOWINIT --check-prefix=NOINIT
@@ -9,4 +10,5 @@
# WARNINIT: There is a .lldbinit file in the current directory which is not being read.
# NOINIT-NOT: There is a .lldbinit file in the current directory which is not being read.
# CHECK-NOT: bogus
+# ALLOWINIT: name 'prlnt' is not defined
# ALLOWINIT: bogus
Modified: lldb/trunk/source/Breakpoint/BreakpointOptions.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointOptions.cpp?rev=360216&r1=360215&r2=360216&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointOptions.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointOptions.cpp Tue May 7 18:23:47 2019
@@ -646,6 +646,7 @@ bool BreakpointOptions::BreakpointOption
options.SetStopOnError(data->stop_on_error);
options.SetEchoCommands(true);
options.SetPrintResults(true);
+ options.SetPrintErrors(true);
options.SetAddToHistory(false);
debugger.GetCommandInterpreter().HandleCommands(commands, &exe_ctx,
Modified: lldb/trunk/source/Commands/CommandObjectBugreport.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBugreport.cpp?rev=360216&r1=360215&r2=360216&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectBugreport.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectBugreport.cpp Tue May 7 18:23:47 2019
@@ -94,6 +94,7 @@ protected:
options.SetStopOnError(false);
options.SetEchoCommands(true);
options.SetPrintResults(true);
+ options.SetPrintErrors(true);
options.SetAddToHistory(false);
m_interpreter.HandleCommands(commands, &m_exe_ctx, options, result);
Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=360216&r1=360215&r2=360216&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Tue May 7 18:23:47 2019
@@ -322,6 +322,7 @@ protected:
options.SetSilent(true);
} else {
options.SetPrintResults(true);
+ options.SetPrintErrors(true);
options.SetEchoCommands(m_interpreter.GetEchoCommands());
options.SetEchoCommentCommands(m_interpreter.GetEchoCommentCommands());
}
Modified: lldb/trunk/source/Commands/CommandObjectSettings.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectSettings.cpp?rev=360216&r1=360215&r2=360216&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectSettings.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectSettings.cpp Tue May 7 18:23:47 2019
@@ -501,6 +501,7 @@ protected:
options.SetAddToHistory(false);
options.SetEchoCommands(false);
options.SetPrintResults(true);
+ options.SetPrintErrors(true);
options.SetStopOnError(false);
m_interpreter.HandleCommandsFromFile(file, &clean_ctx, options, result);
return result.Succeeded();
Modified: lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp?rev=360216&r1=360215&r2=360216&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp Tue May 7 18:23:47 2019
@@ -295,6 +295,7 @@ are no syntax errors may indicate that a
options.SetStopOnError(data->stop_on_error);
options.SetEchoCommands(false);
options.SetPrintResults(true);
+ options.SetPrintErrors(true);
options.SetAddToHistory(false);
debugger.GetCommandInterpreter().HandleCommands(commands, &exe_ctx,
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=360216&r1=360215&r2=360216&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Tue May 7 18:23:47 2019
@@ -2173,6 +2173,7 @@ void CommandInterpreter::SourceInitFile(
const bool saved_batch = SetBatchCommandMode(true);
CommandInterpreterRunOptions options;
options.SetSilent(true);
+ options.SetPrintErrors(true);
options.SetStopOnError(false);
options.SetStopOnContinue(true);
@@ -2364,7 +2365,8 @@ enum {
eHandleCommandFlagEchoCommand = (1u << 2),
eHandleCommandFlagEchoCommentCommand = (1u << 3),
eHandleCommandFlagPrintResult = (1u << 4),
- eHandleCommandFlagStopOnCrash = (1u << 5)
+ eHandleCommandFlagPrintErrors = (1u << 5),
+ eHandleCommandFlagStopOnCrash = (1u << 6)
};
void CommandInterpreter::HandleCommandsFromFile(
@@ -2463,6 +2465,17 @@ void CommandInterpreter::HandleCommandsF
flags |= eHandleCommandFlagPrintResult;
}
+ if (options.m_print_errors == eLazyBoolCalculate) {
+ if (m_command_source_flags.empty()) {
+ // Print output by default
+ flags |= eHandleCommandFlagPrintErrors;
+ } else if (m_command_source_flags.back() & eHandleCommandFlagPrintErrors) {
+ flags |= eHandleCommandFlagPrintErrors;
+ }
+ } else if (options.m_print_errors == eLazyBoolYes) {
+ flags |= eHandleCommandFlagPrintErrors;
+ }
+
if (flags & eHandleCommandFlagPrintResult) {
debugger.GetOutputFile()->Printf("Executing commands in '%s'.\n",
cmd_file_path.c_str());
@@ -2790,7 +2803,9 @@ void CommandInterpreter::IOHandlerInputC
HandleCommand(line.c_str(), eLazyBoolCalculate, result);
// Now emit the command output text from the command we just executed
- if (io_handler.GetFlags().Test(eHandleCommandFlagPrintResult)) {
+ if ((result.Succeeded() &&
+ io_handler.GetFlags().Test(eHandleCommandFlagPrintResult)) ||
+ io_handler.GetFlags().Test(eHandleCommandFlagPrintErrors)) {
// Display any STDOUT/STDERR _prior_ to emitting the command result text
GetProcessOutput();
@@ -2960,8 +2975,11 @@ CommandInterpreter::GetIOHandler(bool fo
flags |= eHandleCommandFlagEchoCommentCommand;
if (options->m_print_results != eLazyBoolNo)
flags |= eHandleCommandFlagPrintResult;
+ if (options->m_print_errors != eLazyBoolNo)
+ flags |= eHandleCommandFlagPrintErrors;
} else {
- flags = eHandleCommandFlagEchoCommand | eHandleCommandFlagPrintResult;
+ flags = eHandleCommandFlagEchoCommand | eHandleCommandFlagPrintResult |
+ eHandleCommandFlagPrintErrors;
}
m_command_io_handler_sp = std::make_shared<IOHandlerEditline>(
Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=360216&r1=360215&r2=360216&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Tue May 7 18:23:47 2019
@@ -2652,6 +2652,7 @@ void Target::RunStopHooks() {
options.SetStopOnError(true);
options.SetEchoCommands(false);
options.SetPrintResults(true);
+ options.SetPrintErrors(true);
options.SetAddToHistory(false);
// Force Async:
More information about the lldb-commits
mailing list