[Lldb-commits] [lldb] [lldb][TypeSystem] Enable colored AST dump (PR #86159)

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 21 10:51:53 PDT 2024


https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/86159

This patch sets the necessary `ASTContext` flag
to ensure that the various ASTs (i.e., symbolfile-backed ASTs, scratch AST and the expression AST) in LLDB are dumped using syntax highlighting (i.e., whenever a user runs `target modules dump ast` or calls the `dump() on a `clang::Decl`).

Decided to not put this behind a setting because the diagnostics object persists on some AST and gets re-used, so the setting wouldn't consistenly turn off syntax highlighting (unless we made the setter fetch all live ASTs and turn the highlighting off).

>From fd904cccba7a9d5e295b1b53e25b844e3a8b01ce Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Thu, 21 Mar 2024 17:45:23 +0000
Subject: [PATCH] [lldb][TypeSystem] Enable colored AST dump

This patch sets the necessary `ASTContext` flag
to ensure that the various ASTs (i.e., symbolfile-backed
ASTs, scratch AST and the expression AST) in LLDB are dumped
using syntax highlighting (i.e., whenever a user runs
`target modules dump ast` or calls the `dump() on a `clang::Decl`).

Decided to not put this behind a setting because the diagnostics
object persists on some AST and gets re-used, so the setting wouldn't
consistenly turn off syntax highlighting (unless we made the setter
fetch all live ASTs and turn the highlighting off).
---
 .../Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp   | 3 +++
 lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp       | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 574d661e2a215e..0da497d74ffe86 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -465,6 +465,9 @@ ClangExpressionParser::ClangExpressionParser(
   // A value of 0 means no limit for both LLDB and Clang.
   m_compiler->getDiagnostics().setErrorLimit(target_sp->GetExprErrorLimit());
 
+  // AST nodes will be dumped with color
+  m_compiler->getDiagnostics().setShowColors(true);
+
   auto target_info = TargetInfo::CreateTargetInfo(
       m_compiler->getDiagnostics(), m_compiler->getInvocation().TargetOpts);
   if (log) {
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 51ab13108feb3a..146bfbe965e33e 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -752,6 +752,9 @@ void TypeSystemClang::CreateASTContext() {
   m_diagnostic_consumer_up = std::make_unique<NullDiagnosticConsumer>();
   m_ast_up->getDiagnostics().setClient(m_diagnostic_consumer_up.get(), false);
 
+  // AST nodes will be dumped with color
+  m_ast_up->getDiagnostics().setShowColors(true);
+
   // This can be NULL if we don't know anything about the architecture or if
   // the target for an architecture isn't enabled in the llvm/clang that we
   // built



More information about the lldb-commits mailing list