From patchwork Thu Mar 14 13:07:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aktemur, Tankut Baris" X-Patchwork-Id: 87185 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 62B113857BA0 for ; Thu, 14 Mar 2024 13:08:45 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) by sourceware.org (Postfix) with ESMTPS id 0C3AD3857B9B for ; Thu, 14 Mar 2024 13:08:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C3AD3857B9B 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 0C3AD3857B9B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710421688; cv=none; b=A7DJZb4A6wy/IX//ivBlDsfpoUwaeaiCzNSZUuEeDognLbAhEANUWlGBBrqFJoCGexDb567o/3j1Vox/0orUxVERvv3eaP5NXEwhHzkA2e1RTqw0rR1xHDd7oUV8pK5WvjH7WuBt9yYvUFalX5U47moPK28ERK4VxGgbHnBrDcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710421688; c=relaxed/simple; bh=E4LBiW5Uy77RZhU83SRjFV9NhdMYyhaBujXdVVDUZRo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=rla5Zg0lHcZew55QiGHmb+eTFK8xSeuTn1nKQDGgyXBoIJoXvCSU7+Uo3yqmikUM2Pn6R85IccDrw/UdfDt6tHm1OE6DKrTTirlmdhzbT/1hoePZ3iVNqR/ii2alblI616vOoxtwr64X/4IO4o0WDcOyfNmoDzTyZu6EkvtnJAI= 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=1710421684; x=1741957684; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E4LBiW5Uy77RZhU83SRjFV9NhdMYyhaBujXdVVDUZRo=; b=WwBOzjkpVc1g8JPPFGBLeIruVBIU8rsT39J/JlOV+KTnFaQ3VAjoLHHd wx8trSCHh22xNFUP31sSPeXKCBFO6wnUOg8CgjFCDKmHVJ/uXcdtGdsNa gL4db/Jobsx6g7S6RoY6aL29RzikHUETnDxIMe03prr1zmXIPFscNAB++ 38g4dmOGqP48b4j0kq/3/3EkBp/omUR2vzDFUysGa+u6oJ5utK/k0b2k5 MlhZ1Y+NtFj4ZrCghJQB6A1aZ98Rhy+l3m2ForRX+IMhil1TP8WMfeyY4 te6GZ2M7pX2eM+fnN+Gzd59QrjcKEm4bJtF1wcpwcDPj70AvJt8la6fia A==; X-IronPort-AV: E=McAfee;i="6600,9927,11012"; a="15791656" X-IronPort-AV: E=Sophos;i="6.07,125,1708416000"; d="scan'208";a="15791656" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2024 06:08:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,125,1708416000"; d="scan'208";a="12734981" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2024 06:08:02 -0700 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Cc: tom@tromey.com Subject: [PATCH v2 2/4] gdbserver: allow suppressing the next putpkt remote-debug log Date: Thu, 14 Mar 2024 14:07:29 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 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_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org 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 9bdff962dda..cf8ba777053 100644 --- a/gdbserver/debug.cc +++ b/gdbserver/debug.cc @@ -21,6 +21,8 @@ #if !defined (IN_PROCESS_AGENT) bool remote_debug = false; + +bool suppressed_remote_debug = false; #endif /* Output file for debugging. Default to standard error. */ @@ -118,3 +120,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 95955753401..5e7c38056d0 100644 --- a/gdbserver/remote-utils.cc +++ b/gdbserver/remote-utils.cc @@ -26,6 +26,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" @@ -635,6 +636,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 @@ -669,15 +672,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 ();