1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 06:45:43 +02:00

use new debug target creation methods

This commit is contained in:
David Inglis 2002-10-01 02:00:12 +00:00
parent 75201f7a47
commit 103c42de84
2 changed files with 59 additions and 70 deletions

View file

@ -32,10 +32,8 @@ import org.eclipse.swt.widgets.Shell;
*/
public class CoreFileLaunchDelegate extends AbstractCLaunchDelegate {
public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor)
throws CoreException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
@ -52,39 +50,32 @@ public class CoreFileLaunchDelegate extends AbstractCLaunchDelegate {
ICDISession dsession = null;
ICProject cproject = getCProject(config);
IPath corefile = getCoreFilePath((IProject)cproject.getResource());
if ( corefile == null ) {
IPath corefile = getCoreFilePath((IProject) cproject.getResource());
if (corefile == null) {
cancel("No Corefile selected", ICDTLaunchConfigurationConstants.ERR_NO_COREFILE);
}
try {
dsession = debugConfig.getDebugger().createCoreSession(config, exe, corefile);
}
catch (CDIException e) {
abort( "Failed Launching CDI Debugger", e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
} catch (CDIException e) {
abort("Failed Launching CDI Debugger", e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
}
ICDITarget dtarget = dsession.getTargets()[0];
Process process = dtarget.getProcess();
IProcess iprocess =
DebugPlugin.newProcess(launch, process, renderProcessLabel(projectPath.toOSString()));
CDebugModel.newDebugTarget(
CDebugModel.newCoreFileDebugTarget(
launch,
dsession.getTargets()[0],
dsession.getCurrentTarget(),
renderTargetLabel(debugConfig),
iprocess,
exe.getProject(),
false,
true,
false);
null,
exe.getProject());
}
private IPath getCoreFilePath(final IProject project) throws CoreException {
protected IPath getCoreFilePath(final IProject project) throws CoreException {
final Shell shell = LaunchUIPlugin.getShell();
final String res[] = { null };
if (shell == null) {
abort( "No Shell availible in Launch", null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
abort("No Shell availible in Launch", null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
}
Display display = shell.getDisplay();
display.syncExec(new Runnable() {
@ -95,8 +86,7 @@ public class CoreFileLaunchDelegate extends AbstractCLaunchDelegate {
String initPath = null;
try {
initPath = project.getPersistentProperty(new QualifiedName(LaunchUIPlugin.getUniqueIdentifier(), "SavePath"));
}
catch (CoreException e) {
} catch (CoreException e) {
}
if (initPath == null || initPath.equals("")) {
initPath = project.getLocation().toString();

View file

@ -76,41 +76,44 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) {
dsession = debugConfig.getDebugger().createLaunchSession(config, exe);
}
else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH)) {
ICDIRuntimeOptions opt = dsession.getRuntimeOptions();
opt.setArguments(getProgramArgumentsArray(config));
File wd = getWorkingDir(config);
if (wd != null) {
opt.setWorkingDirectory(wd.toString());
}
opt.setEnvironment(getEnvironmentProperty(config));
ICDITarget dtarget = dsession.getTargets()[0];
Process process = dtarget.getProcess();
IProcess iprocess = DebugPlugin.newProcess(launch, process, renderProcessLabel(commandArray[0]));
boolean stopInMain = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false);
CDebugModel.newDebugTarget(
launch,
dsession.getCurrentTarget(),
renderTargetLabel(debugConfig),
iprocess,
exe.getProject(),
true,
false,
stopInMain);
} else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH)) {
int pid = getProcessID();
if ( pid == -1 ) {
if (pid == -1) {
cancel("No Process ID selected", ICDTLaunchConfigurationConstants.ERR_NO_PROCESSID);
}
dsession = debugConfig.getDebugger().createAttachSession(config, exe, pid);
CDebugModel.newAttachDebugTarget(
launch,
dsession.getCurrentTarget(),
renderTargetLabel(debugConfig),
null,
exe.getProject());
}
} catch (CDIException e) {
abort("Failed Launching CDI Debugger", e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
}
catch (CDIException e) {
abort( "Failed Launching CDI Debugger", e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
}
ICDIRuntimeOptions opt = dsession.getRuntimeOptions();
opt.setArguments(getProgramArgumentsArray(config));
File wd = getWorkingDir(config);
if (wd != null) {
opt.setWorkingDirectory(wd.toString());
}
opt.setEnvironment(getEnvironmentProperty(config));
ICDITarget dtarget = dsession.getTargets()[0];
Process process = dtarget.getProcess();
IProcess iprocess =
DebugPlugin.newProcess(launch, process, renderProcessLabel(commandArray[0]));
boolean stopInMain = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false);
CDebugModel.newDebugTarget(
launch,
dsession.getTargets()[0],
renderTargetLabel(debugConfig),
iprocess,
exe.getProject(),
true,
false,
stopInMain);
}
else {
} else {
Process process = exec(commandArray, getEnvironmentArray(config), getWorkingDir(config));
DebugPlugin.getDefault().newProcess(launch, process, renderProcessLabel(commandArray[0]));
}
@ -119,29 +122,29 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
private int getProcessID() throws CoreException {
final Shell shell = LaunchUIPlugin.getShell();
final int pid[] = {-1};
if ( shell == null ) {
abort( "No Shell availible in Launch", null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
final int pid[] = { -1 };
if (shell == null) {
abort("No Shell availible in Launch", null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
}
Display display = shell.getDisplay();
display.syncExec(new Runnable() {
public void run() {
ElementListSelectionDialog dialog = new ElementListSelectionDialog( shell, new LabelProvider() {
ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell, new LabelProvider() {
public String getText(Object element) {
IProcessInfo info = (IProcessInfo)element;
IProcessInfo info = (IProcessInfo) element;
return info.getPid() + " " + info.getName();
}
} );
dialog.setTitle( "Select Process" );
});
dialog.setTitle("Select Process");
dialog.setMessage("Select a Process to attach debugger to:");
IProcessList plist = CCorePlugin.getDefault().getProcessList();
if ( plist == null ) {
if (plist == null) {
MessageDialog.openError(shell, "CDT Launch Error", "Current platform does not support listing processes");
return;
}
dialog.setElements(plist.getProcessList());
if ( dialog.open() == dialog.OK ) {
IProcessInfo info = (IProcessInfo)dialog.getFirstResult();
if (dialog.open() == dialog.OK) {
IProcessInfo info = (IProcessInfo) dialog.getFirstResult();
pid[0] = info.getPid();
}
}
@ -149,7 +152,6 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
return pid[0];
}
/**
* Performs a runtime exec on the given command line in the context
* of the specified working directory, and returns
@ -169,18 +171,15 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
try {
if (workingDirectory == null) {
p = Runtime.getRuntime().exec(cmdLine, envp);
}
else {
} else {
p = Runtime.getRuntime().exec(cmdLine, envp, workingDirectory);
}
}
catch (IOException e) {
} catch (IOException e) {
if (p != null) {
p.destroy();
}
abort("Error starting process", e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
}
catch (NoSuchMethodError e) {
} catch (NoSuchMethodError e) {
//attempting launches on 1.2.* - no ability to set working directory
IStatus status =
@ -201,7 +200,7 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
}
return p;
}
protected String getPluginID() {
return LaunchUIPlugin.getUniqueIdentifier();
}