mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 14:55:41 +02:00
[289123 ] - fixed problem introduced by fix of 287927 - delay in gdb start
This commit is contained in:
parent
3596f15371
commit
7b8a297a52
1 changed files with 26 additions and 5 deletions
|
@ -14,6 +14,7 @@ package org.eclipse.cdt.debug.mi.core;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.io.PushbackInputStream;
|
||||||
|
|
||||||
import org.eclipse.cdt.utils.spawner.ProcessFactory;
|
import org.eclipse.cdt.utils.spawner.ProcessFactory;
|
||||||
import org.eclipse.cdt.utils.spawner.Spawner;
|
import org.eclipse.cdt.utils.spawner.Spawner;
|
||||||
|
@ -25,6 +26,7 @@ import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
public class MIProcessAdapter implements MIProcess {
|
public class MIProcessAdapter implements MIProcess {
|
||||||
|
|
||||||
Process fGDBProcess;
|
Process fGDBProcess;
|
||||||
|
InputStream gdbInputStream;
|
||||||
private static final int ONE_SECOND = 1000;
|
private static final int ONE_SECOND = 1000;
|
||||||
private long commandTimeout;
|
private long commandTimeout;
|
||||||
|
|
||||||
|
@ -47,6 +49,18 @@ public class MIProcessAdapter implements MIProcess {
|
||||||
*/
|
*/
|
||||||
protected Process getGDBProcess(String[] args, int launchTimeout, IProgressMonitor monitor) throws IOException {
|
protected Process getGDBProcess(String[] args, int launchTimeout, IProgressMonitor monitor) throws IOException {
|
||||||
final Process pgdb = createGDBProcess(args);
|
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;
|
int timepass = 0;
|
||||||
if (launchTimeout <= 0) {
|
if (launchTimeout <= 0) {
|
||||||
|
@ -54,9 +68,11 @@ public class MIProcessAdapter implements MIProcess {
|
||||||
launchTimeout = Integer.MAX_VALUE;
|
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) {
|
for (timepass = 0; timepass < launchTimeout; timepass += ONE_SECOND) {
|
||||||
if (stream.available()<=0 && !monitor.isCanceled()) {
|
if (syncStartup.isAlive() && !monitor.isCanceled()) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(ONE_SECOND);
|
Thread.sleep(ONE_SECOND);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -66,7 +82,12 @@ public class MIProcessAdapter implements MIProcess {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
syncStartup.interrupt();
|
||||||
|
syncStartup.join(ONE_SECOND);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
if (monitor.isCanceled()) {
|
if (monitor.isCanceled()) {
|
||||||
pgdb.destroy();
|
pgdb.destroy();
|
||||||
throw new OperationCanceledException();
|
throw new OperationCanceledException();
|
||||||
|
@ -158,7 +179,7 @@ public class MIProcessAdapter implements MIProcess {
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream getInputStream() {
|
public InputStream getInputStream() {
|
||||||
return fGDBProcess.getInputStream();
|
return gdbInputStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OutputStream getOutputStream() {
|
public OutputStream getOutputStream() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue