diff options
author | Tom Tromey <tom@tromey.com> | 2021-12-31 12:00:11 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2022-03-28 14:13:28 -0600 |
commit | 52a4a5885af15e7ef32d5f4e5b77f98349c32276 (patch) | |
tree | 1ca6af096a9c652bbe8aa4f7347eb178e39ed1f1 /gdb/utils.c | |
parent | 3c6c449e304413f513db5635abd2181776f7db92 (diff) | |
download | gdb-52a4a5885af15e7ef32d5f4e5b77f98349c32276.zip gdb-52a4a5885af15e7ef32d5f4e5b77f98349c32276.tar.gz gdb-52a4a5885af15e7ef32d5f4e5b77f98349c32276.tar.bz2 |
Switch gdb_stdlog to use timestamped_file
Currently, timestamps for logging are done by looking for the use of
gdb_stdlog in vfprintf_unfiltered. This seems potentially buggy, in
that during logging or other redirects (like execute_fn_to_ui_file) we
might have gdb_stdout==gdb_stdlog and so, conceivably, wind up with
timestamps in a log when they were not desired.
It seems better, instead, for timestamps to be a property of the
ui_file itself.
This patch changes gdb to use the new timestamped_file for gdb_stdlog
where appropriate, and removes the special case from
vfprintf_unfiltered.
Note that this may somewhat change the output in some cases -- in
particular, when going through execute_fn_to_ui_file (or the _string
variant), timestamps won't be emitted. This could be fixed in those
functions, but it wasn't clear to me whether this is really desirable.
Note also that this changes the TUI to send gdb_stdlog to gdb_stderr.
I imagine that the previous use of gdb_stdout here was inadvertent.
(And in any case it probably doesn't matter.)
Diffstat (limited to 'gdb/utils.c')
-rw-r--r-- | gdb/utils.c | 30 |
1 files changed, 1 insertions, 29 deletions
diff --git a/gdb/utils.c b/gdb/utils.c index 8dd7008..48aedb0 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1938,35 +1938,7 @@ vfprintf_filtered (struct ui_file *stream, const char *format, va_list args) void vfprintf_unfiltered (struct ui_file *stream, const char *format, va_list args) { - if (debug_timestamp && stream == gdb_stdlog) - { - static bool needs_timestamp = true; - - /* Print timestamp if previous print ended with a \n. */ - if (needs_timestamp) - { - using namespace std::chrono; - - steady_clock::time_point now = steady_clock::now (); - seconds s = duration_cast<seconds> (now.time_since_epoch ()); - microseconds us = duration_cast<microseconds> (now.time_since_epoch () - s); - std::string timestamp = string_printf ("%ld.%06ld ", - (long) s.count (), - (long) us.count ()); - fputs_unfiltered (timestamp.c_str (), stream); - } - - /* Print the message. */ - string_file sfile; - cli_ui_out (&sfile, 0).vmessage (ui_file_style (), format, args); - const std::string &linebuffer = sfile.string (); - fputs_unfiltered (linebuffer.c_str (), stream); - - size_t len = linebuffer.length (); - needs_timestamp = (len > 0 && linebuffer[len - 1] == '\n'); - } - else - vfprintf_maybe_filtered (stream, format, args, false); + vfprintf_maybe_filtered (stream, format, args, false); } void |