Skip to content

[lldb][DataFormatter] Unwrap reference type when formatting std::unordered_map #145872

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 2 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ CompilerType lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::
// 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())) {
if (isUnorderedMap(m_backend.GetCompilerType()
.GetNonReferenceType()
.GetCanonicalType()
.GetTypeName())) {
std::string name;
CompilerType field_type =
element_type.GetFieldAtIndex(0, name, nullptr, nullptr, nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@


class LibcxxUnorderedMapDataFormatterTestCase(TestBase):
def check_reference(self, var_name: str, expected_type: str):
self.expect_var_path(
var_name,
summary="size=1",
type=expected_type,
children=[
ValueCheck(
name="[0]",
children=[
ValueCheck(name="first", summary='"Hello"'),
ValueCheck(name="second", summary='"World"'),
],
),
],
)

@add_test_categories(["libc++"])
def test_iterator_formatters(self):
"""Test that std::unordered_map related structures are formatted correctly when printed.
Expand Down Expand Up @@ -64,3 +80,20 @@ def test_iterator_formatters(self):
ValueCheck(name="second", summary='"Qux"'),
],
)

lldbutil.continue_to_breakpoint(process, bkpt)

# Test references to std::unordered_map
self.check_reference("ref1", "const StringMapT &")
self.check_reference("ref2", "StringMapT &")
self.check_reference("ref3", "StringMapTRef")
self.check_reference("ref4", "const StringMapT &")
self.check_reference("ref5", "const StringMapT &&")
self.check_reference("ref6", "StringMapT &&")

# FIXME: we're getting this wrong.
Copy link
Collaborator

Choose a reason for hiding this comment

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

ha!

self.expect_var_path(
"ref7",
summary="size=0",
type="const StringMapT *const &",
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
#include <unordered_map>

using StringMapT = std::unordered_map<std::string, std::string>;
using StringMapTRef = const StringMapT &;

static void check_references(const StringMapT &ref1, StringMapT &ref2,
StringMapTRef ref3, StringMapTRef &ref4,
const StringMapT &&ref5, StringMapT &&ref6,
const StringMapT *const &ref7) {
std::printf("Break here");
}

int main() {
StringMapT string_map;
Expand All @@ -21,7 +29,12 @@ int main() {
StringMapT::const_iterator const_baz = string_map.find("Baz");
auto bucket_it = string_map.begin(string_map.bucket("Baz"));
auto const_bucket_it = string_map.cbegin(string_map.bucket("Baz"));

std::printf("Break here");

StringMapT tmp{{"Hello", "World"}};
check_references(tmp, tmp, tmp, tmp, StringMapT{tmp}, StringMapT{tmp},
&tmp);
}

return 0;
Expand Down
Loading