From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by sourceware.org (Postfix) with ESMTPS id 3EFC8385842C for ; Tue, 9 Apr 2024 07:49:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3EFC8385842C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3EFC8385842C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712649003; cv=none; b=KqW7j2T8Tkscam5pyEp1NZwq5JM/vHedP147dZQtQY1nhRvThneGBue4pvpP6IU8mkE4WD91Ai7/4Ioqt9QWHQGIQ5PAnYnE9TgLnskmka4g8b3T8byBVZr+NSBEFqv4m/uPa4A/5KThmNHFuDNQ960J8DUU8D2fRrkG7oMdS2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712649003; c=relaxed/simple; bh=RTLVO93XJw7wHvqZksPaM72YQHMunO3flKFbhzla8x8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=HkPR/SZ7ieJ1dOgAcRXo/SkJne+rXiUJIere97D0sXSTwtAZZ4P2ej6Dp3DBtG3ZlE9G/M1QVF4BaNAGJUqkh00udUqwAQigB+X2amtMWD7/gjRyNBOq+1j+0KYYY0HQYHxeS+1DYHnCDPIyXNRWknNdEbRu/Ye45l5nh7s6RH4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712648999; x=1744184999; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RTLVO93XJw7wHvqZksPaM72YQHMunO3flKFbhzla8x8=; b=hi0/gPgdYSK01UeA0adBFmuWRz3IaO+x3VQgqkIFAGa461wUdqxvyFkZ 90w9gNH9Yj5fBNtJ0GHBQxQqEeSOw4paTd5jMwVcqKo+G4Z8VB9TJYiDa 9YL0b1De3gNkehhxJee7ugTTj04cMqpJkauAD4ujqKDmmqjwq49ABTY9I RfhJysEfBbg7F0e3nPrYaXCxYXFMsae8tT8XS+t7YMm3JwYA/KtdwL4Ie 8jhElR2yhMGRerX0WBShLxPywDVeN1+Oe073o/3Y7Scu5UyIaw2MuD1U7 bGLCWN6F2fssuDaTBI//q0SZOsQZxp5sM15wx/2u4T9ouDIvs/M9p2lD+ g==; X-CSE-ConnectionGUID: RQporNkCQEq/Y0DGJE2F+Q== X-CSE-MsgGUID: SWuSwjL0SBSVkhC3WCSvsA== X-IronPort-AV: E=McAfee;i="6600,9927,11038"; a="30443865" X-IronPort-AV: E=Sophos;i="6.07,189,1708416000"; d="scan'208";a="30443865" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2024 00:49:58 -0700 X-CSE-ConnectionGUID: oSUA3tsIT/ujoBXzo4z9ww== X-CSE-MsgGUID: 4p0Eyh+RQPqBAo3IGFZ2ag== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,189,1708416000"; d="scan'208";a="24636511" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2024 00:49:57 -0700 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Cc: tom@tromey.com, aburgess@redhat.com Subject: [PATCH v3 2/3] gdbserver: allow suppressing the next putpkt remote-debug log Date: Tue, 9 Apr 2024 09:48:10 +0200 Message-Id: <5fd2173aef207baed2491874ee4cc024c67af28a.1712648465.git.tankut.baris.aktemur@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: When started with the --remote-debug 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. --- gdbserver/debug.cc | 10 ++++++++++ gdbserver/debug.h | 10 ++++++++++ gdbserver/remote-utils.cc | 13 ++++++++----- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/gdbserver/debug.cc b/gdbserver/debug.cc index ae9ca5cd768..3d05a76b26a 100644 --- a/gdbserver/debug.cc +++ b/gdbserver/debug.cc @@ -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; +} diff --git a/gdbserver/debug.h b/gdbserver/debug.h index f78ef2580c3..eb6f69549ae 100644 --- a/gdbserver/debug.h +++ b/gdbserver/debug.h @@ -22,6 +22,11 @@ #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 */ diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc index 5a8eb9ae52a..a5b5d25dd5e 100644 --- a/gdbserver/remote-utils.cc +++ b/gdbserver/remote-utils.cc @@ -25,6 +25,7 @@ #include "debug.h" #include "dll.h" #include "gdbsupport/rsp-low.h" +#include "gdbsupport/scope-exit.h" #include "gdbsupport/netstuff.h" #include "gdbsupport/filestuff.h" #include "gdbsupport/gdb-sigmask.h" @@ -634,6 +635,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 @@ -668,15 +671,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 (); -- 2.34.1 Intel Deutschland GmbH Registered Address: Am Campeon 10, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928