This is the mail archive of the
gdb-patches@sourceware.cygnus.com
mailing list for the GDB project.
RFC: serial_t->fd cleanup
- To: gdb-patches AT sourceware.cygnus dot com
- Subject: RFC: serial_t->fd cleanup
- From: Andrew Cagney <ac131313 AT cygnus dot com>
- Date: Tue, 14 Sep 1999 15:32:04 +1000
- DJ-Gateway: from newsgroup cygnus.patches.gdb
- Newsgroups: cygnus.patches.gdb
- Organization: Cygnus Solutions
Hello,
[Stan, note the question.]
GDB's serial code attempts to provide a fairly generic interface to
pipes, devices, sockets, etc to the main parts of GDB.
While the original serial code assumed a UNIX file-descriptor, that code
was recently updated (er, back in '92) with the more abstract serial_t.
Unfortunately, some code was never converted, and other code has again
found a need to directly access that FD. Interestingly, in the latter
case, that code is typically implementing a mini-event-loop. With the
introduction of event-loop.[hc] that code can finally be cleaned up.
The attached patch:
o defines DEPRECATED_SERIAL_FD().
I figured that the name might
discourage its use :-)
*Q.* is this a reasonable name?
I'm tempted to wrap the code in
#if ECREPIT_GDB
#endif
[sic]
o Replaces (hopefully) all uses of
scb->fd with DEPRECATED_SERIAL_FD()
and, in the process, fixed bugs in
remote-st.c and remote-os9k.c.
enjoy,
Andrew
PS: I'm tempted to make serial_t opaque :-)
Tue Sep 14 14:34:28 1999 Andrew Cagney <cagney@b1.cygnus.com>
* serial.h (DEPRECATED_SERIAL_FD): Define.
* serial.c (deprecated_serial_fd): New function.
* remote.c (remote_async_open_1, remote_async_open_1,
remote_async_detach, remote_async_kill,
extended_remote_async_create_inferior, minitelnet): Update.
* remote-es.c (es1800_open, es1800_close, es1800_transparent): Update.
* remote-st.c (connect_command), remote-os9k.c (connect_command):
Fix. Call FD_SET et.al. with FD instead of serial_t.
Index: ChangeLog
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/ChangeLog,v
retrieving revision 1.5416
diff -p -r1.5416 ChangeLog
*** ChangeLog 1999/09/14 03:43:25 1.5416
--- ChangeLog 1999/09/14 04:46:41
***************
*** 1,3 ****
--- 1,16 ----
+ Tue Sep 14 14:34:28 1999 Andrew Cagney <cagney@b1.cygnus.com>
+
+ * serial.h (DEPRECATED_SERIAL_FD): Define.
+ * serial.c (deprecated_serial_fd): New function.
+
+ * remote.c (remote_async_open_1, remote_async_open_1,
+ remote_async_detach, remote_async_kill,
+ extended_remote_async_create_inferior, minitelnet): Update.
+ * remote-es.c (es1800_open, es1800_close, es1800_transparent): Update.
+
+ * remote-st.c (connect_command), remote-os9k.c (connect_command):
+ Fix. Call FD_SET et.al. with FD instead of serial_t.
+
Tue Sep 14 12:37:33 1999 Andrew Cagney <cagney@b1.cygnus.com>
* serial.h (SERIAL_PRINT_TTY_STATE): Add STREAM parameter.
Index: remote-es.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/remote-es.c,v
retrieving revision 2.22
diff -p -r2.22 remote-es.c
*** remote-es.c 1999/07/07 23:51:42 2.22
--- remote-es.c 1999/09/14 04:46:45
*************** es1800_open (name, from_tty)
*** 360,373 ****
es1800_saved_ttystate = SERIAL_GET_TTY_STATE (es1800_desc);
! if ((fcflag = fcntl (es1800_desc->fd, F_GETFL, 0)) == -1)
{
perror_with_name ("fcntl serial");
}
es1800_fc_save = fcflag;
fcflag = (fcflag & (FREAD | FWRITE)); /* mask out any funny stuff */
! if (fcntl (es1800_desc->fd, F_SETFL, fcflag) == -1)
{
perror_with_name ("fcntl serial");
}
--- 360,373 ----
es1800_saved_ttystate = SERIAL_GET_TTY_STATE (es1800_desc);
! if ((fcflag = fcntl (DEPRECATED_SERIAL_FD (es1800_desc), F_GETFL, 0)) == -1)
{
perror_with_name ("fcntl serial");
}
es1800_fc_save = fcflag;
fcflag = (fcflag & (FREAD | FWRITE)); /* mask out any funny stuff */
! if (fcntl (DEPRECATED_SERIAL_FD (es1800_desc), F_SETFL, fcflag) == -1)
{
perror_with_name ("fcntl serial");
}
*************** es1800_close (quitting)
*** 470,476 ****
printf ("\nClosing connection to emulator...\n");
if (SERIAL_SET_TTY_STATE (es1800_desc, es1800_saved_ttystate) < 0)
print_sys_errmsg ("warning: unable to restore tty state", errno);
! fcntl (es1800_desc->fd, F_SETFL, es1800_fc_save);
SERIAL_CLOSE (es1800_desc);
es1800_desc = NULL;
}
--- 470,476 ----
printf ("\nClosing connection to emulator...\n");
if (SERIAL_SET_TTY_STATE (es1800_desc, es1800_saved_ttystate) < 0)
print_sys_errmsg ("warning: unable to restore tty state", errno);
! fcntl (DEPRECATED_SERIAL_FD (es1800_desc), F_SETFL, es1800_fc_save);
SERIAL_CLOSE (es1800_desc);
es1800_desc = NULL;
}
*************** es1800_transparent (args, from_tty)
*** 1876,1882 ****
perror_with_name ("ioctl console");
}
! if ((fcflag = fcntl (es1800_desc->fd, F_GETFL, 0)) == -1)
{
perror_with_name ("fcntl serial");
}
--- 1876,1882 ----
perror_with_name ("ioctl console");
}
! if ((fcflag = fcntl (DEPRECATED_SERIAL_FD (es1800_desc), F_GETFL, 0)) == -1)
{
perror_with_name ("fcntl serial");
}
*************** es1800_transparent (args, from_tty)
*** 1884,1890 ****
es1800_fc_save = fcflag;
fcflag = fcflag | FNDELAY;
! if (fcntl (es1800_desc->fd, F_SETFL, fcflag) == -1)
{
perror_with_name ("fcntl serial");
}
--- 1884,1890 ----
es1800_fc_save = fcflag;
fcflag = fcflag | FNDELAY;
! if (fcntl (DEPRECATED_SERIAL_FD (es1800_desc), F_SETFL, fcflag) == -1)
{
perror_with_name ("fcntl serial");
}
*************** es1800_transparent (args, from_tty)
*** 1920,1926 ****
perror_with_name ("FEL! read:");
}
! cc = read (es1800_desc->fd, inputbuf, inputcnt);
if (cc != -1)
{
for (i = 0; i < cc;)
--- 1920,1926 ----
perror_with_name ("FEL! read:");
}
! cc = read (DEPRECATED_SERIAL_FD (es1800_desc), inputbuf, inputcnt);
if (cc != -1)
{
for (i = 0; i < cc;)
*************** es1800_transparent (args, from_tty)
*** 1959,1965 ****
close (console);
! if (fcntl (es1800_desc->fd, F_SETFL, es1800_fc_save) == -1)
{
perror_with_name ("FEL! fcntl");
}
--- 1959,1965 ----
close (console);
! if (fcntl (DEPRECATED_SERIAL_FD (es1800_desc), F_SETFL, es1800_fc_save) == -1)
{
perror_with_name ("FEL! fcntl");
}
Index: remote-os9k.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/remote-os9k.c,v
retrieving revision 2.28
diff -p -r2.28 remote-os9k.c
*** remote-os9k.c 1999/09/01 00:16:02 2.28
--- remote-os9k.c 1999/09/14 04:46:48
*************** connect_command (args, fromtty)
*** 1074,1080 ****
do
{
FD_SET (0, &readfds);
! FD_SET (monitor_desc, &readfds);
numfds = select (sizeof (readfds) * 8, &readfds, 0, 0, 0);
}
while (numfds == 0);
--- 1074,1080 ----
do
{
FD_SET (0, &readfds);
! FD_SET (DEPRECATED_SERIAL_FD (monitor_desc), &readfds);
numfds = select (sizeof (readfds) * 8, &readfds, 0, 0, 0);
}
while (numfds == 0);
*************** connect_command (args, fromtty)
*** 1109,1115 ****
}
}
! if (FD_ISSET (monitor_desc, &readfds))
{
while (1)
{
--- 1109,1115 ----
}
}
! if (FD_ISSET (DEPRECATED_SERIAL_FD (monitor_desc), &readfds))
{
while (1)
{
Index: remote-st.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/remote-st.c,v
retrieving revision 2.20
diff -p -r2.20 remote-st.c
*** remote-st.c 1999/08/08 01:25:47 2.20
--- remote-st.c 1999/09/14 04:46:50
*************** connect_command (args, fromtty)
*** 729,735 ****
do
{
FD_SET (0, &readfds);
! FD_SET (st2000_desc, &readfds);
numfds = select (sizeof (readfds) * 8, &readfds, 0, 0, 0);
}
while (numfds == 0);
--- 729,735 ----
do
{
FD_SET (0, &readfds);
! FD_SET (DEPRECATED_SERIAL_FD (st2000_desc), &readfds);
numfds = select (sizeof (readfds) * 8, &readfds, 0, 0, 0);
}
while (numfds == 0);
*************** connect_command (args, fromtty)
*** 764,770 ****
}
}
! if (FD_ISSET (st2000_desc, &readfds))
{
while (1)
{
--- 764,770 ----
}
}
! if (FD_ISSET (DEPRECATED_SERIAL_FD (st2000_desc), &readfds))
{
while (1)
{
Index: remote.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/remote.c,v
retrieving revision 1.224
diff -p -r1.224 remote.c
*** remote.c 1999/09/13 20:59:07 1.224
--- remote.c 1999/09/14 04:46:59
*************** serial device is attached to the remote
*** 1842,1848 ****
file descriptor, the event loop will call fetch_inferior_event,
which will do the proper analysis to determine what happened. */
if (async_p)
! add_file_handler (remote_desc->fd, fetch_inferior_event, 0);
push_target (target); /* Switch to using remote target now */
--- 1842,1848 ----
file descriptor, the event loop will call fetch_inferior_event,
which will do the proper analysis to determine what happened. */
if (async_p)
! add_file_handler (DEPRECATED_SERIAL_FD (remote_desc), fetch_inferior_event, 0);
push_target (target); /* Switch to using remote target now */
*************** serial device is attached to the remote
*** 1879,1885 ****
{
/* Unregister the file descriptor from the event loop. */
if (async_p)
! delete_file_handler (remote_desc->fd);
pop_target ();
return;
}
--- 1879,1885 ----
{
/* Unregister the file descriptor from the event loop. */
if (async_p)
! delete_file_handler (DEPRECATED_SERIAL_FD (remote_desc));
pop_target ();
return;
}
*************** remote_async_detach (args, from_tty)
*** 1950,1956 ****
/* Unregister the file descriptor from the event loop. */
if (async_p)
! delete_file_handler (remote_desc->fd);
pop_target ();
if (from_tty)
--- 1950,1956 ----
/* Unregister the file descriptor from the event loop. */
if (async_p)
! delete_file_handler (DEPRECATED_SERIAL_FD (remote_desc));
pop_target ();
if (from_tty)
*************** remote_async_kill ()
*** 3757,3763 ****
{
/* Unregister the file descriptor from the event loop. */
if (async_p)
! delete_file_handler (remote_desc->fd);
/* For some mysterious reason, wait_for_inferior calls kill instead of
mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
--- 3757,3763 ----
{
/* Unregister the file descriptor from the event loop. */
if (async_p)
! delete_file_handler (DEPRECATED_SERIAL_FD (remote_desc));
/* For some mysterious reason, wait_for_inferior calls kill instead of
mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
*************** extended_remote_async_create_inferior (e
*** 3856,3862 ****
/* If running asynchronously, register the target file descriptor
with the event loop. */
if (async_p)
! add_file_handler (remote_desc->fd, fetch_inferior_event, 0);
/* Now restart the remote server. */
extended_remote_restart ();
--- 3856,3862 ----
/* If running asynchronously, register the target file descriptor
with the event loop. */
if (async_p)
! add_file_handler (DEPRECATED_SERIAL_FD (remote_desc), fetch_inferior_event, 0);
/* Now restart the remote server. */
extended_remote_restart ();
*************** minitelnet ()
*** 4940,4946 ****
FD_ZERO (&input);
FD_SET (fileno (stdin), &input);
! FD_SET (remote_desc->fd, &input);
status = select (tablesize, &input, 0, 0, 0);
if ((status == -1) && (errno != EINTR))
--- 4940,4946 ----
FD_ZERO (&input);
FD_SET (fileno (stdin), &input);
! FD_SET (DEPRECATED_SERIAL_FD (remote_desc), &input);
status = select (tablesize, &input, 0, 0, 0);
if ((status == -1) && (errno != EINTR))
Index: serial.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/serial.c,v
retrieving revision 2.36
diff -p -r2.36 serial.c
*** serial.c 1999/09/14 04:18:06 2.36
--- serial.c 1999/09/14 04:46:59
*************** serial_setstopbits (serial_t scb, int nu
*** 442,447 ****
--- 442,459 ----
return scb->ops->setstopbits (scb, num);
}
+ int
+ deprecated_serial_fd (serial_t scb)
+ {
+ /* FIXME: should this output a warning that deprecated code is being
+ called? */
+ if (scb->fd < 0)
+ {
+ internal_error ("serial: FD not valid");
+ }
+ return scb->fd; /* sigh */
+ }
+
#if 0
/*
The connect command is #if 0 because I hadn't thought of an elegant
Index: serial.h
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/serial.h,v
retrieving revision 2.36
diff -p -r2.36 serial.h
*** serial.h 1999/09/14 04:18:06 2.36
--- serial.h 1999/09/14 04:46:59
*************** extern int serial_setbaudrate (serial_t
*** 196,201 ****
--- 196,209 ----
extern int serial_setstopbits (serial_t scb, int num);
#define SERIAL_SETSTOPBITS(SERIAL_T, NUM) serial_setstopbits ((SERIAL_T), (NUM))
+ /* Provide direct access to the underlying FD (if any) used to
+ implement the serial device. This interface is clearly
+ deprecated. Will call internal_error() if the operation isn't
+ applicable to the current serial device. */
+
+ extern int deprecated_serial_fd (serial_t scb);
+ #define DEPRECATED_SERIAL_FD(SERIAL_T) deprecated_serial_fd ((SERIAL_T))
+
/* File in which to record the remote debugging session */
extern void serial_log_command (const char *);