From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id eSrKKVwQ42qLlwYAWB0awg (envelope-from ) for ; Thu, 29 Oct 2026 05:22:36 -0400 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=tKf5SOfR; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 9FF181E023; Thu, 29 Oct 2026 05:22:36 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 B1B671E023 for ; Thu, 29 Oct 2026 05:22:32 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A4A54BA2E39 for ; Thu, 29 Oct 2026 09:22:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A4A54BA2E39 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=tKf5SOfR Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id AF2574BA23D6 for ; Thu, 29 Oct 2026 09:21:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF2574BA23D6 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 AF2574BA23D6 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793265715; cv=none; b=dmT2MxoES4WtIaGjdxXmfJKySEIGB0hPX3Diixws5rjppUc3+/PPJcdK1tk2z923QQ/8v06t9lZMB7K2BJgTWP2rxpLzd739PjtM7q/KobDJp8CuuCn/dXB9IFJjYm0B6wvMZPXJEOprYl4cNA9dsk2zcYaVcLbAEToBvVxWaiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793265715; c=relaxed/simple; bh=E4UnhR7Ca9dPqUPXWbaAE/fIBS2JQgHW8iCm+VLsBbQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xz7Yg7hM7jFvpsSiCMUTgSVhyT0xtiYKNAdis3KLXOM+WgVYnLPSXEdzFab5bwfx17kM1PNBScXlWhvbT2T0I8JdORIJMCx9mx9MsQfcbn4w8+16CfjVeh0G8eHDtVjrmt8SgLaoaMadnL7LuYaK1WsulUh8SmRlJN+So7zMTUk= 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=tKf5SOfR DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AF2574BA23D6 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69T9E96V3699483; Thu, 29 Oct 2026 09:21:50 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=64n1ZfmdxZLvSUo87 g9YPY/AGR85h5KG/nT8Voi5bVk=; b=tKf5SOfRFDqCfyzvPtb6XhTarUyEQYE8L z/lvcIi59QzUMn5i1QEiiWEEZ+w7uzcgFe6zStpjayr2HvmqtGLbBA/bxosMYl4e FwBFX/NoK1NvxK2DK6pb2YV0VcToFn7IclWLmlHKM3vpn3GKaiYT4chFKE6FouWF SbiaxZHs9mWvNSSviQ3ht7ooFj8u5kFlTeX0Kca2751PZLiLLSPnvFMfTV46dlPN Jrjhc18oSY5k9dTYtJ7PlLnlgY2Vd7y4WySTNbAZfh/N27c3y/V8MN2FxlTEPkGU d2aYPAxzlYHn1Oc5yX8POCyUCNR8I+vyuDxI3KGZyh7rBzRh9d7DQ== 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 4hgj3mhaxx-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 29 Oct 2026 09:21:50 +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 69T94sF82829600; Thu, 29 Oct 2026 09:21:49 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4hjtnngtmm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 29 Oct 2026 09:21:49 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 69T9LhB747907218 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 29 Oct 2026 09:21:43 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7B07220043; Thu, 29 Oct 2026 09:21:43 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8AEB720040; Thu, 29 Oct 2026 09:21:42 +0000 (GMT) Received: from kubota.pok.stglabs.ibm.com (unknown [9.114.39.181]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 29 Oct 2026 09:21:42 +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 v4 2/2] gdb: add stat64 and fstat64 to the F-packet file-i/o protocol Date: Thu, 29 Oct 2026 04:21:24 -0500 Message-ID: <20261029092124.233055-3-abhay@linux.ibm.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20261029092124.233055-1-abhay@linux.ibm.com> References: <20261029092124.233055-1-abhay@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Spam-Info: AW1haW4tMjYxMDI5MDAzNSBTYWx0ZWRfX0QKysgd3tZ3X EEcwaIvygnLHuM470OP90CXPqrunEDnKvCsAMrABDE7hxz4FKf/OOWdqq2luFK7k/YFrX5Mepm0 y9IMN9vc9dqk1oicZgXa7JFaejLxSGE= X-Proofpoint-ORIG-GUID: reUucSb-t-ilVtlPhv0YwqkkQ1vUOkos X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI5MDAzNSBTYWx0ZWRfX95uqRGRcBcLe ET4sS/NT862l7ww7hy3I6imoAPEoZA+jM9b1oeU1UlTrU+NCUAWIUTL26PX3Ho78q/ooSCnLiIv NAoc5U7G9PfCVizS3V3zwWS/YziPyxdvw1a6py0FwlmFVuy6duZf8Y34rfyzg80lSblONDgPqsq ikd7baBtp+/hL8DXdh2v5diPh8sJOUfW51TKpg+ldK0zr3HHUsghRqCMlc5rZm7iJmuy9t/FeRJ K/bbQOUfEUepquXT4qMuEuLZVmm3bK9uW7dEmOa+UN+FLZYYIMBg1Mc38JUCzqdAN3U2VgK30wa ZiAjwGkR47vxKB/PH/GPxJhGcfBen/V5+eWnG7Ms0M3iXzqN+ZSzyUdGYhlzAPbjEnCKq20uzP9 onECJnSEwftunD200gtVsGqBnxWwNQqUgmbp26x2fmnJgkIMoiPFJ0XEy35rGvrdCpowM2EUfhR tu/n0qBn7DYeYtruT+w== X-Authority-Analysis: v=2.4 cv=G7uJgNk5 c=1 sm=1 tr=0 ts=6ae3102e cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=660iZSQnnn4A:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=CCpqsmhAAAAA:8 a=VnNF1IyMAAAA:8 a=wAdn11-CNiMixW_R7yoA:9 a=ul9cdbp4aOFLsgKbc677:22 X-Proofpoint-GUID: reUucSb-t-ilVtlPhv0YwqkkQ1vUOkos 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-10-29_03,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 adultscore=0 impostorscore=0 suspectscore=0 clxscore=1015 phishscore=0 spamscore=0 malwarescore=0 lowpriorityscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610290035 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. The F-packet calls cannot use qSupported, since the buffer is read directly by the target. But each 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 --- 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 47425535661..5815a8c2261 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -83,6 +83,15 @@ info locals The new "-shadowed on|off" option overrides the "set print shadowed" setting for a single invocation of the command. +* 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 4d606377987..2b28d64af01 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 @{ @@ -48863,8 +48909,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..c24c3c2ab9f 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, or an errno value. */ + +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 44b9bdcafc6..e158b45a9b4 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