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

added attach/core/run modes in lauch pages

This commit is contained in:
David Inglis 2002-08-28 20:36:59 +00:00
parent f5bea71c1d
commit 5f42e5c287
7 changed files with 367 additions and 263 deletions

View file

@ -26,7 +26,8 @@ import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDelegate { abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDelegate {
abstract public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException; abstract public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
throws CoreException;
protected String[] getEnvironmentArray(ILaunchConfiguration config) { protected String[] getEnvironmentArray(ILaunchConfiguration config) {
// Map env = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map) null); // Map env = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map) null);
@ -60,7 +61,10 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel
} }
File dir = new File(path); File dir = new File(path);
if (!dir.isDirectory()) { if (!dir.isDirectory()) {
abort("Specified working directory does not exist or is not a directory", null, ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST); abort(
"Specified working directory does not exist or is not a directory",
null,
ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST);
} }
return dir; return dir;
} }
@ -147,7 +151,8 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel
if (ch == '"') { if (ch == '"') {
v.add(parseString()); v.add(parseString());
} else { }
else {
v.add(parseToken()); v.add(parseToken());
} }
} }
@ -196,12 +201,15 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel
} }
buf.append((char) ch); buf.append((char) ch);
ch = getNext(); ch = getNext();
} else if (ch == -1) { // Don't lose a trailing backslash }
else if (ch == -1) { // Don't lose a trailing backslash
buf.append('\\'); buf.append('\\');
} }
} else if (ch == '"') { }
else if (ch == '"') {
buf.append(parseString()); buf.append(parseString());
} else { }
else {
buf.append((char) ch); buf.append((char) ch);
ch = getNext(); ch = getNext();
} }

View file

@ -50,26 +50,50 @@ public interface ICDTLaunchConfigurationConstants {
*/ */
public static final String ATTR_PROGRAM_ENVIROMENT_MAP = LaunchUIPlugin.getUniqueIdentifier() + ".ENVIRONMENT_MAP"; //$NON-NLS-1$ public static final String ATTR_PROGRAM_ENVIROMENT_MAP = LaunchUIPlugin.getUniqueIdentifier() + ".ENVIRONMENT_MAP"; //$NON-NLS-1$
/**
* Launch configuration attribute key. The value is the platform string of the launch configuration
*/
public static final String ATTR_PLATFORM = LaunchUIPlugin.getUniqueIdentifier() + ".PLATFFORM"; //$NON-NLS-1$
/** /**
* Launch configuration attribute key. The value is the debugger id * Launch configuration attribute key. The value is the debugger id
* used when launching a C/C++ application for debug. * used when launching a C/C++ application for debug.
*/ */
public static final String ATTR_DEBUGGER_ID = LaunchUIPlugin.getUniqueIdentifier() + ".DEBUGGER_ID"; //$NON-NLS-1$ public static final String ATTR_DEBUGGER_ID = LaunchUIPlugin.getUniqueIdentifier() + ".DEBUGGER_ID"; //$NON-NLS-1$
/**
* Launch configuration attribute key. The value is the platform string of the launch configuration
*/
public static final String ATTR_PLATFORM = LaunchUIPlugin.getUniqueIdentifier() + ".PLATFFORM"; //$NON-NLS-1$
/** /**
* Launch configuration attribute key. The value is the platform string of the launch configuration * Launch configuration attribute key. The value is the platform string of the launch configuration
*/ */
public static final String ATTR_DEBUGGER_SPECIFIC_ATTRS_MAP = LaunchUIPlugin.getUniqueIdentifier() + ".DEBUGGER_SPECIFIC_ATTRS_MAP"; //$NON-NLS-1$ public static final String ATTR_DEBUGGER_SPECIFIC_ATTRS_MAP = LaunchUIPlugin.getUniqueIdentifier() + ".DEBUGGER_SPECIFIC_ATTRS_MAP"; //$NON-NLS-1$
/** /**
* Launch configuration attribute key. The value is the platform string of the launch configuration * Launch configuration attribute key. The value is a boolean specifying whether to stop at main().
*/ */
public static final String ATTR_DEBUGGER_STOP_AT_MAIN = LaunchUIPlugin.getUniqueIdentifier() + ".DEBUGGER_STOP_AT_MAIN"; //$NON-NLS-1$ public static final String ATTR_DEBUGGER_STOP_AT_MAIN = LaunchUIPlugin.getUniqueIdentifier() + ".DEBUGGER_STOP_AT_MAIN"; //$NON-NLS-1$
/**
* Launch configuration attribute key. The value is the startup mode for the debugger.
*/
public static final String ATTR_DEBUGGER_START_MODE = LaunchUIPlugin.getUniqueIdentifier() + ".DEBUGGER_START_MODE"; //$NON-NLS-1$
/**
* Launch configuration attribute value. The key is ATTR_DEBUGGER_START_MODE.
* Startup debugger running the program.
*/
public static String DEBUGGER_MODE_RUN = "run";
/**
* Launch configuration attribute value. The key is ATTR_DEBUGGER_START_MODE.
* Startup debugger and attach to running process.
*/
public static String DEBUGGER_MODE_ATTACH = "attach";
/**
* Launch configuration attribute value. The key is ATTR_DEBUGGER_START_MODE.
* Startup debugger to view a core file.
*/
public static String DEBUGGER_MODE_CORE = "core";
/** /**
* Status code indicating that the Eclipse runtime does not support * Status code indicating that the Eclipse runtime does not support
* launching a program with a working directory. This feature is only * launching a program with a working directory. This feature is only

View file

@ -34,6 +34,8 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunch;
@ -41,6 +43,9 @@ import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.IStatusHandler; import org.eclipse.debug.core.IStatusHandler;
import org.eclipse.debug.core.model.IProcess; import org.eclipse.debug.core.model.IProcess;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
/** /**
* Insert the type's description here. * Insert the type's description here.
@ -81,11 +86,19 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
ICDebugConfiguration dbgCfg = null; ICDebugConfiguration dbgCfg = null;
ICDebugger cdebugger = null; ICDebugger cdebugger = null;
try { try {
dbgCfg = CDebugCorePlugin.getDefault().getDebugConfiguration(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, "")); dbgCfg =
CDebugCorePlugin.getDefault().getDebugConfiguration(
config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, ""));
cdebugger = dbgCfg.getDebugger(); cdebugger = dbgCfg.getDebugger();
} }
catch (CoreException e) { catch (CoreException e) {
IStatus status = new Status(IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(), ICDTLaunchConfigurationConstants.ERR_DEBUGGER_NOT_INSTALLED, "CDT Debubger not installed", e); IStatus status =
new Status(
IStatus.ERROR,
LaunchUIPlugin.getUniqueIdentifier(),
ICDTLaunchConfigurationConstants.ERR_DEBUGGER_NOT_INSTALLED,
"CDT Debubger not installed",
e);
IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(status); IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(status);
if (handler != null) { if (handler != null) {
@ -98,10 +111,30 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
IFile exe = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(projectPath); IFile exe = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(projectPath);
ICDISession dsession = null; ICDISession dsession = null;
try { try {
String debugMode =
config.getAttribute(
ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
if (mode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) {
dsession = cdebugger.createLaunchSession(config, exe); dsession = cdebugger.createLaunchSession(config, exe);
} }
else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH)) {
int pid = getProcessID();
dsession = cdebugger.createAttachSession(config, exe, pid);
}
else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_CORE)) {
IPath corefile = getCoreFilePath((IProject)cproject.getResource());
dsession = cdebugger.createCoreSession(config, exe, corefile);
}
}
catch (CDIException e) { catch (CDIException e) {
IStatus status = new Status(0, LaunchUIPlugin.getUniqueIdentifier(), ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR,"CDI Error", e); IStatus status =
new Status(
0,
LaunchUIPlugin.getUniqueIdentifier(),
ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR,
"CDI Error",
e);
throw new CoreException(status); throw new CoreException(status);
} }
ICDIRuntimeOptions opt = dsession.getRuntimeOptions(); ICDIRuntimeOptions opt = dsession.getRuntimeOptions();
@ -113,9 +146,18 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
opt.setEnvironment(getEnvironmentProperty(config)); opt.setEnvironment(getEnvironmentProperty(config));
ICDITarget dtarget = dsession.getTargets()[0]; ICDITarget dtarget = dsession.getTargets()[0];
Process process = dtarget.getProcess(); Process process = dtarget.getProcess();
IProcess iprocess = DebugPlugin.newProcess(launch, process, renderProcessLabel((String [])command.toArray(new String[command.size()]))); IProcess iprocess =
DebugPlugin.newProcess(launch, process, renderProcessLabel((String[]) command.toArray(new String[command.size()])));
boolean stopInMain = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false); boolean stopInMain = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false);
CDebugModel.newDebugTarget(launch, dsession.getTargets()[0], dbgCfg.getName(), iprocess, exe.getProject(), true, false, stopInMain ); CDebugModel.newDebugTarget(
launch,
dsession.getTargets()[0],
dbgCfg.getName(),
iprocess,
exe.getProject(),
true,
false,
stopInMain);
} }
else { else {
String[] commandArray = (String[]) command.toArray(new String[command.size()]); String[] commandArray = (String[]) command.toArray(new String[command.size()]);
@ -125,6 +167,34 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
monitor.done(); monitor.done();
} }
private IPath getCoreFilePath(IProject project) {
Shell shell = LaunchUIPlugin.getShell();
if ( shell == null )
return null;
FileDialog dialog = new FileDialog( shell );
dialog.setText( "Select Corefile" );
String initPath = null;
try {
initPath = project.getPersistentProperty(new QualifiedName(LaunchUIPlugin.getUniqueIdentifier(), "SavePath"));
}
catch (CoreException e) {
}
if ( initPath == null || initPath.equals("") ) {
initPath = project.getLocation().toString();
}
dialog.setFilterPath( initPath );
String res = dialog.open();
if ( res != null )
return new Path( res );
return null;
}
private int getProcessID() {
return -1;
}
/** /**
* Performs a runtime exec on the given command line in the context * Performs a runtime exec on the given command line in the context
@ -159,7 +229,13 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
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 = new Status(IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(), ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_NOT_SUPPORTED, "Eclipse runtime does not support working directory", e); IStatus status =
new Status(
IStatus.ERROR,
LaunchUIPlugin.getUniqueIdentifier(),
ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_NOT_SUPPORTED,
"Eclipse runtime does not support working directory",
e);
IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(status); IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(status);
if (handler != null) { if (handler != null) {

View file

@ -41,7 +41,8 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
if (!ss.isEmpty()) { if (!ss.isEmpty()) {
Object obj = ss.getFirstElement(); Object obj = ss.getFirstElement();
if (obj instanceof ICElement) { if (obj instanceof ICElement) {
ICProjectDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(((ICElement)obj).getCProject().getProject()); ICProjectDescriptor descriptor =
CCorePlugin.getDefault().getCProjectDescription(((ICElement) obj).getCProject().getProject());
if (descriptor.getPlatform().equals(getPlatform(config))) if (descriptor.getPlatform().equals(getPlatform(config)))
return (ICElement) obj; return (ICElement) obj;
} }
@ -52,7 +53,8 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
ce = CoreModel.getDefault().create(pro); ce = CoreModel.getDefault().create(pro);
} }
if (ce != null) { if (ce != null) {
ICProjectDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(ce.getCProject().getProject()); ICProjectDescriptor descriptor =
CCorePlugin.getDefault().getCProjectDescription(ce.getCProject().getProject());
if (descriptor.getPlatform().equals(getPlatform(config))) if (descriptor.getPlatform().equals(getPlatform(config)))
return ce; return ce;
} }
@ -81,8 +83,13 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
} }
protected String getPlatform(ILaunchConfiguration config) throws CoreException { protected String getPlatform(ILaunchConfiguration config) {
String platform = BootLoader.getOS(); String platform = BootLoader.getOS();
try {
return config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PLATFORM, platform); return config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PLATFORM, platform);
} }
catch (CoreException e) {
return platform;
}
}
} }

View file

@ -46,6 +46,13 @@ public class LaunchUIPlugin extends AbstractUIPlugin {
return fgPlugin; return fgPlugin;
} }
public static Shell getShell() {
if (getActiveWorkbenchWindow() != null) {
return getActiveWorkbenchWindow().getShell();
}
return null;
}
/** /**
* Convenience method which returns the unique identifier of this plugin. * Convenience method which returns the unique identifier of this plugin.
*/ */
@ -54,7 +61,7 @@ public class LaunchUIPlugin extends AbstractUIPlugin {
// If the default instance is not yet initialized, // If the default instance is not yet initialized,
// return a static identifier. This identifier must // return a static identifier. This identifier must
// match the plugin id defined in plugin.xml // match the plugin id defined in plugin.xml
return "org.eclipse.jdt.debug.ui"; //$NON-NLS-1$ return "org.eclipse.cdt.launch"; //$NON-NLS-1$
} }
return getDefault().getDescriptor().getUniqueIdentifier(); return getDefault().getDescriptor().getUniqueIdentifier();
} }

