#include #include #include #include #include #include void get_output (int fd); int main () { int master; pid_t pid; if ((pid = forkpty (&master, NULL, NULL, NULL)) < 0) { perror ("forkpty"); exit (1); } /* child */ if (pid == 0) { char *argv[3]; argv[0] = "gdb"; argv[1] = "-i=mi"; argv[2] = '\0'; execvp (argv[0], argv); /* shouldn't get here */ exit (1); } /* parent */ char *input[10]; input[0] = "1-inferior-tty-set /dev/pty3\n"; input[1] = "2-gdb-set height 0\n"; input[2] = "3-gdb-set non-stop 1\n"; input[3] = "4-file-list-exec-source-files\n"; input[4] = "5-file-list-exec-source-file\n"; input[5] = "6-gdb-show prompt\n"; input[6] = "7-stack-info-frame\n"; input[7] = "8-thread-info\n"; input[8] = "9-break-list\n"; input[9] = "q\n"; int i; for (i = 0; i < 10; ++i) write (master, input[i], strlen (input[i])); get_output (master); wait (NULL); } void get_output (int fd) { #define BUFSIZE 1024 char buf[BUFSIZE]; int i; for (i = 0; i < 10; ++i) { int nread; nread = read (fd, buf, BUFSIZE); if (nread > 0) write (STDOUT_FILENO, buf, nread); else { printf ("No more output.\n"); break; } } }