Skip to content

[lldb] add TemplateRange and NameQualifiersRange to DemangledNameInfo #150999

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 2 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. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add a Swift exapmle

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks 👍

+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ``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
25 changes: 25 additions & 0 deletions lldb/include/lldb/Core/DemangledNameInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ struct DemangledNameInfo {
/// \endcode
std::pair<size_t, size_t> BasenameRange;

/// A [start, end) pair for the function template arguments.
/// The basename is the name without scope qualifiers
/// and without template parameters. E.g.,
/// \code{.cpp}
/// void foo::bar<int>::someFunc<float>(int) const &&
/// ^ ^
/// start end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it really start at the opening bracket? I think it starts at the f in this example. And ends at >

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the CPlusPlusLanguage implementation, this is currently:

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

My implementation in Swift is quite similar.

So in the example above, it should be <float>. I should move the end ^ to the right.

Are you saying that we should only return float instead and let the plugin decide how to format the brackets? i.e return float only and let the .td file decide if we should add the < and > ?

/// \endcode
std::pair<size_t, size_t> TemplateRange;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::pair<size_t, size_t> TemplateRange;
std::pair<size_t, size_t> TemplateArgumentsRange;


/// A [start, end) pair for the function scope qualifiers.
/// E.g., for
/// \code{.cpp}
Expand Down Expand Up @@ -59,6 +69,11 @@ 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 arguments,
/// that is not tracked by the rest of the pairs.
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 +90,11 @@ struct DemangledNameInfo {
return BasenameRange.second > BasenameRange.first;
}

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

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

Expand All @@ -88,6 +108,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
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 @@ -1842,6 +1844,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
Loading
Loading