View file

@ -7,7 +7,6 @@ package org.eclipse.cdt.launch.ui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.ICDebugConfiguration; import org.eclipse.cdt.debug.core.ICDebugConfiguration;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
@ -21,8 +20,8 @@ import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
@ -34,14 +33,17 @@ import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
public class CDebuggerTab extends CLaunchConfigurationTab { public class CDebuggerTab extends CLaunchConfigurationTab {
ArrayList fDinfo;
int fDindex;
Combo fDCombo; Combo fDCombo;
Button stopInMain; Button stopInMain;
protected Button fAttachButton;
protected Button fCoreButton;
protected Button fRunButton;
// Dynamic Debugger UI widgets // Dynamic Debugger UI widgets
protected ILaunchConfigurationTab fDynamicTab; protected ILaunchConfigurationTab fDynamicTab;
protected Composite fDynamicTabHolder; protected Composite fDynamicTabHolder;
protected ICDebugConfiguration fCurrentDebugConfig;
protected ILaunchConfigurationWorkingCopy fWorkingCopy; protected ILaunchConfigurationWorkingCopy fWorkingCopy;
protected ILaunchConfiguration fLaunchConfiguration; protected ILaunchConfiguration fLaunchConfiguration;
@ -62,9 +64,21 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
stopInMain = new Button(comp, SWT.CHECK); stopInMain = new Button(comp, SWT.CHECK);
stopInMain.setText("Stop at main() on startup."); stopInMain.setText("Stop at main() on startup.");
GridData gd = new GridData(); GridData gd = new GridData();
gd.grabExcessHorizontalSpace = true; gd.horizontalIndent = 10;
gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_END;
stopInMain.setLayoutData(gd); stopInMain.setLayoutData(gd);
Composite radioComp = new Composite(comp, SWT.NONE);
GridLayout radioLayout = new GridLayout(3, true);
radioLayout.marginHeight = 0;
radioLayout.marginWidth = 0;
radioComp.setLayout(radioLayout);
gd = new GridData();
gd.horizontalSpan = 3;
radioComp.setLayoutData(gd);
fRunButton = createRadioButton(radioComp, "Run program in debugger.");
fAttachButton = createRadioButton(radioComp, "Attach to running process.");
fCoreButton = createRadioButton(radioComp, "View Corefile.");
Group debuggerGroup = new Group(comp, SWT.SHADOW_ETCHED_IN); Group debuggerGroup = new Group(comp, SWT.SHADOW_ETCHED_IN);
debuggerGroup.setText("Debugger Options"); debuggerGroup.setText("Debugger Options");
setDynamicTabHolder(debuggerGroup); setDynamicTabHolder(debuggerGroup);
@ -94,7 +108,13 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
return fDynamicTab; return fDynamicTab;
} }
protected ICDebugConfiguration getDebugConfig() {
return fCurrentDebugConfig;
}
protected void setDebugConfig(ICDebugConfiguration config) {
fCurrentDebugConfig = config;
}
/** /**
* Notification that the user changed the selection in the JRE combo box. * Notification that the user changed the selection in the JRE combo box.
*/ */
@ -113,88 +133,72 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
if (wc != null) { if (wc != null) {
wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_SPECIFIC_ATTRS_MAP, (Map) null); wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_SPECIFIC_ATTRS_MAP, (Map) null);
} }
} else { }
else {
if (wc == null) { if (wc == null) {
try { try {
if (getLaunchConfiguration().isWorkingCopy()) { if (getLaunchConfiguration().isWorkingCopy()) {
// get a fresh copy to work on // get a fresh copy to work on
wc = ((ILaunchConfigurationWorkingCopy) getLaunchConfiguration()).getOriginal().getWorkingCopy(); wc = ((ILaunchConfigurationWorkingCopy) getLaunchConfiguration()).getOriginal().getWorkingCopy();
} else { }
else {
wc = getLaunchConfiguration().getWorkingCopy(); wc = getLaunchConfiguration().getWorkingCopy();
} }
} catch (CoreException e) { }
catch (CoreException e) {
return; return;
} }
} }
getDynamicTab().setDefaults(wc); getDynamicTab().setDefaults(wc);
getDynamicTab().initializeFrom(wc); getDynamicTab().initializeFrom(wc);
} }
updateLaunchConfigurationDialog(); updateLaunchConfigurationDialog();
} }
protected void loadDebuggerComboBox(ILaunchConfiguration config) { protected void loadDebuggerComboBox(ILaunchConfiguration config, String selection) {
ICDebugConfiguration[] debugConfigs; ICDebugConfiguration[] debugConfigs;
String platform; String platform = getPlatform(config);
try {
platform = getPlatform(config);
}
catch (CoreException e) {
return;
}
fDCombo.removeAll(); fDCombo.removeAll();
if ( fDinfo != null ) {
fDinfo.clear();
}
debugConfigs = CDebugCorePlugin.getDefault().getDebugConfigurations(); debugConfigs = CDebugCorePlugin.getDefault().getDebugConfigurations();
fDinfo = new ArrayList(debugConfigs.length); int x = 0;
int selndx = 0;
for (int i = 0; i < debugConfigs.length; i++) { for (int i = 0; i < debugConfigs.length; i++) {
String supported[] = debugConfigs[i].getPlatforms(); String supported[] = debugConfigs[i].getPlatforms();
for (int j = 0; j < supported.length; j++) { for (int j = 0; j < supported.length; j++) {
if (supported[j].equals("*") || supported[j].equalsIgnoreCase(platform)) { if (supported[j].equals("*") || supported[j].equalsIgnoreCase(platform)) {
fDinfo.add(debugConfigs[i]);
fDCombo.add(debugConfigs[i].getName()); fDCombo.add(debugConfigs[i].getName());
fDCombo.setData(Integer.toString(x), debugConfigs[i]);
if (selection.equals(debugConfigs[i].getID())) {
selndx = x;
}
x++;
break; break;
} }
} }
} }
fDCombo.getParent().layout(); fDCombo.select(selndx);
} fDCombo.getParent().layout(true);
protected void setSelection(String id) {
for (int i = 0; i < fDinfo.size(); i++ ) {
ICDebugConfiguration debugConfig = (ICDebugConfiguration) fDinfo.get(i);
if ( debugConfig != null && debugConfig.getID().equals(id) ) {
fDCombo.select(i);
return;
}
}
} }
public void setDefaults(ILaunchConfigurationWorkingCopy config) { public void setDefaults(ILaunchConfigurationWorkingCopy config) {
setLaunchConfigurationWorkingCopy(config); setLaunchConfigurationWorkingCopy(config);
loadDebuggerComboBox(config);
if ( fDinfo.size() > 0 ) {
ICDebugConfiguration dbgCfg = (ICDebugConfiguration) fDinfo.get(0);
if ( dbgCfg != null ) {
setSelection(dbgCfg.getID());
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, dbgCfg.getID());
}
}
ILaunchConfigurationTab dynamicTab = getDynamicTab(); ILaunchConfigurationTab dynamicTab = getDynamicTab();
if (dynamicTab != null) { if (dynamicTab != null) {
dynamicTab.setDefaults(config); dynamicTab.setDefaults(config);
} }
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false); config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false);
config.setAttribute(
ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
} }
public void initializeFrom(ILaunchConfiguration config) { public void initializeFrom(ILaunchConfiguration config) {
String id; String id;
setLaunchConfiguration(config); setLaunchConfiguration(config);
loadDebuggerComboBox(config);
try { try {
id = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, ""); id = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, "");
setSelection(id); loadDebuggerComboBox(config, id);
ILaunchConfigurationTab dynamicTab = getDynamicTab(); ILaunchConfigurationTab dynamicTab = getDynamicTab();
if (dynamicTab != null) { if (dynamicTab != null) {
dynamicTab.initializeFrom(config); dynamicTab.initializeFrom(config);
@ -202,6 +206,19 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
if (config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false) == true) { if (config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false) == true) {
stopInMain.setSelection(true); stopInMain.setSelection(true);
} }
String mode =
config.getAttribute(
ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
if (mode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH)) {
fAttachButton.setSelection(true);
}
else if (mode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_CORE)) {
fCoreButton.setSelection(true);
}
else {
fRunButton.setSelection(true);
}
} }
catch (CoreException e) { catch (CoreException e) {
return; return;
@ -210,15 +227,30 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
public void performApply(ILaunchConfigurationWorkingCopy config) { public void performApply(ILaunchConfigurationWorkingCopy config) {
if (isValid(config)) { if (isValid(config)) {
ICDebugConfiguration dbgCfg = (ICDebugConfiguration)fDinfo.get(fDCombo.getSelectionIndex()); config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, getDebugConfig().getID());
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, dbgCfg.getID() );
ILaunchConfigurationTab dynamicTab = getDynamicTab(); ILaunchConfigurationTab dynamicTab = getDynamicTab();
if (dynamicTab == null) { if (dynamicTab == null) {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_SPECIFIC_ATTRS_MAP, (Map) null); config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_SPECIFIC_ATTRS_MAP, (Map) null);
} else { }
else {
dynamicTab.performApply(config); dynamicTab.performApply(config);
} }
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, stopInMain.getSelection()); config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, stopInMain.getSelection());
if (fAttachButton.getSelection() == true) {
config.setAttribute(
ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH);
}
else if (fCoreButton.getSelection() == true) {
config.setAttribute(
ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
ICDTLaunchConfigurationConstants.DEBUGGER_MODE_CORE);
}
else {
config.setAttribute(
ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
}
} }
} }
@ -242,13 +274,9 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
* Return the class that implements <code>ILaunchConfigurationTab</code> * Return the class that implements <code>ILaunchConfigurationTab</code>
* that is registered against the debugger id of the currently selected debugger. * that is registered against the debugger id of the currently selected debugger.
*/ */
protected ILaunchConfigurationTab getTabForCurrentDebugger() { protected ICDebugConfiguration getConfigForCurrentDebugger() {
int selectedIndex = fDCombo.getSelectionIndex(); int selectedIndex = fDCombo.getSelectionIndex();
if (selectedIndex >= 0 && !fDinfo.isEmpty()) { return (ICDebugConfiguration) fDCombo.getData(Integer.toString(selectedIndex));
ICDebugConfiguration dbgCfg = (ICDebugConfiguration) fDinfo.get(selectedIndex);
return CDebugUIPlugin.getDefault().getDebuggerPage(dbgCfg.getID());
}
return null;
} }
/** /**
@ -263,16 +291,25 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
} }
// Retrieve the dynamic UI for the current Debugger // Retrieve the dynamic UI for the current Debugger
setDynamicTab(getTabForCurrentDebugger()); ICDebugConfiguration debugConfig = getConfigForCurrentDebugger();
if (debugConfig == null) {
setDynamicTab(null);
}
else {
setDynamicTab(CDebugUIPlugin.getDefault().getDebuggerPage(debugConfig.getID()));
}
if (getDynamicTab() == null) { if (getDynamicTab() == null) {
return; return;
} }
setDebugConfig(debugConfig);
// Ask the dynamic UI to create its Control // Ask the dynamic UI to create its Control
getDynamicTab().setLaunchConfigurationDialog(getLaunchConfigurationDialog()); getDynamicTab().setLaunchConfigurationDialog(getLaunchConfigurationDialog());
getDynamicTab().createControl(getDynamicTabHolder()); getDynamicTab().createControl(getDynamicTabHolder());
getDynamicTab().getControl().setVisible(true); getDynamicTab().getControl().setVisible(true);
getDynamicTabHolder().layout(true); getDynamicTabHolder().layout(true);
fAttachButton.setEnabled(debugConfig.supportsMode(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH));
fCoreButton.setEnabled(debugConfig.supportsMode(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_CORE));
} }
/** /**
@ -284,7 +321,8 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
ILaunchConfigurationTab tab = getDynamicTab(); ILaunchConfigurationTab tab = getDynamicTab();
if ((super.getErrorMessage() != null) || (tab == null)) { if ((super.getErrorMessage() != null) || (tab == null)) {
return super.getErrorMessage(); return super.getErrorMessage();
} else { }
else {
return tab.getErrorMessage(); return tab.getErrorMessage();
} }
} }

View file

@ -5,9 +5,7 @@ package org.eclipse.cdt.launch.ui;
* All Rights Reserved. * All Rights Reserved.
*/ */
import java.io.FileReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICProjectDescriptor; import org.eclipse.cdt.core.ICProjectDescriptor;
@ -17,23 +15,14 @@ import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.IBinaryContainer; import org.eclipse.cdt.core.model.IBinaryContainer;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ICRoot;
import org.eclipse.cdt.internal.ui.CElementLabelProvider; import org.eclipse.cdt.internal.ui.CElementLabelProvider;
import org.eclipse.cdt.launch.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.launch.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.launch.internal.ui.CLaunchConfigurationTab; import org.eclipse.cdt.launch.internal.ui.CLaunchConfigurationTab;
import org.eclipse.cdt.launch.internal.ui.LaunchImages; import org.eclipse.cdt.launch.internal.ui.LaunchImages;
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
import org.eclipse.cdt.utils.elf.Elf;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
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.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.MessageDialog;
@ -51,8 +40,6 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ElementListSelectionDialog; import org.eclipse.ui.dialogs.ElementListSelectionDialog;
import org.eclipse.ui.dialogs.FilteredList;
import org.eclipse.ui.model.WorkbenchLabelProvider;
/** /**
* A launch configuration tab that displays and edits project and * A launch configuration tab that displays and edits project and
@ -86,7 +73,6 @@ public class CMainTab extends CLaunchConfigurationTab {
Composite comp = new Composite(parent, SWT.NONE); Composite comp = new Composite(parent, SWT.NONE);
setControl(comp); setControl(comp);
// WorkbenchHelp.setHelp(getControl(), IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_MAIN_TAB);
GridLayout topLayout = new GridLayout(); GridLayout topLayout = new GridLayout();
comp.setLayout(topLayout); comp.setLayout(topLayout);
@ -158,13 +144,10 @@ public class CMainTab extends CLaunchConfigurationTab {
* @see ILaunchConfigurationTab#initializeFrom(ILaunchConfiguration) * @see ILaunchConfigurationTab#initializeFrom(ILaunchConfiguration)
*/ */
public void initializeFrom(ILaunchConfiguration config) { public void initializeFrom(ILaunchConfiguration config) {
try {
filterPlatform = getPlatform(config); filterPlatform = getPlatform(config);
}
catch (CoreException e) {
}
updateProjectFromConfig(config); updateProjectFromConfig(config);
updateProgramFromConfig(config); updateProgramFromConfig(config);
} }
protected void updateProjectFromConfig(ILaunchConfiguration config) { protected void updateProjectFromConfig(ILaunchConfiguration config) {
@ -197,26 +180,22 @@ public class CMainTab extends CLaunchConfigurationTab {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String) fProgText.getText()); config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String) fProgText.getText());
} }
/**
* @see ILaunchConfigurationTab#dispose()
*/
public void dispose() {
}
/** /**
* Show a dialog that lists all main types * Show a dialog that lists all main types
*/ */
protected void handleSearchButtonSelected() { protected void handleSearchButtonSelected() {
String project = fProjText.getText();
if(project == null || project.length() == 0) { if (getCProject() == null) {
MessageDialog.openInformation(getShell(), "Project required", "Project must first be entered before searching for a program"); MessageDialog.openInformation(
getShell(),
"Project required",
"Project must first be entered before searching for a program");
return; return;
} }
IFile [] executables = getExeFiles(project); IBinary[] executables = getBinaryFiles(getCProject());
ILabelProvider labelProvider = new WorkbenchLabelProvider(); ILabelProvider labelProvider = new CElementLabelProvider();
ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider); ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider);
dialog.setTitle("Program Selection"); dialog.setTitle("Program Selection");
dialog.setMessage("Choose a &program to run"); dialog.setMessage("Choose a &program to run");
@ -229,8 +208,12 @@ public class CMainTab extends CLaunchConfigurationTab {
*/ */
if (dialog.open() == dialog.OK) { if (dialog.open() == dialog.OK) {
IFile file = (IFile)dialog.getFirstResult(); IBinary binary = (IBinary) dialog.getFirstResult();
fProgText.setText(file.getProjectRelativePath().toString()); try {
fProgText.setText(binary.getResource().getProjectRelativePath().toString());
}
catch (CModelException e) {
}
} }
} }
@ -238,49 +221,10 @@ public class CMainTab extends CLaunchConfigurationTab {
* Iterate through and suck up all of the executable files that * Iterate through and suck up all of the executable files that
* we can find. * we can find.
*/ */
protected IFile [] getExeFiles(String projectName) { protected IBinary[] getBinaryFiles(ICProject cproject) {
ArrayList exeList = new ArrayList(1); return cproject.getBinaryContainer().getBinaries();
IProject project;
project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if(project == null) {
return new IFile[0];
} }
ArrayList kids = new ArrayList();
try {
kids.addAll(Arrays.asList(project.members()));
} catch(Exception e) { /* Ignore */ }
for(int i = 0; i < kids.size(); i++) {
Object res = kids.get(i);
if(res instanceof IFile) {
Elf elf = null;
try {
elf = new Elf(((IFile)res).getLocation().toOSString());
switch(elf.getAttributes().getType()) {
case Elf.Attribute.ELF_TYPE_EXE:
exeList.add(res);
break;
}
} catch(Exception e) {
/* Ignore */
} finally {
if(elf != null) {
elf.dispose();
}
}
} else if(res instanceof IContainer) {
try {
kids.addAll(Arrays.asList(((IContainer)res).members()));
} catch(Exception e) { /* Ignore */ }
}
}
return (IFile [])exeList.toArray(new IFile[0]);
}
/** /**
* Show a dialog that lets the user select a project. This in turn provides * Show a dialog that lets the user select a project. This in turn provides
* context for the main type, allowing the user to key a main type name, or * context for the main type, allowing the user to key a main type name, or