Skip to content

[lldb][Formatter] Get element type for unordered_maps from __hash_table::value_type #144517

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
merged 3 commits into from
Jun 17, 2025
Merged
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
18 changes: 12 additions & 6 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,20 @@ static bool isUnorderedMap(ConstString type_name) {

CompilerType lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::
GetElementType(CompilerType table_type) {
auto element_type = table_type.GetTypedefedType().GetTypeTemplateArgument(0);
auto element_type =
table_type.GetDirectNestedTypeWithName("value_type").GetTypedefedType();

// In newer unordered_map layouts, the std::pair element type isn't wrapped
// in any helper types. So return it directly.
if (isStdTemplate(element_type.GetTypeName(), "pair"))
return element_type;

// This synthetic provider is used for both unordered_(multi)map and
// unordered_(multi)set. For unordered_map, the element type has an
// additional type layer, an internal struct (`__hash_value_type`)
// that wraps a std::pair. Peel away the internal wrapper type - whose
// structure is of no value to users, to expose the std::pair. This
// matches the structure returned by the std::map synthetic provider.
// unordered_(multi)set. For older unordered_map layouts, the element type has
// an additional type layer, an internal struct (`__hash_value_type`) that
// wraps a std::pair. Peel away the internal wrapper type - whose structure is
// of no value to users, to expose the std::pair. This matches the structure
// returned by the std::map synthetic provider.
if (isUnorderedMap(
m_backend.GetCompilerType().GetCanonicalType().GetTypeName())) {
std::string name;
Expand Down
Loading