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

via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 21 10:52:24 PDT 2024

llvmbot wrote:



Author: Michael Buch (Michael137)


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).

Full diff: https://github.com/llvm/llvm-project/pull/86159.diff

2 Files Affected:

- (modified) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (+3) 
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+3) 

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.
+  // 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