Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlena Laskavaia2009-09-11 10:51:09 -0400
committerAlena Laskavaia2009-09-11 10:51:09 -0400
commit7b8a297a521177eea88b4e345a920ee4a95e845f (patch)
treea6e25bf33c4b3fde97bc44cb37481242cb7f860e /debug/org.eclipse.cdt.debug.mi.core
parent3596f15371f2f5c510694f3d2adf993b2cce0e55 (diff)
downloadorg.eclipse.cdt-7b8a297a521177eea88b4e345a920ee4a95e845f.tar.gz
org.eclipse.cdt-7b8a297a521177eea88b4e345a920ee4a95e845f.tar.xz
org.eclipse.cdt-7b8a297a521177eea88b4e345a920ee4a95e845f.zip
[289123 ] - fixed problem introduced by fix of 287927 - delay in gdb start
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.java31
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 6efa195f4b..e25bc8c668 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() {

Back to the top