Skip to content

Commit 382e3fd

Browse files
authored
[lldb][Formatter] Get element type for unordered_maps from __hash_table::value_type (#144517)
#143501 changes usage of `__hash_value_type` in libcxx to an empty tag type. This type will no longer have a definition in DWARF. Currently the LLDB unordered_map formatter deduces the map's `element_type` by looking at the `__cc_` member of `__hash_value_type`. But that will no longer work because we only have its forward declaration. Since what we're really after is the type that `__hash_value_type` is wrapping, we can just look at the `__hash_table::value_type` typedef. With #143501 that will now point to the `std::pair` element type (which used to be what we got from `__cc_`). TBD: need to double-check this works for older layouts. Quick glance at the code makes me suspicious of cases like `unordered_map<std::pair<int, int>, int>`
1 parent 9ec75a5 commit 382e3fd

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,20 @@ static bool isUnorderedMap(ConstString type_name) {
9999

100100
CompilerType lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::
101101
GetElementType(CompilerType table_type) {
102-
auto element_type = table_type.GetTypedefedType().GetTypeTemplateArgument(0);
102+
auto element_type =
103+
table_type.GetDirectNestedTypeWithName("value_type").GetTypedefedType();
104+
105+
// In newer unordered_map layouts, the std::pair element type isn't wrapped
106+
// in any helper types. So return it directly.
107+
if (isStdTemplate(element_type.GetTypeName(), "pair"))
108+
return element_type;
103109

104110
// This synthetic provider is used for both unordered_(multi)map and
105-
// unordered_(multi)set. For unordered_map, the element type has an
106-
// additional type layer, an internal struct (`__hash_value_type`)
107-
// that wraps a std::pair. Peel away the internal wrapper type - whose
108-
// structure is of no value to users, to expose the std::pair. This
109-
// matches the structure returned by the std::map synthetic provider.
111+
// unordered_(multi)set. For older unordered_map layouts, the element type has
112+
// an additional type layer, an internal struct (`__hash_value_type`) that
113+
// wraps a std::pair. Peel away the internal wrapper type - whose structure is
114+
// of no value to users, to expose the std::pair. This matches the structure
115+
// returned by the std::map synthetic provider.
110116
if (isUnorderedMap(
111117
m_backend.GetCompilerType().GetCanonicalType().GetTypeName())) {
112118
std::string name;

0 commit comments

Comments
 (0)