From 7edb51d4cc34b6683562170428b5d31bfbe5d6f4 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Fri, 6 Sep 2002 03:39:19 +0000 Subject: [PATCH] Add support to create a pseudo master terminal for the debugger. --- .../library/.cvsignore | 1 + .../library/Makefile | 25 ++++- core/org.eclipse.cdt.core.linux/library/PTY.h | 21 ++++ .../library/PTYInputStream.h | 32 ++++++ .../library/PTYOutputStream.h | 29 +++++ .../library/openpty.c | 105 ++++++++++++++++++ .../library/openpty.h | 10 ++ core/org.eclipse.cdt.core.linux/library/pty.c | 36 ++++++ .../library/ptyio.c | 103 +++++++++++++++++ .../os/linux/x86/libpty.so | Bin 0 -> 9320 bytes .../eclipse/cdt/debug/mi/core/MIInferior.java | 11 +- .../eclipse/cdt/debug/mi/core/MIPlugin.java | 32 ++++-- .../eclipse/cdt/debug/mi/core/MISession.java | 16 ++- 13 files changed, 402 insertions(+), 19 deletions(-) create mode 100644 core/org.eclipse.cdt.core.linux/library/.cvsignore create mode 100644 core/org.eclipse.cdt.core.linux/library/PTY.h create mode 100644 core/org.eclipse.cdt.core.linux/library/PTYInputStream.h create mode 100644 core/org.eclipse.cdt.core.linux/library/PTYOutputStream.h create mode 100644 core/org.eclipse.cdt.core.linux/library/openpty.c create mode 100644 core/org.eclipse.cdt.core.linux/library/openpty.h create mode 100644 core/org.eclipse.cdt.core.linux/library/pty.c create mode 100644 core/org.eclipse.cdt.core.linux/library/ptyio.c create mode 100644 core/org.eclipse.cdt.core.linux/os/linux/x86/libpty.so diff --git a/core/org.eclipse.cdt.core.linux/library/.cvsignore b/core/org.eclipse.cdt.core.linux/library/.cvsignore new file mode 100644 index 00000000000..5761abcfdf0 --- /dev/null +++ b/core/org.eclipse.cdt.core.linux/library/.cvsignore @@ -0,0 +1 @@ +*.o diff --git a/core/org.eclipse.cdt.core.linux/library/Makefile b/core/org.eclipse.cdt.core.linux/library/Makefile index 5f6639b0a00..4c971acb856 100644 --- a/core/org.eclipse.cdt.core.linux/library/Makefile +++ b/core/org.eclipse.cdt.core.linux/library/Makefile @@ -5,14 +5,27 @@ JDK_INCLUDES=/usr/local/jdk/include JDK_OS_INCLUDES=/usr/local/jdk/include/linux CC=gcc -LIB_NAME = libspawner.so -LIB_NAME_FULL = ../os/linux/x86/libspawner.so -OBJS=spawner.o io.o exec_unix.o pfind.o CPPFLAGS = -I. -I$(JDK_INCLUDES) -I$(JDK_OS_INCLUDES) CFLAGS +=-fpic -D_REENTRANT -spawner : $(OBJS) - $(CC) -g -shared -Wl,-soname,$(LIB_NAME) -o $(LIB_NAME_FULL) $(OBJS) -lc +LIB_NAME_SPAWNER = libspawner.so +LIB_NAME_FULL_SPAWNER = ../os/linux/x86/libspawner.so +OBJS_SPAWNER=spawner.o io.o exec_unix.o pfind.o + +LIB_NAME_PTY = libpty.so +LIB_NAME_FULL_PTY = ../os/linux/x86/libpty.so +OBJS_PTY= openpty.o pty.o ptyio.o + +OBJS = $(OBJS_SPAWNER) $(OBJS_PTY) + +all: $(LIB_NAME_FULL_SPAWNER) $(LIB_NAME_FULL_PTY) + +$(LIB NAME_FULL_SPAWNER) : $(OBJS_SPAWNER) + $(CC) -g -shared -Wl,-soname,$(LIB_NAME_SPAWNER) -o $(LIB_NAME_FULL_SPAWNER) $(OBJS_SPAWNER) -lc + +$(LIB_NAME_FULL_PTY): $(OBJS_PTY) + $(CC) -g -shared -Wl,-soname,$(LIB_NAME_PTY) -o $(LIB_NAME_FULL_PTY) $(OBJS_PTY) clean : - rm $(OBJS) + echo -rm $(OBJS_SPAWNER) $(LIB_NAME_FULL_SPAWNER) + -rm $(OBJS_PTY) $(LIB_NAME_FULL_PTY) diff --git a/core/org.eclipse.cdt.core.linux/library/PTY.h b/core/org.eclipse.cdt.core.linux/library/PTY.h new file mode 100644 index 00000000000..fabf58152d0 --- /dev/null +++ b/core/org.eclipse.cdt.core.linux/library/PTY.h @@ -0,0 +1,21 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_eclipse_cdt_utils_pty_PTY */ + +#ifndef _Included_org_eclipse_cdt_utils_pty_PTY +#define _Included_org_eclipse_cdt_utils_pty_PTY +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_eclipse_cdt_utils_pty_PTY + * Method: forkpty + * Signature: ()I + */ +JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_pty_PTY_forkpty + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/core/org.eclipse.cdt.core.linux/library/PTYInputStream.h b/core/org.eclipse.cdt.core.linux/library/PTYInputStream.h new file mode 100644 index 00000000000..e7349272b56 --- /dev/null +++ b/core/org.eclipse.cdt.core.linux/library/PTYInputStream.h @@ -0,0 +1,32 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_eclipse_cdt_utils_pty_PTYInputStream */ + +#ifndef _Included_org_eclipse_cdt_utils_pty_PTYInputStream +#define _Included_org_eclipse_cdt_utils_pty_PTYInputStream +#ifdef __cplusplus +extern "C" { +#endif +#undef org_eclipse_cdt_utils_pty_PTYInputStream_SKIP_BUFFER_SIZE +#define org_eclipse_cdt_utils_pty_PTYInputStream_SKIP_BUFFER_SIZE 2048L +/* Inaccessible static: skipBuffer */ +/* + * Class: org_eclipse_cdt_utils_pty_PTYInputStream + * Method: read0 + * Signature: (I[BI)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_pty_PTYInputStream_read0 + (JNIEnv *, jobject, jint, jbyteArray, jint); + +/* + * Class: org_eclipse_cdt_utils_pty_PTYInputStream + * Method: close0 + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_pty_PTYInputStream_close0 + (JNIEnv *, jobject, jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/core/org.eclipse.cdt.core.linux/library/PTYOutputStream.h b/core/org.eclipse.cdt.core.linux/library/PTYOutputStream.h new file mode 100644 index 00000000000..fb28491060e --- /dev/null +++ b/core/org.eclipse.cdt.core.linux/library/PTYOutputStream.h @@ -0,0 +1,29 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_eclipse_cdt_utils_pty_PTYOutputStream */ + +#ifndef _Included_org_eclipse_cdt_utils_pty_PTYOutputStream +#define _Included_org_eclipse_cdt_utils_pty_PTYOutputStream +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_eclipse_cdt_utils_pty_PTYOutputStream + * Method: write0 + * Signature: (I[BI)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_pty_PTYOutputStream_write0 + (JNIEnv *, jobject, jint, jbyteArray, jint); + +/* + * Class: org_eclipse_cdt_utils_pty_PTYOutputStream + * Method: close0 + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_pty_PTYOutputStream_close0 + (JNIEnv *, jobject, jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/core/org.eclipse.cdt.core.linux/library/openpty.c b/core/org.eclipse.cdt.core.linux/library/openpty.c new file mode 100644 index 00000000000..28f5363cf1d --- /dev/null +++ b/core/org.eclipse.cdt.core.linux/library/openpty.c @@ -0,0 +1,105 @@ +/* + * (c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/** + * This is taken from R. W. Stevens book. + * Alain Magloire. + */ + +int ptym_open (char *pts_name); +int ptys_open (int fdm, char * pts_name); + +int +openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize *winp) +{ + char line[20]; + line[0]=0; + *amaster = ptym_open(line); + if (*amaster < 0) + return -1; + *aslave = ptys_open(*amaster, line); + if (*aslave < 0) { + close(*amaster); + return -1; + } + if (name) + strcpy(name, line); +#ifndef TCSAFLUSH +#define TCSAFLUSH TCSETAF +#endif + if (termp) + (void) tcsetattr(*aslave, TCSAFLUSH, termp); +#ifdef TIOCSWINSZ + if (winp) + (void) ioctl(*aslave, TIOCSWINSZ, (char *)winp); +#endif + return 0; +} + +int +ptym_open(char * pts_name) +{ + int fdm; + char *ptr; + + strcpy(pts_name, "/dev/ptmx"); + fdm = getpt(); + if (fdm < 0) + return -1; + if (grantpt(fdm) < 0) { /* grant access to slave */ + close(fdm); + return -2; + } + if (unlockpt(fdm) < 0) { /* clear slave's lock flag */ + close(fdm); + return -3; + } + ptr = ptsname(fdm); + if (ptr == NULL) { /* get slave's name */ + close (fdm); + return -4; + } + strcpy(pts_name, ptr); /* return name of slave */ + return fdm; /* return fd of master */ +} + +int +ptys_open(int fdm, char * pts_name) +{ + int fds; + /* following should allocate controlling terminal */ + fds = open(pts_name, O_RDWR); + if (fds < 0) { + close(fdm); + return -5; + } + if (ioctl(fds, I_PUSH, "ptem") < 0) { + printf("pterm:%s\n", strerror(errno)); + close(fdm); + close(fds); + return -6; + } + if (ioctl(fds, I_PUSH, "ldterm") < 0) { + printf("ldterm %s\n", strerror(errno)); + close(fdm); + close(fds); + return -7; + } + return fds; +} diff --git a/core/org.eclipse.cdt.core.linux/library/openpty.h b/core/org.eclipse.cdt.core.linux/library/openpty.h new file mode 100644 index 00000000000..fd7b7be1b2f --- /dev/null +++ b/core/org.eclipse.cdt.core.linux/library/openpty.h @@ -0,0 +1,10 @@ +/* + * (c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + * + */ +#ifndef _OPENPTY_H +#define _OPENPTY_H +int ptym_open (char *pts_name); +int ptys_open (int fdm, char * pts_name); +#endif diff --git a/core/org.eclipse.cdt.core.linux/library/pty.c b/core/org.eclipse.cdt.core.linux/library/pty.c new file mode 100644 index 00000000000..3e1c55f123b --- /dev/null +++ b/core/org.eclipse.cdt.core.linux/library/pty.c @@ -0,0 +1,36 @@ +#include "PTY.h" +#include "openpty.h" + +/* + * Class: org_eclipse_cdt_utils_pty_PTY + * Method: forkpty + * Signature: ()I + */ +JNIEXPORT jstring JNICALL +Java_org_eclipse_cdt_utils_pty_PTY_forkpty (JNIEnv *env, jobject jobj) { + jfieldID fid; /* Store the field ID */ + jstring jstr = NULL; + int master = -1; + char line[1024]; /* FIXME: Should be enough */ + int err; + jclass cls; + + line[0] = '\0'; + + master = ptym_open(line); + if (err >= 0) { + /* Get a reference to the obj's class */ + cls = (*env)->GetObjectClass(env, jobj); + + /* Set the master fd. */ + fid = (*env)->GetFieldID(env, cls, "master", "I"); + if (fid == NULL) { + return NULL; + } + (*env)->SetIntField(env, jobj, fid, (jint)master); + + /* Create a new String for the slave. */ + jstr = (*env)->NewStringUTF(env, line); + } + return jstr; +} diff --git a/core/org.eclipse.cdt.core.linux/library/ptyio.c b/core/org.eclipse.cdt.core.linux/library/ptyio.c new file mode 100644 index 00000000000..fbf4b314dcf --- /dev/null +++ b/core/org.eclipse.cdt.core.linux/library/ptyio.c @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include + +/* Header for class _org_eclipse_cdt_utils_pty_PTYInputStream */ +/* Header for class _org_eclipse_cdt_utils_pty_PTYOutputStream */ + +/* + * Class: org_eclipse_cdt_utils_pty_PTYInputStream + * Method: read0 + * Signature: (I)I + */ +JNIEXPORT jint JNICALL +Java_org_eclipse_cdt_utils_pty_PTYInputStream_read0(JNIEnv * env, + jobject jobj, + jint jfd, + jbyteArray buf, + jint buf_len) +{ + int fd; + int status; + jbyte *data; + int data_len; + + data = (*env)->GetByteArrayElements(env, buf, 0); + data_len = buf_len; + fd = jfd; + + status = read( fd, data, data_len ); + (*env)->ReleaseByteArrayElements(env, buf, data, 0); + + if (status == 0) { + /* EOF. */ + status = -1; + } else if (status == -1) { + /* Error, toss an exception */ + jclass exception = (*env)->FindClass(env, "java/io/IOException"); + if (exception == NULL) { + /* Give up. */ + return -1; + } + (*env)->ThrowNew(env, exception, "read error"); + } + + return status; +} + + +/* + * Class: org_eclipse_cdt_utils_pty_PTYInputStream + * Method: close0 + * Signature: (I)I + */ +JNIEXPORT jint JNICALL +Java_org_eclipse_cdt_utils_pty_PTYInputStream_close0(JNIEnv * env, + jobject jobj, + jint fd) +{ + return close(fd); +} + +/* + * Class: org_eclipse_cdt_utils_pty_PTYOutputStream + * Method: write0 + * Signature: (II)I + */ +JNIEXPORT jint JNICALL +Java_org_eclipse_cdt_utils_pty_PTYOutputStream_write0(JNIEnv * env, + jobject jobj, + jint jfd, + jbyteArray buf, + jint buf_len) +{ + int status; + int fd; + jbyte *data; + int data_len; + + data = (*env)->GetByteArrayElements(env, buf, 0); + data_len = buf_len; + fd = jfd; + + status = write(fd, data, data_len); + (*env)->ReleaseByteArrayElements(env, buf, data, 0); + + return status; +} + + +/* + * Class: org_eclipse_cdt_utils_pty_PTYOutputStream + * Method: close0 + * Signature: (I)I + */ +JNIEXPORT jint JNICALL +Java_org_eclipse_cdt_utils_pty_PTYOutputStream_close0(JNIEnv * env, + jobject jobj, + jint fd) +{ + return close(fd); +} diff --git a/core/org.eclipse.cdt.core.linux/os/linux/x86/libpty.so b/core/org.eclipse.cdt.core.linux/os/linux/x86/libpty.so new file mode 100644 index 0000000000000000000000000000000000000000..418f8f2658bd8886d7f3a58a5cec161651cd51a7 GIT binary patch literal 9320 zcmeHMeQ;D)6~Eb}G>{ZROxu)xEtIw(Wl7Qs0kyLP7Dx>cAysOvk7cvTE^c<$-M5%9 zWK6nbB;7`%pjHP*TCme;`v)L4}a|R^+wLQ+yj7t_DxjdKcsv^kdMI4*-*?F9F{SUJfQfou}(`Y6&FU zwoGH%yLH-#MM&HLz6o3dUI-@DgKw89^>>?2f5MTs80k6(X0jH1%cQ*jCA=P$UE`>5 zj!w^Y$r#)IO)pD}fr!&;-5Tc5M2r3pTap*FGi)G@S z%MIp;Vjh$ltPBt3v78m+NFJ+#ujjE!*wamUm3T0ZF;PLBucTs8Cgs>{DS*pmVkYJr zsaRYgCFdroSj?0%p2xE!w(}Sh8ni2qmE+xctQ>P5lZwU1q#WeL0~L!ZDGT^YiOpZJ z&}6QEu&oApZ?fV^PZ zo3UJ>@fV;!fyd;$s6_w$1(L)$Py2@nKq1%>|5hS_oj~DlB7Yp^yCp6YT%TsVD#dis z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Ao|}9$$f!TBxcF@!~utX5AwN=xQ2?vmEv2FhaGyx z3&tGyG2nu~nSvKG+)qeFnAwX|QvRFgIiQ9Kd1c}_{ts!)_Pq++=_t?o&N%dw>w6P= zbB^Zoj{_IlGYf4fkg4CqL0G@bVPN!yjkQeh>d27MGw!4aahECdjN2If9O%t?yT~gn)Xj?%y~h49M~DhdROaf zwf+hh5+D=Dnx`?xpXKiacE+)6U}qd_C+#t*Uy=4@;(lHJN#J?l9|Jq%Sic8$#<6B$ zk8{Sct^sz&v2NCTV4d`j_%^T^KgO{>t@S33b&tkgZ65}9#<7yXPX9ZB`Mx5te|ctd z#<9KwO!9)+ACGE`t8Iy&)p(1>FHN$4O=GBq8~m2WHAvH+;9-;JOHV+w2Lg2#j*0Pb zB-rW^0e>Xoh+>IA!cN+$wl-MCJvE4TtZv!3$!coc+=2iXi$#Jq%GENW6|>qSv2Ff{ zB~PW6Kh=p`-#Tl}rj_e`R)cSC;|3IBy;f_gqoYg2wrvjvY)_p~5ipg>wrM@WN`atd z$1ELdS>>qPS)V)%>-waPZ^LTF-&A7_P|Z+CN7VRKh}Ovea10V&lQApgkG4jFCQRn_ z=0iCb5jM)l!gSQlS-KEDoGQ#$u+%{+XNC+wIWs;yD(4Kf>G+ii?KvIgV}{Pm$w5J< z?!#-ID(t3$p(c{~0rAgEtH$|&DwcSOP1C)CDWHR?&TyWJemYw;RV25dXPl3ZSIDX1 u{K83z!S^f)F$Y9C2Z%!M^~Yg|)!| literal 0 HcmV?d00001 diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIInferior.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIInferior.java index b551506cdfb..e5c1f1610ec 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIInferior.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIInferior.java @@ -18,6 +18,7 @@ import org.eclipse.cdt.debug.mi.core.command.MIGDBShowExitCode; import org.eclipse.cdt.debug.mi.core.event.MIInferiorExitEvent; import org.eclipse.cdt.debug.mi.core.output.MIGDBShowExitCodeInfo; import org.eclipse.cdt.debug.mi.core.output.MIInfo; +import org.eclipse.cdt.utils.pty.PTY; import org.eclipse.cdt.utils.spawner.Spawner; /** @@ -35,15 +36,19 @@ public class MIInferior extends Process { MISession session; OutputStream out; - - PipedInputStream in; + InputStream in; + PipedOutputStream inPiped; PipedInputStream err; PipedOutputStream errPiped; - MIInferior(MISession mi) { + MIInferior(MISession mi, PTY pty) { session = mi; + if (pty != null) { + out = pty.getOutputStream(); + in = pty.getInputStream(); + } } /** diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java index a975582b706..9b3162b762e 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java @@ -5,15 +5,13 @@ package org.eclipse.cdt.debug.mi.core; import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; import org.eclipse.cdt.debug.core.cdi.ICDISession; import org.eclipse.cdt.debug.mi.core.cdi.CSession; import org.eclipse.cdt.debug.mi.core.command.CommandFactory; -import org.eclipse.cdt.debug.mi.core.command.MIBreakInsert; import org.eclipse.cdt.debug.mi.core.command.MITargetAttach; import org.eclipse.cdt.debug.mi.core.output.MIInfo; +import org.eclipse.cdt.utils.pty.PTY; import org.eclipse.cdt.utils.spawner.ProcessFactory; import org.eclipse.core.runtime.IPluginDescriptor; import org.eclipse.core.runtime.Plugin; @@ -44,14 +42,23 @@ public class MIPlugin extends Plugin { /** * Method createMISession. - * @param in - * @param out + * @param Process * @return MISession */ public MISession createMISession(Process process) throws MIException { return new MISession(process); } + /** + * Method createMISession. + * @param Process + * @param PTY + * @return MISession + */ + public MISession createMISession(Process process, PTY pty) throws MIException { + return new MISession(process, pty); + } + /** * Method createCSession. * @param program @@ -59,9 +66,20 @@ public class MIPlugin extends Plugin { * @throws IOException */ public ICDISession createCSession(String program) throws IOException, MIException { - String[]args = new String[]{"gdb", "-q", "-nw", "-i", "mi", program}; + String[] args; + PTY pty = null; + try { + pty = new PTY(); + String ttyName = pty.getSlaveName(); + args = new String[]{"gdb", "-q", "-nw", "-tty", ttyName, "-i", "mi", program}; + } catch (IOException e) { + e.printStackTrace(); + pty = null; + args = new String[]{"gdb", "-q", "-nw", "-i", "mi", program}; + } + Process gdb = ProcessFactory.getFactory().exec(args); - MISession session = createMISession(gdb); + MISession session = createMISession(gdb, pty); /* try { CommandFactory factory = session.getCommandFactory(); diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MISession.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MISession.java index 5471d2c0f25..88afbebb005 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MISession.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MISession.java @@ -22,6 +22,7 @@ import org.eclipse.cdt.debug.mi.core.event.MIGDBExitEvent; import org.eclipse.cdt.debug.mi.core.output.MIInfo; import org.eclipse.cdt.debug.mi.core.output.MIOutput; import org.eclipse.cdt.debug.mi.core.output.MIParser; +import org.eclipse.cdt.utils.pty.PTY; /** * Represents a GDB/MI session. @@ -56,10 +57,19 @@ public class MISession extends Observable { /** * Create the gdb session. * - * @param i the gdb input channel. - * @param o gdb output channel. + * @param Process gdb Process. */ public MISession(Process process) throws MIException { + this(process, null); + } + + /** + * Create the gdb session. + * + * @param Process gdb Process. + * @param pty Terminal to use for the inferior. + */ + public MISession(Process process, PTY pty) throws MIException { miProcess = process; inChannel = process.getInputStream(); outChannel = process.getOutputStream(); @@ -69,7 +79,7 @@ public class MISession extends Observable { parser = new MIParser(); // Do this first. - inferior = new MIInferior(this); + inferior = new MIInferior(this, pty); txQueue = new CommandQueue(); rxQueue = new CommandQueue();