[Lldb-commits] [lldb] 382e3fd - [lldb][Formatter] Get element type for unordered_maps from __hash_table::value_type (#144517)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 17 09:37:31 PDT 2025
Author: Michael Buch
Date: 2025-06-17T17:37:27+01:00
New Revision: 382e3fdbb476a5d5771b315daedcd05a15883fbc
URL: https://github.com/llvm/llvm-project/commit/382e3fdbb476a5d5771b315daedcd05a15883fbc
DIFF: https://github.com/llvm/llvm-project/commit/382e3fdbb476a5d5771b315daedcd05a15883fbc.diff
LOG: [lldb][Formatter] Get element type for unordered_maps from __hash_table::value_type (#144517)
https://github.com/llvm/llvm-project/pull/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
https://github.com/llvm/llvm-project/pull/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>`
Added:
Modified:
lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
index 642723dd91132..ffc33395830bb 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
@@ -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;
More information about the lldb-commits
mailing list