From patchwork Thu Mar 21 13:30:18 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: 87448 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 763523858422 for ; Thu, 21 Mar 2024 13:31:13 +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.17]) by sourceware.org (Postfix) with ESMTPS id B16B23858D28 for ; Thu, 21 Mar 2024 13:30:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B16B23858D28 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 B16B23858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711027851; cv=none; b=iiY6Kgdsrd4Zwci2tsaW9iq8R/KA4vlBA8mYnEkxscRps0OJam9iZbptsiWeRYNqhkHxjnskTfo6TLizuzXeceBv2Rn/6H0W40lDmrr/iBXqWe4robQ5CudsJbFWouR+9u1JcnS2AlUOIPmNsWEQWQVtGspH5DUZ2X0G9g+6IiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711027851; c=relaxed/simple; bh=Zn95JmkpWJn1WXuG1KaJUWbcE5Hc/MOKJdE1t9EaK+s=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=gv2NsFnzOKbbJHUULiaYzUT6X76lNBj1JggFf5KVolZyQIQI9YWt0KwabE49Y8f0Xxm8tZRf8xEajuyigSXs/aIjb4+jEWiAyRER6SHaFbqp0iY3xmPc/S8NwqPGhMVWGRJbHaePQorfxJ9OCxMHKC0XZ/oJ9csmBVSYhm16jyk= 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=1711027849; x=1742563849; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=Zn95JmkpWJn1WXuG1KaJUWbcE5Hc/MOKJdE1t9EaK+s=; b=Z/uNc/ItAymgx05LVhwIs1LA7HzViQBsw0nv7cCfGTTZZex77Y0k0tzS mPtUEff9e1SiHxIGAOWFQeBJc/l0wOD2WLn6+6aYYofwprAVNYOuRwc3W bHNvIbdLeFKPAhbUudrer+RLdQk+PtvDRPAsvallJmHxJYvDqTz1ixJ4H 7ntbo/A/GPOCJN8787HlX5uS+lfND1J/mjRNv5DnR3RyXsvTAz28zvVEy J5wYxVWdbZY2joOPob3/txpwZAz+ZU9wC2J2zHnuwdPv0fAiNm2fWtkd6 dvGVv5cy2EfpYzQqZpUtw2Rju9dX85VeiaaZBIMMcJSdDFiTVFy7yoYXI w==; X-IronPort-AV: E=McAfee;i="6600,9927,11019"; a="5866593" X-IronPort-AV: E=Sophos;i="6.07,142,1708416000"; d="scan'208";a="5866593" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2024 06:30:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,142,1708416000"; d="scan'208";a="45503797" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2024 06:30:34 -0700 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Subject: [RFC PATCH] gdb, rsp: clarify a 0-length memory access Date: Thu, 21 Mar 2024 14:30:18 +0100 Message-Id: <20240321133018.602537-1-tankut.baris.aktemur@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-9.6 required=5.0 tests=AC_FROM_MANY_DOTS, 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 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 Currently GDB uses a 0-length write access to probe for the 'X' packet support. However, it is not clear from the document what a 0-length read or write attempt should do. Clarify the document that it is an error. Also update gdbserver's implementation to return an error. Note that for probing, returning an error is fine. It successfully shows that the packet is supported. Regression-tested on X86-64 Linux using the default (unix) and native-extended-gdbserver board files. Reviewed-By: Eli Zaretskii --- gdb/doc/gdb.texinfo | 9 +++++++++ gdbserver/target.cc | 9 ++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 6099d125a60..0a08c73f8df 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -42755,6 +42755,9 @@ suitable for accessing memory-mapped I/O devices. @cindex size of remote memory accesses @cindex memory, alignment and size of remote accesses +The @var{length} argument has to be a positive value; otherwise, an +error is returned. + Reply: @table @samp @item @var{XX@dots{}} @@ -42771,6 +42774,9 @@ Write @var{length} addressable memory units starting at address @var{addr} (@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each byte is transmitted as a two-digit hexadecimal number. +The @var{length} argument has to be a positive value; otherwise, an +error is returned. + Reply: @table @samp @item OK @@ -43127,6 +43133,9 @@ Memory is specified by its address @var{addr} and number of addressable memory units @var{length} (@pxref{addressable memory unit}); @samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}). +The @var{length} argument has to be a positive value; otherwise, an +error is returned. + Reply: @table @samp @item OK diff --git a/gdbserver/target.cc b/gdbserver/target.cc index 23b699d33bb..6173ebb79f8 100644 --- a/gdbserver/target.cc +++ b/gdbserver/target.cc @@ -89,7 +89,7 @@ read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len) doesn't hurt to prevent problems if it ever does, or we're connected to some client other than GDB that does. */ if (len == 0) - return 0; + return EINVAL; int res = the_target->read_memory (memaddr, myaddr, len); check_mem_read (memaddr, myaddr, len); @@ -121,9 +121,12 @@ target_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, /* GDB may send X packets with LEN==0, for probing packet support. If we let such a request go through, then buffer.data() below may return NULL, which may confuse target implementations. Handle it - here to avoid lower levels having to care about this case. */ + here to avoid lower levels having to care about this case. + + Sending an error code is sufficient for GDB to conclude that the + server supports the packet. */ if (len == 0) - return 0; + return EINVAL; /* Make a copy of the data because check_mem_write may need to update it. */