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

View file

@ -76,41 +76,44 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN); ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) {
dsession = debugConfig.getDebugger().createLaunchSession(config, exe); dsession = debugConfig.getDebugger().createLaunchSession(config, exe);
} ICDIRuntimeOptions opt = dsession.getRuntimeOptions();
else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH)) { 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(); int pid = getProcessID();
if ( pid == -1 ) { if (pid == -1) {
cancel("No Process ID selected", ICDTLaunchConfigurationConstants.ERR_NO_PROCESSID); cancel("No Process ID selected", ICDTLaunchConfigurationConstants.ERR_NO_PROCESSID);
} }
dsession = debugConfig.getDebugger().createAttachSession(config, exe, pid); 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) { } else {
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 {
Process process = exec(commandArray, getEnvironmentArray(config), getWorkingDir(config)); Process process = exec(commandArray, getEnvironmentArray(config), getWorkingDir(config));
DebugPlugin.getDefault().newProcess(launch, process, renderProcessLabel(commandArray[0])); DebugPlugin.getDefault().newProcess(launch, process, renderProcessLabel(commandArray[0]));
} }
@ -119,29 +122,29 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
private int getProcessID() throws CoreException { private int getProcessID() throws CoreException {
final Shell shell = LaunchUIPlugin.getShell(); final Shell shell = LaunchUIPlugin.getShell();
final int pid[] = {-1}; final int pid[] = { -1 };
if ( shell == 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 display = shell.getDisplay();
display.syncExec(new Runnable() { display.syncExec(new Runnable() {
public void run() { public void run() {
ElementListSelectionDialog dialog = new ElementListSelectionDialog( shell, new LabelProvider() { ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell, new LabelProvider() {
public String getText(Object element) { public String getText(Object element) {
IProcessInfo info = (IProcessInfo)element; IProcessInfo info = (IProcessInfo) element;
return info.getPid() + " " + info.getName(); return info.getPid() + " " + info.getName();
} }
} ); });
dialog.setTitle( "Select Process" ); dialog.setTitle("Select Process");
dialog.setMessage("Select a Process to attach debugger to:"); dialog.setMessage("Select a Process to attach debugger to:");
IProcessList plist = CCorePlugin.getDefault().getProcessList(); IProcessList plist = CCorePlugin.getDefault().getProcessList();
if ( plist == null ) { if (plist == null) {
MessageDialog.openError(shell, "CDT Launch Error", "Current platform does not support listing processes"); MessageDialog.openError(shell, "CDT Launch Error", "Current platform does not support listing processes");
return; return;
} }
dialog.setElements(plist.getProcessList()); dialog.setElements(plist.getProcessList());
if ( dialog.open() == dialog.OK ) { if (dialog.open() == dialog.OK) {
IProcessInfo info = (IProcessInfo)dialog.getFirstResult(); IProcessInfo info = (IProcessInfo) dialog.getFirstResult();
pid[0] = info.getPid(); pid[0] = info.getPid();
} }
} }
@ -149,7 +152,6 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
return pid[0]; return pid[0];
} }
/** /**
* Performs a runtime exec on the given command line in the context * Performs a runtime exec on the given command line in the context
* of the specified working directory, and returns * of the specified working directory, and returns
@ -169,18 +171,15 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
try { try {
if (workingDirectory == null) { if (workingDirectory == null) {
p = Runtime.getRuntime().exec(cmdLine, envp); p = Runtime.getRuntime().exec(cmdLine, envp);
} } else {
else {
p = Runtime.getRuntime().exec(cmdLine, envp, workingDirectory); p = Runtime.getRuntime().exec(cmdLine, envp, workingDirectory);
} }
} } catch (IOException e) {
catch (IOException e) {
if (p != null) { if (p != null) {
p.destroy(); p.destroy();
} }
abort("Error starting process", e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); 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 //attempting launches on 1.2.* - no ability to set working directory
IStatus status = IStatus status =