]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: add target_fileio_stat, but no implementations yet
authorAndrew Burgess <aburgess@redhat.com>
Tue, 21 May 2024 14:39:37 +0000 (15:39 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 18 Jul 2024 12:24:20 +0000 (13:24 +0100)
In a later commit I want target_fileio_stat, that is a call that
operates on a filename rather than an open file descriptor as
target_fileio_fstat does.

This commit adds the initial framework for target_fileio_stat, I've
added the top level target function and the virtual target_ops methods
in the target_ops base class.

At this point no actual targets override target_ops::fileio_stat, so
any attempts to call this function will return ENOSYS error code.

gdb/target.c
gdb/target.h

index d23743729325b6d165eb721b802e69d3af6a4911..a80b133a1b33ba5d45ed109c6ed95b26fdf391e8 100644 (file)
@@ -3198,6 +3198,14 @@ target_ops::fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno)
   return -1;
 }
 
+int
+target_ops::fileio_stat (struct inferior *inf, const char *filename,
+                        struct stat *sb, fileio_error *target_errno)
+{
+  *target_errno = FILEIO_ENOSYS;
+  return -1;
+}
+
 int
 target_ops::fileio_close (int fd, fileio_error *target_errno)
 {
@@ -3317,6 +3325,29 @@ target_fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno)
 
 /* See target.h.  */
 
+int
+target_fileio_stat (struct inferior *inf, const char *filename,
+                   struct stat *sb, fileio_error *target_errno)
+{
+  for (target_ops *t = default_fileio_target (); t != NULL; t = t->beneath ())
+    {
+      int ret = t->fileio_stat (inf, filename, sb, target_errno);
+
+      if (ret == -1 && *target_errno == FILEIO_ENOSYS)
+       continue;
+
+      target_debug_printf_nofunc ("target_fileio_stat (%s) = %d (%d)",
+                                 filename, ret,
+                                 ret != -1 ? 0 : *target_errno);
+      return ret;
+    }
+
+  *target_errno = FILEIO_ENOSYS;
+  return -1;
+}
+
+/* See target.h.  */
+
 int
 target_fileio_close (int fd, fileio_error *target_errno)
 {
index f1b97cfb7d32343c9de0d421674c4db25b21abe5..dcf68a6cca0bde5e0d016e702210386bcd1d5a8a 100644 (file)
@@ -1011,6 +1011,14 @@ struct target_ops
        *TARGET_ERRNO).  */
     virtual int fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno);
 
+    /* Get information about the file FILENAME and put it in SB.  Look for
+       FILENAME in the filesystem as seen by INF.  If INF is NULL, use the
+       filesystem seen by the debugger (GDB or, for remote targets, the
+       remote stub).  Return 0 on success, or -1 if an error occurs (and
+       set *TARGET_ERRNO).  */
+    virtual int fileio_stat (struct inferior *inf, const char *filename,
+                            struct stat *sb, fileio_error *target_errno);
+
     /* Close FD on the target.  Return 0, or -1 if an error occurs
        (and set *TARGET_ERRNO).  */
     virtual int fileio_close (int fd, fileio_error *target_errno);
@@ -2220,6 +2228,14 @@ extern int target_fileio_pread (int fd, gdb_byte *read_buf, int len,
 extern int target_fileio_fstat (int fd, struct stat *sb,
                                fileio_error *target_errno);
 
+/* Get information about the file at FILENAME on the target and put it in
+   SB.  Look in the filesystem as seen by INF.  If INF is NULL, use the
+   filesystem seen by the debugger (GDB or, for remote targets, the remote
+   stub).  Return 0 on success, or -1 if an error occurs (and set
+   *TARGET_ERRNO).  */
+extern int target_fileio_stat (struct inferior *inf, const char *filename,
+                              struct stat *sb, fileio_error *target_errno);
+
 /* Close FD on the target.  Return 0, or -1 if an error occurs
    (and set *TARGET_ERRNO).  */
 extern int target_fileio_close (int fd, fileio_error *target_errno);