From b3d373866e814d9251f7a5fce6b0a4720df0bc79 Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Thu, 11 Dec 2025 10:05:50 +0000 Subject: [PATCH 1/2] Revert "[lldb] fix failing tests due to CI diagnostics rendering (#171685)" This reverts commit 871dabc8eadcf013df6475369ba7ce34c4c93ffe. --- lldb/test/Shell/Commands/command-dwim-print.test | 6 +++--- lldb/test/Shell/Commands/command-expr-diagnostics.test | 10 +++++----- lldb/test/Shell/Commands/command-options.test | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lldb/test/Shell/Commands/command-dwim-print.test b/lldb/test/Shell/Commands/command-dwim-print.test index 88e7314976ad8..9153edbd21791 100644 --- a/lldb/test/Shell/Commands/command-dwim-print.test +++ b/lldb/test/Shell/Commands/command-dwim-print.test @@ -1,16 +1,16 @@ # RUN: echo quit | %lldb -o "dwim-print a" \ # RUN: | FileCheck %s --strict-whitespace --check-prefix=CHECK1 # (lldb) dwim-print a -# CHECK1:{{^ (\^|˄)}} +# CHECK1:{{^ \^}} # CHECK1: {{^ error: use of undeclared identifier 'a'}} # RUN: echo quit | %lldb -o "p a" \ # RUN: | FileCheck %s --strict-whitespace --check-prefix=CHECK2 # (lldb) p a -# CHECK2:{{^ (\^|˄)}} +# CHECK2:{{^ \^}} # RUN: echo quit | %lldb -o "dwim-print -- a" \ # RUN: | FileCheck %s --strict-whitespace --check-prefix=CHECK3 # (lldb) dwim-print -- a -# CHECK3:{{^ (\^|˄)}} +# CHECK3:{{^ \^}} # RUN: echo quit | %lldb -o "settings set show-inline-diagnostics false" \ # RUN: -o "dwim-print a" 2>&1 | FileCheck %s --check-prefix=CHECK4 # CHECK4: error: :1:1: use of undeclared identifier diff --git a/lldb/test/Shell/Commands/command-expr-diagnostics.test b/lldb/test/Shell/Commands/command-expr-diagnostics.test index cde0e6c6768f7..3c827fb4516ec 100644 --- a/lldb/test/Shell/Commands/command-expr-diagnostics.test +++ b/lldb/test/Shell/Commands/command-expr-diagnostics.test @@ -2,19 +2,19 @@ # RUN: echo quit | %lldb -o "expression a+b" \ # RUN: | FileCheck %s --strict-whitespace --check-prefix=CHECK1 # (lldb) expression a+b -# CHECK1:{{^ (\^|˄) (\^|˄)}} -# CHECK1: {{^ (\||│) error: use of undeclared identifier 'b'}} +# CHECK1:{{^ \^ \^}} +# CHECK1: {{^ | error: use of undeclared identifier 'b'}} # CHECK1: {{^ error: use of undeclared identifier 'a'}} # RUN: echo quit | %lldb -o "expr a" \ # RUN: | FileCheck %s --strict-whitespace --check-prefix=CHECK2 # (lldb) expr a -# CHECK2:{{^ (\^|˄)}} +# CHECK2:{{^ \^}} # RUN: echo quit | %lldb -o "expr -i 0 -o 0 -- a" \ # RUN: | FileCheck %s --strict-whitespace --check-prefix=CHECK3 # (lldb) expr -i 0 -o 0 -- a -# CHECK3:{{^ (\^|˄)}} +# CHECK3:{{^ \^}} # CHECK3: {{^ error: use of undeclared identifier 'a'}} # RUN: echo "int main(){return 0;}">%t.c @@ -23,7 +23,7 @@ # RUN: "expr --top-level -- template T FOO(T x) { return x/2;}" -o \ # RUN: "expression -- FOO(\"\")" 2>&1 | FileCheck %s --check-prefix=CHECK4 # (lldb) expression -- FOO("") -# CHECK4:{{^ (\^|˄)}} +# CHECK4:{{^ \^}} # CHECK4: {{^ note: in instantiation of function template}} # CHECK4: error: Date: Thu, 11 Dec 2025 10:06:14 +0000 Subject: [PATCH 2/2] Revert "[lldb] improve the heuristics for checking if a terminal supports Unicode (#171491)" This reverts commit 844590974f7518147d6f809ae14116e5acbe19d7. --- lldb/include/lldb/Host/Terminal.h | 12 ------------ .../lldb/Host/common/DiagnosticsRendering.h | 19 +------------------ .../Host/common/DiagnosticsRendering.cpp | 11 ++++++----- lldb/source/Host/common/Terminal.cpp | 16 ---------------- .../Host/common/DiagnosticsRenderingTest.cpp | 2 +- 5 files changed, 8 insertions(+), 52 deletions(-) diff --git a/lldb/include/lldb/Host/Terminal.h b/lldb/include/lldb/Host/Terminal.h index 3d66515c18812..da0d05e8bd265 100644 --- a/lldb/include/lldb/Host/Terminal.h +++ b/lldb/include/lldb/Host/Terminal.h @@ -68,18 +68,6 @@ class Terminal { llvm::Error SetHardwareFlowControl(bool enabled); - /// Returns whether or not the current terminal supports Unicode rendering. - /// - /// The value is cached after the first computation. - /// - /// On POSIX systems, we check if the LANG environment variable contains the - /// substring "UTF-8", case insensitive. - /// - /// On Windows, we always return true since we use the `WriteConsoleW` API - /// internally. Note that the default Windows codepage (437) does not support - /// all Unicode characters. This function does not check the codepage. - static bool SupportsUnicode(); - protected: struct Data; diff --git a/lldb/include/lldb/Host/common/DiagnosticsRendering.h b/lldb/include/lldb/Host/common/DiagnosticsRendering.h index 3eea0647da37e..dd33d671c24a5 100644 --- a/lldb/include/lldb/Host/common/DiagnosticsRendering.h +++ b/lldb/include/lldb/Host/common/DiagnosticsRendering.h @@ -59,27 +59,10 @@ struct DiagnosticDetail { StructuredData::ObjectSP Serialize(llvm::ArrayRef details); -/// Renders an array of DiagnosticDetail instances. -/// -/// \param[in] stream -/// The stream to render the diagnostics to. -/// \param offset_in_command -/// An optional offset to the column position of the diagnostic in the -/// source. -/// \param show_inline -/// Whether to show the diagnostics inline. -/// \param details -/// The array of DiagnosticsDetail to render. -/// \param force_ascii -/// Whether to force ascii rendering. If false, Unicode characters will be -/// used if the output file supports them. -/// -/// \see lldb_private::Terminal::SupportsUnicode void RenderDiagnosticDetails(Stream &stream, std::optional offset_in_command, bool show_inline, - llvm::ArrayRef details, - bool force_ascii = false); + llvm::ArrayRef details); class DiagnosticError : public llvm::ErrorInfo { diff --git a/lldb/source/Host/common/DiagnosticsRendering.cpp b/lldb/source/Host/common/DiagnosticsRendering.cpp index 2c9d33a6c325c..f2cd3968967fb 100644 --- a/lldb/source/Host/common/DiagnosticsRendering.cpp +++ b/lldb/source/Host/common/DiagnosticsRendering.cpp @@ -7,8 +7,6 @@ //===----------------------------------------------------------------------===// #include "lldb/Host/common/DiagnosticsRendering.h" -#include "lldb/Host/Terminal.h" - #include using namespace lldb_private; @@ -87,8 +85,7 @@ static llvm::raw_ostream &PrintSeverity(Stream &stream, void RenderDiagnosticDetails(Stream &stream, std::optional offset_in_command, bool show_inline, - llvm::ArrayRef details, - bool force_ascii) { + llvm::ArrayRef details) { if (details.empty()) return; @@ -100,8 +97,12 @@ void RenderDiagnosticDetails(Stream &stream, return; } + // Since there is no other way to find this out, use the color + // attribute as a proxy for whether the terminal supports Unicode + // characters. In the future it might make sense to move this into + // Host so it can be customized for a specific platform. llvm::StringRef cursor, underline, vbar, joint, hbar, spacer; - if (Terminal::SupportsUnicode() && !force_ascii) { + if (stream.AsRawOstream().colors_enabled()) { cursor = "˄"; underline = "˜"; vbar = "│"; diff --git a/lldb/source/Host/common/Terminal.cpp b/lldb/source/Host/common/Terminal.cpp index d3647835e3937..436dfd8130d9b 100644 --- a/lldb/source/Host/common/Terminal.cpp +++ b/lldb/source/Host/common/Terminal.cpp @@ -400,22 +400,6 @@ llvm::Error Terminal::SetHardwareFlowControl(bool enabled) { #endif // LLDB_ENABLE_TERMIOS } -bool Terminal::SupportsUnicode() { - static std::optional g_result; - if (g_result) - return g_result.value(); -#ifdef _WIN32 - return true; -#else - const char *lang_var = std::getenv("LANG"); - if (!lang_var) - return false; - g_result = - llvm::StringRef(lang_var).lower().find("utf-8") != std::string::npos; -#endif - return g_result.value(); -} - TerminalState::TerminalState(Terminal term, bool save_process_group) : m_tty(term) { Save(term, save_process_group); diff --git a/lldb/unittests/Host/common/DiagnosticsRenderingTest.cpp b/lldb/unittests/Host/common/DiagnosticsRenderingTest.cpp index 896ce1995fe1c..851b478def32e 100644 --- a/lldb/unittests/Host/common/DiagnosticsRenderingTest.cpp +++ b/lldb/unittests/Host/common/DiagnosticsRenderingTest.cpp @@ -10,7 +10,7 @@ class ErrorDisplayTest : public ::testing::Test {}; std::string Render(std::vector details) { StreamString stream; - RenderDiagnosticDetails(stream, 0, true, details, /*force_ascii=*/true); + RenderDiagnosticDetails(stream, 0, true, details); return stream.GetData(); } } // namespace