diff options
Diffstat (limited to 'debug/org.eclipse.cdt.debug.mi.core')
-rw-r--r-- | debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIProcessAdapter.java | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIProcessAdapter.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIProcessAdapter.java index 6efa195f4bb..e25bc8c668d 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIProcessAdapter.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIProcessAdapter.java @@ -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() { |