1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 18:05:33 +02:00

[289123 ] - fixed problem introduced by fix of 287927 - delay in gdb start

This commit is contained in:
Alena Laskavaia 2009-09-11 14:51:09 +00:00
parent 3596f15371
commit 7b8a297a52

View file

@ -14,6 +14,7 @@ package org.eclipse.cdt.debug.mi.core;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PushbackInputStream;
import org.eclipse.cdt.utils.spawner.ProcessFactory;
import org.eclipse.cdt.utils.spawner.Spawner;
@ -25,6 +26,7 @@ import org.eclipse.core.runtime.OperationCanceledException;
public class MIProcessAdapter implements MIProcess {
Process fGDBProcess;
InputStream gdbInputStream;
private static final int ONE_SECOND = 1000;
private long commandTimeout;
@ -47,16 +49,30 @@ public class MIProcessAdapter implements MIProcess {
*/
protected Process getGDBProcess(String[] args, int launchTimeout, IProgressMonitor monitor) throws IOException {
final Process pgdb = createGDBProcess(args);
Thread syncStartup = new Thread("GDB Start") { //$NON-NLS-1$
public void run() {
try {
PushbackInputStream pb = new PushbackInputStream(pgdb.getInputStream());
gdbInputStream = pb;
pb.unread(pb.read()); // actually read something, then return it
} catch (Exception e) {
// Do nothing, ignore the errors
}
}
};
syncStartup.start();
int timepass = 0;
if (launchTimeout <= 0) {
// Simulate we are waiting forever.
launchTimeout = Integer.MAX_VALUE;
}
InputStream stream = pgdb.getInputStream();
// To respect the IProgressMonitor we can not use wait/notify
// instead we have to loop and check for the monitor to allow to cancel the thread.
// The monitor is check every 1 second delay;
for (timepass = 0; timepass < launchTimeout; timepass += ONE_SECOND) {
if (stream.available()<=0 && !monitor.isCanceled()) {
if (syncStartup.isAlive() && !monitor.isCanceled()) {
try {
Thread.sleep(ONE_SECOND);
} catch (InterruptedException e) {
@ -66,7 +82,12 @@ public class MIProcessAdapter implements MIProcess {
break;
}
}
try {
syncStartup.interrupt();
syncStartup.join(ONE_SECOND);
} catch (InterruptedException e) {
// ignore
}
if (monitor.isCanceled()) {
pgdb.destroy();
throw new OperationCanceledException();
@ -158,7 +179,7 @@ public class MIProcessAdapter implements MIProcess {
}
public InputStream getInputStream() {
return fGDBProcess.getInputStream();
return gdbInputStream;
}
public OutputStream getOutputStream() {