Skip to content

Commit 4477bfb

Browse files
committed
[lldb] Fix printf formatting of std::time_t seconds
This formatter llvm#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 0d7f232 commit 4477bfb

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
@@ -1105,16 +1105,16 @@ bool lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
11051105

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

1116-
stream.Printf("date/time=%s timestamp=%" PRIu64 " s", str.data(),
1117-
static_cast<uint64_t>(seconds));
1116+
stream.Printf("date/time=%s timestamp=%" PRId64 " s", str.data(),
1117+
static_cast<int64_t>(seconds));
11181118
}
11191119

11201120
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)