From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id 1B8323858422; Wed, 21 Sep 2022 18:13:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B8323858422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663784002; bh=hRVGQ9v/HfSnX78Ttm8dS7QOu2n3hCc8nqCl18+Ozs0=; h=From:To:Subject:Date:From; b=yqzyyAyKkS6hPi1laFZ1FZh8581j02EEfO+nfWZR4HxktDZQhhHcZS0dOvcGUNDVH 0qkwP4aaUqp9HDSAL/ASlBYxE3a7T5Xm1mhgepPANXSjqiEx0DPE8BaHb/uX3B8hSk PkbeoFwCxMgvFGnfjxcnO6Ztakvu82OklKk1c+qs= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdbsupport: convert FILEIO_* macros to an enum X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 198f946ffe9fbfeeb187531e57cab6c3fd9d8b3d X-Git-Newrev: b872057a63c53106e4bf6033a52d53b988f30dfd Message-Id: <20220921181322.1B8323858422@sourceware.org> Date: Wed, 21 Sep 2022 18:13:22 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Db872057a63c5= 3106e4bf6033a52d53b988f30dfd commit b872057a63c53106e4bf6033a52d53b988f30dfd Author: Simon Marchi Date: Fri Aug 26 15:38:26 2022 -0400 gdbsupport: convert FILEIO_* macros to an enum =20 Converting from free-form macros to an enum gives a bit of type-safety. This caught places where we would assign host error numbers to what should contain a target fileio error number, for instance in target_fileio_pread. =20 I added the FILEIO_SUCCESS enumerator, because remote.c:remote_hostio_parse_result initializes the remote_errno output variable to 0. It seems better to have an explicit enumerator than to assign a value for which there is no enumerator. I considered initializing this variable to FILEIO_EUNKNOWN instead, such that if the remote side replies with an error and omits the errno value, we'll get an errno that represents an error instead of 0 (which reprensents no error). But it's not clear what the consequences of that change would be, so I prefer to err on the side of caution and just keep the existing behavior (there is no intended change in behavior with this patch). =20 Note that remote_hostio_parse_resul still reads blindly what the remote side sends as a target errno into this variable, so we can still end up with a nonsensical value here. It's not good, but out of the scope of this patch. =20 Convert host_to_fileio_error and fileio_errno_to_host to return / accept a fileio_error instead of an int, and cascade the change in the whole chain that uses that. =20 Change-Id: I454b0e3fcf0732447bc872252fa8e57d138b0e03 Diff: --- gdb/gdb_bfd.c | 11 ++++--- gdb/inf-child.c | 14 ++++----- gdb/inf-child.h | 14 ++++----- gdb/linux-nat.c | 6 ++-- gdb/linux-nat.h | 6 ++-- gdb/linux-tdep.c | 2 +- gdb/remote.c | 86 +++++++++++++++++++++++++++---------------------= ---- gdb/sparc64-tdep.c | 8 ++--- gdb/target.c | 46 ++++++++++++++-------------- gdb/target.h | 29 +++++++++--------- gdbsupport/fileio.cc | 2 +- gdbsupport/fileio.h | 50 ++++++++++++++++-------------- 12 files changed, 142 insertions(+), 132 deletions(-) diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 7631e274d82..14388159c52 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -306,7 +306,7 @@ gdb_bfd_open_from_target_memory (CORE_ADDR addr, ULONGE= ST size, /* Return the system error number corresponding to ERRNUM. */ =20 static int -fileio_errno_to_host (int errnum) +fileio_errno_to_host (fileio_error errnum) { switch (errnum) { @@ -370,7 +370,8 @@ static void * gdb_bfd_iovec_fileio_open (struct bfd *abfd, void *open_closure) { const char *filename =3D bfd_get_filename (abfd); - int fd, target_errno; + int fd; + fileio_error target_errno; int *stream; gdb_bfd_open_closure *oclosure =3D (gdb_bfd_open_closure *) open_closure; =20 @@ -400,7 +401,7 @@ gdb_bfd_iovec_fileio_pread (struct bfd *abfd, void *str= eam, void *buf, file_ptr nbytes, file_ptr offset) { int fd =3D *(int *) stream; - int target_errno; + fileio_error target_errno; file_ptr pos, bytes; =20 pos =3D 0; @@ -443,7 +444,7 @@ static int gdb_bfd_iovec_fileio_close (struct bfd *abfd, void *stream) { int fd =3D *(int *) stream; - int target_errno; + fileio_error target_errno; =20 xfree (stream); =20 @@ -472,7 +473,7 @@ gdb_bfd_iovec_fileio_fstat (struct bfd *abfd, void *str= eam, struct stat *sb) { int fd =3D *(int *) stream; - int target_errno; + fileio_error target_errno; int result; =20 result =3D target_fileio_fstat (fd, sb, &target_errno); diff --git a/gdb/inf-child.c b/gdb/inf-child.c index 56ebd2a5549..ca0af4c1b03 100644 --- a/gdb/inf-child.c +++ b/gdb/inf-child.c @@ -233,7 +233,7 @@ inf_child_target::pid_to_exec_file (int pid) int inf_child_target::fileio_open (struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, - int *target_errno) + fileio_error *target_errno) { int nat_flags; mode_t nat_mode; @@ -257,7 +257,7 @@ inf_child_target::fileio_open (struct inferior *inf, co= nst char *filename, =20 int inf_child_target::fileio_pwrite (int fd, const gdb_byte *write_buf, int le= n, - ULONGEST offset, int *target_errno) + ULONGEST offset, fileio_error *target_errno) { int ret; =20 @@ -284,7 +284,7 @@ inf_child_target::fileio_pwrite (int fd, const gdb_byte= *write_buf, int len, =20 int inf_child_target::fileio_pread (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *target_errno) + ULONGEST offset, fileio_error *target_errno) { int ret; =20 @@ -310,7 +310,7 @@ inf_child_target::fileio_pread (int fd, gdb_byte *read_= buf, int len, /* Implementation of to_fileio_fstat. */ =20 int -inf_child_target::fileio_fstat (int fd, struct stat *sb, int *target_errno) +inf_child_target::fileio_fstat (int fd, struct stat *sb, fileio_error *tar= get_errno) { int ret; =20 @@ -324,7 +324,7 @@ inf_child_target::fileio_fstat (int fd, struct stat *sb= , int *target_errno) /* Implementation of to_fileio_close. */ =20 int -inf_child_target::fileio_close (int fd, int *target_errno) +inf_child_target::fileio_close (int fd, fileio_error *target_errno) { int ret; =20 @@ -339,7 +339,7 @@ inf_child_target::fileio_close (int fd, int *target_err= no) =20 int inf_child_target::fileio_unlink (struct inferior *inf, const char *filenam= e, - int *target_errno) + fileio_error *target_errno) { int ret; =20 @@ -354,7 +354,7 @@ inf_child_target::fileio_unlink (struct inferior *inf, = const char *filename, =20 gdb::optional inf_child_target::fileio_readlink (struct inferior *inf, const char *filen= ame, - int *target_errno) + fileio_error *target_errno) { /* We support readlink only on systems that also provide a compile-time maximum path length (PATH_MAX), at least for now. */ diff --git a/gdb/inf-child.h b/gdb/inf-child.h index ae5ace46f30..16782038011 100644 --- a/gdb/inf-child.h +++ b/gdb/inf-child.h @@ -75,19 +75,19 @@ public: =20 int fileio_open (struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, - int *target_errno) override; + fileio_error *target_errno) override; int fileio_pwrite (int fd, const gdb_byte *write_buf, int len, - ULONGEST offset, int *target_errno) override; + ULONGEST offset, fileio_error *target_errno) override; int fileio_pread (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *target_errno) override; - int fileio_fstat (int fd, struct stat *sb, int *target_errno) override; - int fileio_close (int fd, int *target_errno) override; + ULONGEST offset, fileio_error *target_errno) override; + int fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno) o= verride; + int fileio_close (int fd, fileio_error *target_errno) override; int fileio_unlink (struct inferior *inf, const char *filename, - int *target_errno) override; + fileio_error *target_errno) override; gdb::optional fileio_readlink (struct inferior *inf, const char *filename, - int *target_errno) override; + fileio_error *target_errno) override; bool use_agent (bool use) override; =20 bool can_use_agent () override; diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index e638e8ad04e..d4639766088 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -4372,7 +4372,7 @@ linux_nat_fileio_pid_of (struct inferior *inf) int linux_nat_target::fileio_open (struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, - int *target_errno) + fileio_error *target_errno) { int nat_flags; mode_t nat_mode; @@ -4397,7 +4397,7 @@ linux_nat_target::fileio_open (struct inferior *inf, = const char *filename, =20 gdb::optional linux_nat_target::fileio_readlink (struct inferior *inf, const char *filen= ame, - int *target_errno) + fileio_error *target_errno) { char buf[PATH_MAX]; int len; @@ -4417,7 +4417,7 @@ linux_nat_target::fileio_readlink (struct inferior *i= nf, const char *filename, =20 int linux_nat_target::fileio_unlink (struct inferior *inf, const char *filenam= e, - int *target_errno) + fileio_error *target_errno) { int ret; =20 diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h index 38e253eff36..a9b91a5e908 100644 --- a/gdb/linux-nat.h +++ b/gdb/linux-nat.h @@ -101,16 +101,16 @@ public: =20 int fileio_open (struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, - int *target_errno) override; + fileio_error *target_errno) override; =20 gdb::optional fileio_readlink (struct inferior *inf, const char *filename, - int *target_errno) override; + fileio_error *target_errno) override; =20 int fileio_unlink (struct inferior *inf, const char *filename, - int *target_errno) override; + fileio_error *target_errno) override; =20 int insert_fork_catchpoint (int) override; int remove_fork_catchpoint (int) override; diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 85fad70b06a..adf518023bb 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -813,7 +813,7 @@ linux_info_proc (struct gdbarch *gdbarch, const char *a= rgs, int status_f =3D (what =3D=3D IP_STATUS || what =3D=3D IP_ALL); int stat_f =3D (what =3D=3D IP_STAT || what =3D=3D IP_ALL); char filename[100]; - int target_errno; + fileio_error target_errno; =20 if (args && isdigit (args[0])) { diff --git a/gdb/remote.c b/gdb/remote.c index 5bae65472ed..b57d26a70ed 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -560,26 +560,26 @@ public: =20 int fileio_open (struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, - int *target_errno) override; + fileio_error *target_errno) override; =20 int fileio_pwrite (int fd, const gdb_byte *write_buf, int len, - ULONGEST offset, int *target_errno) override; + ULONGEST offset, fileio_error *target_errno) override; =20 int fileio_pread (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *target_errno) override; + ULONGEST offset, fileio_error *target_errno) override; =20 - int fileio_fstat (int fd, struct stat *sb, int *target_errno) override; + int fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno) o= verride; =20 - int fileio_close (int fd, int *target_errno) override; + int fileio_close (int fd, fileio_error *target_errno) override; =20 int fileio_unlink (struct inferior *inf, const char *filename, - int *target_errno) override; + fileio_error *target_errno) override; =20 gdb::optional fileio_readlink (struct inferior *inf, const char *filename, - int *target_errno) override; + fileio_error *target_errno) override; =20 bool supports_enable_disable_tracepoint () override; =20 @@ -701,25 +701,25 @@ public: /* Remote specific methods. */ void remote_file_delete (const char *remote_file, int from_tty); =20 int remote_hostio_pread (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *remote_errno); + ULONGEST offset, fileio_error *remote_errno); int remote_hostio_pwrite (int fd, const gdb_byte *write_buf, int len, - ULONGEST offset, int *remote_errno); + ULONGEST offset, fileio_error *remote_errno); int remote_hostio_pread_vFile (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *remote_errno); + ULONGEST offset, fileio_error *remote_errno); =20 int remote_hostio_send_command (int command_bytes, int which_packet, - int *remote_errno, const char **attachment, + fileio_error *remote_errno, const char **attachment, int *attachment_len); int remote_hostio_set_filesystem (struct inferior *inf, - int *remote_errno); + fileio_error *remote_errno); /* We should get rid of this and use fileio_open directly. */ int remote_hostio_open (struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, - int *remote_errno); - int remote_hostio_close (int fd, int *remote_errno); + fileio_error *remote_errno); + int remote_hostio_close (int fd, fileio_error *remote_errno); =20 int remote_hostio_unlink (inferior *inf, const char *filename, - int *remote_errno); + fileio_error *remote_errno); =20 struct remote_state *get_remote_state (); =20 @@ -12130,7 +12130,7 @@ remote_buffer_add_int (char **buffer, int *left, UL= ONGEST value) } =20 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return - value, *REMOTE_ERRNO to the remote error number or zero if none + value, *REMOTE_ERRNO to the remote error number or FILEIO_SUCCESS if no= ne was included, and *ATTACHMENT to point to the start of the annex if any. The length of the packet isn't needed here; there may be NUL bytes in BUFFER, but they will be after *ATTACHMENT. @@ -12140,11 +12140,11 @@ remote_buffer_add_int (char **buffer, int *left, = ULONGEST value) =20 static int remote_hostio_parse_result (const char *buffer, int *retcode, - int *remote_errno, const char **attachment) + fileio_error *remote_errno, const char **attachment) { char *p, *p2; =20 - *remote_errno =3D 0; + *remote_errno =3D FILEIO_SUCCESS; *attachment =3D NULL; =20 if (buffer[0] !=3D 'F') @@ -12159,7 +12159,7 @@ remote_hostio_parse_result (const char *buffer, int= *retcode, if (*p =3D=3D ',') { errno =3D 0; - *remote_errno =3D strtol (p + 1, &p2, 16); + *remote_errno =3D (fileio_error) strtol (p + 1, &p2, 16); if (errno !=3D 0 || p + 1 =3D=3D p2) return -1; p =3D p2; @@ -12196,7 +12196,7 @@ remote_hostio_parse_result (const char *buffer, int= *retcode, =20 int remote_target::remote_hostio_send_command (int command_bytes, int which_pa= cket, - int *remote_errno, const char **attachment, + fileio_error *remote_errno, const char **attachment, int *attachment_len) { struct remote_state *rs =3D get_remote_state (); @@ -12281,7 +12281,7 @@ readahead_cache::invalidate_fd (int fd) =20 int remote_target::remote_hostio_set_filesystem (struct inferior *inf, - int *remote_errno) + fileio_error *remote_errno) { struct remote_state *rs =3D get_remote_state (); int required_pid =3D (inf =3D=3D NULL || inf->fake_pid_p) ? 0 : inf->pid; @@ -12318,7 +12318,7 @@ remote_target::remote_hostio_set_filesystem (struct= inferior *inf, int remote_target::remote_hostio_open (inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, - int *remote_errno) + fileio_error *remote_errno) { struct remote_state *rs =3D get_remote_state (); char *p =3D rs->buf.data (); @@ -12361,7 +12361,7 @@ remote_target::remote_hostio_open (inferior *inf, c= onst char *filename, int remote_target::fileio_open (struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, - int *remote_errno) + fileio_error *remote_errno) { return remote_hostio_open (inf, filename, flags, mode, warn_if_slow, remote_errno); @@ -12371,7 +12371,7 @@ remote_target::fileio_open (struct inferior *inf, c= onst char *filename, =20 int remote_target::remote_hostio_pwrite (int fd, const gdb_byte *write_buf, in= t len, - ULONGEST offset, int *remote_errno) + ULONGEST offset, fileio_error *remote_errno) { struct remote_state *rs =3D get_remote_state (); char *p =3D rs->buf.data (); @@ -12398,7 +12398,7 @@ remote_target::remote_hostio_pwrite (int fd, const = gdb_byte *write_buf, int len, =20 int remote_target::fileio_pwrite (int fd, const gdb_byte *write_buf, int len, - ULONGEST offset, int *remote_errno) + ULONGEST offset, fileio_error *remote_errno) { return remote_hostio_pwrite (fd, write_buf, len, offset, remote_errno); } @@ -12408,7 +12408,7 @@ remote_target::fileio_pwrite (int fd, const gdb_byt= e *write_buf, int len, =20 int remote_target::remote_hostio_pread_vFile (int fd, gdb_byte *read_buf, int = len, - ULONGEST offset, int *remote_errno) + ULONGEST offset, fileio_error *remote_errno) { struct remote_state *rs =3D get_remote_state (); char *p =3D rs->buf.data (); @@ -12468,7 +12468,7 @@ readahead_cache::pread (int fd, gdb_byte *read_buf,= size_t len, =20 int remote_target::remote_hostio_pread (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *remote_errno) + ULONGEST offset, fileio_error *remote_errno) { int ret; struct remote_state *rs =3D get_remote_state (); @@ -12508,7 +12508,7 @@ remote_target::remote_hostio_pread (int fd, gdb_byt= e *read_buf, int len, =20 int remote_target::fileio_pread (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *remote_errno) + ULONGEST offset, fileio_error *remote_errno) { return remote_hostio_pread (fd, read_buf, len, offset, remote_errno); } @@ -12516,7 +12516,7 @@ remote_target::fileio_pread (int fd, gdb_byte *read= _buf, int len, /* Implementation of to_fileio_close. */ =20 int -remote_target::remote_hostio_close (int fd, int *remote_errno) +remote_target::remote_hostio_close (int fd, fileio_error *remote_errno) { struct remote_state *rs =3D get_remote_state (); char *p =3D rs->buf.data (); @@ -12533,7 +12533,7 @@ remote_target::remote_hostio_close (int fd, int *re= mote_errno) } =20 int -remote_target::fileio_close (int fd, int *remote_errno) +remote_target::fileio_close (int fd, fileio_error *remote_errno) { return remote_hostio_close (fd, remote_errno); } @@ -12542,7 +12542,7 @@ remote_target::fileio_close (int fd, int *remote_er= rno) =20 int remote_target::remote_hostio_unlink (inferior *inf, const char *filename, - int *remote_errno) + fileio_error *remote_errno) { struct remote_state *rs =3D get_remote_state (); char *p =3D rs->buf.data (); @@ -12562,7 +12562,7 @@ remote_target::remote_hostio_unlink (inferior *inf,= const char *filename, =20 int remote_target::fileio_unlink (struct inferior *inf, const char *filename, - int *remote_errno) + fileio_error *remote_errno) { return remote_hostio_unlink (inf, filename, remote_errno); } @@ -12571,7 +12571,7 @@ remote_target::fileio_unlink (struct inferior *inf,= const char *filename, =20 gdb::optional remote_target::fileio_readlink (struct inferior *inf, const char *filename, - int *remote_errno) + fileio_error *remote_errno) { struct remote_state *rs =3D get_remote_state (); char *p =3D rs->buf.data (); @@ -12608,7 +12608,7 @@ remote_target::fileio_readlink (struct inferior *in= f, const char *filename, /* Implementation of to_fileio_fstat. */ =20 int -remote_target::fileio_fstat (int fd, struct stat *st, int *remote_errno) +remote_target::fileio_fstat (int fd, struct stat *st, fileio_error *remote= _errno) { struct remote_state *rs =3D get_remote_state (); char *p =3D rs->buf.data (); @@ -12680,7 +12680,8 @@ remote_target::filesystem_is_local () =20 if (ps =3D=3D PACKET_SUPPORT_UNKNOWN) { - int fd, remote_errno; + int fd; + fileio_error remote_errno; =20 /* Try opening a file to probe support. The supplied filename is irrelevant, we only care about whether @@ -12715,7 +12716,7 @@ remote_target::filesystem_is_local () } =20 static int -remote_fileio_errno_to_host (int errnum) +remote_fileio_errno_to_host (fileio_error errnum) { switch (errnum) { @@ -12766,7 +12767,7 @@ remote_fileio_errno_to_host (int errnum) } =20 static char * -remote_hostio_error (int errnum) +remote_hostio_error (fileio_error errnum) { int host_error =3D remote_fileio_errno_to_host (errnum); =20 @@ -12792,7 +12793,7 @@ public: { try { - int remote_errno; + fileio_error remote_errno; m_remote->remote_hostio_close (m_fd, &remote_errno); } catch (...) @@ -12843,7 +12844,8 @@ void remote_target::remote_file_put (const char *local_file, const char *remote= _file, int from_tty) { - int retcode, remote_errno, bytes, io_size; + int retcode, bytes, io_size; + fileio_error remote_errno; int bytes_in_buffer; int saw_eof; ULONGEST offset; @@ -12935,7 +12937,8 @@ void remote_target::remote_file_get (const char *remote_file, const char *local= _file, int from_tty) { - int remote_errno, bytes, io_size; + fileio_error remote_errno; + int bytes, io_size; ULONGEST offset; =20 scoped_remote_fd fd @@ -12993,7 +12996,8 @@ remote_file_delete (const char *remote_file, int fr= om_tty) void remote_target::remote_file_delete (const char *remote_file, int from_tty) { - int retcode, remote_errno; + int retcode; + fileio_error remote_errno; =20 retcode =3D remote_hostio_unlink (NULL, remote_file, &remote_errno); if (retcode =3D=3D -1) diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c index 7b6e99197ac..5e696579f1f 100644 --- a/gdb/sparc64-tdep.c +++ b/gdb/sparc64-tdep.c @@ -166,7 +166,7 @@ get_adi_info (pid_t pid) void sparc64_forget_process (pid_t pid) { - int target_errno; + fileio_error target_errno; =20 for (auto pit =3D adi_proc_list.before_begin (), it =3D std::next (pit); @@ -287,7 +287,7 @@ adi_tag_fd (void) =20 char cl_name[MAX_PROC_NAME_SIZE]; snprintf (cl_name, sizeof(cl_name), "/proc/%ld/adi/tags", (long) pid); - int target_errno; + fileio_error target_errno; proc->stat.tag_fd =3D target_fileio_open (NULL, cl_name, O_RDWR|O_EXCL, = false, 0, &target_errno); return proc->stat.tag_fd; @@ -350,7 +350,7 @@ adi_read_versions (CORE_ADDR vaddr, size_t size, gdb_by= te *tags) paddress (target_gdbarch (), vaddr * ast.blksize)); } =20 - int target_errno; + fileio_error target_errno; return target_fileio_pread (fd, tags, size, vaddr, &target_errno); } =20 @@ -371,7 +371,7 @@ adi_write_versions (CORE_ADDR vaddr, size_t size, unsig= ned char *tags) paddress (target_gdbarch (), vaddr * ast.blksize)); } =20 - int target_errno; + fileio_error target_errno; return target_fileio_pwrite (fd, tags, size, vaddr, &target_errno); } =20 diff --git a/gdb/target.c b/gdb/target.c index 9d698afb09d..28560983625 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -3206,7 +3206,7 @@ fileio_fd_to_fh (int fd) int target_ops::fileio_open (struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, - int *target_errno) + fileio_error *target_errno) { *target_errno =3D FILEIO_ENOSYS; return -1; @@ -3214,7 +3214,7 @@ target_ops::fileio_open (struct inferior *inf, const = char *filename, =20 int target_ops::fileio_pwrite (int fd, const gdb_byte *write_buf, int len, - ULONGEST offset, int *target_errno) + ULONGEST offset, fileio_error *target_errno) { *target_errno =3D FILEIO_ENOSYS; return -1; @@ -3222,21 +3222,21 @@ target_ops::fileio_pwrite (int fd, const gdb_byte *= write_buf, int len, =20 int target_ops::fileio_pread (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *target_errno) + ULONGEST offset, fileio_error *target_errno) { *target_errno =3D FILEIO_ENOSYS; return -1; } =20 int -target_ops::fileio_fstat (int fd, struct stat *sb, int *target_errno) +target_ops::fileio_fstat (int fd, struct stat *sb, fileio_error *target_er= rno) { *target_errno =3D FILEIO_ENOSYS; return -1; } =20 int -target_ops::fileio_close (int fd, int *target_errno) +target_ops::fileio_close (int fd, fileio_error *target_errno) { *target_errno =3D FILEIO_ENOSYS; return -1; @@ -3244,7 +3244,7 @@ target_ops::fileio_close (int fd, int *target_errno) =20 int target_ops::fileio_unlink (struct inferior *inf, const char *filename, - int *target_errno) + fileio_error *target_errno) { *target_errno =3D FILEIO_ENOSYS; return -1; @@ -3252,7 +3252,7 @@ target_ops::fileio_unlink (struct inferior *inf, cons= t char *filename, =20 gdb::optional target_ops::fileio_readlink (struct inferior *inf, const char *filename, - int *target_errno) + fileio_error *target_errno) { *target_errno =3D FILEIO_ENOSYS; return {}; @@ -3262,7 +3262,7 @@ target_ops::fileio_readlink (struct inferior *inf, co= nst char *filename, =20 int target_fileio_open (struct inferior *inf, const char *filename, - int flags, int mode, bool warn_if_slow, int *target_errno) + int flags, int mode, bool warn_if_slow, fileio_error *target_errno) { for (target_ops *t =3D default_fileio_target (); t !=3D NULL; t =3D t->b= eneath ()) { @@ -3296,15 +3296,15 @@ target_fileio_open (struct inferior *inf, const cha= r *filename, =20 int target_fileio_pwrite (int fd, const gdb_byte *write_buf, int len, - ULONGEST offset, int *target_errno) + ULONGEST offset, fileio_error *target_errno) { fileio_fh_t *fh =3D fileio_fd_to_fh (fd); int ret =3D -1; =20 if (fh->is_closed ()) - *target_errno =3D EBADF; + *target_errno =3D FILEIO_EBADF; else if (fh->target =3D=3D NULL) - *target_errno =3D EIO; + *target_errno =3D FILEIO_EIO; else ret =3D fh->target->fileio_pwrite (fh->target_fd, write_buf, len, offset, target_errno); @@ -3322,15 +3322,15 @@ target_fileio_pwrite (int fd, const gdb_byte *write= _buf, int len, =20 int target_fileio_pread (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *target_errno) + ULONGEST offset, fileio_error *target_errno) { fileio_fh_t *fh =3D fileio_fd_to_fh (fd); int ret =3D -1; =20 if (fh->is_closed ()) - *target_errno =3D EBADF; + *target_errno =3D FILEIO_EBADF; else if (fh->target =3D=3D NULL) - *target_errno =3D EIO; + *target_errno =3D FILEIO_EIO; else ret =3D fh->target->fileio_pread (fh->target_fd, read_buf, len, offset, target_errno); @@ -3347,15 +3347,15 @@ target_fileio_pread (int fd, gdb_byte *read_buf, in= t len, /* See target.h. */ =20 int -target_fileio_fstat (int fd, struct stat *sb, int *target_errno) +target_fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno) { fileio_fh_t *fh =3D fileio_fd_to_fh (fd); int ret =3D -1; =20 if (fh->is_closed ()) - *target_errno =3D EBADF; + *target_errno =3D FILEIO_EBADF; else if (fh->target =3D=3D NULL) - *target_errno =3D EIO; + *target_errno =3D FILEIO_EIO; else ret =3D fh->target->fileio_fstat (fh->target_fd, sb, target_errno); =20 @@ -3369,13 +3369,13 @@ target_fileio_fstat (int fd, struct stat *sb, int *= target_errno) /* See target.h. */ =20 int -target_fileio_close (int fd, int *target_errno) +target_fileio_close (int fd, fileio_error *target_errno) { fileio_fh_t *fh =3D fileio_fd_to_fh (fd); int ret =3D -1; =20 if (fh->is_closed ()) - *target_errno =3D EBADF; + *target_errno =3D FILEIO_EBADF; else { if (fh->target !=3D NULL) @@ -3397,7 +3397,7 @@ target_fileio_close (int fd, int *target_errno) =20 int target_fileio_unlink (struct inferior *inf, const char *filename, - int *target_errno) + fileio_error *target_errno) { for (target_ops *t =3D default_fileio_target (); t !=3D NULL; t =3D t->b= eneath ()) { @@ -3423,7 +3423,7 @@ target_fileio_unlink (struct inferior *inf, const cha= r *filename, =20 gdb::optional target_fileio_readlink (struct inferior *inf, const char *filename, - int *target_errno) + fileio_error *target_errno) { for (target_ops *t =3D default_fileio_target (); t !=3D NULL; t =3D t->b= eneath ()) { @@ -3461,7 +3461,7 @@ public: { if (m_fd >=3D 0) { - int target_errno; + fileio_error target_errno; =20 target_fileio_close (m_fd, &target_errno); } @@ -3493,7 +3493,7 @@ target_fileio_read_alloc_1 (struct inferior *inf, con= st char *filename, size_t buf_alloc, buf_pos; gdb_byte *buf; LONGEST n; - int target_errno; + fileio_error target_errno; =20 scoped_target_fd fd (target_fileio_open (inf, filename, FILEIO_O_RDONLY, 0700, false, &target_errno)); diff --git a/gdb/target.h b/gdb/target.h index 7e52716a9e8..0b784278c4f 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -81,6 +81,7 @@ struct inferior; #include "command.h" #include "disasm-flags.h" #include "tracepoint.h" +#include "gdbsupport/fileio.h" =20 #include "gdbsupport/break-common.h" /* For enum target_hw_bp_type. */ =20 @@ -952,28 +953,28 @@ struct target_ops *TARGET_ERRNO). */ virtual int fileio_open (struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, - int *target_errno); + fileio_error *target_errno); =20 /* Write up to LEN bytes from WRITE_BUF to FD on the target. Return the number of bytes written, or -1 if an error occurs (and set *TARGET_ERRNO). */ virtual int fileio_pwrite (int fd, const gdb_byte *write_buf, int len, - ULONGEST offset, int *target_errno); + ULONGEST offset, fileio_error *target_errno); =20 /* Read up to LEN bytes FD on the target into READ_BUF. Return the number of bytes read, or -1 if an error occurs (and set *TARGET_ERRNO). */ virtual int fileio_pread (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *target_errno); + ULONGEST offset, fileio_error *target_errno); =20 /* Get information about the file opened as FD and put it in SB. Return 0 on success, or -1 if an error occurs (and set *TARGET_ERRNO). */ - virtual int fileio_fstat (int fd, struct stat *sb, int *target_errno); + virtual int fileio_fstat (int fd, struct stat *sb, fileio_error *targe= t_errno); =20 /* Close FD on the target. Return 0, or -1 if an error occurs (and set *TARGET_ERRNO). */ - virtual int fileio_close (int fd, int *target_errno); + virtual int fileio_close (int fd, fileio_error *target_errno); =20 /* Unlink FILENAME on the target, in the filesystem as seen by INF. If INF is NULL, use the filesystem seen by the debugger @@ -981,7 +982,7 @@ struct target_ops -1 if an error occurs (and set *TARGET_ERRNO). */ virtual int fileio_unlink (struct inferior *inf, const char *filename, - int *target_errno); + fileio_error *target_errno); =20 /* Read value of symbolic link FILENAME on the target, in the filesystem as seen by INF. If INF is NULL, use the filesystem @@ -990,7 +991,7 @@ struct target_ops occurs (and set *TARGET_ERRNO). */ virtual gdb::optional fileio_readlink (struct inferior *i= nf, const char *filename, - int *target_errno); + fileio_error *target_errno); =20 /* Implement the "info proc" command. Returns true if the target actually implemented the command, false otherwise. */ @@ -2165,29 +2166,29 @@ extern bool target_filesystem_is_local (); extern int target_fileio_open (struct inferior *inf, const char *filename, int flags, int mode, bool warn_if_slow, - int *target_errno); + fileio_error *target_errno); =20 /* Write up to LEN bytes from WRITE_BUF to FD on the target. Return the number of bytes written, or -1 if an error occurs (and set *TARGET_ERRNO). */ extern int target_fileio_pwrite (int fd, const gdb_byte *write_buf, int le= n, - ULONGEST offset, int *target_errno); + ULONGEST offset, fileio_error *target_errno); =20 /* Read up to LEN bytes FD on the target into READ_BUF. Return the number of bytes read, or -1 if an error occurs (and set *TARGET_ERRNO). */ extern int target_fileio_pread (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *target_errno); + ULONGEST offset, fileio_error *target_errno); =20 /* Get information about the file opened as FD on the target and put it in SB. Return 0 on success, or -1 if an error occurs (and set *TARGET_ERRNO). */ extern int target_fileio_fstat (int fd, struct stat *sb, - int *target_errno); + fileio_error *target_errno); =20 /* Close FD on the target. Return 0, or -1 if an error occurs (and set *TARGET_ERRNO). */ -extern int target_fileio_close (int fd, int *target_errno); +extern int target_fileio_close (int fd, fileio_error *target_errno); =20 /* Unlink FILENAME on the target, in the filesystem as seen by INF. If INF is NULL, use the filesystem seen by the debugger (GDB or, @@ -2195,7 +2196,7 @@ extern int target_fileio_close (int fd, int *target_e= rrno); occurs (and set *TARGET_ERRNO). */ extern int target_fileio_unlink (struct inferior *inf, const char *filename, - int *target_errno); + fileio_error *target_errno); =20 /* Read value of symbolic link FILENAME on the target, in the filesystem as seen by INF. If INF is NULL, use the filesystem seen @@ -2203,7 +2204,7 @@ extern int target_fileio_unlink (struct inferior *inf, Return a null-terminated string allocated via xmalloc, or NULL if an error occurs (and set *TARGET_ERRNO). */ extern gdb::optional target_fileio_readlink - (struct inferior *inf, const char *filename, int *target_errno); + (struct inferior *inf, const char *filename, fileio_error *target_errn= o); =20 /* Read target file FILENAME, in the filesystem as seen by INF. If INF is NULL, use the filesystem seen by the debugger (GDB or, for diff --git a/gdbsupport/fileio.cc b/gdbsupport/fileio.cc index b4feb8583ab..db7c1a7c488 100644 --- a/gdbsupport/fileio.cc +++ b/gdbsupport/fileio.cc @@ -24,7 +24,7 @@ =20 /* See fileio.h. */ =20 -int +fileio_error host_to_fileio_error (int error) { switch (error) diff --git a/gdbsupport/fileio.h b/gdbsupport/fileio.h index 9809c162314..6a5297c6433 100644 --- a/gdbsupport/fileio.h +++ b/gdbsupport/fileio.h @@ -67,28 +67,32 @@ #define FILEIO_SEEK_END 2 =20 /* errno values */ -#define FILEIO_EPERM 1 -#define FILEIO_ENOENT 2 -#define FILEIO_EINTR 4 -#define FILEIO_EIO 5 -#define FILEIO_EBADF 9 -#define FILEIO_EACCES 13 -#define FILEIO_EFAULT 14 -#define FILEIO_EBUSY 16 -#define FILEIO_EEXIST 17 -#define FILEIO_ENODEV 19 -#define FILEIO_ENOTDIR 20 -#define FILEIO_EISDIR 21 -#define FILEIO_EINVAL 22 -#define FILEIO_ENFILE 23 -#define FILEIO_EMFILE 24 -#define FILEIO_EFBIG 27 -#define FILEIO_ENOSPC 28 -#define FILEIO_ESPIPE 29 -#define FILEIO_EROFS 30 -#define FILEIO_ENOSYS 88 -#define FILEIO_ENAMETOOLONG 91 -#define FILEIO_EUNKNOWN 9999 +enum fileio_error +{ + FILEIO_SUCCESS =3D 0, + FILEIO_EPERM =3D 1, + FILEIO_ENOENT =3D 2, + FILEIO_EINTR =3D 4, + FILEIO_EIO =3D 5, + FILEIO_EBADF =3D 9, + FILEIO_EACCES =3D 13, + FILEIO_EFAULT =3D 14, + FILEIO_EBUSY =3D 16, + FILEIO_EEXIST =3D 17, + FILEIO_ENODEV =3D 19, + FILEIO_ENOTDIR =3D 20, + FILEIO_EISDIR =3D 21, + FILEIO_EINVAL =3D 22, + FILEIO_ENFILE =3D 23, + FILEIO_EMFILE =3D 24, + FILEIO_EFBIG =3D 27, + FILEIO_ENOSPC =3D 28, + FILEIO_ESPIPE =3D 29, + FILEIO_EROFS =3D 30, + FILEIO_ENOSYS =3D 88, + FILEIO_ENAMETOOLONG =3D 91, + FILEIO_EUNKNOWN =3D 9999, +}; =20 #define FIO_INT_LEN 4 #define FIO_UINT_LEN 4 @@ -133,7 +137,7 @@ struct fio_timeval =20 /* Convert a host-format errno value to a File-I/O error number. */ =20 -extern int host_to_fileio_error (int error); +extern fileio_error host_to_fileio_error (int error); =20 /* Convert File-I/O open flags FFLAGS to host format, storing the result in *FLAGS. Return 0 on success, -1 on error. */