[Lldb-commits] [lldb] 6622c14 - [formatters] Add a pointer and reference tests for a list and forward_list formatters for libstdcpp and libcxx

Walter Erquinigo via lldb-commits lldb-commits at lists.llvm.org
Mon Dec 6 13:42:16 PST 2021


Author: Danil Stefaniuc
Date: 2021-12-06T13:42:03-08:00
New Revision: 6622c1411339488aa086704ac3fad3b040604dff

URL: https://github.com/llvm/llvm-project/commit/6622c1411339488aa086704ac3fad3b040604dff
DIFF: https://github.com/llvm/llvm-project/commit/6622c1411339488aa086704ac3fad3b040604dff.diff

LOG: [formatters] Add a pointer and reference tests for a list and forward_list formatters for libstdcpp and libcxx

This adds extra tests for libstdcpp and libcxx list and forward_list formatters to check whether formatter behaves correctly when applied on pointer and reference values.

Reviewed By: wallace

Differential Revision: https://reviews.llvm.org/D115137

Added: 
    

Modified: 
    lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
    lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/forward_list/TestDataFormatterGenericForwardList.py
    lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/forward_list/main.cpp
    lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/list/TestDataFormatterGenericList.py
    lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/list/main.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index 589fb3190ac6a..55b3af8123073 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -936,7 +936,7 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
   cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
       RegularExpression("^std::(__cxx11::)?list<.+>(( )?&)?$"),
       SyntheticChildrenSP(new ScriptedSyntheticChildren(
-          stl_synth_flags,
+          stl_deref_flags,
           "lldb.formatters.cpp.gnu_libstdcpp.StdListSynthProvider")));
   cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
       RegularExpression("^std::(__cxx11::)?forward_list<.+>(( )?&)?$"),

diff  --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/forward_list/TestDataFormatterGenericForwardList.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/forward_list/TestDataFormatterGenericForwardList.py
index c99807dd3cf0a..8870c4ce79c71 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/forward_list/TestDataFormatterGenericForwardList.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/forward_list/TestDataFormatterGenericForwardList.py
@@ -84,10 +84,100 @@ def do_test(self, stdlib_type):
                              '...'
                              ])
 
+    def do_test_ptr_and_ref(self, stdlib_type):
+        """Test that ref and ptr to std::forward_list is displayed correctly"""
+        self.build(dictionary={stdlib_type: "1"})
+
+        (_, process, _, bkpt) = lldbutil.run_to_source_breakpoint(self,
+                'Check ref and ptr',
+                lldb.SBFileSpec("main.cpp", False))
+
+        self.expect("frame variable ref",
+                    substrs=[
+                             'size=0',
+                             '{}'])
+
+        self.expect("frame variable *ptr",
+                    substrs=[
+                             'size=0',
+                               '{}'])
+
+        lldbutil.continue_to_breakpoint(process, bkpt)
+
+        self.expect("frame variable ref",
+                    substrs=[
+                             '{',
+                             '[0] = 47',
+                             '}'])
+
+        self.expect("frame variable *ptr",
+                    substrs=[
+                             '{',
+                             '[0] = 47',
+                             '}'])
+
+        lldbutil.continue_to_breakpoint(process, bkpt)
+
+        self.expect("frame variable ref",
+                    substrs=[
+                             'size=5',
+                             '{',
+                             '[0] = 1',
+                             '[1] = 22',
+                             '[2] = 333',
+                             '[3] = 4444',
+                             '[4] = 55555',
+                             '}'])
+
+        self.expect("frame variable *ptr",
+                    substrs=[
+                             'size=5',
+                             '{',
+                             '[0] = 1',
+                             '[1] = 22',
+                             '[2] = 333',
+                             '[3] = 4444',
+                             '[4] = 55555',
+                             '}'])
+
+        lldbutil.continue_to_breakpoint(process, bkpt)
+
+        self.runCmd(
+                "settings set target.max-children-count 256",
+                check=False)
+
+        self.expect("settings show target.max-children-count", matching=True,
+                    substrs=['target.max-children-count (int) = 256'])
+
+
+        self.expect("frame variable ref",matching=True,
+                    substrs=[
+                             'size=256',
+                             '[0] = 999',
+                             '[1] = 998',
+                             '[2] = 997',
+                             ])
+
+        self.expect("frame variable *ptr",matching=True,
+                    substrs=[
+                             'size=256',
+                             '[0] = 999',
+                             '[1] = 998',
+                             '[2] = 997',
+                             ])
+
     @add_test_categories(["libstdcxx"])
     def test_libstdcpp(self):
         self.do_test(USE_LIBSTDCPP)
 
+    @add_test_categories(["libstdcxx"])
+    def test_ptr_and_ref_libstdcpp(self):
+        self.do_test_ptr_and_ref(USE_LIBSTDCPP)
+
     @add_test_categories(["libc++"])
     def test_libcpp(self):
          self.do_test(USE_LIBCPP)
