From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id aYdiDQsU62rZhxgAWB0awg (envelope-from ) for ; Wed, 04 Nov 2026 06:16:27 -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=dY31Q5fs; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 32CF01E09A; Wed, 04 Nov 2026 06:16:27 -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 0CBAE1E052 for ; Wed, 04 Nov 2026 06:16:26 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4246A4BA79BA for ; Wed, 4 Nov 2026 11:16:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4246A4BA79BA 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=dY31Q5fs Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 5CDC84BA79B4 for ; Wed, 4 Nov 2026 11:15:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5CDC84BA79B4 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 5CDC84BA79B4 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=1793790954; cv=none; b=lvIFeC6WGaozitfEA6H800YYECJ3KT8Xs5eDqOyS8MZvSO1HOTI6iAYDk0PnMndrpnZd4XFezAVh0pQRzcNF6MhzEUPwTlmyyOw/URoetYaY0I67hsYcGK+fiEgPUi6vn4SZWZSSf+Mi4tvK2Zn9w79nKUVn4mUrqLNictp51+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793790954; c=relaxed/simple; bh=bD1o+U5Xw2il34VdVLNlkFsMUpNN1d3dvMSTNsB+qXo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=x1EM/6q3DRafF5hLAAbXCjRX7N0fQhrUygt3aW37QrDPEG5pperZOmTsR4Lu9duiAaIXnmNMwhHFiptS0k613I3or7trMIMDHVCjkmnjfIQh4nkSKMJA8JZky3U3+zoda2qsYs6vcMAij85wVb8razBoGeYON//edV153w8dO3Y= 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=dY31Q5fs DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5CDC84BA79B4 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 6A4BEALJ618249; Wed, 4 Nov 2026 11:15:48 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=j8MuNr8qvq8VOHWmm XOShDa7S1wTp0YkHTcyMmG+9W4=; b=dY31Q5fstLAvYcrm+tQxuybx9u8TBc6f5 GbnuFPNiNCk5/LHsM94+4sg4tjgdz7JTsOzUtXWNA/QT0kTDS82s5/oNpVOe7ASm pQ7+c9/k7uIMCQYMT2A76LdwXh89Hmhm5VOWVCxavL/n8jx76tSJ9z0GLBj7sMe7 X9JH36W2EDA5jV7m+dGbCo7VlfswpF5VnqOjTo/En6YqKSNFUn28XQ7nhp9CpD1P 9kGW52QW2jNcllaZzUrni+UE345WOQCbKRtHjzDLmUsw33BhUAAjwFRsV0T93pqi CeUKb8XjqnXsLlnQej51y+mwilJhhfqaY/DBSW6vRvhtohflEjmnw== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4hn7u3kf74-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 04 Nov 2026 11:15:48 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6A48YtJr3877886; Wed, 4 Nov 2026 11:15:47 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4hqv1usn61-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Nov 2026 11:15:47 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6A4BFfNK49611010 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 4 Nov 2026 11:15:41 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4120720040; Wed, 4 Nov 2026 11:15:41 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4A7D920049; Wed, 4 Nov 2026 11:15:40 +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:40 +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 2/2] gdb: add stat64 and fstat64 to the F-packet file-i/o protocol Date: Wed, 4 Nov 2026 06:15:21 -0500 Message-ID: <20261104111521.3042934-3-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=6aeb13e4 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=zJRp6_cAMcgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=CCpqsmhAAAAA:8 a=VnNF1IyMAAAA:8 a=20KFwNOVAAAA:8 a=wAdn11-CNiMixW_R7yoA:9 a=ul9cdbp4aOFLsgKbc677:22 X-Proofpoint-ORIG-GUID: gX9wYy9bpZJdrVPoSmgzEb8gYj0BCu-K X-Proofpoint-GUID: gX9wYy9bpZJdrVPoSmgzEb8gYj0BCu-K X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTA0MDA0NCBTYWx0ZWRfX9ImWjH9FEl1I 5kKrAb8UGh8IjoylW38R30zyHCQ+oF2KArqujpZdmCeiWQsz1CJ22Il9YzB5r6ll6TgcNU1Xfck 64YQVb5iEtiPp/dlMWXUwEiBBfpctElXcQ1+paZXBpQ4yk+ro/Xf1lxtVuApNH7TjGztVyx7XWB 1pWEFsNydzubq4Da+RDrr8PAudGVEvEEkUOoq8zGhoUvqWmiw6y7aMVwWUbi7t7wwgJoG7tsE2Q oqEopMms9lyGs+9pRd3AAM69VKt+3L9BxNd2ylzmURShtRWObIS8RKcsNsahIRl6ovcmAU1VwUZ nBtsp5hLUzCryxYAeucYczBKuy4q+fbvPPtu0i2FzfZe4yMX0QerM/L68QWbfJyYLrIIirgrVp1 o/zgpHN6nfDihMm5Yql0dO+rFTwo/Vqc6+SuaSAqNdyZTzl3pKNYLQzDTNeOxJDnEJgvN0KhWu+ ijxbcpshpbuB7RFgdLA== X-Proofpoint-Spam-Info: AW1haW4tMjYxMTA0MDA0NCBTYWx0ZWRfX/TyRjmpqWEzr jNaFHoDvc3EjMtW8mOMn0MtNlHX9kxAypstD86puQrKBp36MwgGIo8rg2Cv47zmwPHbww/1ovpH RDg94gI06z1s1u9/VYIm/vG2eqGiZ9c= 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 previous patch widened the stat fields returned by the vFile packets, using a qSupported feature to keep old and new GDB and gdbserver compatible. The F-packet file-i/o protocol has the same problem: the Fstat and Ffstat calls write struct fio_stat into target memory, in which st_dev, st_ino, st_nlink, st_rdev and the three timestamps are 4 bytes, so those values are truncated on a 64-bit host. Each F-packet request names the call it wants, so add two new calls, Fstat64 and Ffstat64, which are identical to Fstat and Ffstat except that they write struct fio_stat_wide. Existing targets keep using Fstat and Ffstat and see no change. A GDB which does not know the new calls already replies with ENOSYS, so a target can try Fstat64 and fall back to Fstat. The stat and fstat handlers become remote_fileio_do_stat and remote_fileio_do_fstat, with a flag selecting the layout, and share a new remote_fileio_write_stat helper. The stat handler has always reported st_dev as zero; that is now done on the struct stat before packing, which gives the same result in either layout. The console case in the fstat handler stored 1 into fst_dev, but that was then overwritten when the struct was packed, so the target always saw zero. Drop the dead store; behaviour is unchanged. Tested on powerpc64le-linux, on an xfs filesystem with inode numbers above 2^32, using a fake remote stub which issues File-I/O requests and checks the buffer GDB writes into target memory. Fstat64 and Ffstat64 return the full inode number; Fstat and Ffstat return the same truncated values as before. An unpatched GDB answers Fstat64 and Ffstat64 with ENOSYS. gdb.server/fileio-packets.exp continues to pass. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34567 Suggested-by: Ulrich Weigand Approved-By: Andrew Burgess --- gdb/NEWS | 9 ++++++ gdb/doc/gdb.texinfo | 52 ++++++++++++++++++++++++++++++-- gdb/remote-fileio.c | 73 +++++++++++++++++++++++++++++++++++++-------- gdbsupport/fileio.h | 14 ++++----- 4 files changed, 126 insertions(+), 22 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 99072d2b758..9983863b721 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -85,6 +85,15 @@ info locals 'allow_pending' argument. Setting it to False causes GDB to raise an error instead of creating a pending breakpoint. +* New remote packets + +Fstat64, Ffstat64 + New File-I/O calls, identical to Fstat and Ffstat except that they + fill in the wider struct stat64 layout, in which st_dev, st_ino, + st_nlink, st_rdev and the three timestamps are 8 bytes rather than + 4. A GDB without these calls replies with ENOSYS, so a target can + fall back to Fstat and Ffstat. + * Changed remote packets stat64 in qSupported diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 3804ce71711..f2395fe5223 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -48136,6 +48136,7 @@ is stopped at the user's request. * rename:: * unlink:: * stat/fstat:: +* stat64/fstat64:: * gettimeofday:: * isatty:: * system:: @@ -48581,6 +48582,49 @@ The call was interrupted by the user. @end table +The buffer uses the narrow @code{struct stat} layout, in which some +members may be truncated on a 64-bit host. @xref{stat64/fstat64}, for +calls which use a wider layout. + +@node stat64/fstat64 +@unnumberedsubsubsec stat64/fstat64 +@cindex fstat64, file-i/o system call +@cindex stat64, file-i/o system call + +@table @asis +@item Synopsis: +@smallexample +int stat64(const char *pathname, struct stat64 *buf); +int fstat64(int fd, struct stat64 *buf); +@end smallexample + +@item Request: +@samp{Fstat64,@var{pathnameptr}/@var{len},@var{bufptr}}@* +@samp{Ffstat64,@var{fd},@var{bufptr}} + +These calls are identical to @samp{Fstat} and @samp{Ffstat} +(@pxref{stat/fstat}), except that the buffer at @var{bufptr} is +filled in using the wider @code{struct stat64} layout +(@pxref{struct stat64}), which can hold the values found on a 64-bit +host without truncation. + +A version of @value{GDBN} which does not support these calls replies +with an @code{ENOSYS} error. The target can then fall back to +@samp{Fstat} or @samp{Ffstat}. + +@item Return value: +On success, zero is returned. On error, -1 is returned. + +@item Errors: +As for @samp{Fstat} and @samp{Ffstat}, and in addition: + +@table @code +@item ENOSYS +@value{GDBN} does not support this call. +@end table + +@end table + @node gettimeofday @unnumberedsubsubsec gettimeofday @cindex gettimeofday, file-i/o system call @@ -48837,7 +48881,9 @@ get truncated on the target. 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: +packets uses the following representation instead. The +@samp{Fstat64} and @samp{Ffstat64} File-I/O calls +(@pxref{stat64/fstat64}) always use it. @smallexample struct stat64 @{ @@ -48865,8 +48911,8 @@ as in the narrow form (@pxref{struct stat}), but @code{st_dev}, 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}). +The @samp{Fstat} and @samp{Ffstat} File-I/O calls always use the narrow +form (@pxref{struct stat}). @node struct timeval @unnumberedsubsubsec struct timeval diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c index a65db27d04e..f893f8dfda0 100644 --- a/gdb/remote-fileio.c +++ b/gdb/remote-fileio.c @@ -791,14 +791,39 @@ remote_fileio_func_unlink (remote_target *remote, char *buf) remote_fileio_return_success (remote, ret); } +/* Write ST into target memory at ADDR, using the struct fio_stat + layout or, if WIDE, the struct fio_stat_wide layout. Return 0 on + success, -1 on error. */ + +static int +remote_fileio_write_stat (CORE_ADDR addr, struct stat *st, bool wide) +{ + if (wide) + { + struct fio_stat_wide fst; + + host_to_fileio_stat_wide (st, &fst); + return target_write_memory (addr, (gdb_byte *) &fst, sizeof fst); + } + else + { + struct fio_stat fst; + + host_to_fileio_stat (st, &fst); + return target_write_memory (addr, (gdb_byte *) &fst, sizeof fst); + } +} + +/* Handle the stat and stat64 calls. WIDE selects the struct + fio_stat_wide layout. */ + static void -remote_fileio_func_stat (remote_target *remote, char *buf) +remote_fileio_do_stat (remote_target *remote, char *buf, bool wide) { CORE_ADDR statptr, nameptr; int ret, namelength; LONGEST lnum; struct stat st; - struct fio_stat fst; /* 1. Parameter: Ptr to pathname / length incl. trailing zero */ if (remote_fileio_extract_ptr_w_len (&buf, &nameptr, &namelength)) @@ -839,10 +864,9 @@ remote_fileio_func_stat (remote_target *remote, char *buf) } if (statptr) { - host_to_fileio_stat (&st, &fst); - host_to_fileio_uint (0, fst.fst_dev); - - errno = target_write_memory (statptr, (gdb_byte *) &fst, sizeof fst); + /* The stat call has always reported st_dev as zero. */ + st.st_dev = 0; + errno = remote_fileio_write_stat (statptr, &st, wide); if (errno != 0) { remote_fileio_return_errno (remote, -1); @@ -853,14 +877,28 @@ remote_fileio_func_stat (remote_target *remote, char *buf) } static void -remote_fileio_func_fstat (remote_target *remote, char *buf) +remote_fileio_func_stat (remote_target *remote, char *buf) +{ + remote_fileio_do_stat (remote, buf, false); +} + +static void +remote_fileio_func_stat64 (remote_target *remote, char *buf) +{ + remote_fileio_do_stat (remote, buf, true); +} + +/* Handle the fstat and fstat64 calls. WIDE selects the struct + fio_stat_wide layout. */ + +static void +remote_fileio_do_fstat (remote_target *remote, char *buf, bool wide) { CORE_ADDR ptrval; int fd, ret; long target_fd; LONGEST lnum; struct stat st; - struct fio_stat fst; struct timeval tv; /* 1. Parameter: file descriptor */ @@ -885,7 +923,6 @@ remote_fileio_func_fstat (remote_target *remote, char *buf) if (fd == FIO_FD_CONSOLE_IN || fd == FIO_FD_CONSOLE_OUT) { - host_to_fileio_uint (1, fst.fst_dev); memset (&st, 0, sizeof (st)); st.st_mode = S_IFCHR | (fd == FIO_FD_CONSOLE_IN ? S_IRUSR : S_IWUSR); st.st_nlink = 1; @@ -917,9 +954,7 @@ remote_fileio_func_fstat (remote_target *remote, char *buf) } if (ptrval) { - host_to_fileio_stat (&st, &fst); - - errno = target_write_memory (ptrval, (gdb_byte *) &fst, sizeof fst); + errno = remote_fileio_write_stat (ptrval, &st, wide); if (errno != 0) { remote_fileio_return_errno (remote, -1); @@ -929,6 +964,18 @@ remote_fileio_func_fstat (remote_target *remote, char *buf) remote_fileio_return_success (remote, ret); } +static void +remote_fileio_func_fstat (remote_target *remote, char *buf) +{ + remote_fileio_do_fstat (remote, buf, false); +} + +static void +remote_fileio_func_fstat64 (remote_target *remote, char *buf) +{ + remote_fileio_do_fstat (remote, buf, true); +} + static void remote_fileio_func_gettimeofday (remote_target *remote, char *buf) { @@ -1062,6 +1109,8 @@ static struct { { "unlink", remote_fileio_func_unlink }, { "stat", remote_fileio_func_stat }, { "fstat", remote_fileio_func_fstat }, + { "stat64", remote_fileio_func_stat64 }, + { "fstat64", remote_fileio_func_fstat64 }, { "gettimeofday", remote_fileio_func_gettimeofday }, { "isatty", remote_fileio_func_isatty }, { "system", remote_fileio_func_system }, diff --git a/gdbsupport/fileio.h b/gdbsupport/fileio.h index 4ca9b9aff30..bf48e0e8731 100644 --- a/gdbsupport/fileio.h +++ b/gdbsupport/fileio.h @@ -121,10 +121,10 @@ using fio_long_t = char[FIO_LONG_LEN]; using fio_ulong_t = char[FIO_ULONG_LEN]; /* 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. */ + F-packet file-i/o stat and fstat calls, 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 { @@ -145,9 +145,9 @@ struct fio_stat /* 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. */ + host are widened to 8 bytes. This layout is used by the vFile stat + packets when the stat64 feature has been negotiated with the peer, + and by the F-packet file-i/o stat64 and fstat64 calls. */ struct fio_stat_wide { -- 2.51.1