Skip to content

Commit 0e4264a

Browse files
committed
[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
1 parent 7b8e686 commit 0e4264a

File tree

4 files changed

+109
-0
lines changed

4 files changed

+109
-0
lines changed

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,57 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
979979
"std::unordered_map iterator synthetic children",
980980
"^std::__[[:alnum:]]+::__hash_map_(const_)?iterator<.+>$",
981981
stl_synth_flags, true);
982+
// Chrono duration typedefs
983+
cpp_category_sp->AddTypeSummary(
984+
"^std::__[[:alnum:]]+::chrono::nanoseconds", eFormatterMatchRegex,
985+
TypeSummaryImplSP(new StringSummaryFormat(
986+
eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} ns")));
987+
cpp_category_sp->AddTypeSummary(
988+
"^std::__[[:alnum:]]+::chrono::microseconds", eFormatterMatchRegex,
989+
TypeSummaryImplSP(new StringSummaryFormat(
990+
eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} µs")));
991+
cpp_category_sp->AddTypeSummary(
992+
"^std::__[[:alnum:]]+::chrono::milliseconds", eFormatterMatchRegex,
993+
TypeSummaryImplSP(new StringSummaryFormat(
994+
eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} ms")));
995+
cpp_category_sp->AddTypeSummary(
996+
"^std::__[[:alnum:]]+::chrono::seconds", eFormatterMatchRegex,
997+
TypeSummaryImplSP(new StringSummaryFormat(
998+
eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} s")));
999+
cpp_category_sp->AddTypeSummary(
1000+
"^std::__[[:alnum:]]+::chrono::minutes", eFormatterMatchRegex,
1001+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1002+
eTypeOptionHideValue,
1003+
"${var.__rep_} min")));
1004+
cpp_category_sp->AddTypeSummary(
1005+
"^std::__[[:alnum:]]+::chrono::hours", eFormatterMatchRegex,
1006+
TypeSummaryImplSP(new StringSummaryFormat(
1007+
eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} h")));
1008+
1009+
cpp_category_sp->AddTypeSummary(
1010+
"^std::__[[:alnum:]]+::chrono::days", eFormatterMatchRegex,
1011+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1012+
eTypeOptionHideValue,
1013+
"${var.__rep_} days")));
1014+
cpp_category_sp->AddTypeSummary(
1015+
"^std::__[[:alnum:]]+::chrono::weeks", eFormatterMatchRegex,
1016+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1017+
eTypeOptionHideValue,
1018+
"${var.__rep_} weeks")));
1019+
cpp_category_sp->AddTypeSummary(
1020+
"^std::__[[:alnum:]]+::chrono::months", eFormatterMatchRegex,
1021+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1022+
eTypeOptionHideValue,
1023+
"${var.__rep_} months")));
1024+
cpp_category_sp->AddTypeSummary(
1025+
"^std::__[[:alnum:]]+::chrono::years", eFormatterMatchRegex,
1026+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1027+
eTypeOptionHideValue,
1028+
"${var.__rep_} years")));
1029+
cpp_category_sp->AddTypeSummary(
1030+
"^std::__[[:alnum:]]+::chrono::seconds", eFormatterMatchRegex,
1031+
TypeSummaryImplSP(new StringSummaryFormat(
1032+
eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} s")));
9821033
}
9831034

9841035
static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CXX_SOURCES := main.cpp
2+
3+
USE_LIBCPP := 1
4+
5+
CXXFLAGS_EXTRAS := -std=c++20
6+
include Makefile.rules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Test lldb data formatter subsystem.
3+
"""
4+
5+
6+
import lldb
7+
from lldbsuite.test.decorators import *
8+
from lldbsuite.test.lldbtest import *
9+
from lldbsuite.test import lldbutil
10+
11+
12+
class LibcxxChronoDataFormatterTestCase(TestBase):
13+
@add_test_categories(["libc++"])
14+
def test_with_run_command(self):
15+
"""Test that that file and class static variables display correctly."""
16+
self.build()
17+
(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
18+
self, "break here", lldb.SBFileSpec("main.cpp", False)
19+
)
20+
21+
lldbutil.continue_to_breakpoint(process, bkpt)
22+
self.expect("frame variable ns", substrs=["ns = 1 ns"])
23+
self.expect("frame variable us", substrs=["us = 12 µs"])
24+
self.expect("frame variable ms", substrs=["ms = 123 ms"])
25+
self.expect("frame variable s", substrs=["s = 1234 s"])
26+
self.expect("frame variable min", substrs=["min = 12345 min"])
27+
self.expect("frame variable h", substrs=["h = 123456 h"])
28+
29+
self.expect("frame variable d", substrs=["d = 654321 days"])
30+
self.expect("frame variable w", substrs=["w = 54321 weeks"])
31+
self.expect("frame variable m", substrs=["m = 4321 months"])
32+
self.expect("frame variable y", substrs=["y = 321 years"])
33+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <chrono>
2+
#include <iostream>
3+
4+
int main() {
5+
// break here
6+
std::chrono::nanoseconds ns{1};
7+
std::chrono::microseconds us{12};
8+
std::chrono::milliseconds ms{123};
9+
std::chrono::seconds s{1234};
10+
std::chrono::minutes min{12345};
11+
std::chrono::hours h{123456};
12+
13+
std::chrono::days d{654321};
14+
std::chrono::weeks w{54321};
15+
std::chrono::months m{4321};
16+
std::chrono::years y{321};
17+
18+
std::cout << "break here\n";
19+
}

0 commit comments

Comments
 (0)