Author: Michael Buch Date: 2025-07-02T11:21:02+01:00 New Revision: 40275a4ee31203b9ed014b0b830f456a1c267063
URL: https://github.com/llvm/llvm-project/commit/40275a4ee31203b9ed014b0b830f456a1c267063 DIFF: https://github.com/llvm/llvm-project/commit/40275a4ee31203b9ed014b0b830f456a1c267063.diff LOG: [lldb][test] Add tests for formatting pointers to std::unordered_map Ever since #143501 and #144517, these should pass. Adds tests for https://github.com/llvm/llvm-project/issues/146040 Added: Modified: 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/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 2b1bd676a5b34..bf103aa78baba 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,21 +9,28 @@ 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"'), - ], - ), - ], - ) + def check_ptr_or_ref(self, var_name: str): + var = self.frame().FindVariable(var_name) + self.assertTrue(var) + + pair = var.GetChildAtIndex(0) + self.assertTrue(pair) + + self.assertEqual(pair.GetChildAtIndex(0).summary, '"Hello"') + self.assertEqual(pair.GetChildAtIndex(1).summary, '"World"') + + def check_ptr_ptr(self, var_name: str): + var = self.frame().FindVariable(var_name) + self.assertTrue(var) + + ptr = var.GetChildAtIndex(0) + self.assertTrue(ptr) + + pair = ptr.GetChildAtIndex(0) + self.assertTrue(pair) + + self.assertEqual(pair.GetChildAtIndex(0).summary, '"Hello"') + self.assertEqual(pair.GetChildAtIndex(1).summary, '"World"') @add_test_categories(["libc++"]) def test_iterator_formatters(self): @@ -84,12 +91,12 @@ def test_iterator_formatters(self): 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 &&") + self.check_ptr_or_ref("ref1") + self.check_ptr_or_ref("ref2") + self.check_ptr_or_ref("ref3") + self.check_ptr_or_ref("ref4") + self.check_ptr_or_ref("ref5") + self.check_ptr_or_ref("ref6") # FIXME: we're getting this wrong. self.expect_var_path( @@ -97,3 +104,12 @@ def test_iterator_formatters(self): summary="size=0", type="const StringMapT *const &", ) + + lldbutil.continue_to_breakpoint(process, bkpt) + + self.check_ptr_or_ref("ptr1") + self.check_ptr_or_ref("ptr2") + self.check_ptr_or_ref("ptr3") + self.check_ptr_ptr("ptr4") + self.check_ptr_ptr("ptr5") + self.check_ptr_ptr("ptr6") 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 c581fded1ec5f..26cbb9476119d 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 @@ -4,6 +4,7 @@ using StringMapT = std::unordered_map<std::string, std::string>; using StringMapTRef = const StringMapT &; +using StringMapTPtr = const StringMapT *; static void check_references(const StringMapT &ref1, StringMapT &ref2, StringMapTRef ref3, StringMapTRef &ref4, @@ -12,6 +13,12 @@ static void check_references(const StringMapT &ref1, StringMapT &ref2, std::printf("Break here"); } +static void check_pointer(const StringMapT *ptr1, StringMapT *ptr2, + StringMapTPtr ptr3, StringMapTPtr *ptr4, + const StringMapT *const *ptr5, StringMapT **ptr6) { + std::printf("Break here"); +} + int main() { StringMapT string_map; { @@ -35,6 +42,11 @@ int main() { StringMapT tmp{{"Hello", "World"}}; check_references(tmp, tmp, tmp, tmp, StringMapT{tmp}, StringMapT{tmp}, &tmp); + + StringMapT *tmp_ptr = &tmp; + const StringMapT *const_tmp_ptr = &tmp; + check_pointer(tmp_ptr, tmp_ptr, tmp_ptr, &const_tmp_ptr, &tmp_ptr, + &tmp_ptr); } return 0; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits