Skip to content

Commit f219cda

Browse files
authored
[lldb] Fix printf formatting of std::time_t seconds (#81078)
This formatter #78609 was originally passing the signed seconds (which can refer to times in the past) with an unsigned printf formatter, and had tests that expected to see negative values from the printf which always failed on macOS. I'm not clear how they ever passed on any platform. Fix the printf to print seconds as a signed value, and re-enable the tests.
1 parent bdde5f9 commit f219cda

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,16 +1108,16 @@ bool lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
11081108

11091109
const std::time_t seconds = ptr_sp->GetValueAsSigned(0);
11101110
if (seconds < chrono_timestamp_min || seconds > chrono_timestamp_max)
1111-
stream.Printf("timestamp=%" PRIu64 " s", static_cast<uint64_t>(seconds));
1111+
stream.Printf("timestamp=%" PRId64 " s", static_cast<int64_t>(seconds));
11121112
else {
11131113
std::array<char, 128> str;
11141114
std::size_t size =
11151115
std::strftime(str.data(), str.size(), "%FT%H:%M:%SZ", gmtime(&seconds));
11161116
if (size == 0)
11171117
return false;
11181118

1119-
stream.Printf("date/time=%s timestamp=%" PRIu64 " s", str.data(),
1120-
static_cast<uint64_t>(seconds));
1119+
stream.Printf("date/time=%s timestamp=%" PRId64 " s", str.data(),
1120+
static_cast<int64_t>(seconds));
11211121
}
11221122

11231123
return true;

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,16 @@ def test_with_run_command(self):
5454
substrs=["ss_0 = date/time=1970-01-01T00:00:00Z timestamp=0 s"],
5555
)
5656

57-
# FIXME disabled temporarily, macOS is printing this as an unsigned?
58-
#self.expect(
59-
# "frame variable ss_neg_date_time",
60-
# substrs=[
61-
# "ss_neg_date_time = date/time=-32767-01-01T00:00:00Z timestamp=-1096193779200 s"
62-
# ],
63-
#)
64-
#self.expect(
65-
# "frame variable ss_neg_seconds",
66-
# substrs=["ss_neg_seconds = timestamp=-1096193779201 s"],
67-
#)
57+
self.expect(
58+
"frame variable ss_neg_date_time",
59+
substrs=[
60+
"ss_neg_date_time = date/time=-32767-01-01T00:00:00Z timestamp=-1096193779200 s"
61+
],
62+
)
63+
self.expect(
64+
"frame variable ss_neg_seconds",
65+
substrs=["ss_neg_seconds = timestamp=-1096193779201 s"],
66+
)
6867

6968
self.expect(
7069
"frame variable ss_pos_date_time",
@@ -77,11 +76,10 @@ def test_with_run_command(self):
7776
substrs=["ss_pos_seconds = timestamp=971890963200 s"],
7877
)
7978

80-
# FIXME disabled temporarily, macOS is printing this as an unsigned?
81-
#self.expect(
82-
# "frame variable ss_min",
83-
# substrs=["ss_min = timestamp=-9223372036854775808 s"],
84-
#)
79+
self.expect(
80+
"frame variable ss_min",
81+
substrs=["ss_min = timestamp=-9223372036854775808 s"],
82+
)
8583
self.expect(
8684
"frame variable ss_max",
8785
substrs=["ss_max = timestamp=9223372036854775807 s"],

0 commit comments

Comments
 (0)