Mordante created this revision.
Mordante added reviewers: Michael137, aprantl.
Herald added a project: All.
Mordante requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This adds the data formatters for chrono duration typedefs.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159127

Files:
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/Makefile
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/main.cpp

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/main.cpp
===================================================================
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/main.cpp
@@ -0,0 +1,18 @@
+#include <chrono>
+
+int main() {
+  // break here
+  std::chrono::nanoseconds ns{1};
+  std::chrono::microseconds us{12};
+  std::chrono::milliseconds ms{123};
+  std::chrono::seconds s{1234};
+  std::chrono::minutes min{12345};
+  std::chrono::hours h{123456};
+
+  std::chrono::days d{654321};
+  std::chrono::weeks w{54321};
+  std::chrono::months m{4321};
+  std::chrono::years y{321};
+
+  return 0; // break here
+}
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py
===================================================================
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py
@@ -0,0 +1,58 @@
+"""
+Test lldb data formatter subsystem.
+"""
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class LibcxxChronoDataFormatterTestCase(TestBase):
+    @add_test_categories(["libc++"])
+    def test_with_run_command(self):
+        """Test that that file and class static variables display correctly."""
+        self.build()
+        (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+            self, "break here", lldb.SBFileSpec("main.cpp", False)
+        )
+
+        # This is the function to remove the custom formats in order to have a
+        # clean slate for the next test case.
+        def cleanup():
+            self.runCmd("type format clear", check=False)
+            self.runCmd("type summary clear", check=False)
+            self.runCmd("type filter clear", check=False)
+            self.runCmd("type synth clear", check=False)
+            self.runCmd("settings set target.max-children-count 256", check=False)
+
+        # Execute the cleanup function during test case tear down.
+        self.addTearDownHook(cleanup)
+
+        # empty vectors (and storage pointers SHOULD BOTH BE NULL..)
+        self.expect("frame variable ns", substrs=["ns = 0"])
+        self.expect("frame variable us", substrs=["us = 0"])
+        self.expect("frame variable ms", substrs=["ms = 0"])
+        self.expect("frame variable s", substrs=["s = 0"])
+        self.expect("frame variable min", substrs=["min = 0"])
+        self.expect("frame variable h", substrs=["h = 0"])
+
+        self.expect("frame variable d", substrs=["d = 0"])
+        self.expect("frame variable w", substrs=["w = 0"])
+        self.expect("frame variable m", substrs=["m = 0"])
+        self.expect("frame variable y", substrs=["y = 0"])
+
+        lldbutil.continue_to_breakpoint(process, bkpt)
+        self.expect("frame variable ns", substrs=["ns = 1"])
+        self.expect("frame variable us", substrs=["us = 12"])
+        self.expect("frame variable ms", substrs=["ms = 123"])
+        self.expect("frame variable s", substrs=["s = 1234"])
+        self.expect("frame variable min", substrs=["min = 12345"])
+        self.expect("frame variable h", substrs=["h = 123456"])
+
+        self.expect("frame variable d", substrs=["d = 654321"])
+        self.expect("frame variable w", substrs=["w = 54321"])
+        self.expect("frame variable m", substrs=["m = 4321"])
+        self.expect("frame variable y", substrs=["y = 321"])
+
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/Makefile
@@ -0,0 +1,6 @@
+CXX_SOURCES := main.cpp
+
+USE_LIBCPP := 1
+
+CXXFLAGS_EXTRAS := -std=c++20
+include Makefile.rules
Index: lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===================================================================
--- lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -981,6 +981,19 @@
                   "std::unordered_map iterator synthetic children",
                   "^std::__[[:alnum:]]+::__hash_map_(const_)?iterator<.+>$",
                   stl_synth_flags, true);
+  // Chrono duration typedefs
+  cpp_category_sp->AddTypeSummary(
+      "^std::__[[:alnum:]]+::chrono::"
+      "(((nano)|(micro)|(milli)|())seconds)|"
+      "(minutes)|"
+      "(hours)|"
+      "(days)|"
+      "(weeks)|"
+      "(months)|"
+      "(years)",
+      eFormatterMatchRegex,
+      TypeSummaryImplSP(new StringSummaryFormat(
+          eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_}")));
 }
 
 static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to