pretty-print for time_point
Is it possible to add pretty-print to humanly display time_point in the gdb debugger?
I don't know what's involved in doing that.
The debugger displays time_point as a number, from which it is difficult to understand what date and time it represents:
The GDB debugger uses special scripts to represent complex binary structures such as strings, containers, etc. in a readable format.
for example
It would be very convenient to be able to understand the date and time during debugging in GDB.
On first glance it doesn't appear that this requires any changes to the date lib.
I am not the right person to develop these scripts. For one, I don't have gdb installed to test them with.
Perhaps someone has already done this? time_point has been part of the std <chrono> header for a decade now.
I checked in 8 and 10 (GDB) versions:
...
def register_type_printers(obj):
global _use_type_printing
if not _use_type_printing:
return
...
# Add type printers for <chrono> typedefs.
for dur in ('nanoseconds', 'microseconds', 'milliseconds',
'seconds', 'minutes', 'hours'):
add_one_type_printer(obj, 'duration', dur)
...
other than that I couldn't find anything else in /usr/share/gcc...
Found discussion on a similar topic Tried adding to my .gdbinit:
python
import gdb.printing
def nsepoch_to_time(ns, precision=6):
return "time"
class NSSinceEpochPrinter:
def __init__(self, val):
self.val = val
def to_string(self):
if self.val.address and self.val.address != 0 and not self.val.is_optimized_out:
return nsepoch_to_time(int(self.val["__d"]["__r"]))
else:
return "<unknown>"
def build_pretty_printer():
pp = gdb.printing.RegexpCollectionPrettyPrinter("iat_clocks")
pp.add_printer('NSSinceEpoch', '^std::chrono::time_point<my_ns_since_epoch_clock_impl.*1000000000', NSSinceEpochPrinter)
return pp
end
But I didn't see any result.
In MSVC, the situation is similar:

Windows 10 x64 Microsoft Visual C++ 2019