aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/utils.c34
2 files changed, 24 insertions, 15 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f113bff..e0da11f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2021-01-04 Simon Marchi <simon.marchi@efficios.com>
+
+ * utils.c (vfprintf_unfiltered): Print timestamp only when
+ previous debug output ended with a newline.
+
2021-01-04 Luis Machado <luis.machado@linaro.org>
Update all users of trad_frame_saved_reg to use the new member
diff --git a/gdb/utils.c b/gdb/utils.c
index f22beea..414e7b1 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -2126,26 +2126,30 @@ vfprintf_unfiltered (struct ui_file *stream, const char *format, va_list args)
{
if (debug_timestamp && stream == gdb_stdlog)
{
- using namespace std::chrono;
- int len, need_nl;
+ 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);
std::string linebuffer = std::move (sfile.string ());
+ fputs_unfiltered (linebuffer.c_str (), stream);
- 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);
-
- len = linebuffer.size ();
- need_nl = (len > 0 && linebuffer[len - 1] != '\n');
-
- std::string timestamp = string_printf ("%ld.%06ld %s%s",
- (long) s.count (),
- (long) us.count (),
- linebuffer.c_str (),
- need_nl ? "\n": "");
- fputs_unfiltered (timestamp.c_str (), stream);
+ size_t len = linebuffer.length ();
+ needs_timestamp = (len > 0 && linebuffer[len - 1] == '\n');
}
else
vfprintf_maybe_filtered (stream, format, args, false, true);