From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ubaFLiIU62rZhxgAWB0awg (envelope-from ) for ; Wed, 04 Nov 2026 06:16:50 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=X04N72h7; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B84671E09A; Wed, 04 Nov 2026 06:16:50 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 0E9091E052 for ; Wed, 04 Nov 2026 06:16:49 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7941E4BA902F for ; Wed, 4 Nov 2026 11:16:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7941E4BA902F Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=X04N72h7 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 2DE314BA79BF for ; Wed, 4 Nov 2026 11:15:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2DE314BA79BF Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2DE314BA79BF Authentication-Results: sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793790951; cv=none; b=wOUYW+rpA2XIQNXOZ9cz5sZXbat+dBjpZnWcKLqkfCaBq4Dvo/fXgiSKXwPg7RYf/kwukVGpLhl1uQNDLinRU5r/O0FU5lEn7xoyTN0GAr8mT2sOXDzTGpcHrYv2bSSXrVkaAB/vtZqlL8AI8B7druksTUfHyOxgvVu4rG4GIKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793790951; c=relaxed/simple; bh=QnqkWuIb12l0UOd+h1UDvaPvL/cdrVD/nXsz2dH9p+s=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dhJl6gI49A9b3yDnOfWXTapBA2RMAjUsfO5B5+JaYc/1PnGl1+UJfAcSHFPWMf2bTyBaajiqe+pNIB4ucp2/zuY79cX4jabbQuzs4ENcRx7PvvaNHcDwz/qLYdX1/aQIHjIykg9WC1sZuwWUKB8zGj8uU5bapmueYGdr1zlfPxg= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=X04N72h7 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2DE314BA79BF Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A4BEBhH618263; Wed, 4 Nov 2026 11:15:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=fq70zBk1Ygogw66bb rwA03h9S4iwn/DSY2Op2/fv8IM=; b=X04N72h7obuHiB9fGy8+AakPWpH1JklzM 3q5xf8+kirOFvuj5TZ5AdUPTCpi4K6AQXi0kgYV6j/A41LpSVf9mXU54pZWJFy/I pcSLxZH46T/V8dg+7bB15cIM/+7uDe5PzW1ofhe+04SduAy4vfggnxdJHieqPktV FxuJoIRqWdmfBQg6zZLDoAYNIv5Y99fCfp/U4/nHl0dRRfpuNP/rAPWWsHP7BOTX kK3bEQqW3/7JY365Gc+/8XhavffYLk1W1mCTPrxpgJOyjI80yqwQVQL2maBfq894 Oj3qtAdvC41e89QM7uTNY3Aqc6vIQed6YJzX9us8ODOxaq0UOnbSA== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4hn7u3kf6p-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 04 Nov 2026 11:15:43 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6A4B5TxA3962480; Wed, 4 Nov 2026 11:15:42 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4hqcrcdspb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Nov 2026 11:15:42 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6A4BFZDD47120810 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 4 Nov 2026 11:15:35 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D511B20049; Wed, 4 Nov 2026 11:15:34 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C450120040; Wed, 4 Nov 2026 11:15:33 +0000 (GMT) Received: from kubota.pok.stglabs.ibm.com (unknown [9.114.39.181]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 4 Nov 2026 11:15:33 +0000 (GMT) From: Abhay Kandpal To: gdb-patches@sourceware.org Cc: aburgess@redhat.com, Ulrich.Weigand@de.ibm.com, eliz@gnu.org, cel@linux.ibm.com, abhay.k@ibm.com, Abhay Kandpal Subject: [PATCH v5 1/2] gdbserver: widen the stat fields returned by the vFile packets Date: Wed, 4 Nov 2026 06:15:20 -0500 Message-ID: <20261104111521.3042934-2-abhay@linux.ibm.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20261104111521.3042934-1-abhay@linux.ibm.com> References: <20261104111521.3042934-1-abhay@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Authority-Analysis: v=2.4 cv=Zsp4uN7G c=1 sm=1 tr=0 ts=6aeb13df cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=zJRp6_cAMcgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=CCpqsmhAAAAA:8 a=mDV3o1hIAAAA:8 a=2_N1zx4-w4ZWZmNlXsAA:9 a=3ZKOabzyN94A:10 a=ul9cdbp4aOFLsgKbc677:22 X-Proofpoint-ORIG-GUID: X4hbPx_dkHHQSoPBznpLiL5YHqm6PXHw X-Proofpoint-GUID: X4hbPx_dkHHQSoPBznpLiL5YHqm6PXHw X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTA0MDA0NCBTYWx0ZWRfX9mW7hYVS/eks Rd7+5JiGhIuoPqnJuQ1+4o95Jae/WaBTyf77Mj0P3XXq8FOkCUSZledP2gAWG/whi/MUfQda2LD /udiuiMlb/9AsCGtcago4MwK5Q6kW5kiMznSmLOsHF3lkyJzUaC6ji0BUx7m+lnHBTRyvhqYKlD fL3DXtkbgA55VDXO9mqMb9VWUtVHRFrR4yrN6uLhu8pVL2m1DtSadjHP8XjCOFPPm831VcYTnKj Nl1wqi9mnqqM3xDHVIeD0+wgf1nZOtwWDeSD8/MkjGlV8HCV0U8cAmlDt2uWSnhPWWAc4mtTk36 cfNHFnJLhMDavYLGDP9lVhdUC1MRqoJOHHgN6ouaBHhk7E2MSedsA1/Hx00Wea/GY/eqtHL2qpC 4WvqvBJK69LXvBX6jQs+bqlY58zaYh4Qi1vvZ/8I345iLrgxpT93TvB65/dMgDvOHXQAu0myqkk AD7o4Dqi5lrV2pdHsVQ== X-Proofpoint-Spam-Info: AW1haW4tMjYxMTA0MDA0NCBTYWx0ZWRfXx76tnVw0BWf9 Lh4Hzcu7pT/y3f9mFzni/uMBlRZ+Vyi/mIfz4eiWeTd9YDKWla4NzXy2sHiTXlMpxbFYHJabg3G u8aISON5gfFrm/y/A9LCqy3WNk0la7c= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-04_03,2026-11-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 bulkscore=0 clxscore=1015 impostorscore=0 spamscore=0 malwarescore=0 suspectscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611040044 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~public-inbox=simark.ca@sourceware.org The struct sent by the vFile:fstat, vFile:stat and vFile:lstat packets declares st_dev, st_ino, st_nlink, st_rdev and the three timestamps as 4-byte fields, while the corresponding struct stat members are 8 bytes on a 64-bit host. The values are silently truncated. This is not visible on a filesystem whose inode numbers stay below 2^32, but it is on a large one. On an 86 TB xfs volume, gdb.server/fileio-packets.exp fails because the inode reported by vFile:lstat does not match the one reported locally: remote = {..., 'st_ino': 2161233200, ...} local = {..., 'st_ino': 122420317488, ...} The field widths cannot simply be changed, as that would alter the wire layout and break communication between different versions of GDB and gdbserver. Add a new 'stat64' qSupported feature instead. When both sides report it, the vFile stat packets return struct fio_stat_wide, in which the seven too-narrow fields are 8 bytes; otherwise the existing struct fio_stat is used, exactly as before. gdbserver packs the host struct stat directly into whichever form was negotiated, and GDB selects the unpacker by the length of the reply. The feature flag is reset on each new connection, like the other qSupported flags. A value which does not fit in a narrow field now produces a warning rather than being truncated silently. The check is in host_to_fileio_uint, which now takes a ULONGEST so the value reaches it intact, and host_to_fileio_time. Both are also used by the F-packet stat and fstat calls, so GDB now warns there too. The F-packet file-i/o protocol uses the same struct. It is handled separately in the next patch. While here, drop a duplicate include of gdbsupport/fileio.h from gdbserver/hostio.cc, and add a missing blank line after a comment in gdbserver/hostio.h. Tested on powerpc64le-linux; gdb.server/fileio-packets.exp now passes on a filesystem with inode numbers above 2^32 and continues to pass on one without, with no regressions in the full testsuite. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34567 Reviewed-By: Eli Zaretskii --- gdb/NEWS | 14 ++++ gdb/doc/gdb.texinfo | 52 +++++++++++++++ gdb/remote-fileio.c | 24 +++++++ gdb/remote-fileio.h | 5 ++ gdb/remote.c | 35 +++++++--- gdb/testsuite/gdb.server/fileio-packets.py | 59 ++++++++++------- gdbserver/hostio.cc | 77 +++++++++++----------- gdbserver/hostio.h | 1 + gdbserver/server.cc | 5 +- gdbserver/server.h | 5 ++ gdbsupport/fileio.cc | 44 +++++++++++-- gdbsupport/fileio.h | 50 ++++++++++++-- 12 files changed, 291 insertions(+), 80 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index db3fa820df1..99072d2b758 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -85,6 +85,20 @@ info locals 'allow_pending' argument. Setting it to False causes GDB to raise an error instead of creating a pending breakpoint. +* Changed remote packets + +stat64 in qSupported + + The new stat64 feature within the qSupported packet allows GDB and + the stub to agree on a wider form of the stat structure returned by + the vFile:fstat, vFile:stat and vFile:lstat packets, in which st_dev, + st_ino, st_nlink, st_rdev and the three timestamps are 8 bytes rather + than 4. The wider form is used only when both sides report the + feature; otherwise the existing format is used, and values which do + not fit are truncated with a warning. Note that the narrow form + reads timestamps as unsigned, so it overflows in 2106 rather than + 2038. + *** Changes in GDB 18 * Support for the Common Trace Format (CTF) has been removed. GDB now diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 66152d2582e..3804ce71711 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -46232,6 +46232,11 @@ inspected, if @samp{qIsAddressTagged} (@pxref{qIsAddressTagged}) packet is not supported by the stub. Access to the @file{/proc/@var{pid}/smaps} file is done via @samp{vFile} requests. +@item stat64 +The remote stub supports the wider form of the stat structure returned +by the @samp{vFile:fstat}, @samp{vFile:stat} and @samp{vFile:lstat} +packets (@pxref{struct stat64}). + @item error-message The remote stub supports replying with an error in a @samp{E.@var{errtext}} (@xref{textual error reply}) format from the @@ -47478,6 +47483,9 @@ On success the information is returned as a binary attachment and the return value is the size of this attachment in bytes. If an error occurs the return value is -1. The format of the returned binary attachment is as described in @ref{struct stat}. +If both @value{GDBN} and the stub report the @samp{stat64} feature in +the @samp{qSupported} exchange, the wider format is used instead +(@pxref{struct stat64}). @item vFile:stat: @var{filename} Get information about the file @var{filename} on the target as if from @@ -47485,6 +47493,9 @@ a @samp{stat} call. On success the information is returned as a binary attachment and the return value is the size of this attachment in bytes. If an error occurs the return value is -1. The format of the returned binary attachment is as described in @ref{struct stat}. +If both @value{GDBN} and the stub report the @samp{stat64} feature in +the @samp{qSupported} exchange, the wider format is used instead +(@pxref{struct stat64}). If @var{filename} is a symbolic link, then the information returned is about the file the link refers to, this is inline with the @samp{stat} @@ -47496,6 +47507,9 @@ an @samp{lstat} call. On success the information is returned as a binary attachment and the return value is the size of this attachment in bytes. If an error occurs the return value is -1. The format of the returned binary attachment is as described in @ref{struct stat}. +If both @value{GDBN} and the stub report the @samp{stat64} feature in +the @samp{qSupported} exchange, the wider format is used instead +(@pxref{struct stat64}). This packet is identical to @samp{vFile:stat}, except if @var{filename} is a symbolic link, then this packet returns @@ -48690,6 +48704,7 @@ protocol. * Pointer Values:: * Memory Transfer:: * struct stat:: +* struct stat64:: * struct timeval:: @end menu @@ -48816,6 +48831,43 @@ Note that due to size differences between the host, target, and protocol representations of @code{struct stat} members, these members could eventually get truncated on the target. +@node struct stat64 +@unnumberedsubsubsec struct stat64 +@cindex struct stat64, in file-i/o protocol + +When the @samp{stat64} feature has been negotiated, the buffer returned +by the @samp{vFile:fstat}, @samp{vFile:stat} and @samp{vFile:lstat} +packets uses the following representation instead: + +@smallexample +struct stat64 @{ + unsigned long st_dev; /* device */ + unsigned long st_ino; /* inode */ + mode_t st_mode; /* protection */ + unsigned long st_nlink; /* number of hard links */ + unsigned int st_uid; /* user ID of owner */ + unsigned int st_gid; /* group ID of owner */ + unsigned long st_rdev; /* device type (if inode device) */ + unsigned long st_size; /* total size, in bytes */ + unsigned long st_blksize; /* blocksize for filesystem I/O */ + unsigned long st_blocks; /* number of blocks allocated */ + unsigned long st_atime; /* time of last access */ + unsigned long st_mtime; /* time of last modification */ + unsigned long st_ctime; /* time of last change */ +@}; +@end smallexample + +The integral datatypes conform to the definitions given in the +appropriate section (@pxref{Integral Datatypes}, for details) so this +structure is of size 92 bytes. The fields have the same meanings +as in the narrow form (@pxref{struct stat}), but @code{st_dev}, +@code{st_ino}, @code{st_nlink}, @code{st_rdev} and the three timestamps +are wide enough to hold the values found on a 64-bit host without +truncation. + +This representation is only used by the @samp{vFile} packets; the +File-I/O protocol always uses the narrow form (@pxref{struct stat}). + @node struct timeval @unnumberedsubsubsec struct timeval @cindex struct timeval, in file-i/o protocol diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c index a151161371d..a65db27d04e 100644 --- a/gdb/remote-fileio.c +++ b/gdb/remote-fileio.c @@ -1221,6 +1221,30 @@ remote_fileio_to_host_stat (struct fio_stat *fst, struct stat *st) st->st_ctime = remote_fileio_to_host_time (fst->fst_ctime); } +/* See remote-fileio.h. */ + +void +remote_fileio_wide_to_host_stat (struct fio_stat_wide *fst, struct stat *st) +{ + memset (st, 0, sizeof (struct stat)); + st->st_dev = remote_fileio_to_host_ulong (fst->fst_dev); + st->st_ino = remote_fileio_to_host_ulong (fst->fst_ino); + st->st_mode = remote_fileio_to_host_mode (fst->fst_mode); + st->st_nlink = remote_fileio_to_host_ulong (fst->fst_nlink); + st->st_uid = remote_fileio_to_host_uint (fst->fst_uid); + st->st_gid = remote_fileio_to_host_uint (fst->fst_gid); + st->st_rdev = remote_fileio_to_host_ulong (fst->fst_rdev); + st->st_size = remote_fileio_to_host_ulong (fst->fst_size); +#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE + st->st_blksize = remote_fileio_to_host_ulong (fst->fst_blksize); +#endif +#if HAVE_STRUCT_STAT_ST_BLOCKS + st->st_blocks = remote_fileio_to_host_ulong (fst->fst_blocks); +#endif + st->st_atime = remote_fileio_to_host_ulong (fst->fst_atime); + st->st_mtime = remote_fileio_to_host_ulong (fst->fst_mtime); + st->st_ctime = remote_fileio_to_host_ulong (fst->fst_ctime); +} static void set_system_call_allowed (const char *args, int from_tty) diff --git a/gdb/remote-fileio.h b/gdb/remote-fileio.h index d01b3df92ca..105a13851c4 100644 --- a/gdb/remote-fileio.h +++ b/gdb/remote-fileio.h @@ -44,4 +44,9 @@ extern void initialize_remote_fileio ( extern void remote_fileio_to_host_stat (struct fio_stat *fst, struct stat *st); +/* Unpack a struct fio_stat_wide. */ + +extern void remote_fileio_wide_to_host_stat (struct fio_stat_wide *fst, + struct stat *st); + #endif /* GDB_REMOTE_FILEIO_H */ diff --git a/gdb/remote.c b/gdb/remote.c index 6e3a2089b9e..39d975684eb 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -389,6 +389,9 @@ enum { packets and the tag violation stop replies. */ PACKET_memory_tagging_feature, + /* Support for the wide form of struct stat in vFile stat replies. */ + PACKET_stat64_feature, + /* Support for the qIsAddressTagged packet. */ PACKET_qIsAddressTagged, @@ -6188,6 +6191,8 @@ 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 }, + { "stat64", PACKET_DISABLE, remote_supported_packet, + PACKET_stat64_feature }, { "error-message", PACKET_ENABLE, remote_supported_packet, PACKET_accept_error_message }, { "binary-upload", PACKET_DISABLE, remote_supported_packet, PACKET_x }, @@ -6298,6 +6303,10 @@ remote_target::remote_query_supported () != AUTO_BOOLEAN_FALSE) remote_query_supported_append (&q, "QThreadOptions+"); + if (m_features.packet_set_cmd_state (PACKET_stat64_feature) + != AUTO_BOOLEAN_FALSE) + remote_query_supported_append (&q, "stat64+"); + if (m_features.packet_set_cmd_state (PACKET_no_resumed) != AUTO_BOOLEAN_FALSE) remote_query_supported_append (&q, "no-resumed+"); @@ -13656,7 +13665,11 @@ remote_target::fileio_readlink (struct inferior *inf, const char *filename, remote syscall reply. EXPECTED_LEN is the length returned from the fstat or stat call, this the length of the returned data (in ATTACHMENT) once it has been decoded. The fstat/stat result (from the ATTACHMENT - data) is to be placed in ST. */ + data) is to be placed in ST. + + The reply holds either a struct fio_stat or, if the stat64 feature was + negotiated, the wider struct fio_stat_wide; the two are distinguished + by their length. */ static int fileio_process_fstat_and_lstat_reply (const char *attachment, @@ -13664,21 +13677,24 @@ fileio_process_fstat_and_lstat_reply (const char *attachment, int expected_len, struct stat *st) { - struct fio_stat fst; + gdb_byte buf[sizeof (struct fio_stat_wide)]; int read_len = remote_unescape_input ((gdb_byte *) attachment, attachment_len, - (gdb_byte *) &fst, sizeof (fst)); + buf, sizeof (buf)); if (read_len != expected_len) error (_("vFile:fstat returned %d, but %d bytes."), expected_len, read_len); - if (read_len != sizeof (fst)) - error (_("vFile:fstat returned %d bytes, but expecting %d."), - read_len, (int) sizeof (fst)); - - remote_fileio_to_host_stat (&fst, st); + if (read_len == sizeof (struct fio_stat_wide)) + remote_fileio_wide_to_host_stat ((struct fio_stat_wide *) buf, st); + else if (read_len == sizeof (struct fio_stat)) + remote_fileio_to_host_stat ((struct fio_stat *) buf, st); + else + error (_("vFile:fstat returned %d bytes, but expecting %d or %d."), + read_len, (int) sizeof (struct fio_stat), + (int) sizeof (struct fio_stat_wide)); return 0; } @@ -17032,6 +17048,9 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL, add_packet_config_cmd (PACKET_memory_tagging_feature, "memory-tagging-feature", "memory-tagging-feature", 0); + add_packet_config_cmd (PACKET_stat64_feature, + "stat64-feature", "stat64-feature", 0); + add_packet_config_cmd (PACKET_qIsAddressTagged, "qIsAddressTagged", "memory-tagging-address-check", 0); diff --git a/gdb/testsuite/gdb.server/fileio-packets.py b/gdb/testsuite/gdb.server/fileio-packets.py index 54ae56fa68a..7e3a68bcdd9 100644 --- a/gdb/testsuite/gdb.server/fileio-packets.py +++ b/gdb/testsuite/gdb.server/fileio-packets.py @@ -57,33 +57,48 @@ def decode_stat_reply(buf, byteorder="big"): buf = unescape_remote_data(buf) - if ( - buf[0] != ord("F") - or buf[1] != ord("4") - or buf[2] != ord("0") - or buf[3] != ord(";") - or len(buf) != 68 - ): + if buf[0:4] == b"F40;" and len(buf) == 68: + wide = False + elif buf[0:4] == b"F5c;" and len(buf) == 96: + wide = True + else: print(f"decode_stat_reply failed: {buf}\t(length = {len(buf)})") return None - # Discard the 'F40;' prefix. The rest is the 64 bytes of data to - # be decoded. + # Discard the 'FNN;' prefix. buf = buf[4:] - st_dev = int.from_bytes(buf[0:4], byteorder=byteorder) - st_ino = int.from_bytes(buf[4:8], byteorder=byteorder) - st_mode = int.from_bytes(buf[8:12], byteorder=byteorder) - st_nlink = int.from_bytes(buf[12:16], byteorder=byteorder) - st_uid = int.from_bytes(buf[16:20], byteorder=byteorder) - st_gid = int.from_bytes(buf[20:24], byteorder=byteorder) - st_rdev = int.from_bytes(buf[24:28], byteorder=byteorder) - st_size = int.from_bytes(buf[28:36], byteorder=byteorder) - st_blksize = int.from_bytes(buf[36:44], byteorder=byteorder) - st_blocks = int.from_bytes(buf[44:52], byteorder=byteorder) - st_atime = int.from_bytes(buf[52:56], byteorder=byteorder) - st_mtime = int.from_bytes(buf[56:60], byteorder=byteorder) - st_ctime = int.from_bytes(buf[60:64], byteorder=byteorder) + def field(off, size): + return int.from_bytes(buf[off : off + size], byteorder=byteorder) + + if wide: + st_dev = field(0, 8) + st_ino = field(8, 8) + st_mode = field(16, 4) + st_nlink = field(20, 8) + st_uid = field(28, 4) + st_gid = field(32, 4) + st_rdev = field(36, 8) + st_size = field(44, 8) + st_blksize = field(52, 8) + st_blocks = field(60, 8) + st_atime = field(68, 8) + st_mtime = field(76, 8) + st_ctime = field(84, 8) + else: + st_dev = field(0, 4) + st_ino = field(4, 4) + st_mode = field(8, 4) + st_nlink = field(12, 4) + st_uid = field(16, 4) + st_gid = field(20, 4) + st_rdev = field(24, 4) + st_size = field(28, 8) + st_blksize = field(36, 8) + st_blocks = field(44, 8) + st_atime = field(52, 4) + st_mtime = field(56, 4) + st_ctime = field(60, 4) return { "st_dev": st_dev, diff --git a/gdbserver/hostio.cc b/gdbserver/hostio.cc index b9ca27c2ff4..9966ecb0842 100644 --- a/gdbserver/hostio.cc +++ b/gdbserver/hostio.cc @@ -26,7 +26,6 @@ #include #include #include -#include "gdbsupport/fileio.h" struct fd_list { @@ -459,13 +458,47 @@ handle_pwrite (char *own_buf, int packet_len) free (data); } +/* Reply to a vFile stat request with the result in ST: in the wide + form if GDB has asked for it, otherwise in the narrow form. */ + +static void +hostio_send_stat_reply (char *own_buf, struct stat *st, + int *new_packet_len) +{ + client_state &cs = get_client_state (); + struct fio_stat narrow; + struct fio_stat_wide wide; + char *data; + int len; + + if (cs.stat64_feature) + { + host_to_fileio_stat_wide (st, &wide); + data = (char *) &wide; + len = sizeof (wide); + } + else + { + host_to_fileio_stat (st, &narrow); + data = (char *) &narrow; + len = sizeof (narrow); + } + + int bytes_sent = hostio_reply_with_data (own_buf, data, len, + new_packet_len); + + /* If the response does not fit into a single packet, do not attempt + to return a partial response, but simply fail. */ + if (bytes_sent < len) + write_enn (own_buf); +} + static void handle_fstat (char *own_buf, int *new_packet_len) { - int fd, bytes_sent; + int fd; char *p; struct stat st; - struct fio_stat fst; p = own_buf + strlen ("vFile:fstat:"); @@ -483,25 +516,14 @@ handle_fstat (char *own_buf, int *new_packet_len) return; } - host_to_fileio_stat (&st, &fst); - - bytes_sent = hostio_reply_with_data (own_buf, - (char *) &fst, sizeof (fst), - new_packet_len); - - /* If the response does not fit into a single packet, do not attempt - to return a partial response, but simply fail. */ - if (bytes_sent < sizeof (fst)) - write_enn (own_buf); + hostio_send_stat_reply (own_buf, &st, new_packet_len); } static void handle_stat (char *own_buf, int *new_packet_len) { - int bytes_sent; char *p; struct stat st; - struct fio_stat fst; char filename[HOSTIO_PATH_MAX]; p = own_buf + strlen ("vFile:stat:"); @@ -519,25 +541,15 @@ handle_stat (char *own_buf, int *new_packet_len) return; } - host_to_fileio_stat (&st, &fst); - - bytes_sent = hostio_reply_with_data (own_buf, - (char *) &fst, sizeof (fst), - new_packet_len); - - /* If the response does not fit into a single packet, do not attempt - to return a partial response, but simply fail. */ - if (bytes_sent < sizeof (fst)) - write_enn (own_buf); + hostio_send_stat_reply (own_buf, &st, new_packet_len); } static void handle_lstat (char *own_buf, int *new_packet_len) { - int ret, bytes_sent; + int ret; char *p; struct stat st; - struct fio_stat fst; char filename[HOSTIO_PATH_MAX]; p = own_buf + strlen ("vFile:lstat:"); @@ -560,16 +572,7 @@ handle_lstat (char *own_buf, int *new_packet_len) return; } - host_to_fileio_stat (&st, &fst); - - bytes_sent = hostio_reply_with_data (own_buf, - (char *) &fst, sizeof (fst), - new_packet_len); - - /* If the response does not fit into a single packet, do not attempt - to return a partial response, but simply fail. */ - if (bytes_sent < sizeof (fst)) - write_enn (own_buf); + hostio_send_stat_reply (own_buf, &st, new_packet_len); } static void diff --git a/gdbserver/hostio.h b/gdbserver/hostio.h index 7a6fb94cd2c..4061292f094 100644 --- a/gdbserver/hostio.h +++ b/gdbserver/hostio.h @@ -20,6 +20,7 @@ #define GDBSERVER_HOSTIO_H /* Per-connection setup. */ + extern void hostio_handle_new_gdb_connection (void); extern int handle_vFile (char *, int, int *); diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 74774fcde7c..d16b9552003 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -2744,6 +2744,8 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p) cs.single_inferior_argument = true; else if (feature == "multi-wp-addr+") cs.multiple_wp_addr_feature = true; + else if (feature == "stat64+") + cs.stat64_feature = true; else { /* Move the unknown features all together. */ @@ -2760,7 +2762,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p) "PacketSize=%x;QPassSignals+;QProgramSignals+;" "QStartupWithShell+;QEnvironmentHexEncoded+;" "QEnvironmentReset+;QEnvironmentUnset+;" - "QSetWorkingDir+;binary-upload+", + "QSetWorkingDir+;binary-upload+;stat64+", PBUFSIZ - 1); if (target_supports_catch_syscall ()) @@ -4630,6 +4632,7 @@ captured_main (int argc, char *argv[]) cs.memory_tagging_feature = false; cs.error_message_supported = false; cs.multiple_wp_addr_feature = false; + cs.stat64_feature = false; remote_open (port); diff --git a/gdbserver/server.h b/gdbserver/server.h index 1a9e6ef62f8..f86a8701301 100644 --- a/gdbserver/server.h +++ b/gdbserver/server.h @@ -179,6 +179,11 @@ struct client_state /* If true, memory tagging features are supported. */ bool memory_tagging_feature = false; + /* True if GDB supports the wide form of struct stat in the vFile + fstat, stat and lstat replies. When false, gdbserver sends the + narrow struct fio_stat. */ + bool stat64_feature = false; + /* If true then E.errtext style errors are supported everywhere, including for the qRcmd and m packet. When false E.errtext errors are not supported with qRcmd and m packets, but are still supported diff --git a/gdbsupport/fileio.cc b/gdbsupport/fileio.cc index 6d2ffb14544..d2295018613 100644 --- a/gdbsupport/fileio.cc +++ b/gdbsupport/fileio.cc @@ -277,13 +277,13 @@ host_to_fileio_stat (struct stat *st, struct fio_stat *fst) { LONGEST blksize; - host_to_fileio_uint ((long) st->st_dev, fst->fst_dev); - host_to_fileio_uint ((long) st->st_ino, fst->fst_ino); + host_to_fileio_uint ((ULONGEST) st->st_dev, fst->fst_dev); + host_to_fileio_uint ((ULONGEST) st->st_ino, fst->fst_ino); host_to_fileio_mode (st->st_mode, fst->fst_mode); - host_to_fileio_uint ((long) st->st_nlink, fst->fst_nlink); - host_to_fileio_uint ((long) st->st_uid, fst->fst_uid); - host_to_fileio_uint ((long) st->st_gid, fst->fst_gid); - host_to_fileio_uint ((long) st->st_rdev, fst->fst_rdev); + host_to_fileio_uint ((ULONGEST) st->st_nlink, fst->fst_nlink); + host_to_fileio_uint ((ULONGEST) st->st_uid, fst->fst_uid); + host_to_fileio_uint ((ULONGEST) st->st_gid, fst->fst_gid); + host_to_fileio_uint ((ULONGEST) st->st_rdev, fst->fst_rdev); host_to_fileio_ulong ((LONGEST) st->st_size, fst->fst_size); #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE blksize = st->st_blksize; @@ -305,3 +305,35 @@ host_to_fileio_stat (struct stat *st, struct fio_stat *fst) host_to_fileio_time (st->st_mtime, fst->fst_mtime); host_to_fileio_time (st->st_ctime, fst->fst_ctime); } + +/* See fileio.h. */ + +void +host_to_fileio_stat_wide (struct stat *st, struct fio_stat_wide *fst) +{ + LONGEST blksize; + + host_to_fileio_ulong ((LONGEST) st->st_dev, fst->fst_dev); + host_to_fileio_ulong ((LONGEST) st->st_ino, fst->fst_ino); + host_to_fileio_mode (st->st_mode, fst->fst_mode); + host_to_fileio_ulong ((LONGEST) st->st_nlink, fst->fst_nlink); + host_to_fileio_uint ((ULONGEST) st->st_uid, fst->fst_uid); + host_to_fileio_uint ((ULONGEST) st->st_gid, fst->fst_gid); + host_to_fileio_ulong ((LONGEST) st->st_rdev, fst->fst_rdev); + host_to_fileio_ulong ((LONGEST) st->st_size, fst->fst_size); +#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE + blksize = st->st_blksize; +#else + blksize = 512; +#endif + host_to_fileio_ulong (blksize, fst->fst_blksize); +#if HAVE_STRUCT_STAT_ST_BLOCKS + host_to_fileio_ulong ((LONGEST) st->st_blocks, fst->fst_blocks); +#else + host_to_fileio_ulong (((LONGEST) st->st_size + blksize - 1) / blksize, + fst->fst_blocks); +#endif + host_to_fileio_ulong ((LONGEST) st->st_atime, fst->fst_atime); + host_to_fileio_ulong ((LONGEST) st->st_mtime, fst->fst_mtime); + host_to_fileio_ulong ((LONGEST) st->st_ctime, fst->fst_ctime); +} diff --git a/gdbsupport/fileio.h b/gdbsupport/fileio.h index c2592cf8c15..4ca9b9aff30 100644 --- a/gdbsupport/fileio.h +++ b/gdbsupport/fileio.h @@ -120,9 +120,11 @@ using fio_time_t = char[FIO_TIME_LEN]; using fio_long_t = char[FIO_LONG_LEN]; using fio_ulong_t = char[FIO_ULONG_LEN]; -/* Struct stat as used in protocol. For complete independence - of host/target systems, it's defined as an array with offsets - to the members. */ +/* Struct stat as used in the protocol. This is the format used by the + F-packet file-i/o protocol, and by the vFile stat packets when the + stat64 feature has not been negotiated. Several fields are too narrow + to hold the corresponding struct stat member on a 64-bit host; see + struct fio_stat_wide. */ struct fio_stat { @@ -141,6 +143,29 @@ struct fio_stat fio_time_t fst_ctime; }; +/* Struct stat as used in the wide form of the protocol. The fields + which cannot hold the corresponding struct stat member on a 64-bit + host are widened to 8 bytes. This layout is only used by the vFile + stat packets, and only when the stat64 feature has been negotiated + with the peer. */ + +struct fio_stat_wide +{ + fio_ulong_t fst_dev; + fio_ulong_t fst_ino; + fio_mode_t fst_mode; + fio_ulong_t fst_nlink; + fio_uint_t fst_uid; + fio_uint_t fst_gid; + fio_ulong_t fst_rdev; + fio_ulong_t fst_size; + fio_ulong_t fst_blksize; + fio_ulong_t fst_blocks; + fio_ulong_t fst_atime; + fio_ulong_t fst_mtime; + fio_ulong_t fst_ctime; +}; + struct fio_timeval { fio_time_t ftv_sec; @@ -179,19 +204,27 @@ host_to_bigendian (LONGEST num, char *buf, int bytes) buf[i] = (num >> (8 * (bytes - i - 1))) & 0xff; } -/* Pack a host-format integer into an fio_uint_t. */ +/* Pack a host-format integer into an fio_uint_t, warning if the value + does not fit. */ static inline void -host_to_fileio_uint (long num, fio_uint_t fnum) +host_to_fileio_uint (ULONGEST num, fio_uint_t fnum) { + if (num > 0xffffffff) + warning (_("file-i/o: value %s does not fit in 32 bits and will be " + "truncated"), pulongest (num)); host_to_bigendian ((LONGEST) num, (char *) fnum, 4); } -/* Pack a host-format time_t into an fio_time_t. */ +/* Pack a host-format time_t into an fio_time_t, warning if the value + does not fit. */ static inline void host_to_fileio_time (time_t num, fio_time_t fnum) { + if ((ULONGEST) num > 0xffffffff) + warning (_("file-i/o: time value %s does not fit in 32 bits and " + "will be truncated"), plongest (num)); host_to_bigendian ((LONGEST) num, (char *) fnum, 4); } @@ -199,4 +232,9 @@ host_to_fileio_time (time_t num, fio_time_t fnum) extern void host_to_fileio_stat (struct stat *st, struct fio_stat *fst); +/* Pack a host-format struct stat into a struct fio_stat_wide. */ + +extern void host_to_fileio_stat_wide (struct stat *st, + struct fio_stat_wide *fst); + #endif /* GDBSUPPORT_FILEIO_H */ -- 2.51.1