diff options
author | Michael Buch <michaelbuch12@gmail.com> | 2025-04-28 10:46:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-28 10:46:00 +0100 |
commit | cebf86eb1de163faaf5f9781f6bbded70dc1f9f0 (patch) | |
tree | 93191260440c498b1733464e3f0a8d3362c6584f /lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp | |
parent | 32059ce1210da09ed3abfe3ff257b11897251650 (diff) | |
download | llvm-cebf86eb1de163faaf5f9781f6bbded70dc1f9f0.zip llvm-cebf86eb1de163faaf5f9781f6bbded70dc1f9f0.tar.gz llvm-cebf86eb1de163faaf5f9781f6bbded70dc1f9f0.tar.bz2 |
[lldb][Format] Make function name frame-format variables work without debug-info (#137408)
This patch makes the frame-format variables introduced in
https://github.com/llvm/llvm-project/pull/131836 also work when no
debug-info is available. Previously, we assumed `sc.function` was
available, but without debug-info we might only have `sc.symbol`. We
don't really need the `sc.function` apart from when formatting
arguments.
For the function arguments case I added a fallback that will just print
the arguments we get from the demangler (which is what LLDB does for
stacktraces with no debug-info anyway). Ideally we'd have a separate
`FormatEntity::Entry::Type::FunctionArguments` that will just print the
arguments from the demangler and have something like the following in
the `plugin.cplusplus.display.function-name-format`:
```
{ ${function.formatted-arguments} || ${function.arguments} }
```
I.e., when we can't format the arguments, print the ones from the
demangler. But we currently don't have the `||` operator in the
frame-format language yet.
Diffstat (limited to 'lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp')
-rw-r--r-- | lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp index 283e867..ab8e9883 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp @@ -381,6 +381,34 @@ GetDemangledScope(const SymbolContext &sc) { return demangled_name.slice(info->ScopeRange.first, info->ScopeRange.second); } +static bool PrintDemangledArgumentList(Stream &s, const SymbolContext &sc) { + assert(sc.symbol); + + Mangled mangled = sc.GetPossiblyInlinedFunctionName(); + if (!mangled) + return false; + + auto demangled_name = mangled.GetDemangledName().GetStringRef(); + if (demangled_name.empty()) + return false; + + const std::optional<DemangledNameInfo> &info = mangled.GetDemangledInfo(); + if (!info) + return false; + + // Function without a basename is nonsense. + if (!info->hasBasename()) + return false; + + if (info->ArgumentsRange.second < info->ArgumentsRange.first) + return false; + + s << demangled_name.slice(info->ArgumentsRange.first, + info->ArgumentsRange.second); + + return true; +} + 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 @@ -1890,8 +1918,6 @@ bool CPlusPlusLanguage::GetFunctionDisplayName( bool CPlusPlusLanguage::HandleFrameFormatVariable( const SymbolContext &sc, const ExecutionContext *exe_ctx, FormatEntity::Entry::Type type, Stream &s) { - assert(sc.function); - switch (type) { case FormatEntity::Entry::Type::FunctionScope: { std::optional<llvm::StringRef> scope = GetDemangledScope(sc); @@ -1925,6 +1951,14 @@ bool CPlusPlusLanguage::HandleFrameFormatVariable( } case FormatEntity::Entry::Type::FunctionFormattedArguments: { + // This ensures we print the arguments even when no debug-info is available. + // + // FIXME: we should have a Entry::Type::FunctionArguments and + // use it in the plugin.cplusplus.display.function-name-format + // once we have a "fallback operator" in the frame-format language. + if (!sc.function && sc.symbol) + return PrintDemangledArgumentList(s, sc); + VariableList args; if (auto variable_list_sp = GetFunctionVariableList(sc)) variable_list_sp->AppendVariablesWithScope(eValueTypeVariableArgument, |