diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2020-06-09 10:21:09 -0700 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2020-06-09 10:45:45 -0700 |
commit | de019b88dd5804ec996fe8c12cddcc6feb13afa1 (patch) | |
tree | a21779363a65262f657354b00eef1e7be681555c /lldb/source | |
parent | 1f48f8f6e289d3ae14d28ad9bd000ef5ba209fc0 (diff) | |
download | llvm-de019b88dd5804ec996fe8c12cddcc6feb13afa1.zip llvm-de019b88dd5804ec996fe8c12cddcc6feb13afa1.tar.gz llvm-de019b88dd5804ec996fe8c12cddcc6feb13afa1.tar.bz2 |
[lldb/Interpreter] Support color in CommandReturnObject
Color the error: and warning: part of the CommandReturnObject output,
similar to how an error is printed from the driver when colors are
enabled.
Differential revision: https://reviews.llvm.org/D81058
Diffstat (limited to 'lldb/source')
-rw-r--r-- | lldb/source/API/SBCommandReturnObject.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Breakpoint/BreakpointOptions.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectExpression.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectWatchpointCommand.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Expression/REPL.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandAlias.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 6 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandObject.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandReturnObject.cpp | 30 | ||||
-rw-r--r-- | lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Target/Target.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Utility/Stream.cpp | 9 |
12 files changed, 42 insertions, 28 deletions
diff --git a/lldb/source/API/SBCommandReturnObject.cpp b/lldb/source/API/SBCommandReturnObject.cpp index 102877e..fddf90b 100644 --- a/lldb/source/API/SBCommandReturnObject.cpp +++ b/lldb/source/API/SBCommandReturnObject.cpp @@ -22,7 +22,7 @@ using namespace lldb_private; class lldb_private::SBCommandReturnObjectImpl { public: SBCommandReturnObjectImpl() - : m_ptr(new CommandReturnObject()), m_owned(true) {} + : m_ptr(new CommandReturnObject(false)), m_owned(true) {} SBCommandReturnObjectImpl(CommandReturnObject &ref) : m_ptr(&ref), m_owned(false) {} SBCommandReturnObjectImpl(const SBCommandReturnObjectImpl &rhs) diff --git a/lldb/source/Breakpoint/BreakpointOptions.cpp b/lldb/source/Breakpoint/BreakpointOptions.cpp index db2a2f1..3886d03 100644 --- a/lldb/source/Breakpoint/BreakpointOptions.cpp +++ b/lldb/source/Breakpoint/BreakpointOptions.cpp @@ -630,11 +630,11 @@ bool BreakpointOptions::BreakpointOptionsCallbackFunction( ExecutionContext exe_ctx(context->exe_ctx_ref); Target *target = exe_ctx.GetTargetPtr(); if (target) { - CommandReturnObject result; Debugger &debugger = target->GetDebugger(); + CommandReturnObject result(debugger.GetUseColor()); + // Rig up the results secondary output stream to the debugger's, so the // output will come out synchronously if the debugger is set up that way. - StreamSP output_stream(debugger.GetAsyncOutputStream()); StreamSP error_stream(debugger.GetAsyncErrorStream()); result.SetImmediateOutputStream(output_stream); diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index 7cec714..b23adb0 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -500,7 +500,8 @@ void CommandObjectExpression::IOHandlerInputComplete(IOHandler &io_handler, StreamFileSP output_sp = io_handler.GetOutputStreamFileSP(); StreamFileSP error_sp = io_handler.GetErrorStreamFileSP(); - CommandReturnObject return_obj; + CommandReturnObject return_obj( + GetCommandInterpreter().GetDebugger().GetUseColor()); EvaluateExpression(line.c_str(), *output_sp, *error_sp, return_obj); if (output_sp) output_sp->Flush(); diff --git a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp index 11bf88d..fe3052a 100644 --- a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp @@ -282,12 +282,12 @@ are no syntax errors may indicate that a function was declared but never called. ExecutionContext exe_ctx(context->exe_ctx_ref); Target *target = exe_ctx.GetTargetPtr(); if (target) { - CommandReturnObject result; Debugger &debugger = target->GetDebugger(); + CommandReturnObject result(debugger.GetUseColor()); + // Rig up the results secondary output stream to the debugger's, so the // output will come out synchronously if the debugger is set up that // way. - StreamSP output_stream(debugger.GetAsyncOutputStream()); StreamSP error_stream(debugger.GetAsyncErrorStream()); result.SetImmediateOutputStream(output_stream); diff --git a/lldb/source/Expression/REPL.cpp b/lldb/source/Expression/REPL.cpp index a55fe09..b49b304 100644 --- a/lldb/source/Expression/REPL.cpp +++ b/lldb/source/Expression/REPL.cpp @@ -216,7 +216,7 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) { ci.SetPromptOnQuit(false); // Execute the command - CommandReturnObject result; + CommandReturnObject result(debugger.GetUseColor()); result.SetImmediateOutputStream(output_sp); result.SetImmediateErrorStream(error_sp); ci.HandleCommand(code.c_str(), eLazyBoolNo, result); diff --git a/lldb/source/Interpreter/CommandAlias.cpp b/lldb/source/Interpreter/CommandAlias.cpp index 35bf5c4..a5e0339 100644 --- a/lldb/source/Interpreter/CommandAlias.cpp +++ b/lldb/source/Interpreter/CommandAlias.cpp @@ -32,7 +32,7 @@ static bool ProcessAliasOptionsArgs(lldb::CommandObjectSP &cmd_obj_sp, std::string options_string(options_args); // TODO: Find a way to propagate errors in this CommandReturnObject up the // stack. - CommandReturnObject result; + CommandReturnObject result(false); // Check to see if the command being aliased can take any command options. Options *options = cmd_obj_sp->GetOptions(); if (options) { diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 61288fc..2eedfc2 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -209,7 +209,7 @@ void CommandInterpreter::Initialize() { static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION); - CommandReturnObject result; + CommandReturnObject result(m_debugger.GetUseColor()); LoadCommandDictionary(); @@ -2264,7 +2264,7 @@ void CommandInterpreter::HandleCommands(const StringList &commands, m_debugger.GetPrompt().str().c_str(), cmd); } - CommandReturnObject tmp_result; + CommandReturnObject tmp_result(m_debugger.GetUseColor()); // If override_context is not NULL, pass no_context_switching = true for // HandleCommand() since we updated our context already. @@ -2792,7 +2792,7 @@ void CommandInterpreter::IOHandlerInputComplete(IOHandler &io_handler, StartHandlingCommand(); - lldb_private::CommandReturnObject result; + lldb_private::CommandReturnObject result(m_debugger.GetUseColor()); HandleCommand(line.c_str(), eLazyBoolCalculate, result); // Now emit the command output text from the command we just executed diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp index 4cadaa3..dfae7be 100644 --- a/lldb/source/Interpreter/CommandObject.cpp +++ b/lldb/source/Interpreter/CommandObject.cpp @@ -282,7 +282,7 @@ void CommandObject::HandleCompletion(CompletionRequest &request) { } else { // Can we do anything generic with the options? Options *cur_options = GetOptions(); - CommandReturnObject result; + CommandReturnObject result(m_interpreter.GetDebugger().GetUseColor()); OptionElementVector opt_element_vector; if (cur_options != nullptr) { diff --git a/lldb/source/Interpreter/CommandReturnObject.cpp b/lldb/source/Interpreter/CommandReturnObject.cpp index a0ede45..6f3732e 100644 --- a/lldb/source/Interpreter/CommandReturnObject.cpp +++ b/lldb/source/Interpreter/CommandReturnObject.cpp @@ -14,6 +14,18 @@ using namespace lldb; using namespace lldb_private; +static llvm::raw_ostream &error(Stream &strm) { + return llvm::WithColor(strm.AsRawOstream(), llvm::HighlightColor::Error, + llvm::ColorMode::Enable) + << "error: "; +} + +static llvm::raw_ostream &warning(Stream &strm) { + return llvm::WithColor(strm.AsRawOstream(), llvm::HighlightColor::Warning, + llvm::ColorMode::Enable) + << "warning: "; +} + static void DumpStringToStreamWithNewline(Stream &strm, const std::string &s) { bool add_newline = false; if (!s.empty()) { @@ -28,9 +40,10 @@ static void DumpStringToStreamWithNewline(Stream &strm, const std::string &s) { strm.EOL(); } -CommandReturnObject::CommandReturnObject() - : m_out_stream(), m_err_stream(), m_status(eReturnStatusStarted), - m_did_change_process_state(false), m_interactive(true) {} +CommandReturnObject::CommandReturnObject(bool colors) + : m_out_stream(colors), m_err_stream(colors), + m_status(eReturnStatusStarted), m_did_change_process_state(false), + m_interactive(true) {} CommandReturnObject::~CommandReturnObject() {} @@ -45,9 +58,8 @@ void CommandReturnObject::AppendErrorWithFormat(const char *format, ...) { const std::string &s = std::string(sstrm.GetString()); if (!s.empty()) { - Stream &error_strm = GetErrorStream(); - error_strm.PutCString("error: "); - DumpStringToStreamWithNewline(error_strm, s); + error(GetErrorStream()); + DumpStringToStreamWithNewline(GetErrorStream(), s); } } @@ -72,7 +84,7 @@ void CommandReturnObject::AppendWarningWithFormat(const char *format, ...) { sstrm.PrintfVarArg(format, args); va_end(args); - GetErrorStream() << "warning: " << sstrm.GetString(); + warning(GetErrorStream()) << sstrm.GetString(); } void CommandReturnObject::AppendMessage(llvm::StringRef in_string) { @@ -84,7 +96,7 @@ void CommandReturnObject::AppendMessage(llvm::StringRef in_string) { void CommandReturnObject::AppendWarning(llvm::StringRef in_string) { if (in_string.empty()) return; - GetErrorStream() << "warning: " << in_string << "\n"; + warning(GetErrorStream()) << in_string << '\n'; } // Similar to AppendWarning, but do not prepend 'warning: ' to message, and @@ -99,7 +111,7 @@ void CommandReturnObject::AppendRawWarning(llvm::StringRef in_string) { void CommandReturnObject::AppendError(llvm::StringRef in_string) { if (in_string.empty()) return; - GetErrorStream() << "error: " << in_string << "\n"; + error(GetErrorStream()) << in_string << '\n'; } void CommandReturnObject::SetError(const Status &error, diff --git a/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp b/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp index e61d963..5ceaf88 100644 --- a/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp +++ b/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp @@ -981,7 +981,7 @@ EnableOptionsSP ParseAutoEnableOptions(Status &error, Debugger &debugger) { EnableOptionsSP options_sp(new EnableOptions()); options_sp->NotifyOptionParsingStarting(&exe_ctx); - CommandReturnObject result; + CommandReturnObject result(debugger.GetUseColor()); // Parse the arguments. auto options_property_sp = @@ -1036,7 +1036,7 @@ bool RunEnableCommand(CommandInterpreter &interpreter) { } // Run the command. - CommandReturnObject return_object; + CommandReturnObject return_object(interpreter.GetDebugger().GetUseColor()); interpreter.HandleCommand(command_stream.GetData(), eLazyBoolNo, return_object); return return_object.Succeeded(); diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index c1575db..21d2957 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -2556,7 +2556,7 @@ void Target::RunStopHooks() { if (!any_active_hooks) return; - CommandReturnObject result; + CommandReturnObject result(m_debugger.GetUseColor()); std::vector<ExecutionContext> exc_ctx_with_reasons; std::vector<SymbolContext> sym_ctx_with_reasons; diff --git a/lldb/source/Utility/Stream.cpp b/lldb/source/Utility/Stream.cpp index 8c09ead..a0623bf 100644 --- a/lldb/source/Utility/Stream.cpp +++ b/lldb/source/Utility/Stream.cpp @@ -22,13 +22,14 @@ using namespace lldb; using namespace lldb_private; -Stream::Stream(uint32_t flags, uint32_t addr_size, ByteOrder byte_order) +Stream::Stream(uint32_t flags, uint32_t addr_size, ByteOrder byte_order, + bool colors) : m_flags(flags), m_addr_size(addr_size), m_byte_order(byte_order), - m_indent_level(0), m_forwarder(*this) {} + m_indent_level(0), m_forwarder(*this, colors) {} -Stream::Stream() +Stream::Stream(bool colors) : m_flags(0), m_addr_size(4), m_byte_order(endian::InlHostByteOrder()), - m_indent_level(0), m_forwarder(*this) {} + m_indent_level(0), m_forwarder(*this, colors) {} // Destructor Stream::~Stream() {} |