add range tracking when demangling a name #82298
Open
+1,043
−865
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements range tracking for the name and parameters of a demangled function.
Motivation
In this patch, @Michael137 implemented name highlighting for methods in the C++ plugin of LLDB. This results in better readability when reading backtraces of functions with long scopes.
I am working on implementing the same feature for the Swift plugin in LLDB. Please see an example below:

Before:
After:

Notice how the name and parameters of the functions are highlighted differently than the rest.
(Please note that the difference in text contents are temporary, and should disappear before for the final patch).
Implementation details
To implement this feature in the Swift plugin of LLDB, we need to provide LLDB with the ranges of the "components" of the demangled name. For instance the
baseName
ofbar.foo()
spans4...7
, while theparameters
span7...9
.This information allows LLDB to build the name that is displayed in the backtraces.
Original implementation
This patch introduces a new class called
TrackingDemanglerPrinter
which stores the information needed to track the ranges. It can later be extended to track more ranges. The methods it defines are called in theprint
method ofNodePrinter.cpp
.The previous behavior is still available when calling
DemangleSymbolAsString
without aprinter
, as this will result in a no op whenstartName
is called for instance.Current implementation
2 methods were made virtual in
NodePrinter
, so that any consumer can override them and track the ranges they need. This is less lldb specific than the previous method.Testing (removed, relevant only for the original implementation)
To implement the tests for the range tracking, I used the
manglings.txt
file. It now contains the ranges for the name and parameters where that's relevant. The format I chose to serialize the ranges is arbitrary and I'm happy to discuss any change, especially when considering we might want to add more tracked ranges.I also developed a Python script to help review the test cases by coloring them. Please find it here for reference. It could be interesting to add it to the repo.
Follow ups
swift-demangle
, as these changes make it fairly trivial to implement, and it would greatly help with readability.Please note that it was originally opened here #81511 but I moved to a different target branch.
This PR depends on #82303