Skip to content

🍒 [lldb] add TemplateRange and NameQualifiersRange to DemangledNameInfo #11123

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lldb/docs/use/formatting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ A complete list of currently supported format string variables is listed below:
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ``function.name-without-args`` | The name of the current function without arguments and values (used to include a function name in-line in the ``disassembly-format``) |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ``function.name-qualifiers`` | Any qualifiers added after the name of a function and before its arguments or template arguments. E.g., for Swift the name qualifier for ``closure #1 in A.foo<Int>()`` is `` in A.foo``. |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ``function.basename`` | The basename of the current function depending on the frame's language. E.g., for C++ the basename for ``void ns::foo<float>::bar<int>(int) const`` is ``bar``. |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ``function.prefix`` | Any prefix added to the demangled function name of the current function. This depends on the frame's language. E.g., for C++ the prefix will always be empty. |
Expand Down Expand Up @@ -332,6 +334,7 @@ The function names displayed in backtraces/``frame info``/``thread info`` are th
- ``${function.prefix}``
- ``${function.scope}``
- ``${function.basename}``
- ``${function.name-qualifiers}``
- ``${function.template-arguments}``
- ``${function.formatted-arguments}``
- ``${function.qualifiers}``
Expand Down
41 changes: 39 additions & 2 deletions lldb/include/lldb/Core/DemangledNameInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,29 @@ namespace lldb_private {
struct DemangledNameInfo {
/// A [start, end) pair for the function basename.
/// The basename is the name without scope qualifiers
/// and without template parameters. E.g.,
/// and without template parameters.
///
/// E.g.,
/// \code{.cpp}
/// void foo::bar<int>::someFunc<float>(int) const &&
/// ^ ^
/// start end
/// \endcode
std::pair<size_t, size_t> BasenameRange;

/// A [start, end) pair for the function template arguments.
///
/// E.g.,
/// \code{.cpp}
/// void foo::bar<int>::someFunc<float>(int) const &&
/// ^ ^
/// start end
/// \endcode
std::pair<size_t, size_t> TemplateArgumentsRange;

/// A [start, end) pair for the function scope qualifiers.
/// E.g., for
///
/// E.g.,
/// \code{.cpp}
/// void foo::bar<int>::qux<float>(int) const &&
/// ^ ^
Expand All @@ -40,6 +53,7 @@ struct DemangledNameInfo {
std::pair<size_t, size_t> ScopeRange;

/// Indicates the [start, end) of the function argument list.
///
/// E.g.,
/// \code{.cpp}
/// int (*getFunc<float>(float, double))(int, int)
Expand All @@ -59,6 +73,19 @@ struct DemangledNameInfo {
/// \endcode
std::pair<size_t, size_t> QualifiersRange;

/// Indicates the [start, end) of the function's name qualifiers. This is a
/// catch-all range for anything in between the basename and the function's
/// arguments or template arguments, that is not tracked by the rest of the
/// pairs.
///
/// E.g.,
/// \code{.swift}
/// closure #1 in A.foo<Int>()
/// ^ ^
/// start end
/// \endcode
std::pair<size_t, size_t> NameQualifiersRange;

/// Indicates the [start, end) of the function's prefix. This is a
/// catch-all range for anything that is not tracked by the rest of
/// the pairs.
Expand All @@ -75,6 +102,11 @@ struct DemangledNameInfo {
return BasenameRange.second > BasenameRange.first;
}

/// Returns \c true if this object holds a valid template arguments range.
bool hasTemplateArguments() const {
return TemplateArgumentsRange.second >= TemplateArgumentsRange.first;
}

/// Returns \c true if this object holds a valid scope range.
bool hasScope() const { return ScopeRange.second >= ScopeRange.first; }

Expand All @@ -88,6 +120,11 @@ struct DemangledNameInfo {
return QualifiersRange.second >= QualifiersRange.first;
}

/// Returns \c true if this object holds a valid name qualifiers range.
bool hasNameQualifiers() const {
return NameQualifiersRange.second >= NameQualifiersRange.first;
}

/// Returns \c true if this object holds a valid prefix range.
bool hasPrefix() const { return PrefixRange.second >= PrefixRange.first; }

Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/Core/FormatEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct Entry {
FunctionPrefix,
FunctionScope,
FunctionBasename,
FunctionNameQualifiers,
FunctionTemplateArguments,
FunctionFormattedArguments,
FunctionReturnLeft,
Expand Down
8 changes: 8 additions & 0 deletions lldb/source/Core/DemangledNameInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ void TrackingOutputBuffer::finalizeStart() {
if (NameInfo.BasenameRange.second == 0)
NameInfo.BasenameRange.second = getCurrentPosition();

// There is something between the basename and the start of the function
// arguments. Assume those are template arguments (which *should* be true for
// C++ demangled names, but this assumption may change in the future, in
// which case this needs to be adjusted).
if (NameInfo.BasenameRange.second != NameInfo.ArgumentsRange.first)
NameInfo.TemplateArgumentsRange = {NameInfo.BasenameRange.second,
NameInfo.ArgumentsRange.first};

assert(!shouldTrack());
assert(canFinalize());
}
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Core/FormatEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ constexpr Definition g_function_child_entries[] = {
Definition("prefix", EntryType::FunctionPrefix),
Definition("scope", EntryType::FunctionScope),
Definition("basename", EntryType::FunctionBasename),
Definition("name-qualifiers", EntryType::FunctionNameQualifiers),
Definition("template-arguments", EntryType::FunctionTemplateArguments),
Definition("formatted-arguments", EntryType::FunctionFormattedArguments),
Definition("return-left", EntryType::FunctionReturnLeft),
Expand Down Expand Up @@ -390,6 +391,7 @@ const char *FormatEntity::Entry::TypeToCString(Type t) {
ENUM_TO_CSTR(FunctionPrefix);
ENUM_TO_CSTR(FunctionScope);
ENUM_TO_CSTR(FunctionBasename);
ENUM_TO_CSTR(FunctionNameQualifiers);
ENUM_TO_CSTR(FunctionTemplateArguments);
ENUM_TO_CSTR(FunctionFormattedArguments);
ENUM_TO_CSTR(FunctionReturnLeft);
Expand Down Expand Up @@ -1852,6 +1854,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
case Entry::Type::FunctionPrefix:
case Entry::Type::FunctionScope:
case Entry::Type::FunctionBasename:
case Entry::Type::FunctionNameQualifiers:
case Entry::Type::FunctionTemplateArguments:
case Entry::Type::FunctionFormattedArguments:
case Entry::Type::FunctionReturnRight:
Expand Down
10 changes: 5 additions & 5 deletions lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,12 @@ GetDemangledTemplateArguments(const SymbolContext &sc) {

auto [demangled_name, info] = *info_or_err;

if (info.ArgumentsRange.first < info.BasenameRange.second)
return llvm::createStringError("Arguments range for '%s' is invalid.",
demangled_name.data());
if (!info.hasTemplateArguments())
return llvm::createStringError(
"Template arguments range for '%s' is invalid.", demangled_name.data());

return demangled_name.slice(info.BasenameRange.second,
info.ArgumentsRange.first);
return demangled_name.slice(info.TemplateArgumentsRange.first,
info.TemplateArgumentsRange.second);
}

static llvm::Expected<llvm::StringRef>
Expand Down
Loading