+
+    @add_test_categories(["libc++"])
+    def test_ptr_and_ref_libcpp(self):
+         self.do_test_ptr_and_ref(USE_LIBCPP)

diff  --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/forward_list/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/forward_list/main.cpp
index b13602e8c3d7d..5ac8811c3c869 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/forward_list/main.cpp
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/forward_list/main.cpp
@@ -1,10 +1,21 @@
 #include <forward_list>
 
+
+void by_ref_and_ptr(std::forward_list<int> &ref, std::forward_list<int> *ptr) {
+  // Check ref and ptr
+  return;
+}
+
 int main() {
   std::forward_list<int> empty{}, one_elt{47},
       five_elts{1, 22, 333, 4444, 55555}, thousand_elts{};
   for(int i = 0; i<1000;i++){
     thousand_elts.push_front(i);
   }
-  return 0; // break here
+
+  by_ref_and_ptr(empty, &empty); // break here
+  by_ref_and_ptr(one_elt, &one_elt);
+  by_ref_and_ptr(five_elts, &five_elts);
+  by_ref_and_ptr(thousand_elts, &thousand_elts);
+  return 0;
 }

diff  --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/list/TestDataFormatterGenericList.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/list/TestDataFormatterGenericList.py
index 789f5496b2bd2..d4303515c6f93 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/list/TestDataFormatterGenericList.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/list/TestDataFormatterGenericList.py
@@ -205,11 +205,58 @@ def cleanup():
         self.assertTrue(
             self.frame().FindVariable("text_list").MightHaveChildren(),
             "text_list.MightHaveChildren() says False for non empty!")
+
+    def do_test_ptr_and_ref(self, stdlib_type):
+        """Test that ref and ptr to std::list is displayed correctly"""
+        self.build(dictionary={stdlib_type: "1"})
+
+        (_, process, _, bkpt) = lldbutil.run_to_source_breakpoint(self,
+                'Check ref and ptr',
+                lldb.SBFileSpec("main.cpp", False))
+
+        self.expect("frame variable ref",
+                    substrs=['size=4',
+                             '[0] = ', '1',
+                             '[1] = ', '2',
+                             '[2] = ', '3',
+                             '[3] = ', '4'])
+
+
+        self.expect("frame variable *ptr",
+                    substrs=['size=4',
+                             '[0] = ', '1',
+                             '[1] = ', '2',
+                             '[2] = ', '3',
+                             '[3] = ', '4'])
+
+        lldbutil.continue_to_breakpoint(process, bkpt)
+
+        self.expect("frame variable ref",
+                    substrs=['size=4',
+                             '[0]', 'goofy',
+                             '[1]', 'is',
+                             '[2]', 'smart',
+                             '[3]', '!!!'])
+
+        self.expect("frame variable *ptr",
+                    substrs=['size=4',
+                             '[0]', 'goofy',
+                             '[1]', 'is',
+                             '[2]', 'smart',
+                             '[3]', '!!!'])
     
     @add_test_categories(["libstdcxx"])
     def test_with_run_command_libstdcpp(self):
         self.do_test_with_run_command(USE_LIBSTDCPP)
 
+    @add_test_categories(["libstdcxx"])
+    def test_ptr_and_ref_libstdcpp(self):
+        self.do_test_ptr_and_ref(USE_LIBSTDCPP)
+
     @add_test_categories(["libc++"])
     def test_with_run_command_libcpp(self):
-        self.do_test_with_run_command(USE_LIBCPP)
\ No newline at end of file
+        self.do_test_with_run_command(USE_LIBCPP)
+
+    @add_test_categories(["libc++"])
+    def test_ptr_and_ref_libcpp(self):
+        self.do_test_ptr_and_ref(USE_LIBCPP)
\ No newline at end of file

diff  --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/list/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/list/main.cpp
index 191acdcc97be1..5537b20f4763e 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/list/main.cpp
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/list/main.cpp
@@ -4,6 +4,12 @@
 typedef std::list<int> int_list;
 typedef std::list<std::string> string_list;
 
+
+template <typename T> void by_ref_and_ptr(T &ref, T *ptr) {
+  // Check ref and ptr
+  return;
+}
+
 int main()
 {
     int_list numbers_list;
@@ -21,13 +27,16 @@ int main()
     numbers_list.push_back(2);
     numbers_list.push_back(3);
     numbers_list.push_back(4);
+
+    by_ref_and_ptr(numbers_list, &numbers_list);
     
     string_list text_list;
     text_list.push_back(std::string("goofy")); // Optional break point at this line.
     text_list.push_back(std::string("is"));
     text_list.push_back(std::string("smart"));
-    
     text_list.push_back(std::string("!!!"));
+
+    by_ref_and_ptr(text_list, &text_list);
         
     return 0; // Set final break point at this line.
 }


        


More information about the lldb-commits mailing list