-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
mordante
merged 1 commit into
llvm:main
from
mordante:review/lldb_local_clock_data_formatters
Apr 13, 2024
Merged
[lldb][libc++] Adds local_t clock data formatters. #88178
mordante
merged 1 commit into
llvm:main
from
mordante:review/lldb_local_clock_data_formatters
Apr 13, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-lldb Author: Mark de Wever (mordante) ChangesFull diff: https://github.com/llvm/llvm-project/pull/88178.diff 5 Files Affected:
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index 4a536096a066ff..5c28f6fe059e1a 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -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<long long, "
+ "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(
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index d2d50152c07cf8..e160fd07639395 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
index d8b807d180e068..8e97174dc30757 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
@@ -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
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
index c306315895960e..fb35481d555149 100644
--- 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
@@ -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"])
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
index 315c88a787d823..0ea42d1a107e1b 100644
--- 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
@@ -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};
|
Michael137
reviewed
Apr 12, 2024
Michael137
approved these changes
Apr 12, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
656ee03
to
5140ce2
Compare
bazuzi
pushed a commit
to bazuzi/llvm-project
that referenced
this pull request
Apr 15, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.