[Lldb-commits] [lldb] aeea062 - [lldb][DataFormatter] Unwrap reference type when formatting std::unordered_map (#145872)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Jun 26 09:10:15 PDT 2025
Author: Michael Buch
Date: 2025-06-26T17:10:12+01:00
New Revision: aeea062dd43e164889f35c24b98cb1994ead50cb
URL: https://github.com/llvm/llvm-project/commit/aeea062dd43e164889f35c24b98cb1994ead50cb
DIFF: https://github.com/llvm/llvm-project/commit/aeea062dd43e164889f35c24b98cb1994ead50cb.diff
LOG: [lldb][DataFormatter] Unwrap reference type when formatting std::unordered_map (#145872)
Desugar any potential references/typedefs before checking
`isStdTemplate`. Previously, the typename might've been:
```
const std::unordered_map<...> &
```
for references. This patch gets the pointee type before grabbing the
canonical type. `GetNonReferenceType` will unwrap typedefs too, so we
should always end up with a non-reference before we get to
`GetCanonicalType`.
https://github.com/llvm/llvm-project/issues/145847
Added:
Modified:
lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
index ffc33395830bb..501fd0945b82c 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
@@ -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);
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
index c021a46a17b51..2b1bd676a5b34 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
@@ -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.
@@ -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.
+ self.expect_var_path(
+ "ref7",
+ summary="size=0",
+ type="const StringMapT *const &",
+ )
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp
index adcea69629770..c581fded1ec5f 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp
@@ -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;
@@ -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;
More information about the lldb-commits
mailing list