]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdbserver: allow suppressing the next putpkt remote-debug log
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Thu, 19 Dec 2024 11:31:50 +0000 (12:31 +0100)
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Thu, 19 Dec 2024 11:31:50 +0000 (12:31 +0100)
When started with the --debug=remote flag, gdbserver enables the debug
logs for the received and sent remote packets.  If the packet contents
are too long or contain verbatim binary data, printing the contents
may create noise in the logs or even distortion in the terminal output.

Introduce a function, `suppress_next_putpkt_log`, that allows omitting
the contents of a sent package in the logs.  This can be useful when a
certain packet handler knows that it is sending binary data.

My first attempt was to implement this mechanism by passing an extra
parameter to putpt_binary_1 that could be controlled by the caller,
putpkt_binary or putpkt.  However, all qxfer handlers, regardless of
whether they send binary or ascii data, cause the data to be sent via
putpkt_binary. Hence, the solution was going to be either too
suppressive or too intrusive.  I opted for the approach where a package
handler would suppress the log explicitly.

Approved-By: Tom Tromey <tom@tromey.com>
gdbserver/debug.cc
gdbserver/debug.h
gdbserver/remote-utils.cc

index ae9ca5cd76874411248d9461c2fdb60347b821f2..3d05a76b26a81f78eb9eadfdf86ea3a32d512f6d 100644 (file)
@@ -20,6 +20,8 @@
 
 #if !defined (IN_PROCESS_AGENT)
 bool remote_debug = false;
+
+bool suppressed_remote_debug = false;
 #endif
 
 /* Output file for debugging.  Default to standard error.  */
@@ -117,3 +119,11 @@ debug_write (const void *buf, size_t nbyte)
   int fd = fileno (debug_file);
   return write (fd, buf, nbyte);
 }
+
+/* See debug.h.  */
+
+void
+suppress_next_putpkt_log ()
+{
+  suppressed_remote_debug = true;
+}
index f78ef2580c3956935cae96355646cc285deb6325..eb6f69549aedd2094d445203a58610b6d26e6fa2 100644 (file)
 #if !defined (IN_PROCESS_AGENT)
 extern bool remote_debug;
 
+/* If true, do not print the packet content sent with the next putpkt.
+   This flag is reset to false after each putpkt logging.  Useful to
+   omit printing binary packet contents.  */
+extern bool suppressed_remote_debug;
+
 /* Print a "remote" debug statement.  */
 
 #define remote_debug_printf(fmt, ...) \
@@ -59,4 +64,9 @@ void debug_flush (void);
 /* Async signal safe debug output function that calls write directly.  */
 ssize_t debug_write (const void *buf, size_t nbyte);
 
+/* Suppress the next putpkt debug log by omitting the packet contents.
+   Useful to reduce the logs when sending binary packets.  */
+
+void suppress_next_putpkt_log ();
+
 #endif /* GDBSERVER_DEBUG_H */
index 3584697b2abb92fc7a8e658e702262c9c70bc160..df606c71bba8e2f4721a66373f8729d9f50d0bd3 100644 (file)
@@ -26,6 +26,7 @@
 #include "dll.h"
 #include "gdbsupport/common-gdbthread.h"
 #include "gdbsupport/rsp-low.h"
+#include "gdbsupport/scope-exit.h"
 #include "gdbsupport/netstuff.h"
 #include "gdbsupport/filestuff.h"
 #include "gdbsupport/gdb-sigmask.h"
@@ -638,6 +639,8 @@ putpkt_binary_1 (char *buf, int cnt, int is_notif)
   char *p;
   int cc;
 
+  SCOPE_EXIT { suppressed_remote_debug = false; };
+
   buf2 = (char *) xmalloc (strlen ("$") + cnt + strlen ("#nn") + 1);
 
   /* Copy the packet into buffer BUF2, encapsulating it
@@ -672,15 +675,15 @@ putpkt_binary_1 (char *buf, int cnt, int is_notif)
       if (cs.noack_mode || is_notif)
        {
          /* Don't expect an ack then.  */
-         if (is_notif)
-           remote_debug_printf ("putpkt (\"%s\"); [notif]", buf2);
-         else
-           remote_debug_printf ("putpkt (\"%s\"); [noack mode]", buf2);
+         remote_debug_printf ("putpkt (\"%s\"); [%s]",
+                              (suppressed_remote_debug ? "..." : buf2),
+                              (is_notif ? "notif" : "noack mode"));
 
          break;
        }
 
-      remote_debug_printf ("putpkt (\"%s\"); [looking for ack]", buf2);
+      remote_debug_printf ("putpkt (\"%s\"); [looking for ack]",
+                          (suppressed_remote_debug ? "..." : buf2));
 
       cc = readchar ();