26 #include <sys/types.h>
28 #include <sys/socket.h>
44 static int serial_hwflow;
46 show_serial_hwflow (
struct ui_file *file,
int from_tty,
122 if (tcgetattr (scb->
fd, &state->
termios) < 0)
129 if (ioctl (scb->
fd, TCGETA, &state->termio) < 0)
135 if (ioctl (scb->
fd, TIOCGETP, &state->sgttyb) < 0)
137 if (ioctl (scb->
fd, TIOCGETC, &state->tc) < 0)
139 if (ioctl (scb->
fd, TIOCGLTC, &state->ltc) < 0)
141 if (ioctl (scb->
fd, TIOCLGET, &state->lmode) < 0)
152 if (tcsetattr (scb->
fd, TCSANOW, &state->
termios) < 0)
159 if (ioctl (scb->
fd, TCSETA, &state->termio) < 0)
165 if (ioctl (scb->
fd, TIOCSETN, &state->sgttyb) < 0)
167 if (ioctl (scb->
fd, TIOCSETC, &state->tc) < 0)
169 if (ioctl (scb->
fd, TIOCSLTC, &state->ltc) < 0)
171 if (ioctl (scb->
fd, TIOCLSET, &state->lmode) < 0)
232 if (state->sgttyb.sg_flags & RAW)
233 new_state.sgttyb.sg_flags |= RAW;
235 new_state.sgttyb.sg_flags &= ~RAW;
239 if (state->sgttyb.sg_flags & CBREAK)
240 new_state.sgttyb.sg_flags |= CBREAK;
242 new_state.sgttyb.sg_flags &= ~CBREAK;
269 for (i = 0; i < NCCS; i += 1)
276 state->termio.c_iflag, state->termio.c_oflag);
277 fprintf_filtered (stream,
"c_cflag = 0x%x, c_lflag = 0x%x, c_line = 0x%x.\n",
278 state->termio.c_cflag, state->termio.c_lflag,
279 state->termio.c_line);
281 for (i = 0; i < NCC; i += 1)
288 state->sgttyb.sg_flags);
291 for (i = 0; i < (
int)
sizeof (
struct tchars); i++)
296 for (i = 0; i < (
int)
sizeof (
struct ltchars); i++)
311 return tcdrain (scb->
fd);
315 return ioctl (scb->
fd, TCSBRK, 1);
331 return (ioctl (scb->
fd, TIOCSETP, &state.sgttyb));
341 return tcflush (scb->
fd, TCOFLUSH);
345 return ioctl (scb->
fd, TCFLSH, 1);
350 return ioctl (scb->
fd, TIOCFLUSH, 0);
360 return tcflush (scb->
fd, TCIFLUSH);
364 return ioctl (scb->
fd, TCFLSH, 0);
369 return ioctl (scb->
fd, TIOCFLUSH, 0);
377 return tcsendbreak (scb->
fd, 0);
381 return ioctl (scb->
fd, TCSBRK, 0);
388 status = ioctl (scb->
fd, TIOCSBRK, 0);
394 status = ioctl (scb->
fd, TIOCCBRK, 0);
413 state.
termios.c_cflag &= ~CSIZE;
414 state.
termios.c_cflag |= CLOCAL | CS8;
418 state.
termios.c_cflag |= CRTSCTS;
420 state.
termios.c_cflag &= ~CRTSCTS;
423 state.
termios.c_cflag |= CRTS_IFLOW;
425 state.
termios.c_cflag &= ~CRTS_IFLOW;
433 state.termio.c_iflag = 0;
434 state.termio.c_oflag = 0;
435 state.termio.c_lflag = 0;
436 state.termio.c_cflag &= ~CSIZE;
437 state.termio.c_cflag |= CLOCAL | CS8;
438 state.termio.c_cc[VMIN] = 0;
439 state.termio.c_cc[VTIME] = 0;
443 state.sgttyb.sg_flags |= RAW | ANYP;
444 state.sgttyb.sg_flags &= ~(CBREAK |
ECHO);
487 FD_SET (scb->
fd, &readfds);
497 else if (errno == EINTR)
506 #if defined HAVE_TERMIO || defined HAVE_TERMIOS
529 state.
termios.c_cc[VTIME] = timeout * 10;
530 if (state.
termios.c_cc[VTIME] != timeout * 10)
548 state.termio.c_cc[VTIME] = 0;
549 state.termio.c_cc[VMIN] = 1;
553 state.termio.c_cc[VMIN] = 0;
554 state.termio.c_cc[VTIME] = timeout * 10;
555 if (state.termio.c_cc[VTIME] != timeout * 10)
609 delta = (timeout == 0 ? 0 : 1);
632 status =
read (scb->
fd, scb->
buf, BUFSIZ);
650 else if (errno == EINTR)
783 for (i = 0;
baudtab[i].rate != -1; i++)
796 "Closest values are %d and %d."),
801 warning (
_(
"Invalid baud rate %d. Minimum value is %d."),
810 warning (
_(
"Invalid baud rate %d. Maximum value is %d."),
833 cfsetospeed (&state.
termios, baud_code);
834 cfsetispeed (&state.
termios, baud_code);
842 state.termio.c_cflag &= ~(CBAUD | CIBAUD);
843 state.termio.c_cflag |= baud_code;
847 state.sgttyb.sg_ispeed = baud_code;
848 state.sgttyb.sg_ospeed = baud_code;
878 state.
termios.c_cflag &= ~CSTOPB;
880 state.
termios.c_cflag |= CSTOPB;
885 state.termio.c_cflag &= ~CSTOPB;
887 state.termio.c_cflag |= CSTOPB;
914 newparity = PARENB | PARODD;
921 "Incorrect parity value: %d", parity);
926 state.
termios.c_cflag &= ~(PARENB | PARODD);
927 state.
termios.c_cflag |= newparity;
931 state.termio.c_cflag &= ~(PARENB | PARODD);
932 state.termio.c_cflag |= newparity;
994 Set use of hardware flow control for remote serial I/O."),
_(
"\
995 Show use of hardware flow control for remote serial I/O."),
_(
"\
996 Enable or disable hardware flow control (RTS/CTS) on the serial port\n\
997 when debugging using remote targets."),
1012 status =
read (scb->
fd, scb->
buf, count);
1013 if (status != -1 || errno != EINTR)
1024 return write (scb->
fd, buf, len);
ssize_t read(int fd, void *buf, size_t count)
int generic_readchar(struct serial *scb, int timeout, int(do_readchar)(struct serial *scb, int timeout))
static void hardwire_close(struct serial *scb)
static int hardwire_readchar(struct serial *scb, int timeout)
static int hardwire_setstopbits(struct serial *, int)
static int set_tty_state(struct serial *scb, struct hardwire_ttystate *state)
static int hardwire_drain_output(struct serial *)
void warning(const char *fmt,...)
static int wait_for(struct serial *scb, int timeout)
int ser_unix_write_prim(struct serial *scb, const void *buf, size_t len)
static serial_ttystate hardwire_get_tty_state(struct serial *scb)
int ser_unix_read_prim(struct serial *scb, size_t count)
static serial_ttystate hardwire_copy_tty_state(struct serial *scb, serial_ttystate ttystate)
void ser_base_async(struct serial *scb, int async_p)
struct cmd_list_element * setlist
static int hardwire_setbaudrate(struct serial *scb, int rate)
static int hardwire_setparity(struct serial *scb, int parity)
void fprintf_filtered(struct ui_file *stream, const char *format,...)
static int hardwire_flush_output(struct serial *)
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int status
static int hardwire_noflush_set_tty_state(struct serial *, serial_ttystate, serial_ttystate)
struct cmd_list_element * showlist
static int hardwire_send_break(struct serial *)
int(* write)(struct serial *, const void *buf, size_t count)
static const char * parity
int gdb_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
static int hardwire_set_tty_state(struct serial *scb, serial_ttystate state)
unsigned char buf[BUFSIZ]
static int hardwire_open(struct serial *scb, const char *name)
#define SERIAL_1_AND_A_HALF_STOPBITS
static int hardwire_flush_input(struct serial *)
#define SERIAL_1_STOPBITS
const char const char int
#define SERIAL_2_STOPBITS
void serial_add_interface(const struct serial_ops *optable)
static struct @148 baudtab[]
struct ui_file * gdb_stderr
int ser_base_flush_input(struct serial *scb)
char * safe_strerror(int)
int ser_base_write(struct serial *scb, const void *buf, size_t count)
int gdb_open_cloexec(const char *filename, int flags, unsigned long mode)
void _initialize_ser_hardwire(void)
static void hardwire_print_tty_state(struct serial *, serial_ttystate, struct ui_file *)
static int do_hardwire_readchar(struct serial *scb, int timeout)
void internal_warning(const char *file, int line, const char *fmt,...)
static void hardwire_raw(struct serial *scb)
static int get_tty_state(struct serial *scb, struct hardwire_ttystate *state)
static int rate_to_code(int rate)
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
int(* deprecated_ui_loop_hook)(int signo)
const ULONGEST const LONGEST len