mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 01:36:01 +02:00
Bug 376203: Launch job never completes if getting gdb version hangs.
Change-Id: I4cad8b656856de2222c2e3e618dacf54c6c150d6 Reviewed-on: https://git.eclipse.org/r/8422 Reviewed-by: Mikhail Khodjaiants <mikhailkhod@googlemail.com> IP-Clean: Mikhail Khodjaiants <mikhailkhod@googlemail.com> Tested-by: Mikhail Khodjaiants <mikhailkhod@googlemail.com> Reviewed-by: Marc Khouzam <marc.khouzam@ericsson.com> IP-Clean: Marc Khouzam <marc.khouzam@ericsson.com> Tested-by: Marc Khouzam <marc.khouzam@ericsson.com>
This commit is contained in:
parent
926a7f5052
commit
76b231ca15
1 changed files with 29 additions and 2 deletions
|
@ -9,6 +9,7 @@
|
||||||
* Ericsson - Initial API and implementation
|
* Ericsson - Initial API and implementation
|
||||||
* Ericsson - Added support for Mac OS
|
* Ericsson - Added support for Mac OS
|
||||||
* Sergey Prigogin (Google)
|
* Sergey Prigogin (Google)
|
||||||
|
* Marc Khouzam (Ericsson) - Add timer when fetching GDB version (Bug 376203)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.dsf.gdb.launching;
|
package org.eclipse.cdt.dsf.gdb.launching;
|
||||||
|
|
||||||
|
@ -48,11 +49,13 @@ import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.MultiStatus;
|
import org.eclipse.core.runtime.MultiStatus;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
import org.eclipse.core.variables.VariablesPlugin;
|
import org.eclipse.core.variables.VariablesPlugin;
|
||||||
import org.eclipse.debug.core.DebugException;
|
import org.eclipse.debug.core.DebugException;
|
||||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||||
|
@ -290,7 +293,7 @@ public class LaunchUtils {
|
||||||
* only once and the resulting version string stored for future uses.
|
* only once and the resulting version string stored for future uses.
|
||||||
*/
|
*/
|
||||||
public static String getGDBVersion(final ILaunchConfiguration configuration) throws CoreException {
|
public static String getGDBVersion(final ILaunchConfiguration configuration) throws CoreException {
|
||||||
Process process = null;
|
final Process process;
|
||||||
String cmd = getGDBPath(configuration).toOSString() + " --version"; //$NON-NLS-1$
|
String cmd = getGDBPath(configuration).toOSString() + " --version"; //$NON-NLS-1$
|
||||||
try {
|
try {
|
||||||
process = ProcessFactory.getFactory().exec(cmd, getLaunchEnvironment(configuration));
|
process = ProcessFactory.getFactory().exec(cmd, getLaunchEnvironment(configuration));
|
||||||
|
@ -299,6 +302,21 @@ public class LaunchUtils {
|
||||||
"Error while launching command: " + cmd, e.getCause()));//$NON-NLS-1$
|
"Error while launching command: " + cmd, e.getCause()));//$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start a timeout job to make sure we don't get stuck waiting for
|
||||||
|
// an answer from a gdb that is hanging
|
||||||
|
// Bug 376203
|
||||||
|
Job timeoutJob = new Job("GDB version timeout job") { //$NON-NLS-1$
|
||||||
|
{ setSystem(true); }
|
||||||
|
@Override
|
||||||
|
protected IStatus run(IProgressMonitor arg) {
|
||||||
|
// Took too long. Kill the gdb process and
|
||||||
|
// let things clean up.
|
||||||
|
process.destroy();
|
||||||
|
return Status.OK_STATUS;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
timeoutJob.schedule(10000);
|
||||||
|
|
||||||
InputStream stream = null;
|
InputStream stream = null;
|
||||||
StringBuilder cmdOutput = new StringBuilder(200);
|
StringBuilder cmdOutput = new StringBuilder(200);
|
||||||
try {
|
try {
|
||||||
|
@ -314,6 +332,10 @@ public class LaunchUtils {
|
||||||
throw new DebugException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED,
|
throw new DebugException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED,
|
||||||
"Error reading GDB STDOUT after sending: " + cmd, e.getCause()));//$NON-NLS-1$
|
"Error reading GDB STDOUT after sending: " + cmd, e.getCause()));//$NON-NLS-1$
|
||||||
} finally {
|
} finally {
|
||||||
|
// If we get here we are obviously not stuck so we can cancel the timeout job.
|
||||||
|
// Note that it may already have executed, but that is not a problem.
|
||||||
|
timeoutJob.cancel();
|
||||||
|
|
||||||
// Cleanup to avoid leaking pipes
|
// Cleanup to avoid leaking pipes
|
||||||
// Close the stream we used, and then destroy the process
|
// Close the stream we used, and then destroy the process
|
||||||
// Bug 345164
|
// Bug 345164
|
||||||
|
@ -325,7 +347,12 @@ public class LaunchUtils {
|
||||||
process.destroy();
|
process.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
return getGDBVersionFromText(cmdOutput.toString());
|
String gdbVersion = getGDBVersionFromText(cmdOutput.toString());
|
||||||
|
if (gdbVersion == null || gdbVersion.isEmpty()) {
|
||||||
|
throw new DebugException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED,
|
||||||
|
"Could not determine GDB version after sending: " + cmd, null));//$NON-NLS-1$
|
||||||
|
}
|
||||||
|
return gdbVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getIsAttach(ILaunchConfiguration config) {
|
public static boolean getIsAttach(ILaunchConfiguration config) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue