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

Conversation

Michael137
Copy link
Member

#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>

…le::value_type

llvm#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 llvm#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>`
Copy link

github-actions bot commented Jun 17, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Collaborator

@labath labath left a comment

Choose a reason for hiding this comment

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

I think that should work. One thing to look out for when it comes to typedefs is that they are not emitted if they aren't used (in the compilation unit). It should be fine as long as the type is referenced from a non-template member function, and I think that should be the case with the basic form of the insert method. (references from template member fn's are not enough as these are also only emitted when used)

@Michael137
Copy link
Member Author

To be on the safe side I added an early-return for the new layout. Technically it would work for old layouts even without this early-return, but it kind of only worked by chance. This way regardless of what the std::pair element_type is with the new layout (e.g., could be a std::pair<TypedefToStdPair), we wouldn't try to unwrap it.

@Michael137 Michael137 merged commit 382e3fd into llvm:main Jun 17, 2025
7 checks passed
@Michael137 Michael137 deleted the lldb/unordered_map-value-type branch June 17, 2025 16:37
Michael137 added a commit to swiftlang/llvm-project that referenced this pull request Jun 18, 2025
…le::value_type (llvm#144517)

llvm#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
llvm#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>`

(cherry picked from commit 382e3fd)
fschlimb pushed a commit to fschlimb/llvm-project that referenced this pull request Jun 18, 2025
…le::value_type (llvm#144517)

llvm#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
llvm#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>`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants