Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH v2 2/3] gdb: use infrun_debug_printf in print_target_wait_results
Date: Wed, 16 Dec 2020 15:47:36 -0500	[thread overview]
Message-ID: <20201216204737.900975-2-simon.marchi@efficios.com> (raw)
In-Reply-To: <20201216204737.900975-1-simon.marchi@efficios.com>

The code in print_target_wait_results uses a single call to debug_printf
in order to make sure a single timestamp is emitted, despite printing
multiple lines.  The result is:

    941502.043284 [infrun] target_wait (-1.0.0, status) =
    [infrun]   649832.649832.0 [process 649832],
    [infrun]   status->kind = stopped, signal = GDB_SIGNAL_TRAP

I find this decision a bit counter productive, because it messes up the
alignment of the three lines.  We don't care that three (slightly
different) timestamps are printed.

I suggest to change this function to use infrun_debug_printf, with this
result:

    941601.425771 [infrun] print_target_wait_results: target_wait (-1.0.0 [process -1], status) =
    941601.425824 [infrun] print_target_wait_results:   651481.651481.0 [process 651481],
    941601.425867 [infrun] print_target_wait_results:   status->kind = stopped, signal = GDB_SIGNAL_TRAP

Note that the current code only prints the waiton_ptid as a string
between square brackets if pid != -1.  I don't think this complexity is
needed in a debug print.  I made it so it's always printed, which I
think results in a much simpler function.

gdb/ChangeLog:

	* infrun.c (print_target_wait_results): Use infrun_debug_printf.

Change-Id: I817bd10286b8e641a6c751ac3a1bd1ddf9b18ce0
---
 gdb/infrun.c | 36 +++++++++++-------------------------
 1 file changed, 11 insertions(+), 25 deletions(-)

diff --git a/gdb/infrun.c b/gdb/infrun.c
index f509481e3d3..fe07be5e381 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -3275,31 +3275,17 @@ void
 print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
 			   const struct target_waitstatus *ws)
 {
-  std::string status_string = target_waitstatus_to_string (ws);
-  string_file stb;
-
-  /* The text is split over several lines because it was getting too long.
-     Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
-     output as a unit; we want only one timestamp printed if debug_timestamp
-     is set.  */
-
-  stb.printf ("[infrun] target_wait (%d.%ld.%ld",
-	      waiton_ptid.pid (),
-	      waiton_ptid.lwp (),
-	      waiton_ptid.tid ());
-  if (waiton_ptid.pid () != -1)
-    stb.printf (" [%s]", target_pid_to_str (waiton_ptid).c_str ());
-  stb.printf (", status) =\n");
-  stb.printf ("[infrun]   %d.%ld.%ld [%s],\n",
-	      result_ptid.pid (),
-	      result_ptid.lwp (),
-	      result_ptid.tid (),
-	      target_pid_to_str (result_ptid).c_str ());
-  stb.printf ("[infrun]   %s\n", status_string.c_str ());
-
-  /* This uses %s in part to handle %'s in the text, but also to avoid
-     a gcc error: the format attribute requires a string literal.  */
-  fprintf_unfiltered (gdb_stdlog, "%s", stb.c_str ());
+  infrun_debug_printf ("target_wait (%d.%ld.%ld [%s], status) =",
+		       waiton_ptid.pid (),
+		       waiton_ptid.lwp (),
+		       waiton_ptid.tid (),
+		       target_pid_to_str (waiton_ptid).c_str ());
+  infrun_debug_printf ("  %d.%ld.%ld [%s],",
+		       result_ptid.pid (),
+		       result_ptid.lwp (),
+		       result_ptid.tid (),
+		       target_pid_to_str (result_ptid).c_str ());
+  infrun_debug_printf ("  %s", target_waitstatus_to_string (ws).c_str ());
 }
 
 /* Select a thread at random, out of those which are resumed and have
-- 
2.29.2


  reply	other threads:[~2020-12-16 20:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-16 20:47 [PATCH v2 1/3] gdb: make "set debug timestamp" work nice with new debug printouts Simon Marchi via Gdb-patches
2020-12-16 20:47 ` Simon Marchi via Gdb-patches [this message]
2020-12-16 20:47 ` [PATCH v2 3/3] gdb: introduce scoped debug prints Simon Marchi via Gdb-patches
2020-12-22 21:35   ` Simon Marchi via Gdb-patches
2021-01-04 17:02     ` Simon Marchi via Gdb-patches
2021-01-05  9:01       ` Tom de Vries
2021-01-05  9:23         ` Tom de Vries
2021-01-05 15:33           ` Simon Marchi via Gdb-patches
2021-01-05 17:02             ` Simon Marchi via Gdb-patches
2021-01-05 21:26               ` tdevries
2021-01-05 21:54                 ` Simon Marchi via Gdb-patches
2021-01-06  1:00                   ` Simon Marchi via Gdb-patches
2021-01-06  7:15                     ` Tom de Vries
2021-01-06 19:05                       ` Simon Marchi via Gdb-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201216204737.900975-2-simon.marchi@efficios.com \
    --to=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox