diff options
author | Michael Buch <michaelbuch12@gmail.com> | 2025-04-29 10:02:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-29 10:02:44 +0100 |
commit | 64b5bc876aef6db89c38cf5dc76eebec38187234 (patch) | |
tree | 36a2a4f208b20ddff6394f43352349e87be55c6f /lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp | |
parent | 76aa471698437af49ceda30280bf0fd7d33b4d34 (diff) | |
download | llvm-64b5bc876aef6db89c38cf5dc76eebec38187234.zip llvm-64b5bc876aef6db89c38cf5dc76eebec38187234.tar.gz llvm-64b5bc876aef6db89c38cf5dc76eebec38187234.tar.bz2 |
[lldb][Format] Add function.suffix frame-format variable (#137763)
This patch adds another frame-format variable (currently only
implemented in the CPlusPlus language plugin) that represents the
"suffix" of a function. The name is derived from the `DotSuffix` node of
LLVM's Itanium demangler.
For a function name such as `int foo() (.cold)`, the suffix would be
`(.cold)`.
Diffstat (limited to 'lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp')
-rw-r--r-- | lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp index 283e867..6491fb7 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp @@ -381,6 +381,30 @@ GetDemangledScope(const SymbolContext &sc) { return demangled_name.slice(info->ScopeRange.first, info->ScopeRange.second); } +/// Handles anything printed after the FunctionEncoding ItaniumDemangle +/// node. Most notably the DotSUffix node. +static std::optional<llvm::StringRef> +GetDemangledFunctionSuffix(const SymbolContext &sc) { + Mangled mangled = sc.GetPossiblyInlinedFunctionName(); + if (!mangled) + return std::nullopt; + + auto demangled_name = mangled.GetDemangledName().GetStringRef(); + if (demangled_name.empty()) + return std::nullopt; + + const std::optional<DemangledNameInfo> &info = mangled.GetDemangledInfo(); + if (!info) + return std::nullopt; + + // Function without a basename is nonsense. + if (!info->hasBasename()) + return std::nullopt; + + return demangled_name.slice(info->QualifiersRange.second, + llvm::StringRef::npos); +} + bool CPlusPlusLanguage::CxxMethodName::TrySimplifiedParse() { // This method tries to parse simple method definitions which are presumably // most comman in user programs. Definitions that can be parsed by this @@ -1966,6 +1990,15 @@ bool CPlusPlusLanguage::HandleFrameFormatVariable( return true; } + case FormatEntity::Entry::Type::FunctionSuffix: { + std::optional<llvm::StringRef> suffix = GetDemangledFunctionSuffix(sc); + if (!suffix) + return false; + + s << *suffix; + + return true; + } default: return false; } |