From patchwork Tue Apr 9 07:48:09 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: 88222 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 34C0F385829B for ; Tue, 9 Apr 2024 07:50:33 +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 BC3813861019 for ; Tue, 9 Apr 2024 07:49:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BC3813861019 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 BC3813861019 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=1712648994; cv=none; b=S0InL26qmNMzcOy+YFydpiFvOYLvz1lWGwgENIroFM26uj+evj+5nV1MMVj3RIPv/acPG85HhWwg9ZrQr6d9UBbL/bQtG7OTUF9dm0pzTVYu1A5HtWv1b0LUB7gzFV2Y+lsSfSwB2DGPbncuP9xtxoczZfpT6gscNLknf9igaO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712648994; c=relaxed/simple; bh=8jE4Mj8r1mLjqL4M4Zt3pYptRFklRH+lW5oeMNRnHfg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=StTBl1+y/kZf61JSzVNPjXa97stuj5DOEVagmpgKFtrddHrVlJsE2gvEnRQ/llXSNpCxknXZUePreWDSns3BnLasiT6mf4jWoAVsc4lpKXCVrjmvNZHovtRTAZmn79p8kPYzGpOObxzSWQpzLluh2Og0QdoTOP7TG/DKVv3BadU= 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=1712648993; x=1744184993; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8jE4Mj8r1mLjqL4M4Zt3pYptRFklRH+lW5oeMNRnHfg=; b=VuKEIJudsEnyQ/Rm/tT7TN3wt+tK/yypnaGShPBTC4Rs5wEAnRp/EgDN hmIR9h6vaGQT/YIlQaa12L7sqXiuoVpVZmN9LiPfDBOzgbohtbET3oF9p va1D8goNZCLgXUITZ1PBv3rplavfpfdiwAf+1sVmvfl5wYAkv+R7WzIiT uWefvRqMUOec8TTTxCGt+I2LSqTBtLj7qlT7yF1eSRc+FT8AMLg3KnLSu m0WhsgTVekhrejeyORvNqL5tKz+PebFTw65WApasOhqnsBvcapVrTh/oT dL9Ctq/oRAb9rjIpuIYVJzm5bA+PbC+m5A+y6Qn4S68RVDt2nOsSmpcOz g==; X-CSE-ConnectionGUID: UFyBcmIjRvCW2ee5oNBFZw== X-CSE-MsgGUID: iqZ67c3VRNKwKKnav5Jfzw== X-IronPort-AV: E=McAfee;i="6600,9927,11038"; a="18517538" X-IronPort-AV: E=Sophos;i="6.07,189,1708416000"; d="scan'208";a="18517538" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2024 00:49:52 -0700 X-CSE-ConnectionGUID: Mkrrfp/ZQxqf3GKNCbAfGw== X-CSE-MsgGUID: YxWY/2JYQIGmIFuXlNir9g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,189,1708416000"; d="scan'208";a="20261768" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2024 00:49:50 -0700 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Cc: tom@tromey.com, aburgess@redhat.com Subject: [PATCH v3 1/3] doc: fine-tune the documentation of the 'm' RSP packet Date: Tue, 9 Apr 2024 09:48:09 +0200 Message-Id: <941705a0a04ad587ae42e320574d76deab616864.1712648465.git.tankut.baris.aktemur@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 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 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 Revise a sentence to avoid misinterpretation. Move @cindex entries before the text they index. Refer to trace frames regarding partial reads. Approved-By: Eli Zaretskii --- gdb/doc/gdb.texinfo | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 82a617e9ad3..0c4d602f7f7 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -42841,24 +42841,25 @@ probes the target state as if a new connection was opened @item m @var{addr},@var{length} @cindex @samp{m} packet Read @var{length} addressable memory units starting at address @var{addr} -(@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to -any particular boundary. +(@pxref{addressable memory unit}). Note that @var{addr} does not have to +be aligned to any particular boundary. +@cindex alignment of remote memory accesses +@cindex size of remote memory accesses +@cindex memory, alignment and size of remote accesses The stub need not use any particular size or alignment when gathering data from memory for the response; even if @var{addr} is word-aligned and @var{length} is a multiple of the word size, the stub is free to use byte accesses, or not. For this reason, this packet may not be suitable for accessing memory-mapped I/O devices. -@cindex alignment of remote memory accesses -@cindex size of remote memory accesses -@cindex memory, alignment and size of remote accesses Reply: @table @samp @item @var{XX@dots{}} Memory contents; each byte is transmitted as a two-digit hexadecimal number. The reply may contain fewer addressable memory units than requested if the -server was able to read only part of the region of memory. +server was reading from a trace frame memory and was able to read only part +of the region of memory. @item E @var{NN} @var{NN} is errno @end table From patchwork Tue Apr 9 07:48:10 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: 88223 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 B4BF6384B06A for ; Tue, 9 Apr 2024 07:50:35 +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.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 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 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 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 (); From patchwork Tue Apr 9 07:48:11 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: 88224 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 6E9A0385841E for ; Tue, 9 Apr 2024 07:51:04 +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.9]) by sourceware.org (Postfix) with ESMTPS id 22ECD3858289 for ; Tue, 9 Apr 2024 07:50:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 22ECD3858289 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 22ECD3858289 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=1712649007; cv=none; b=aqNqs0tQS8gb3I/xhZGnikQitobfDMfIcorPwxx0ygZ4OBpusIrQdSH/sAG0mtlqgpFN8Nrt3aT5peUy8AmItNMorAqz/Vj7yb/2aD+DIF9SVWqC0ULpNVBaa+0gcAkPYg+Fv/1niugeh+tb7omiGhP7uBdyDfK/n2KsoNXjj6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712649007; c=relaxed/simple; bh=/QYQWBa7rVDI0Cru1wgpAh6KhVn90YspvLhsAPIAvLI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=ktMZ/Cvq+Lbc2K/AxbYQVZOmOstig83lx2Ik9QTpsusyQ0Awy9KaqfYiDkdW4StjsUUsFbVgvX7447KZnWowMJr3BEw9WK0rl/P4RGlv+E0G+joNwVvzKZla0skw4EI7aWuFk3YQeByzzLnU+ixgQaJLtX9N/BdEJZnqJE818hs= 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=1712649004; x=1744185004; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/QYQWBa7rVDI0Cru1wgpAh6KhVn90YspvLhsAPIAvLI=; b=Hq1X/jQkvYcp6txM8SO01tHDjt7wriNIMmF8aeRa5vzv+00eivDlSCc/ d4J0xQ4OOmMYamrb1RVXksIdLdFVxr//IQFS56Re2v/XzKpb+G/eYq4cD olcDqSMqGFZ6wS/36VoftuZu0JOKkXGcQS67xxhopPMqrr3jY9lIz9sTE A500hoydqG49jCz9/Xli2U+ltM5Zen+mt87Bylg9aDhWTIbwPlLHGNKaI e5MbBR9GdX5tDSWP5YEWZk15bd4lMP5GHuCKdG5kJdm+YBwqCYrfUHu8+ 9dJijocD9IIbtQwD3+Fg62vvmcGkfut6juHzAs7HeZJE4bFnHKk557S5G w==; X-CSE-ConnectionGUID: +W2dUIPlT7G5x/Llagce+w== X-CSE-MsgGUID: K/DIEQADR9KCR9BIDhfBfA== X-IronPort-AV: E=McAfee;i="6600,9927,11038"; a="30443886" X-IronPort-AV: E=Sophos;i="6.07,189,1708416000"; d="scan'208";a="30443886" 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:50:04 -0700 X-CSE-ConnectionGUID: EedK2K2eStGYYxXR9vq5Ww== X-CSE-MsgGUID: vMCXObjfRvC6uyL3vF/GNg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,189,1708416000"; d="scan'208";a="24636522" 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:50:02 -0700 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Cc: tom@tromey.com, aburgess@redhat.com Subject: [PATCH v3 3/3] gdb, gdbserver: introduce the 'x' RSP packet for binary memory read Date: Tue, 9 Apr 2024 09:48:11 +0200 Message-Id: <89ed8debd626735ae02fa1f2fc8e7036c1867329.1712648465.git.tankut.baris.aktemur@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 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 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 Introduce an RSP packet, 'x', for reading from the remote server memory in binary format. The binary write packet, 'X' already exists. The 'x' packet is essentially the same as 'm', except that the returned data is in binary format. For transferring relatively large data from the memory of the remote process, the 'x' packet can reduce the transfer costs. For example, without this patch, fetching ~100MB of data from a remote target takes (gdb) dump binary memory temp.o 0x00007f3ba4c576c0 0x00007f3bab709400 2024-03-13 16:17:42.626 - command started 2024-03-13 16:18:24.151 - command finished Command execution time: 32.136785 (cpu), 41.525515 (wall) (gdb) whereas with this patch, we obtain (gdb) dump binary memory temp.o 0x00007fec39fce6c0 0x00007fec40a80400 2024-03-13 16:20:48.609 - command started 2024-03-13 16:21:16.873 - command finished Command execution time: 20.447970 (cpu), 28.264202 (wall) (gdb) We see improvements not only when reading bulk data as above, but also when making a large number of small memory access requests. For example, without this patch: (gdb) pipe x/100000xw $pc | wc -l 2024-03-13 16:04:57.112 - command started 25000 2024-03-13 16:05:10.798 - command finished Command execution time: 9.952364 (cpu), 13.686581 (wall) With this patch: (gdb) pipe x/100000xw $pc | wc -l 2024-03-13 16:06:48.160 - command started 25000 2024-03-13 16:06:57.750 - command finished Command execution time: 6.541425 (cpu), 9.589839 (wall) (gdb) Another example, where we create a core file of a GDB process. (gdb) gcore /tmp/core.1 ... Command execution time: 85.496967 (cpu), 133.224373 (wall) vs. (gdb) gcore /tmp/core.1 ... Command execution time: 48.328885 (cpu), 115.032289 (wall) Regression-tested on X86-64 using the unix (default) and native-extended-gdbserver board files. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 6 +++ gdb/doc/gdb.texinfo | 27 ++++++++++++ gdb/remote.c | 86 +++++++++++++++++++++++++++++++------- gdbserver/remote-utils.cc | 88 +++++++++++++++++++++++++++++++++++---- gdbserver/remote-utils.h | 2 + gdbserver/server.cc | 29 +++++++++++++ 6 files changed, 217 insertions(+), 21 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index feb3a37393a..3ff6dc75c48 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -192,6 +192,12 @@ QThreadOptions in qSupported QThreadOptions packet, and the qSupported response can contain the set of thread options the remote stub supports. +x addr,length + Given ADDR and LENGTH, fetch LENGTH units from the memory at address + ADDR and send the fetched data in binary format. This packet is + equivalent to 'm', except that the data in the response are in + binary format. + *** Changes in GDB 14 * GDB now supports the AArch64 Scalable Matrix Extension 2 (SME2), which diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 0c4d602f7f7..3d4c17f8db1 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -43218,6 +43218,33 @@ for success (@pxref{Stop Reply Packets}) @cindex @samp{vStopped} packet @xref{Notification Packets}. +@item x @var{addr},@var{length} +@anchor{x packet} +@cindex @samp{x} packet +Read @var{length} addressable memory units starting at address @var{addr} +(@pxref{addressable memory unit}). Note that @var{addr} does not have to +be aligned to any particular boundary. + +@cindex alignment of remote memory accesses +@cindex size of remote memory accesses +@cindex memory, alignment and size of remote accesses +The stub need not use any particular size or alignment when gathering +data from memory for the response; even if @var{addr} is word-aligned +and @var{length} is a multiple of the word size, the stub is free to +use byte accesses, or not. For this reason, this packet may not be +suitable for accessing memory-mapped I/O devices. + +Reply: +@table @samp +@item b @var{XX@dots{}} +Memory contents as binary data (@pxref{Binary Data}). +The reply may contain fewer addressable memory units than requested if the +server was reading from a trace frame memory and was able to read only part +of the region of memory. +@item E @var{NN} +for an error +@end table + @item X @var{addr},@var{length}:@var{XX@dots{}} @anchor{X packet} @cindex @samp{X} packet diff --git a/gdb/remote.c b/gdb/remote.c index a09ba4d715d..f94eb47dc29 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -193,6 +193,7 @@ struct packet_result enum { PACKET_vCont = 0, PACKET_X, + PACKET_x, PACKET_qSymbol, PACKET_P, PACKET_p, @@ -9585,7 +9586,6 @@ remote_target::remote_read_bytes_1 (CORE_ADDR memaddr, gdb_byte *myaddr, { struct remote_state *rs = get_remote_state (); int buf_size_bytes; /* Max size of packet output buffer. */ - char *p; int todo_units; int decoded_bytes; @@ -9597,23 +9597,79 @@ remote_target::remote_read_bytes_1 (CORE_ADDR memaddr, gdb_byte *myaddr, todo_units = std::min (len_units, (ULONGEST) (buf_size_bytes / unit_size) / 2); - /* Construct "m"","". */ memaddr = remote_address_masked (memaddr); - p = rs->buf.data (); - *p++ = 'm'; - p += hexnumstr (p, (ULONGEST) memaddr); - *p++ = ','; - p += hexnumstr (p, (ULONGEST) todo_units); - *p = '\0'; - putpkt (rs->buf); - getpkt (&rs->buf); + + /* Construct "m/x"","". */ + auto send_request = [this, rs, memaddr, todo_units] (char format) -> void + { + char *buffer = rs->buf.data (); + *buffer++ = format; + buffer += hexnumstr (buffer, (ULONGEST) memaddr); + *buffer++ = ','; + buffer += hexnumstr (buffer, (ULONGEST) todo_units); + *buffer = '\0'; + putpkt (rs->buf); + }; + + /* Determine which packet format to use. The target's support for + 'x' may be unknown. We just try. If it doesn't work, we try + again using 'm'. */ + char packet_format; + if (m_features.packet_support (PACKET_x) == PACKET_DISABLE) + packet_format = 'm'; + else + packet_format = 'x'; + + send_request (packet_format); + int packet_len = getpkt (&rs->buf); + if (packet_len < 0) + return TARGET_XFER_E_IO; + + if (m_features.packet_support (PACKET_x) == PACKET_SUPPORT_UNKNOWN) + { + if (rs->buf[0] == '\0') + { + remote_debug_printf ("binary uploading NOT supported by target"); + m_features.m_protocol_packets[PACKET_x].support = PACKET_DISABLE; + + /* Try again using 'm'. */ + packet_format = 'm'; + send_request (packet_format); + packet_len = getpkt (&rs->buf); + if (packet_len < 0) + return TARGET_XFER_E_IO; + } + else + { + remote_debug_printf ("binary uploading supported by target"); + m_features.m_protocol_packets[PACKET_x].support = PACKET_ENABLE; + } + } + packet_result result = packet_check_result (rs->buf, false); if (result.status () == PACKET_ERROR) return TARGET_XFER_E_IO; - /* Reply describes memory byte by byte, each byte encoded as two hex - characters. */ - p = rs->buf.data (); - decoded_bytes = hex2bin (p, myaddr, todo_units * unit_size); + + char *p = rs->buf.data (); + if (packet_format == 'x') + { + if (*p != 'b') + return TARGET_XFER_E_IO; + + /* Adjust for 'b'. */ + p++; + packet_len--; + decoded_bytes = remote_unescape_input ((const gdb_byte *) p, + packet_len, myaddr, + todo_units * unit_size); + } + else + { + /* Reply describes memory byte by byte, each byte encoded as two hex + characters. */ + decoded_bytes = hex2bin (p, myaddr, todo_units * unit_size); + } + /* Return what we have. Let higher layers handle partial reads. */ *xfered_len_units = (ULONGEST) (decoded_bytes / unit_size); return (*xfered_len_units != 0) ? TARGET_XFER_OK : TARGET_XFER_EOF; @@ -15842,6 +15898,8 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL, add_packet_config_cmd (PACKET_X, "X", "binary-download", 1); + add_packet_config_cmd (PACKET_x, "x", "binary-upload", 0); + add_packet_config_cmd (PACKET_vCont, "vCont", "verbose-resume", 0); add_packet_config_cmd (PACKET_QPassSignals, "QPassSignals", "pass-signals", diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc index a5b5d25dd5e..71ac64725af 100644 --- a/gdbserver/remote-utils.cc +++ b/gdbserver/remote-utils.cc @@ -1333,6 +1333,13 @@ decode_M_packet (const char *from, CORE_ADDR *mem_addr_ptr, hex2bin (from, *to_p, *len_ptr); } +void +decode_x_packet (const char *from, CORE_ADDR *mem_addr_ptr, + unsigned int *len_ptr) +{ + decode_m_packet_params (from, mem_addr_ptr, len_ptr, '\0'); +} + int decode_X_packet (char *from, int packet_len, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr, unsigned char **to_p) @@ -1477,12 +1484,13 @@ look_up_one_symbol (const char *name, CORE_ADDR *addrp, int may_ask_gdb) while it figures out the address of the symbol. */ while (1) { + CORE_ADDR mem_addr; + unsigned char *mem_buf; + unsigned int mem_len; + int new_len = -1; + if (cs.own_buf[0] == 'm') { - CORE_ADDR mem_addr; - unsigned char *mem_buf; - unsigned int mem_len; - decode_m_packet (&cs.own_buf[1], &mem_addr, &mem_len); mem_buf = (unsigned char *) xmalloc (mem_len); if (read_inferior_memory (mem_addr, mem_buf, mem_len) == 0) @@ -1493,9 +1501,42 @@ look_up_one_symbol (const char *name, CORE_ADDR *addrp, int may_ask_gdb) if (putpkt (cs.own_buf) < 0) return -1; } + else if (cs.own_buf[0] == 'x') + { + decode_x_packet (&cs.own_buf[1], &mem_addr, &mem_len); + mem_buf = (unsigned char *) xmalloc (mem_len); + if (read_inferior_memory (mem_addr, mem_buf, mem_len) == 0) + { + gdb_byte *buffer = (gdb_byte *) cs.own_buf; + *buffer++ = 'b'; + + int out_len_units; + new_len = remote_escape_output (mem_buf, mem_len, 1, + buffer, + &out_len_units, + PBUFSIZ); + new_len++; /* For the 'b' marker. */ + + if (out_len_units != mem_len) + { + write_enn (cs.own_buf); + new_len = -1; + } + else + suppress_next_putpkt_log (); + } + else + write_enn (cs.own_buf); + + free (mem_buf); + int res = ((new_len == -1) + ? putpkt (cs.own_buf) + : putpkt_binary (cs.own_buf, new_len)); + if (res < 0) + return -1; + } else if (cs.own_buf[0] == 'v') { - int new_len = -1; handle_v_requests (cs.own_buf, len, &new_len); if (new_len != -1) putpkt_binary (cs.own_buf, new_len); @@ -1570,11 +1611,13 @@ relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc) wait for the qRelocInsn "response". That requires re-entering the main loop. For now, this is an adequate approximation; allow GDB to access memory. */ - while (cs.own_buf[0] == 'm' || cs.own_buf[0] == 'M' || cs.own_buf[0] == 'X') + while (cs.own_buf[0] == 'm' || cs.own_buf[0] == 'M' + || cs.own_buf[0] == 'X' || cs.own_buf[0] == 'x') { CORE_ADDR mem_addr; unsigned char *mem_buf = NULL; unsigned int mem_len; + int new_len = -1; if (cs.own_buf[0] == 'm') { @@ -1585,6 +1628,33 @@ relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc) else write_enn (cs.own_buf); } + else if (cs.own_buf[0] == 'x') + { + decode_x_packet (&cs.own_buf[1], &mem_addr, &mem_len); + mem_buf = (unsigned char *) xmalloc (mem_len); + if (read_inferior_memory (mem_addr, mem_buf, mem_len) == 0) + { + gdb_byte *buffer = (gdb_byte *) cs.own_buf; + *buffer++ = 'b'; + + int out_len_units; + new_len = remote_escape_output (mem_buf, mem_len, 1, + buffer, + &out_len_units, + PBUFSIZ); + new_len++; /* For the 'b' marker. */ + + if (out_len_units != mem_len) + { + write_enn (cs.own_buf); + new_len = -1; + } + else + suppress_next_putpkt_log (); + } + else + write_enn (cs.own_buf); + } else if (cs.own_buf[0] == 'X') { if (decode_X_packet (&cs.own_buf[1], len - 1, &mem_addr, @@ -1603,7 +1673,11 @@ relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc) write_enn (cs.own_buf); } free (mem_buf); - if (putpkt (cs.own_buf) < 0) + + int res = ((new_len == -1) + ? putpkt (cs.own_buf) + : putpkt_binary (cs.own_buf, new_len)); + if (res < 0) return -1; len = getpkt (cs.own_buf); if (len < 0) diff --git a/gdbserver/remote-utils.h b/gdbserver/remote-utils.h index 4681ca12f55..65ce604f9dc 100644 --- a/gdbserver/remote-utils.h +++ b/gdbserver/remote-utils.h @@ -57,6 +57,8 @@ void decode_m_packet (const char *from, CORE_ADDR * mem_addr_ptr, unsigned int *len_ptr); void decode_M_packet (const char *from, CORE_ADDR * mem_addr_ptr, unsigned int *len_ptr, unsigned char **to_p); +void decode_x_packet (const char *from, CORE_ADDR *mem_addr_ptr, + unsigned int *len_ptr); int decode_X_packet (char *from, int packet_len, CORE_ADDR * mem_addr_ptr, unsigned int *len_ptr, unsigned char **to_p); int decode_xfer_write (char *buf, int packet_len, diff --git a/gdbserver/server.cc b/gdbserver/server.cc index c7d5cc1c1b0..eccf611c143 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -4689,6 +4689,35 @@ process_serial_event (void) else write_enn (cs.own_buf); break; + case 'x': + { + require_running_or_break (cs.own_buf); + decode_x_packet (&cs.own_buf[1], &mem_addr, &len); + int res = gdb_read_memory (mem_addr, mem_buf, len); + if (res < 0) + write_enn (cs.own_buf); + else + { + gdb_byte *buffer = (gdb_byte *) cs.own_buf; + *buffer++ = 'b'; + + int out_len_units; + new_packet_len = remote_escape_output (mem_buf, res, 1, + buffer, + &out_len_units, + PBUFSIZ); + new_packet_len++; /* For the 'b' marker. */ + + if (out_len_units != res) + { + write_enn (cs.own_buf); + new_packet_len = -1; + } + else + suppress_next_putpkt_log (); + } + } + break; case 'X': require_running_or_break (cs.own_buf); if (decode_X_packet (&cs.own_buf[1], packet_len - 1,