Skip to content

[lldb][libc++] Adds local_t clock data formatters. #88178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
"libc++ std::chrono::sys_seconds summary provider",
"^std::__[[:alnum:]]+::chrono::time_point<"
"std::__[[:alnum:]]+::chrono::system_clock, "
"std::__[[:alnum:]]+::chrono::duration<long long, "
"std::__[[:alnum:]]+::chrono::duration<.*, "
"std::__[[:alnum:]]+::ratio<1, 1> "
"> >$",
eTypeOptionHideChildren | eTypeOptionHideValue |
Expand All @@ -1068,6 +1068,29 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
eTypeOptionCascade,
true);

AddCXXSummary(
cpp_category_sp,
lldb_private::formatters::LibcxxChronoLocalSecondsSummaryProvider,
"libc++ std::chrono::local_seconds summary provider",
"^std::__[[:alnum:]]+::chrono::time_point<"
"std::__[[:alnum:]]+::chrono::local_t, "
"std::__[[:alnum:]]+::chrono::duration<.*, "
"std::__[[:alnum:]]+::ratio<1, 1> "
"> >$",
eTypeOptionHideChildren | eTypeOptionHideValue | eTypeOptionCascade,
true);
AddCXXSummary(cpp_category_sp,
lldb_private::formatters::LibcxxChronoLocalDaysSummaryProvider,
"libc++ std::chrono::local_seconds summary provider",
"^std::__[[:alnum:]]+::chrono::time_point<"
"std::__[[:alnum:]]+::chrono::local_t, "
"std::__[[:alnum:]]+::chrono::duration<int, "
"std::__[[:alnum:]]+::ratio<86400, 1> "
"> >$",
eTypeOptionHideChildren | eTypeOptionHideValue |
eTypeOptionCascade,
true);

// Chrono calendar types

cpp_category_sp->AddTypeSummary(
Expand Down
38 changes: 33 additions & 5 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,8 +1087,10 @@ bool lldb_private::formatters::LibcxxWStringViewSummaryProvider(
dataobj, size);
}

bool lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
static bool
LibcxxChronoTimePointSecondsSummaryProvider(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options,
const char *fmt) {
ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__d_");
if (!ptr_sp)
return false;
Expand All @@ -1112,7 +1114,7 @@ bool lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
else {
std::array<char, 128> str;
std::size_t size =
std::strftime(str.data(), str.size(), "%FT%H:%M:%SZ", gmtime(&seconds));
std::strftime(str.data(), str.size(), fmt, gmtime(&seconds));
if (size == 0)
return false;

Expand All @@ -1123,8 +1125,22 @@ bool lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
return true;
}

bool lldb_private::formatters::LibcxxChronoSysDaysSummaryProvider(
bool lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
return LibcxxChronoTimePointSecondsSummaryProvider(valobj, stream, options,
"%FT%H:%M:%SZ");
}

bool lldb_private::formatters::LibcxxChronoLocalSecondsSummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
return LibcxxChronoTimePointSecondsSummaryProvider(valobj, stream, options,
"%FT%H:%M:%S");
}

static bool
LibcxxChronoTimepointDaysSummaryProvider(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options,
const char *fmt) {
ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__d_");
if (!ptr_sp)
return false;
Expand All @@ -1148,7 +1164,7 @@ bool lldb_private::formatters::LibcxxChronoSysDaysSummaryProvider(

std::array<char, 128> str;
std::size_t size =
std::strftime(str.data(), str.size(), "%FZ", gmtime(&seconds));
std::strftime(str.data(), str.size(), fmt, gmtime(&seconds));
if (size == 0)
return false;

Expand All @@ -1158,6 +1174,18 @@ bool lldb_private::formatters::LibcxxChronoSysDaysSummaryProvider(
return true;
}

bool lldb_private::formatters::LibcxxChronoSysDaysSummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
return LibcxxChronoTimepointDaysSummaryProvider(valobj, stream, options,
"%FZ");
}

bool lldb_private::formatters::LibcxxChronoLocalDaysSummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
return LibcxxChronoTimepointDaysSummaryProvider(valobj, stream, options,
"%F");
}

bool lldb_private::formatters::LibcxxChronoMonthSummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
// FIXME: These are the names used in the C++20 ostream operator. Since LLVM
Expand Down
8 changes: 8 additions & 0 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ bool LibcxxChronoSysDaysSummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // libc++ std::chrono::sys_days

bool LibcxxChronoLocalSecondsSummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // libc++ std::chrono::local_seconds

bool LibcxxChronoLocalDaysSummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // libc++ std::chrono::local_days

bool LibcxxChronoMonthSummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // libc++ std::chrono::month
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,110 @@ def test_with_run_command(self):
substrs=["sd_max = timestamp=2147483647 days"],
)

# local_seconds aliasses

self.expect(
"frame variable ls_tp",
substrs=["ls_tp = date/time=1970-01-01T00:00:00 timestamp=0 s"],
)
self.expect(
"frame variable ls_tp_d",
substrs=["ls_tp_d = date/time=1970-01-01T00:00:00 timestamp=0 s"],
)
self.expect(
"frame variable ls_tp_d_r",
substrs=["ls_tp_d_r = date/time=1970-01-01T00:00:00 timestamp=0 s"],
)
self.expect(
"frame variable ls_tp_d_r2",
substrs=["ls_tp_d_r2 = date/time=1970-01-01T00:00:00 timestamp=0 s"],
)

