int create_and_init_pair() { struct winsize size; int slavefd; pty_pair = pty_pair_create(); if (!pty_pair) { fprintf(stderr, "%s:%d Unable to create PTY pair", __FILE__, __LINE__); return -1; } slavefd = pty_pair_get_slavefd(pty_pair); if (slavefd == -1) { logger_write_pos(logger, __FILE__, __LINE__, "pty_pair_get_slavefd error"); return -1; } /* Set the pty winsize to the winsize of stdout */ if (ioctl(0, TIOCGWINSZ, &size) < 0) return -1; if (ioctl(slavefd, TIOCSWINSZ, &size) < 0) return -1; return 0; }
int a2_open_new_tty(struct annotate_two *a2, int *inferior_stdin, int *inferior_stdout) { close_inferior_connection(a2); a2->pty_pair = pty_pair_create(); if (!a2->pty_pair) { logger_write_pos(logger, __FILE__, __LINE__, "pty_pair_create failed"); return -1; } *inferior_stdin = pty_pair_get_masterfd(a2->pty_pair); *inferior_stdout = pty_pair_get_masterfd(a2->pty_pair); a2_set_inferior_tty(a2); return 0; }
int a2_open_new_tty(struct annotate_two *a2, int *inferior_stdin, int *inferior_stdout) { if (a2->pty_pair) pty_pair_destroy(a2->pty_pair); a2->pty_pair = pty_pair_create(); if (!a2->pty_pair) { logger_write_pos(logger, __FILE__, __LINE__, "pty_pair_create failed"); return -1; } *inferior_stdin = pty_pair_get_masterfd(a2->pty_pair); *inferior_stdout = pty_pair_get_masterfd(a2->pty_pair); commands_issue_command(a2, ANNOTATE_TTY, pty_pair_get_slavename(a2->pty_pair), 1); return 0; }
static int tgdb_open_new_tty(struct tgdb *tgdb, int *inferior_stdin, int *inferior_stdout) { if (tgdb->pty_pair) pty_pair_destroy(tgdb->pty_pair); tgdb->pty_pair = pty_pair_create(); if (!tgdb->pty_pair) { clog_error(CLOG_CGDB, "pty_pair_create failed"); return -1; } *inferior_stdin = pty_pair_get_masterfd(tgdb->pty_pair); *inferior_stdout = pty_pair_get_masterfd(tgdb->pty_pair); tgdb_request_ptr request_ptr; request_ptr = (tgdb_request_ptr)cgdb_malloc(sizeof (struct tgdb_request)); request_ptr->header = TGDB_REQUEST_TTY; request_ptr->choice.tty_command.slavename = pty_pair_get_slavename(tgdb->pty_pair); tgdb_run_or_queue_request(tgdb, request_ptr, true); return 0; }
int main(int argc, char **argv) { int gdb_fd, child_fd, slavefd, masterfd; #if 0 int c; read(0, &c, 1); #endif if (tty_cbreak(STDIN_FILENO, &term_attributes) == -1) logger_write_pos(logger, __FILE__, __LINE__, "tty_cbreak error"); pty_pair = pty_pair_create(); if (!pty_pair) { fprintf(stderr, "%s:%d Unable to create PTY pair", __FILE__, __LINE__); exit(-1); } slavefd = pty_pair_get_slavefd(pty_pair); if (slavefd == -1) { fprintf(stderr, "%s:%d Unable to get slavefd", __FILE__, __LINE__); exit(-1); } masterfd = pty_pair_get_masterfd(pty_pair); if (masterfd == -1) { fprintf(stderr, "%s:%d Unable to get masterfd", __FILE__, __LINE__); exit(-1); } if (tty_off_xon_xoff(masterfd) == -1) exit(-1); rline = rline_initialize(slavefd, rlctx_send_user_command, tab_completion, getenv("TERM")); if ((tgdb = tgdb_initialize(NULL, argc - 1, argv + 1, &gdb_fd, &child_fd)) == NULL) { logger_write_pos(logger, __FILE__, __LINE__, "tgdb_start error"); goto driver_end; } if (tgdb_set_verbose_error_handling(tgdb, 1) != 1) { logger_write_pos(logger, __FILE__, __LINE__, "driver error"); goto driver_end; } /* Ask TGDB to print error messages */ if (tgdb_set_verbose_gui_command_output(tgdb, 1) != 1) { logger_write_pos(logger, __FILE__, __LINE__, "driver error"); goto driver_end; } set_up_signal(); main_loop(gdb_fd, child_fd); if (tgdb_shutdown(tgdb) == -1) logger_write_pos(logger, __FILE__, __LINE__, "could not shutdown"); driver_end: if (tty_set_attributes(STDIN_FILENO, &term_attributes) == -1) logger_write_pos(logger, __FILE__, __LINE__, "tty_reset error"); return 0; }