aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog13
-rw-r--r--gdb/ser-go32.c10
-rw-r--r--gdb/ser-unix.c31
-rw-r--r--gdb/serial.c11
-rw-r--r--gdb/serial.h39
5 files changed, 65 insertions, 39 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 46251b7..4d55718 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,16 @@
+Fri Apr 9 15:01:12 1993 Stu Grossman (grossman@cygnus.com)
+
+ * remote.c (remote_open): Use SERIAL_OPEN instead of serial_open.
+ (putpkt, getpkt): Use new return codes for SERIAL_READCHAR.
+ * ser-go32.c: Return -1 on most failures, 0 on most successes,
+ and use new return codes for go32_readchar().
+ * ser-unix.c: Ditto. Also, move error handling up to caller for
+ SERIAL_SETBAUDRATE().
+ * serial.c (serial_open): Internal call, not SERIAL_OPEN to get
+ to specific routine.
+ (serial_close): New routine to wrap around device close routine.
+ serial.h: Clean & document return values more clearly.
+
Fri Apr 9 10:20:55 1993 Jim Kingdon (kingdon@cygnus.com)
* rs6000-pinsn.c (print_operand): Deal with no operand instructions.
diff --git a/gdb/ser-go32.c b/gdb/ser-go32.c
index 844f861..1d930a8 100644
--- a/gdb/ser-go32.c
+++ b/gdb/ser-go32.c
@@ -222,7 +222,7 @@ go32_open (scb, name)
if (strncasecmp (name, "com", 3) != 0)
{
errno = ENOENT;
- return 1;
+ return -1;
}
port = name[3] - '0';
@@ -230,12 +230,12 @@ go32_open (scb, name)
if ((port != 1) && (port != 2))
{
errno = ENOENT;
- return 1;
+ return -11;
}
scb->fd = dos_async_init(port);
if (!scb->fd)
- return 1;
+ return -1;
return 0;
}
@@ -257,7 +257,7 @@ go32_readchar (scb, timeout)
if (dosasync_read(scb->fd, &buf, 1, timeout))
return buf;
else
- return -2; /* Timeout, I guess */
+ return SERIAL_TIMEOUT;
}
static int
@@ -275,6 +275,8 @@ go32_write (scb, str, len)
int len;
{
dosasync_write(scb->fd, str, len);
+
+ return 0;
}
static void
diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
index 541e4c2..afe6724 100644
--- a/gdb/ser-unix.c
+++ b/gdb/ser-unix.c
@@ -47,7 +47,7 @@ hardwire_open(scb, name)
{
scb->fd = open (name, O_RDWR);
if (scb->fd < 0)
- return errno;
+ return -1;
return 0;
}
@@ -145,17 +145,17 @@ hardwire_readchar(scb, timeout)
if (numfds <= 0)
if (numfds == 0)
- return -2; /* Timeout */
+ return SERIAL_TIMEOUT;
else
- return -3; /* Got an error from select */
+ return SERIAL_ERROR; /* Got an error from select */
scb->bufcnt = read(scb->fd, scb->buf, BUFSIZ);
if (scb->bufcnt <= 0)
if (scb->bufcnt == 0)
- return EOF; /* 0 chars means end of file */
+ return SERIAL_EOF; /* 0 chars means end of file */
else
- return -3; /* Got an error from read */
+ return SERIAL_ERROR; /* Got an error from read */
scb->bufcnt--;
scb->bufp = scb->buf;
@@ -220,24 +220,20 @@ hardwire_setbaudrate(scb, rate)
struct termios termios;
if (tcgetattr (scb->fd, &termios))
- error("hardwire_setbaudrate: tcgetattr failed: %s\n", safe_strerror(errno));
+ return -1;
cfsetospeed (&termios, rate_to_code (rate));
cfsetispeed (&termios, rate_to_code (rate));
if (tcsetattr (scb->fd, TCSANOW, &termios))
- error ("hardwire_setbaudrate: tcsetattr failed: %s\n", safe_strerror(errno));
-
- return 1;
+ return -1;
#endif
#ifdef HAVE_TERMIO
struct termio termio;
if (ioctl (scb->fd, TCGETA, &termio))
- {
- fprintf(stderr, "TCGETA failed: %s\n", safe_strerror(errno));
- }
+ return -1;
#ifndef CIBAUD
#define CIBAUD CBAUD
@@ -247,23 +243,22 @@ hardwire_setbaudrate(scb, rate)
termio.c_cflag |= rate_to_code (rate);
if (ioctl (scb->fd, TCSETA, &termio))
- {
- fprintf(stderr, "TCSETA failed: %s\n", safe_strerror(errno));
- }
+ return -1;
#endif
#ifdef HAVE_SGTTY
struct sgttyb sgttyb;
if (ioctl (scb->fd, TIOCGETP, &sgttyb))
- fprintf (stderr, "TIOCGETP failed: %s\n", safe_strerror (errno));
+ return -1;
sgttyb.sg_ispeed = rate_to_code (rate);
sgttyb.sg_ospeed = rate_to_code (rate);
if (ioctl (scb->fd, TIOCSETP, &sgttyb))
- fprintf (stderr, "TIOCSETP failed: %s\n", safe_strerror (errno));
+ return -1;
#endif
+ return 0;
}
static int
@@ -299,8 +294,6 @@ hardwire_close(scb)
if (scb->fd < 0)
return;
- SERIAL_RESTORE(scb);
-
close(scb->fd);
scb->fd = -1;
}
diff --git a/gdb/serial.c b/gdb/serial.c
index 5a4fcf4..e4c8cbf 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -64,7 +64,7 @@ serial_open(name)
scb->bufcnt = 0;
scb->bufp = scb->buf;
- if (SERIAL_OPEN (scb, name))
+ if (scb->ops->open(scb, name))
{
free (scb);
return NULL;
@@ -73,6 +73,15 @@ serial_open(name)
return scb;
}
+void
+serial_close(scb)
+ serial_t scb;
+{
+ scb->ops->close(scb);
+
+ free(scb);
+}
+
#if 0
/* Connect the user directly to the remote system. This command acts just like
the 'cu' or 'tip' command. Use <CR>~. or <CR>~^D to break out. */
diff --git a/gdb/serial.h b/gdb/serial.h
index 767a91b..1fbd488 100644
--- a/gdb/serial.h
+++ b/gdb/serial.h
@@ -49,38 +49,47 @@ struct serial_ops {
void serial_add_interface PARAMS ((struct serial_ops *optable));
-/* Try to open the serial device "name", returns a serial_t if ok, NULL if not.
- */
-
serial_t serial_open PARAMS ((const char *name));
-/* Internal open routine for specific I/O interface */
+/* For most routines, if a failure is indicated, then errno should be
+ examined. */
+
+/* Try to open NAME. Returns a new serial_t on success, NULL on failure.
+ */
-#define SERIAL_OPEN(SERIAL_T, NAME) (SERIAL_T)->ops->open((SERIAL_T), NAME)
+#define SERIAL_OPEN(NAME) serial_open(NAME)
-/* Turn the port into raw mode. */
+/* Turn the port into raw mode. */
#define SERIAL_RAW(SERIAL_T) (SERIAL_T)->ops->go_raw((SERIAL_T))
-/* Read one char from the serial device with <TO>-second timeout.
- Returns char if ok, else EOF, -2 for timeout, -3 for anything else */
+/* Read one char from the serial device with TIMEOUT seconds timeout.
+ Returns char if ok, else one of the following codes. Note that all
+ error codes are guaranteed to be < 0. */
+
+#define SERIAL_ERROR -1 /* General error, see errno for details */
+#define SERIAL_TIMEOUT -2
+#define SERIAL_EOF -3
#define SERIAL_READCHAR(SERIAL_T, TIMEOUT) ((SERIAL_T)->ops->readchar((SERIAL_T), TIMEOUT))
-/* Set the baudrate to the decimal value supplied. Return 1 on failure,
- 0 otherwise. */
+/* Set the baudrate to the decimal value supplied. Returns 0 for success,
+ -1 for failure. */
#define SERIAL_SETBAUDRATE(SERIAL_T, RATE) ((SERIAL_T)->ops->setbaudrate((SERIAL_T), RATE))
-/* Write some chars to the device, returns 0 for failure. See errno for
- details. */
+/* Write LEN chars from STRING to the port SERIAL_T. Returns 0 for success,
+ -1 for failure. */
#define SERIAL_WRITE(SERIAL_T, STRING, LEN) ((SERIAL_T)->ops->write((SERIAL_T), STRING, LEN))
-/* Close the serial port */
+/* Push out all buffers, close the device and destroy SERIAL_T. */
+
+void serial_close PARAMS ((serial_t));
-#define SERIAL_CLOSE(SERIAL_T) (SERIAL_T)->ops->close((SERIAL_T))
+#define SERIAL_CLOSE(SERIAL_T) serial_close(SERIAL_T)
-/* Restore the serial port to the state saved in oldstate */
+/* Restore the serial port to the state saved in oldstate. XXX - currently
+ unused! */
#define SERIAL_RESTORE(SERIAL_T) (SERIAL_T)->ops->restore((SERIAL_T))