# local_seconds

self.expect(
"frame variable ls_0",
substrs=["ls_0 = date/time=1970-01-01T00:00:00 timestamp=0 s"],
)

self.expect(
"frame variable ls_neg_date_time",
substrs=[
"ls_neg_date_time = date/time=-32767-01-01T00:00:00 timestamp=-1096193779200 s"
],
)
self.expect(
"frame variable ls_neg_seconds",
substrs=["ls_neg_seconds = timestamp=-1096193779201 s"],
)

self.expect(
"frame variable ls_pos_date_time",
substrs=[
"ls_pos_date_time = date/time=32767-12-31T23:59:59 timestamp=971890963199 s"
],
)
self.expect(
"frame variable ls_pos_seconds",
substrs=["ls_pos_seconds = timestamp=971890963200 s"],
)

self.expect(
"frame variable ls_min",
substrs=["ls_min = timestamp=-9223372036854775808 s"],
)
self.expect(
"frame variable ls_max",
substrs=["ls_max = timestamp=9223372036854775807 s"],
)

# local_days aliasses

self.expect(
"frame variable ld_tp",
substrs=["ld_tp = date=1970-01-01 timestamp=0 days"],
)
self.expect(
"frame variable ld_tp_d_r",
substrs=["ld_tp_d_r = date=1970-01-01 timestamp=0 days"],
)
self.expect(
"frame variable ld_tp_d_r2",
substrs=["ld_tp_d_r2 = date=1970-01-01 timestamp=0 days"],
)

# local_days

self.expect(
"frame variable ld_0", substrs=["ld_0 = date=1970-01-01 timestamp=0 days"]
)
self.expect(
"frame variable ld_neg_date",
substrs=["ld_neg_date = date=-32767-01-01 timestamp=-12687428 days"],
)
self.expect(
"frame variable ld_neg_days",
substrs=["ld_neg_days = timestamp=-12687429 days"],
)

self.expect(
"frame variable ld_pos_date",
substrs=["ld_pos_date = date=32767-12-31 timestamp=11248737 days"],
)
self.expect(
"frame variable ld_pos_days",
substrs=["ld_pos_days = timestamp=11248738 days"],
)

self.expect(
"frame variable ld_min",
substrs=["ld_min = timestamp=-2147483648 days"],
)
self.expect(
"frame variable ld_max",
substrs=["ld_max = timestamp=2147483647 days"],
)

self.expect("frame variable d_0", substrs=["d_0 = day=0"])
self.expect("frame variable d_1", substrs=["d_1 = day=1"])
self.expect("frame variable d_31", substrs=["d_31 = day=31"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,58 @@ int main() {
std::chrono::sys_days sd_max{
std::chrono::days{std::numeric_limits<int>::max()}};

// local_seconds aliasses
std::chrono::time_point<std::chrono::local_t, std::chrono::seconds> ls_tp{
std::chrono::seconds{0}};
std::chrono::time_point<std::chrono::local_t,
std::chrono::duration<long long>>
ls_tp_d{std::chrono::seconds{0}};
std::chrono::time_point<std::chrono::local_t,
std::chrono::duration<long long, std::ratio<1>>>
ls_tp_d_r{std::chrono::seconds{0}};
std::chrono::time_point<std::chrono::local_t,
std::chrono::duration<long long, std::ratio<1>>>
ls_tp_d_r2{std::chrono::seconds{0}};

// local_seconds
std::chrono::local_seconds ls_0{std::chrono::seconds{0}};
std::chrono::local_seconds ls_neg_date_time{
std::chrono::seconds{-1'096'193'779'200}};
std::chrono::local_seconds ls_neg_seconds{
std::chrono::seconds{-1'096'193'779'201}};
std::chrono::local_seconds ls_pos_date_time{
std::chrono::seconds{971'890'963'199}};
std::chrono::local_seconds ls_pos_seconds{
std::chrono::seconds{971'890'963'200}};
std::chrono::local_seconds ls_min{
std::chrono::seconds{std::numeric_limits<long long>::min()}};
std::chrono::local_seconds ls_max{
std::chrono::seconds{std::numeric_limits<long long>::max()}};

// local_days aliasses
std::chrono::time_point<std::chrono::local_t, std::chrono::days> ld_tp{
std::chrono::days{0}};
std::chrono::time_point<std::chrono::local_t,
std::chrono::duration<int, std::ratio<86400>>>
ld_tp_d_r{std::chrono::days{0}};
std::chrono::time_point<std::chrono::local_t,
std::chrono::duration<int, std::ratio<86400, 1>>>
ld_tp_d_r2{std::chrono::days{0}};

// local_days
std::chrono::local_days ld_0{std::chrono::days{0}};

std::chrono::local_days ld_neg_date{std::chrono::days{-12'687'428}};
std::chrono::local_days ld_neg_days{std::chrono::days{-12'687'429}};

std::chrono::local_days ld_pos_date{std::chrono::days{11'248'737}};
std::chrono::local_days ld_pos_days{std::chrono::days{11'248'738}};

std::chrono::local_days ld_min{
std::chrono::days{std::numeric_limits<int>::min()}};
std::chrono::local_days ld_max{
std::chrono::days{std::numeric_limits<int>::max()}};

std::chrono::day d_0{0};
std::chrono::day d_1{1};
std::chrono::day d_31{31};
Expand Down