[Lldb-commits] [PATCH] D51243: Disable use-color if the output stream is not a terminal with color support.

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Aug 24 17:11:23 PDT 2018


teemperor created this revision.
teemperor added a reviewer: aprantl.
Herald added a reviewer: javed.absar.
Herald added subscribers: lldb-commits, abidh, kristof.beyls.

LLDB currently only checks the output terminal for color support by looking
at the `TERM` environment variable and comparing it to `"dumb"`. This causes that
when running LLDB on a CI node, the syntax highlighter will not be deactivated by
LLDB and the output log is filled with color codes (unless the terminal emulator
actually exposes itself as dumb).

This patch now relies on the LLVM code for detecting color support which is more
reliable. We now also correctly actually initialize the `m_supports_colors` variable in `File`.
`m_supports_colors` was so far uninitialized, but the code path that uses `m_supports_colors`
was also dead so the sanitizers didn't sound an alarm.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D51243

Files:
  include/lldb/Host/File.h
  lit/Settings/TestDisableColor.test
  lit/Settings/lit.local.cfg
  source/Core/Debugger.cpp


Index: source/Core/Debugger.cpp
===================================================================
--- source/Core/Debugger.cpp
+++ source/Core/Debugger.cpp
@@ -804,6 +804,9 @@
   const char *term = getenv("TERM");
   if (term && !strcmp(term, "dumb"))
     SetUseColor(false);
+  // Turn off use-color if we don't write to a terminal with color support.
+  if (!m_output_file_sp->GetFile().GetIsTerminalWithColors())
+    SetUseColor(false);
 }
 
 Debugger::~Debugger() { Clear(); }
Index: lit/Settings/lit.local.cfg
===================================================================
--- /dev/null
+++ lit/Settings/lit.local.cfg
@@ -0,0 +1 @@
+config.suffixes = ['.test']
Index: lit/Settings/TestDisableColor.test
===================================================================
--- /dev/null
+++ lit/Settings/TestDisableColor.test
@@ -0,0 +1,7 @@
+# RUN: %lldb -x -b -s %s | FileCheck %s
+settings show use-color
+q
+# This tests that LLDB turns off use-color if the output file is not an
+# interactive terminal. In this example, use-color should be off because LLDB
+# is run just by the non-interactive lit test runner.
+# CHECK: use-color (boolean) = false
Index: include/lldb/Host/File.h
===================================================================
--- include/lldb/Host/File.h
+++ include/lldb/Host/File.h
@@ -54,13 +54,15 @@
       : IOObject(eFDTypeFile, false), m_descriptor(kInvalidDescriptor),
         m_stream(kInvalidStream), m_options(0), m_own_stream(false),
         m_is_interactive(eLazyBoolCalculate),
-        m_is_real_terminal(eLazyBoolCalculate) {}
+        m_is_real_terminal(eLazyBoolCalculate),
+        m_supports_colors(eLazyBoolCalculate) {}
 
   File(FILE *fh, bool transfer_ownership)
       : IOObject(eFDTypeFile, false), m_descriptor(kInvalidDescriptor),
         m_stream(fh), m_options(0), m_own_stream(transfer_ownership),
         m_is_interactive(eLazyBoolCalculate),
-        m_is_real_terminal(eLazyBoolCalculate) {}
+        m_is_real_terminal(eLazyBoolCalculate),
+        m_supports_colors(eLazyBoolCalculate) {}
 
   //------------------------------------------------------------------
   /// Constructor with path.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51243.162510.patch
Type: text/x-patch
Size: 2176 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180825/590ffd79/attachment-0001.bin>


More information about the lldb-commits mailing list