[Lldb-commits] [lldb] 0e4264a - [lldb][libc++] Adds chrono data formatters.
Mark de Wever via lldb-commits
lldb-commits at lists.llvm.org
Wed Oct 25 10:36:55 PDT 2023
Author: Mark de Wever
Date: 2023-10-25T19:36:47+02:00
New Revision: 0e4264ab1e7a3d82a32d0d096d014afade1e2fae
URL: https://github.com/llvm/llvm-project/commit/0e4264ab1e7a3d82a32d0d096d014afade1e2fae
DIFF: https://github.com/llvm/llvm-project/commit/0e4264ab1e7a3d82a32d0d096d014afade1e2fae.diff
LOG: [lldb][libc++] Adds chrono data formatters.
This adds the data formatters for chrono duration typedefs.
Reviewed By: Michael137
Differential Revision: https://reviews.llvm.org/D159127
Added:
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
Modified:
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index ad6d627938c0520..8b8d330799cb6c7 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -979,6 +979,57 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
"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::nanoseconds", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(
+ eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} ns")));
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::microseconds", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(
+ eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} µs")));
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::milliseconds", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(
+ eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} ms")));
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::seconds", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(
+ eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} s")));
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::minutes", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+ eTypeOptionHideValue,
+ "${var.__rep_} min")));
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::hours", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(
+ eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} h")));
+
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::days", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+ eTypeOptionHideValue,
+ "${var.__rep_} days")));
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::weeks", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+ eTypeOptionHideValue,
+ "${var.__rep_} weeks")));
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::months", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+ eTypeOptionHideValue,
+ "${var.__rep_} months")));
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::years", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+ eTypeOptionHideValue,
+ "${var.__rep_} years")));
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::seconds", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(
+ eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} s")));
}
static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/Makefile b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/Makefile
new file mode 100644
index 000000000000000..57540fc1a2816d3
--- /dev/null
+++ b/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
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py
new file mode 100644
index 000000000000000..076b0d07b88aec7
--- /dev/null
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py
@@ -0,0 +1,33 @@
+"""
+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)
+ )
+
+ lldbutil.continue_to_breakpoint(process, bkpt)
+ self.expect("frame variable ns", substrs=["ns = 1 ns"])
+ self.expect("frame variable us", substrs=["us = 12 µs"])
+ self.expect("frame variable ms", substrs=["ms = 123 ms"])
+ self.expect("frame variable s", substrs=["s = 1234 s"])
+ self.expect("frame variable min", substrs=["min = 12345 min"])
+ self.expect("frame variable h", substrs=["h = 123456 h"])
+
+ self.expect("frame variable d", substrs=["d = 654321 days"])
+ self.expect("frame variable w", substrs=["w = 54321 weeks"])
+ self.expect("frame variable m", substrs=["m = 4321 months"])
+ self.expect("frame variable y", substrs=["y = 321 years"])
+
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/main.cpp
new file mode 100644
index 000000000000000..9eba7daa2940778
--- /dev/null
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/main.cpp
@@ -0,0 +1,19 @@
+#include <chrono>
+#include <iostream>
+
+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};
+
+ std::cout << "break here\n";
+}
More information about the lldb-commits
mailing list