From 0affb5822f12d754406bf371651b9278ed11fb78 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Sun, 10 Mar 2019 23:15:48 +0000 Subject: [PATCH] Quiet command regex instructions during batch execution Summary: Within .lldbinit, regex commands can be structured as a list of substitutions over multiple lines. It's possible that this is uninentional, but it works and has benefits. For example: command regex s/pat1/repl1/ s/pat2/repl2/ ... I use this form of `command regex` in my `~/.lldbinit`, because it makes it clearer to write and read compared to a single line definition, because multiline substitutions don't need to be quoted, and are broken up one per line. However, multiline definitions result in usage instructions being printed for each use. The result is that every time I run `lldb`, I get a dozen or more lines of noise. With this change, the instructions are only printed when `command regex` is invoked interactively, or from a terminal, neither of which are true when lldb is sourcing `~/.lldbinit`. Reviewers: clayborg, jingham Reviewed By: clayborg Subscribers: jdoerfert, kastiglione, xiaobai, keith, lldb-commits Differential Revision: https://reviews.llvm.org/D48752 llvm-svn: 355793 --- lldb/include/lldb/Core/IOHandler.h | 2 +- lldb/include/lldb/Expression/REPL.h | 2 +- lldb/lit/Commands/command-regex-delete.test | 2 +- lldb/lit/Commands/command-regex-unalias.test | 2 +- lldb/source/Commands/CommandObjectBreakpointCommand.cpp | 4 ++-- lldb/source/Commands/CommandObjectCommands.cpp | 10 +++++----- lldb/source/Commands/CommandObjectTarget.cpp | 4 ++-- lldb/source/Commands/CommandObjectType.cpp | 8 ++++---- lldb/source/Commands/CommandObjectWatchpointCommand.cpp | 4 ++-- lldb/source/Core/IOHandler.cpp | 2 +- lldb/source/Expression/REPL.cpp | 2 +- .../ScriptInterpreter/Python/ScriptInterpreterPython.cpp | 4 ++-- .../Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h | 2 +- 13 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lldb/include/lldb/Core/IOHandler.h b/lldb/include/lldb/Core/IOHandler.h index 2240c1e..da8ad1c 100644 --- a/lldb/include/lldb/Core/IOHandler.h +++ b/lldb/include/lldb/Core/IOHandler.h @@ -200,7 +200,7 @@ public: virtual ~IOHandlerDelegate() = default; - virtual void IOHandlerActivated(IOHandler &io_handler) {} + virtual void IOHandlerActivated(IOHandler &io_handler, bool interactive) {} virtual void IOHandlerDeactivated(IOHandler &io_handler) {} diff --git a/lldb/include/lldb/Expression/REPL.h b/lldb/include/lldb/Expression/REPL.h index 5c88d8a..1e5dbb3 100644 --- a/lldb/include/lldb/Expression/REPL.h +++ b/lldb/include/lldb/Expression/REPL.h @@ -85,7 +85,7 @@ public: //------------------------------------------------------------------ // IOHandler::Delegate functions //------------------------------------------------------------------ - void IOHandlerActivated(IOHandler &io_handler) override; + void IOHandlerActivated(IOHandler &io_handler, bool interactive) override; bool IOHandlerInterrupt(IOHandler &io_handler) override; diff --git a/lldb/lit/Commands/command-regex-delete.test b/lldb/lit/Commands/command-regex-delete.test index 04ac5d0..ddc6259 100644 --- a/lldb/lit/Commands/command-regex-delete.test +++ b/lldb/lit/Commands/command-regex-delete.test @@ -2,7 +2,7 @@ # RUN: %lldb -s %s 2>&1 | FileCheck %s command regex 'Help__' -# CHECK: Enter one of more sed substitution commands in the form +# CHECK: Enter one or more sed substitution commands in the form # We need to leave a new line after to end the regex. s/^$/help/ diff --git a/lldb/lit/Commands/command-regex-unalias.test b/lldb/lit/Commands/command-regex-unalias.test index 3411315..94f1a14 100644 --- a/lldb/lit/Commands/command-regex-unalias.test +++ b/lldb/lit/Commands/command-regex-unalias.test @@ -2,7 +2,7 @@ # RUN: %lldb -s %s 2>&1 | FileCheck %s command regex 'Help__' -# CHECK: Enter one of more sed substitution commands in the form +# CHECK: Enter one or more sed substitution commands in the form # We need to leave a new line after to end the regex. s/^$/help/ diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp index d445cb9..9cd30c1 100644 --- a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp @@ -222,9 +222,9 @@ are no syntax errors may indicate that a function was declared but never called. Options *GetOptions() override { return &m_options; } - 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_reader_instructions); output_sp->Flush(); } diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index 6c92493..662da8a 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -975,10 +975,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///'.\nTerminate the " "substitution list with an empty line.\n"); output_sp->Flush(); @@ -1634,9 +1634,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(); } diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index 676c2cb..6051b6c 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -4738,9 +4738,9 @@ public: Options *GetOptions() override { return &m_options; } protected: - 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( "Enter your stop hook command(s). Type 'DONE' to end.\n"); output_sp->Flush(); diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp index 887d2b8..4df172e 100644 --- a/lldb/source/Commands/CommandObjectType.cpp +++ b/lldb/source/Commands/CommandObjectType.cpp @@ -160,7 +160,7 @@ public: ~CommandObjectTypeSummaryAdd() override = default; - void IOHandlerActivated(IOHandler &io_handler) override { + void IOHandlerActivated(IOHandler &io_handler, bool interactive) override { static const char *g_summary_addreader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n" "def function (valobj,internal_dict):\n" @@ -169,7 +169,7 @@ public: " internal_dict: an LLDB support object not to be used\"\"\"\n"; StreamFileSP output_sp(io_handler.GetOutputStreamFile()); - if (output_sp) { + if (output_sp && interactive) { output_sp->PutCString(g_summary_addreader_instructions); output_sp->Flush(); } @@ -412,9 +412,9 @@ protected: } } - 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_synth_addreader_instructions); output_sp->Flush(); } diff --git a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp index dfb8881..9b5fb4c 100644 --- a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp @@ -207,9 +207,9 @@ are no syntax errors may indicate that a function was declared but never called. Options *GetOptions() override { return &m_options; } - 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( "Enter your debugger command(s). Type 'DONE' to end.\n"); output_sp->Flush(); diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp index 4a6fb0c..257db46 100644 --- a/lldb/source/Core/IOHandler.cpp +++ b/lldb/source/Core/IOHandler.cpp @@ -331,7 +331,7 @@ IOHandlerEditline::~IOHandlerEditline() { void IOHandlerEditline::Activate() { IOHandler::Activate(); - m_delegate.IOHandlerActivated(*this); + m_delegate.IOHandlerActivated(*this, GetIsInteractive()); } void IOHandlerEditline::Deactivate() { diff --git a/lldb/source/Expression/REPL.cpp b/lldb/source/Expression/REPL.cpp index b3f4307..f4ed887 100644 --- a/lldb/source/Expression/REPL.cpp +++ b/lldb/source/Expression/REPL.cpp @@ -92,7 +92,7 @@ lldb::IOHandlerSP REPL::GetIOHandler() { return m_io_handler_sp; } -void REPL::IOHandlerActivated(IOHandler &io_handler) { +void REPL::IOHandlerActivated(IOHandler &io_handler, bool interactive) { lldb::ProcessSP process_sp = m_target.GetProcessSP(); if (process_sp && process_sp->IsAlive()) return; diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 53e98c3..543b889 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -442,7 +442,7 @@ lldb_private::ConstString ScriptInterpreterPython::GetPluginName() { uint32_t ScriptInterpreterPython::GetPluginVersion() { return 1; } -void ScriptInterpreterPython::IOHandlerActivated(IOHandler &io_handler) { +void ScriptInterpreterPython::IOHandlerActivated(IOHandler &io_handler, bool interactive) { const char *instructions = nullptr; switch (m_active_io_handler) { @@ -463,7 +463,7 @@ def function (frame, bp_loc, internal_dict): if (instructions) { StreamFileSP output_sp(io_handler.GetOutputStreamFile()); - if (output_sp) { + if (output_sp && interactive) { output_sp->PutCString(instructions); output_sp->Flush(); } diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h index 54c38ed..ae4d39c4 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h @@ -459,7 +459,7 @@ public: //---------------------------------------------------------------------- // IOHandlerDelegate //---------------------------------------------------------------------- - void IOHandlerActivated(IOHandler &io_handler) override; + void IOHandlerActivated(IOHandler &io_handler, bool interactive) override; void IOHandlerInputComplete(IOHandler &io_handler, std::string &data) override; -- 2.7.4