[PATCH 6/6] Store remote fileio state in remote_state

Tom Tromey
2023-12-31T20:26:59Z

This removes the global 'remote_fio_data', moving it to remote_state.
This in turn lets each remote target manage its own file descriptors.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31189
---
gdb/remote-fileio.c | 16 ----------------
gdb/remote-fileio.h | 8 --------
gdb/remote.c | 8 +++++---
3 files changed, 5 insertions(+), 27 deletions(-)

diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c
index a954ab1bb55..14ca2ecca44 100644
--- a/gdb/remote-fileio.c
+++ b/gdb/remote-fileio.c
@@ -37,8 +37,6 @@
#endif
#include <signal.h>

-static remote_fileio_data remote_fio_data;
-
#define FIO_FD_INVALID -1
#define FIO_FD_CONSOLE_IN -2
#define FIO_FD_CONSOLE_OUT -3
@@ -1141,14 +1139,6 @@ remote_fileio_data::do_request (remote_target *remote, char *buf)
remote_fileio_reply (remote, -1, FILEIO_ENOSYS);
}

-/* Close any open descriptors, and reinitialize the file mapping. */
-
-void
-remote_fileio_reset ()
-{
- remote_fio_data.reset ();
-}
-
/* Handle a file I/O request. BUF points to the packet containing the
request. CTRLC_PENDING_P should be nonzero if the target has not
acknowledged the Ctrl-C sent asynchronously earlier. */
@@ -1193,12 +1183,6 @@ remote_fileio_data::request (remote_target *remote,

quit_handler = remote_fileio_o_quit_handler;
}
-
-void
-remote_fileio_request (remote_target *remote, char *buf, int ctrlc_pending_p)
-{
- remote_fio_data.request (remote, buf, ctrlc_pending_p);
-}
\f

/* Unpack an fio_uint_t. */
diff --git a/gdb/remote-fileio.h b/gdb/remote-fileio.h
index c632c9e40f8..295a4719436 100644
--- a/gdb/remote-fileio.h
+++ b/gdb/remote-fileio.h
@@ -65,14 +65,6 @@ struct remote_fileio_data
std::vector<int> m_fd_map;
};

-/* Unified interface to remote fileio, called in remote.c from
- remote_wait () and remote_async_wait (). */
-extern void remote_fileio_request (remote_target *remote,
- char *buf, int ctrlc_pending_p);
-
-/* Cleanup any remote fileio state. */
-extern void remote_fileio_reset (void);
-
/* Called from _initialize_remote (). */
extern void initialize_remote_fileio (
struct cmd_list_element **remote_set_cmdlist,
diff --git a/gdb/remote.c b/gdb/remote.c
index dcc1a0d0639..7409b014ea4 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -603,6 +603,9 @@ class remote_state
qSupported. */
gdb_thread_options supported_thread_options = 0;

+ /* Data needed for remote fileio. */
+ remote_fileio_data remote_fio;
+
private:
/* Asynchronous signal handle registered as event loop source for
when we have pending events ready to be passed to the core. */
@@ -4428,7 +4431,7 @@ remote_target::extended_remote_restart ()
xsnprintf (rs->buf.data (), get_remote_packet_size (), "R%x", 0);
putpkt (rs->buf);

- remote_fileio_reset ();
+ rs->remote_fio.reset ();
}
\f
/* Clean up connection to a remote debugger. */
@@ -6068,7 +6071,6 @@ remote_target::open_1 (const char *name, int from_tty, int extended_p)
/* Here the possibly existing remote target gets unpushed. */
target_preopen (from_tty);

- remote_fileio_reset ();
reopen_exec_file ();
reread_symbols (from_tty);

@@ -8602,7 +8604,7 @@ remote_target::wait_as (ptid_t ptid, target_waitstatus *status,
for a stop reply. See the comments in putpkt_binary. Set
waiting_for_stop_reply to 0 temporarily. */
rs->waiting_for_stop_reply = 0;
- remote_fileio_request (this, buf, rs->ctrlc_pending_p);
+ rs->remote_fio.request (this, buf, rs->ctrlc_pending_p);
rs->ctrlc_pending_p = 0;
/* GDB handled the File-I/O request, and the target is running
again. Keep waiting for events. */

--
2.43.0