[Lldb-commits] [lldb] [lldb][libc++] Adds system_clock data formatters. (PR #78609)

Jason Molenda via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 5 16:25:35 PST 2024


jasonmolenda wrote:

Agreed, if I change this to 

```
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index d0bdbe1fd4d..b37544f6dd3 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -1105,7 +1105,7 @@ bool lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
 
   const std::time_t seconds = ptr_sp->GetValueAsSigned(0);
   if (seconds < chrono_timestamp_min || seconds > chrono_timestamp_max)
-    stream.Printf("timestamp=%" PRIu64 " s", static_cast<uint64_t>(seconds));
+    stream.Printf("timestamp=%" PRId64 " s", static_cast<int64_t>(seconds));
   else {
     std::array<char, 128> str;
     std::size_t size =
@@ -1113,8 +1113,8 @@ bool lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
     if (size == 0)
       return false;
 
-    stream.Printf("date/time=%s timestamp=%" PRIu64 " s", str.data(),
-                  static_cast<uint64_t>(seconds));
+    stream.Printf("date/time=%s timestamp=%" PRId64 " s", str.data(),
+                  static_cast<int64_t>(seconds));
   }
 
   return true;
```

the tests pass on Darwin.  On Darwin `time_t` is `long`, a signed value - and given that this can represent negative times, that makes sense.  The test is checking that PRIu64 prints a negative value but we're casting this time_t to a uint64_t, I don't understand why this would print as a negative value on Linux (and pass the tests).

https://github.com/llvm/llvm-project/pull/78609


More information about the lldb-commits mailing list