int serial_readchar (struct serial *scb, int timeout) { int ch; /* FIXME: cagney/1999-10-11: Don't enable this check until the ASYNC code is finished. */ if (0 && serial_is_async_p (scb) && timeout < 0) internal_error (__FILE__, __LINE__, _("serial_readchar: blocking read in async mode")); ch = scb->ops->readchar (scb, timeout); if (serial_logfp != NULL) { serial_logchar (serial_logfp, 'r', ch, timeout); /* Make sure that the log file is as up-to-date as possible, in case we are getting ready to dump core or something. */ gdb_flush (serial_logfp); } if (serial_debug_p (scb)) { fprintf_unfiltered (gdb_stdlog, "["); serial_logchar (gdb_stdlog, 'r', ch, timeout); fprintf_unfiltered (gdb_stdlog, "]"); gdb_flush (gdb_stdlog); } return (ch); }
static void reschedule (struct serial *scb) { if (serial_is_async_p (scb)) { int next_state; switch (scb->async_state) { case FD_SCHEDULED: if (scb->bufcnt == 0) next_state = FD_SCHEDULED; else { delete_file_handler (scb->fd); next_state = create_timer (0, push_event, scb); } break; case NOTHING_SCHEDULED: if (scb->bufcnt == 0) { add_file_handler (scb->fd, fd_event, scb); next_state = FD_SCHEDULED; } else { next_state = create_timer (0, push_event, scb); } break; default: /* TIMER SCHEDULED */ if (scb->bufcnt == 0) { delete_timer (scb->async_state); add_file_handler (scb->fd, fd_event, scb); next_state = FD_SCHEDULED; } else next_state = scb->async_state; break; } if (serial_debug_p (scb)) { switch (next_state) { case FD_SCHEDULED: if (scb->async_state != FD_SCHEDULED) fprintf_unfiltered (gdb_stdlog, "[fd%d->fd-scheduled]\n", scb->fd); break; default: /* TIMER SCHEDULED */ if (scb->async_state == FD_SCHEDULED) fprintf_unfiltered (gdb_stdlog, "[fd%d->timer-scheduled]\n", scb->fd); break; } } scb->async_state = next_state; } }
static void ser_base_read_error_fd (struct serial *scb, int close_fd) { if (scb->error_fd != -1) { ssize_t s; char buf[GDB_MI_MSG_WIDTH + 1]; for (;;) { char *current; char *newline; int to_read = GDB_MI_MSG_WIDTH; int num_bytes = -1; if (scb->ops->avail) num_bytes = (scb->ops->avail)(scb, scb->error_fd); if (num_bytes != -1) to_read = (num_bytes < to_read) ? num_bytes : to_read; if (to_read == 0) break; s = read (scb->error_fd, &buf, to_read); if ((s == -1) || (s == 0 && !close_fd)) break; if (s == 0 && close_fd) { /* End of file. */ if (serial_is_async_p (scb)) delete_file_handler (scb->error_fd); close (scb->error_fd); scb->error_fd = -1; break; } /* In theory, embedded newlines are not a problem. But for MI, we want each output line to have just one newline for legibility. So output things in newline chunks. */ gdb_assert (s > 0 && s <= GDB_MI_MSG_WIDTH); buf[s] = '\0'; current = buf; while ((newline = strstr (current, "\n")) != NULL) { *newline = '\0'; fputs_unfiltered (current, gdb_stderr); fputs_unfiltered ("\n", gdb_stderr); current = newline + 1; } fputs_unfiltered (current, gdb_stderr); } } }