1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 14:15:23 +02:00

[291633] Allow the JUnit tests to use GdbLaunchDelegate.

This commit is contained in:
Marc Khouzam 2009-10-07 19:56:28 +00:00
parent 94e7e1504c
commit 08f05612e7
2 changed files with 35 additions and 129 deletions

View file

@ -121,12 +121,7 @@ public class GdbLaunchDelegate extends LaunchConfigurationDelegate
// code that is outside the workspace.
// See bug 244567
if (!attach) {
// First verify we are dealing with a proper project.
ICProject project = LaunchUtils.verifyCProject(config);
// Now verify we know the program to debug.
exePath = LaunchUtils.verifyProgramPath(config, project);
// Finally, make sure the program is a proper binary.
LaunchUtils.verifyBinary(config, exePath);
exePath = checkBinaryDetails(config);
}
monitor.worked( 1 );
@ -213,6 +208,20 @@ public class GdbLaunchDelegate extends LaunchConfigurationDelegate
}
}
/**
* Method used to check that the project, program and binary are correct.
* Can be overridden to avoid checking certain things.
*/
protected IPath checkBinaryDetails(final ILaunchConfiguration config) throws CoreException {
// First verify we are dealing with a proper project.
ICProject project = LaunchUtils.verifyCProject(config);
// Now verify we know the program to debug.
IPath exePath = LaunchUtils.verifyProgramPath(config, project);
// Finally, make sure the program is a proper binary.
LaunchUtils.verifyBinary(config, exePath);
return exePath;
}
/**
* Returns the GDB version.
* Subclass can override for special need.

View file

@ -10,150 +10,47 @@
*******************************************************************************/
package org.eclipse.cdt.tests.dsf.gdb.launching;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.concurrent.ExecutionException;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.dsf.concurrent.ThreadSafe;
import org.eclipse.cdt.dsf.gdb.launching.FinalLaunchSequence;
import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch;
import org.eclipse.cdt.dsf.gdb.launching.LaunchUtils;
import org.eclipse.cdt.dsf.gdb.launching.ServicesLaunchSequence;
import org.eclipse.cdt.dsf.gdb.service.GdbDebugServicesFactory;
import org.eclipse.cdt.dsf.gdb.service.SessionType;
import org.eclipse.cdt.dsf.gdb.launching.GdbLaunchDelegate;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate2;
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
/**
* The launch configuration delegate for the DSF GDB JUnit tests.
*/
@ThreadSafe
public class TestLaunchDelegate extends LaunchConfigurationDelegate
implements ILaunchConfigurationDelegate2
public class TestLaunchDelegate extends GdbLaunchDelegate
{
public final static String GDB_DEBUG_MODEL_ID = "org.eclipse.cdt.tests.dsf.gdb"; //$NON-NLS-1$
public void launch( ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor ) throws CoreException {
if ( monitor == null ) {
monitor = new NullProgressMonitor();
}
if ( mode.equals( ILaunchManager.DEBUG_MODE ) ) {
launchDebugger( config, launch, monitor );
}
}
private void launchDebugger( ILaunchConfiguration config, ILaunch launch, IProgressMonitor monitor ) throws CoreException {
monitor.beginTask("Launching debugger session", 10); //$NON-NLS-1$
if ( monitor.isCanceled() ) {
return;
}
try {
String debugMode = config.getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN );
if ( debugMode.equals( ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN ) ) {
launchLocalDebugSession( config, launch, monitor );
}
}
finally {
monitor.done();
}
}
private void launchLocalDebugSession( final ILaunchConfiguration config, ILaunch l, IProgressMonitor monitor ) throws CoreException {
if ( monitor.isCanceled() ) {
return;
}
final GdbLaunch launch = (GdbLaunch)l;
monitor.subTask("DSF GDB/MI reference JUnit tests"); //$NON-NLS-1$
IPath exePath = new Path(getProgramName(config));
verifyBinary(exePath);
monitor.worked( 1 );
launch.setServiceFactory(new GdbDebugServicesFactory(LaunchUtils.getGDBVersion(config)));
IProgressMonitor subMon1 = new SubProgressMonitor(monitor, 4, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
final ServicesLaunchSequence servicesLaunchSequence =
new ServicesLaunchSequence(launch.getSession(), launch, subMon1);
launch.getSession().getExecutor().execute(servicesLaunchSequence);
try {
servicesLaunchSequence.get();
} catch (InterruptedException e1) {
throw new DebugException(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID, DebugException.INTERNAL_ERROR, "Interrupted Exception in dispatch thread", e1)); //$NON-NLS-1$
} catch (ExecutionException e1) {
throw new DebugException(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Error in services launch sequence", e1.getCause())); //$NON-NLS-1$
}
launch.initializeControl();
// Add the CLI and "inferior" process objects to the launch.
launch.addCLIProcess("gdb"); //$NON-NLS-1$
launch.addInferiorProcess(exePath.lastSegment());
// Create and invoke the final launch sequence to setup GDB
IProgressMonitor subMon2 = new SubProgressMonitor(monitor, 4, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
final FinalLaunchSequence finalLaunchSequence =
new FinalLaunchSequence(launch.getSession().getExecutor(), launch, SessionType.LOCAL, false, subMon2);
launch.getSession().getExecutor().execute(finalLaunchSequence);
try {
finalLaunchSequence.get();
} catch (InterruptedException e1) {
throw new DebugException(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID, DebugException.INTERNAL_ERROR, "Interrupted Exception in dispatch thread", e1)); //$NON-NLS-1$
} catch (ExecutionException e1) {
throw new DebugException(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Error in final launch sequence", e1.getCause())); //$NON-NLS-1$
}
}
/*
* Verify that the specified file exists on the file system.
*/
private void verifyBinary(IPath exePath) throws CoreException {
try {
new FileReader(exePath.toFile());
} catch (Exception e) {
Throwable exception = new FileNotFoundException(exePath.toOSString() + " does not exist"); //$NON-NLS-1$
int code = ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_BINARY;
throw new CoreException(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID, code, exception == null ? "" : exception.getLocalizedMessage(), //$NON-NLS-1$
exception));
}
}
@Override
public boolean preLaunchCheck( ILaunchConfiguration config, String mode, IProgressMonitor monitor ) throws CoreException {
return super.preLaunchCheck( config, mode, monitor );
protected IProject[] getBuildOrder(ILaunchConfiguration configuration,
String mode) throws CoreException {
return null;
}
@Override
protected IProject[] getProjectsForProblemSearch(
ILaunchConfiguration configuration, String mode)
throws CoreException {
return null;
}
@Override
public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
return false;
}
@Override
public boolean finalLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
public boolean finalLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
return true;
}
@Override
public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) throws CoreException {
GdbLaunch launch = new GdbLaunch(configuration, mode, null);
launch.initialize();
return launch;
}
private static String getProgramName(ILaunchConfiguration configuration) throws CoreException {
return configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String)null);
@Override
protected IPath checkBinaryDetails(ILaunchConfiguration config) throws CoreException {
return new Path(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, ""));
}
}
}