From patchwork Thu Mar 14 13:07:28 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: 87184 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 C5B403858C3A for ; Thu, 14 Mar 2024 13:08:32 +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 B37B43857B89 for ; Thu, 14 Mar 2024 13:07:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B37B43857B89 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 B37B43857B89 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=1710421682; cv=none; b=tl/YxYq7x5YKLtmeaXaZwndYv88KlHO8iYsgY27lEk4Btzoh0pZjuwC4d92b7S5JukapeBnAxTsTjB36g1C8JvOPbXf+lKUsvgYWvN7b2mWPeCM1Tmv3vdknoDZehsqj1wmVozIVHJhMXUo7SDIhYkhnlVjaFyBzjiF8qWIfp6w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710421682; c=relaxed/simple; bh=0w2er1eFSg8I+iMjyEGu1nKSPawULgjqw0x0G4hlLVk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=gU5Xy5GRAhXzWTixTMNlg6S/++rBYIBTkBEUOyKHxnUfVNo77Xa2guovJwAgnIuhlxaF+WIFQX39ilGQxXzctwjDwlHMVNWNaXrAPJGZb9+FFG6ouTdxLIVZXlciCccTp+NnMMsxTw0JxP9wdnVGNd8Rcfazax9/cqLuIDBkgJE= 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=1710421680; x=1741957680; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0w2er1eFSg8I+iMjyEGu1nKSPawULgjqw0x0G4hlLVk=; b=PfIVZgeUqzJnvlIE1ARgz6MpjV0HgIgumAJLQLSHfDpVIZU0lBPgw8Q3 rRGqUpFWoizymXqk2lHt8eXtPFUrOQbAyxxabD+QBQn2IDakA1CjdWhJf B5HK2dhRp7/9iPCDAGuo+4TAgEGuUY0cUlVvI4/bVSLL+Cgi6s9O+tatd Q1fT7H4oeb/5XH2Vm1L3pCF19/wFa5UQjiCfxWy7rqo0iZZb2yjTAKk0Y ufj9l28wZy2uzWcg9thGUbwVUab2pbNXuIA+bbJvBw1eO6RCF60Ku6Q1G GnWrXQ5ZCLqBQCg8gR2u1AcJSMvHIqPbgEQdJrMJWmitfiLa9cviKvPPG w==; X-IronPort-AV: E=McAfee;i="6600,9927,11012"; a="15791639" X-IronPort-AV: E=Sophos;i="6.07,125,1708416000"; d="scan'208";a="15791639" 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:07:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,125,1708416000"; d="scan'208";a="12734972" 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:07:57 -0700 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Cc: tom@tromey.com Subject: [PATCH v2 1/4] doc: fine-tune the documentation of the 'm' RSP packet Date: Thu, 14 Mar 2024 14:07:28 +0100 Message-Id: <5d5b5ad695a50a196ff640e710d8d31766d2cf3d.1710420898.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.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 Revise a sentence to avoid misinterpretation. Move @cindex entries before the text they index. Refer to trace frames regarding partial reads. --- 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 6099d125a60..f2b80db94ef 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -42743,24 +42743,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 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 (); From patchwork Thu Mar 14 13:07:30 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: 87186 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 003423857718 for ; Thu, 14 Mar 2024 13:09:06 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) by sourceware.org (Postfix) with ESMTPS id AAD993857815 for ; Thu, 14 Mar 2024 13:08:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AAD993857815 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 AAD993857815 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710421691; cv=none; b=lVcUj+VJdGzIMTX1swZuaivODiQ5aOqzGCePCvciHm/jtkY1IK46uIPXCS5EEYxRrI14tOEDdRr4Q2zsWY9cwXLAMhoEBibY654emguvlJpcZeTnZFG4z5vMNvjMb9+ZeBZpLks2ufMJkchvvB/NbWWCPgJiwagbnuyWGHLet2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710421691; c=relaxed/simple; bh=NXvWzjSdLv7DB0aATc/jXWSt2zMjuWAYjmw/W8ZCMZ0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=xfWiVu+c/R9Zn7Et0AAudT5om3sQqo1mBalZ1s4eaT5WeBwi5Xj9vYycvHoJ7SwIkK7mXbgeAo6yCn40gliLkiCrkXWP4myJIgmj8QDQuRyMEmqTCba6YJpOu3ksoQC8RI2MvKUBNeH0OfsPP3WFRjkvC7CVWlH3RKkmK8C2qRo= 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=1710421690; x=1741957690; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NXvWzjSdLv7DB0aATc/jXWSt2zMjuWAYjmw/W8ZCMZ0=; b=C5zQ18WsLStEPANSIPdYVGHvCKWicjaS8+l8j7Qce6320z5VpLc9gyXX UwVo319s/dJrboq0zNwfNetHbdpIdyjv+gWDZJTCFVuOupTnqCjLDGYlt rO4d53Yz/bQ3Ctx8dSvhznVkacUq12H1uXqn9e2eIv2dpas3J29AIKRnG 53HO1gDgIHDDjlgoyYXWSmfcofSlnYjvUxSjQJdHrurTBlmldaFhSDWaO CpcYuCZAraSNRHF60QLB7Ny2hcQozcPQjRxSyae/AofMyNxUpUS1ESaZk eC1TorGxHARNWmBBr/WwRf4LMlK77TcPWJqsam0NdHAhZFITd0UfSRjnN A==; X-IronPort-AV: E=McAfee;i="6600,9927,11012"; a="5090751" X-IronPort-AV: E=Sophos;i="6.07,125,1708416000"; d="scan'208";a="5090751" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2024 06:08:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,125,1708416000"; d="scan'208";a="12169742" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2024 06:08:07 -0700 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Cc: tom@tromey.com Subject: [PATCH v2 3/4] rsp: add 'E' to escaped characters Date: Thu, 14 Mar 2024 14:07:30 +0100 Message-Id: <2df4539dd59feb3b70f15ed679563a85bb286075.1710420898.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.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 Add 'E' to the list of escaped characters when sending/receiving binary data. This is a preparation for the next patch, to be able to distinguish an error response from binary data that starts with 'E'. Approved-By: Tom Tromey Reviewed-By: Eli Zaretskii --- gdb/doc/gdb.texinfo | 4 +++- gdbsupport/rsp-low.cc | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index f2b80db94ef..9a7d61be65e 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -42389,7 +42389,9 @@ bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}), @samp{@}}) must always be escaped. Responses sent by the stub must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it is not interpreted as the start of a run-length encoded sequence -(described next). +(described next). The @code{0x45} (@sc{ascii} @samp{E}) byte should +also be escaped to distinguish it from an error reply that starts with +the @samp{E} character. Response @var{data} can be run-length encoded to save space. Run-length encoding replaces runs of identical characters with one diff --git a/gdbsupport/rsp-low.cc b/gdbsupport/rsp-low.cc index 37dce9d5c74..0a11adc78e5 100644 --- a/gdbsupport/rsp-low.cc +++ b/gdbsupport/rsp-low.cc @@ -171,7 +171,7 @@ bin2hex (const gdb_byte *bin, int count) static int needs_escaping (gdb_byte b) { - return b == '$' || b == '#' || b == '}' || b == '*'; + return b == '$' || b == '#' || b == '}' || b == '*' || b == 'E'; } /* See rsp-low.h. */ From patchwork Thu Mar 14 13:07:31 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: 87187 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 C9A4D3857B87 for ; Thu, 14 Mar 2024 13:09:16 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) by sourceware.org (Postfix) with ESMTPS id 43B413857B82 for ; Thu, 14 Mar 2024 13:08:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 43B413857B82 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 43B413857B82 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710421697; cv=none; b=s0E0djRRajpJBxb3DusygVmP7YhrS7vWP9LLgl0UoI15peJbtn+JNr9kafhzpc5lXnSX43AvQU0f+K9LExfEzLIkzh+tmZx9nzjkVjzZSQb/rhJ+5i+6TPRObZy3MGfd9KRl9d40MgDc0BHjwcE+U4Q97ov+Va3oFWsRqfCYMtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710421697; c=relaxed/simple; bh=IAiMfuEOVDGcsMjFJSlCJEVNaRkz6kNM9ZfklDqcWOw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=POQkELfgXJU3NZSNmWvWDJ3e5vOGHrxTgAwO0lw+xJMdMu+7s4yzPGt4l+PoSZzyqHx0ndmWEjA91E9DJSQojNWPCedDH+Rl351K57za+pe9zULZEtBgeexwRqlfdKGTFCLF4m2ekM5Taeui2IZXT/Qgqi4hhWCtp4YjQo4kwWw= 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=1710421694; x=1741957694; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IAiMfuEOVDGcsMjFJSlCJEVNaRkz6kNM9ZfklDqcWOw=; b=SYSVdK/fzrtIhOwmwqIAs0pLuEAliRoXb+/RKY80c7SFW5gjAbtqn6VZ M0LtAXD22EIGhj/mtjVIDpUOyp7U03t8ddfFFa3nuEjhs+8X4tHchGqIf 1lhABYcduragkKkuRHK8rlVb6uPy+NRMuqvIWi2ol3YyOHF2huNpDX1qq /GYWOOjWQTScZp+8NjETD+mMqmIvSSof7GlyPFvqIU0V1gb6hB0iDdBld DC+Sggpi4C75NbkyTFryfUqYnu49kQxJ0WzO55CGjfAIAqPTDSbbGTOTi nQd8mB7xPycS0oNmazchqWAafuso4rwXlzBA5Ao9Tf9TkAUd+OLqmKZKS A==; X-IronPort-AV: E=McAfee;i="6600,9927,11012"; a="5090760" X-IronPort-AV: E=Sophos;i="6.07,125,1708416000"; d="scan'208";a="5090760" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2024 06:08:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,125,1708416000"; d="scan'208";a="12169812" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2024 06:08:13 -0700 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Cc: tom@tromey.com Subject: [PATCH v2 4/4] gdb, gdbserver: introduce the 'x' RSP packet for binary memory read Date: Thu, 14 Mar 2024 14:07:31 +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.1 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 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 | 29 ++++++++++++++++ gdb/remote.c | 48 +++++++++++++++++++++++---- gdbserver/remote-utils.cc | 69 +++++++++++++++++++++++++++++++++------ gdbserver/remote-utils.h | 2 ++ gdbserver/server.cc | 21 ++++++++++++ 6 files changed, 159 insertions(+), 16 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index d8ac0bb06a7..5bde7030634 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -152,6 +152,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 9a7d61be65e..a387ad7bd02 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -43122,6 +43122,35 @@ 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. + +This packet is used only if the stub announces support for it using +@samp{qSupported}. + +Reply: +@table @samp +@item @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 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 14c8b020b1e..d1a7cdb2cd5 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -194,6 +194,7 @@ struct packet_result enum { PACKET_vCont = 0, PACKET_X, + PACKET_x, PACKET_qSymbol, PACKET_P, PACKET_p, @@ -5763,6 +5764,7 @@ static const struct protocol_feature remote_protocol_features[] = { { "no-resumed", PACKET_DISABLE, remote_supported_packet, PACKET_no_resumed }, { "memory-tagging", PACKET_DISABLE, remote_supported_packet, PACKET_memory_tagging_feature }, + { "x", PACKET_DISABLE, remote_supported_packet, PACKET_x }, }; static char *remote_support_xml; @@ -9582,24 +9584,56 @@ 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"","". */ + /* Determine which packet format to use. */ + char packet_format = 'm'; + switch (m_features.packet_support (PACKET_x)) + { + case PACKET_ENABLE: + packet_format = 'x'; + break; + + case PACKET_DISABLE: + packet_format = 'm'; + break; + + case PACKET_SUPPORT_UNKNOWN: + internal_error (_("remote_read_bytes_1: bad internal state")); + + default: + /* This is unexpected but we can still continue with 'm'. */ + break; + } + + /* Construct "m/x"","". */ memaddr = remote_address_masked (memaddr); p = rs->buf.data (); - *p++ = 'm'; + *p++ = packet_format; p += hexnumstr (p, (ULONGEST) memaddr); *p++ = ','; p += hexnumstr (p, (ULONGEST) todo_units); *p = '\0'; putpkt (rs->buf); - getpkt (&rs->buf); + int packet_len = getpkt (&rs->buf); + if (packet_len < 0) + return TARGET_XFER_E_IO; + if (rs->buf[0] == 'E' && isxdigit (rs->buf[1]) && isxdigit (rs->buf[2]) && rs->buf[3] == '\0') 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); + if (packet_format == 'x') + 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; @@ -15839,6 +15873,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-read", 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 5e7c38056d0..995fb621ae7 100644 --- a/gdbserver/remote-utils.cc +++ b/gdbserver/remote-utils.cc @@ -1334,6 +1334,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) @@ -1478,25 +1485,45 @@ 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) { - if (cs.own_buf[0] == 'm') + int new_len = -1; + if (cs.own_buf[0] == 'm' || cs.own_buf[0] == 'x') { CORE_ADDR mem_addr; unsigned char *mem_buf; unsigned int mem_len; - decode_m_packet (&cs.own_buf[1], &mem_addr, &mem_len); + if (cs.own_buf[0] == 'm') + decode_m_packet (&cs.own_buf[1], &mem_addr, &mem_len); + else + 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) - bin2hex (mem_buf, cs.own_buf, mem_len); + { + if (cs.own_buf[0] == 'm') + bin2hex (mem_buf, cs.own_buf, mem_len); + else + { + int out_len_units; + new_len + = remote_escape_output (mem_buf, mem_len, 1, + (gdb_byte *) cs.own_buf, + &out_len_units, PBUFSIZ); + suppress_next_putpkt_log (); + } + } else 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; } 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); @@ -1571,18 +1598,36 @@ 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_packet_len = -1; - if (cs.own_buf[0] == 'm') + if (cs.own_buf[0] == 'm' || cs.own_buf[0] == 'x') { - decode_m_packet (&cs.own_buf[1], &mem_addr, &mem_len); + if (cs.own_buf[0] == 'm') + decode_m_packet (&cs.own_buf[1], &mem_addr, &mem_len); + else + 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) - bin2hex (mem_buf, cs.own_buf, mem_len); + { + if (cs.own_buf[0] == 'm') + bin2hex (mem_buf, cs.own_buf, mem_len); + else + { + int out_len_units; + new_packet_len + = remote_escape_output (mem_buf, mem_len, 1, + (gdb_byte *) cs.own_buf, + &out_len_units, PBUFSIZ); + suppress_next_putpkt_log (); + } + } else write_enn (cs.own_buf); } @@ -1604,7 +1649,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_packet_len == -1) + ? putpkt (cs.own_buf) + : putpkt_binary (cs.own_buf, new_packet_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 74c7763d777..96e6e551784 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -2840,6 +2840,9 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p) if (target_supports_memory_tagging ()) strcat (own_buf, ";memory-tagging+"); + /* Binary memory read support. */ + strcat (own_buf, ";x+"); + /* Reinitialize components as needed for the new connection. */ hostio_handle_new_gdb_connection (); target_handle_new_gdb_connection (); @@ -4690,6 +4693,24 @@ 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 + { + int out_len_units; + new_packet_len + = remote_escape_output (mem_buf, res, 1, + (gdb_byte *) cs.own_buf, + &out_len_units, PBUFSIZ); + 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,