-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[lldb][TypeSystem] Enable colored AST dump #86159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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).
@llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) ChangesThis patch sets the necessary 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:
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
|
What happens if you have colors disabled in your terminal? Does this do nothing? Or does it start inserting ANSI escape codes in plain text? |
Yea good question, was about to try this out. It does whatever clang's |
That keys off of the output stream supporting colors, but LLDB also allows you to disable colors globally. Please also try |
Either way, we should add a comment explaining that (and why) this works. |
It behaves correctly for the |
You can't get from a TypeSystem to a Target directly, because TypeSystem's live in Modules and Modules live outside any particular target in the global module cache. Maybe you need to pass this in to the call to dump the functions. The command-line will always have a current target, and if you are doing this through the SB API you probably want local control of whether to use colors or not anyway.
Jim
… On Mar 25, 2024, at 7:35 AM, Michael Buch ***@***.***> wrote:
What happens if you have colors disabled in your terminal? Does this do nothing? Or does it start inserting ANSI escape codes in plain text?
Yea good question, was about to try this out. It does whatever clang's ast-dump would do if colors aren't turned off
That keys off of the output stream supporting colors, but LLDB also allows you to disable colors globally. Please also try lldb --no-use-colors and see if that behaves correctly (it might if we set the properties of the stream correctly). If it doesn't you'll need to read debugger.GetUseColor().
It behaves correctly for the target modules dump ast case because that uses the LLDB streams, as you mentioned. For other diagnostics we would have to use the GetUseColor API, though we'd have to plumb the target through to TypeSystemClang::CreateASTContext first, to get access to the debugger object. Will try that instead
—
Reply to this email directly, view it on GitHub <#86159 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ADUPVW7P36SEQCHKWC6KEETY2AY2XAVCNFSM6AAAAABFB5XJ76VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMJYGE2DONRXGA>.
You are receiving this because you are on a team that was mentioned.
|
This patch sets the necessary
ASTContext
flagto ensure that the various ASTs in LLDB (i.e., symbolfile-backed ASTs, scratch AST and the expression AST) are dumped using syntax highlighting (i.e., whenever a user runs
target modules dump ast
or calls thedump()
method on aclang::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).