1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-19 23:15:24 +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,11 +26,12 @@ import org.eclipse.debug.core.model.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) {
// Map env = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map) null);
// TODO create env array;
// Map env = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map) null);
// TODO create env array;
return null;
}
@ -42,25 +43,28 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel
}
catch (CoreException e) {
}
if ( env == null )
if (env == null)
return prop;
Iterator entries = env.entrySet().iterator();
Entry entry;
while( entries.hasNext() ) {
while (entries.hasNext()) {
entry = (Entry) entries.next();
prop.setProperty((String)entry.getKey(), (String)entry.getValue());
prop.setProperty((String) entry.getKey(), (String) entry.getValue());
}
return prop;
}
protected File getWorkingDir(ILaunchConfiguration config) throws CoreException {
String path = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String)null);
String path = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
if (path == null) {
return null;
}
File dir = new File(path);
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;
}
@ -94,11 +98,11 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel
}
public String getProjectName(ILaunchConfiguration configuration) throws CoreException {
return configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null);
return configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null);
}
public String getProgramName(ILaunchConfiguration configuration) throws CoreException {
return configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String)null);
return configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String) null);
}
/**
@ -107,7 +111,7 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel
* @return the program arguments as a String
*/
public String getProgramArguments(ILaunchConfiguration config) throws CoreException {
return config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null);
return config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String) null);
}
/**
@ -122,37 +126,38 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel
private static String[] parseArguments(String args) {
if (args == null)
return new String[0];
ArgumentParser parser= new ArgumentParser(args);
String[] res= parser.parseArguments();
ArgumentParser parser = new ArgumentParser(args);
String[] res = parser.parseArguments();
return res;
}
private static class ArgumentParser {
private String fArgs;
private int fIndex= 0;
private int ch= -1;
private int fIndex = 0;
private int ch = -1;
public ArgumentParser(String args) {
fArgs= args;
fArgs = args;
}
public String[] parseArguments() {
ArrayList v= new ArrayList();
ArrayList v = new ArrayList();
ch= getNext();
ch = getNext();
while (ch > 0) {
while (Character.isWhitespace((char)ch))
ch= getNext();
while (Character.isWhitespace((char) ch))
ch = getNext();
if (ch == '"') {
v.add(parseString());
} else {
}
else {
v.add(parseToken());
}
}
String[] result= new String[v.size()];
String[] result = new String[v.size()];
v.toArray(result);
return result;
}
@ -164,46 +169,49 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel
}
private String parseString() {
StringBuffer buf= new StringBuffer();
ch= getNext();
StringBuffer buf = new StringBuffer();
ch = getNext();
while (ch > 0 && ch != '"') {
if (ch == '\\') {
ch= getNext();
ch = getNext();
if (ch != '"') { // Only escape double quotes
buf.append('\\');
}
}
if (ch > 0) {
buf.append((char)ch);
ch= getNext();
buf.append((char) ch);
ch = getNext();
}
}
ch= getNext();
ch = getNext();
return buf.toString();
}
private String parseToken() {
StringBuffer buf= new StringBuffer();
StringBuffer buf = new StringBuffer();
while (ch > 0 && !Character.isWhitespace((char)ch)) {
while (ch > 0 && !Character.isWhitespace((char) ch)) {
if (ch == '\\') {
ch= getNext();
ch = getNext();
if (ch > 0) {
if (ch != '"') { // Only escape double quotes
buf.append('\\');
}
buf.append((char)ch);
ch= getNext();
} else if (ch == -1) { // Don't lose a trailing backslash
buf.append((char) ch);
ch = getNext();
}
else if (ch == -1) { // Don't lose a trailing backslash
buf.append('\\');
}
} else if (ch == '"') {
}
else if (ch == '"') {
buf.append(parseString());
} else {
buf.append((char)ch);
ch= getNext();
}
else {
buf.append((char) ch);
ch = getNext();
}
}
return buf.toString();

View file

@ -50,26 +50,50 @@ public interface ICDTLaunchConfigurationConstants {
*/
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
* used when launching a C/C++ application for debug.
*/
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
*/
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$
/**
* 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
* 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.IStatus;
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.debug.core.DebugPlugin;
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.IStatusHandler;
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.
@ -48,15 +53,15 @@ import org.eclipse.debug.core.model.IProcess;
*/
public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
/*
/*
protected String renderDebugTarget(ICDISession session) {
String format= "{0} at localhost {1}";
return MessageFormat.format(format, new String[] { classToRun, String.valueOf(host) });
}
*/
*/
public String renderProcessLabel(String[] commandLine) {
String format= "{0} ({1})";
String timestamp= DateFormat.getInstance().format(new Date(System.currentTimeMillis()));
String format = "{0} ({1})";
String timestamp = DateFormat.getInstance().format(new Date(System.currentTimeMillis()));
return MessageFormat.format(format, new String[] { commandLine[0], timestamp });
}
@ -71,9 +76,9 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
return;
}
ICProject cproject = getCProject(config);
IPath projectPath = ((IProject)cproject.getResource()).getFile(getProgramName(config)).getLocation();
IPath projectPath = ((IProject) cproject.getResource()).getFile(getProgramName(config)).getLocation();
String arguments[] = getProgramArgumentsArray(config);
ArrayList command = new ArrayList(1+arguments.length);
ArrayList command = new ArrayList(1 + arguments.length);
command.add(projectPath.toOSString());
command.addAll(Arrays.asList(arguments));
@ -81,11 +86,19 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
ICDebugConfiguration dbgCfg = null;
ICDebugger cdebugger = null;
try {
dbgCfg = CDebugCorePlugin.getDefault().getDebugConfiguration(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, ""));
dbgCfg =
CDebugCorePlugin.getDefault().getDebugConfiguration(
config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, ""));
cdebugger = dbgCfg.getDebugger();
}
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);
if (handler != null) {
@ -98,33 +111,90 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
IFile exe = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(projectPath);
ICDISession dsession = null;
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);
}
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) {
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);
}
ICDIRuntimeOptions opt = dsession.getRuntimeOptions();
opt.setArguments(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, ""));
File wd = getWorkingDir(config);
if ( wd != null ) {
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((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);
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 {
String []commandArray = (String [])command.toArray(new String[command.size()]);
String[] commandArray = (String[]) command.toArray(new String[command.size()]);
Process process = exec(commandArray, getEnvironmentArray(config), getWorkingDir(config));
DebugPlugin.getDefault().newProcess(launch, process, renderProcessLabel(commandArray));
}
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
@ -159,7 +229,13 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
catch (NoSuchMethodError e) {
//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);
if (handler != null) {

View file

@ -41,8 +41,9 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
if (!ss.isEmpty()) {
Object obj = ss.getFirstElement();
if (obj instanceof ICElement) {
ICProjectDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(((ICElement)obj).getCProject().getProject());
if ( descriptor.getPlatform().equals(getPlatform(config)) )
ICProjectDescriptor descriptor =
CCorePlugin.getDefault().getCProjectDescription(((ICElement) obj).getCProject().getProject());
if (descriptor.getPlatform().equals(getPlatform(config)))
return (ICElement) obj;
}
if (obj instanceof IResource) {
@ -52,8 +53,9 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
ce = CoreModel.getDefault().create(pro);
}
if (ce != null) {
ICProjectDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(ce.getCProject().getProject());
if ( descriptor.getPlatform().equals(getPlatform(config)) )
ICProjectDescriptor descriptor =
CCorePlugin.getDefault().getCProjectDescription(ce.getCProject().getProject());
if (descriptor.getPlatform().equals(getPlatform(config)))
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();
try {
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;
}
public static Shell getShell() {
if (getActiveWorkbenchWindow() != null) {
return getActiveWorkbenchWindow().getShell();
}
return null;
}
/**
* 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,
// return a static identifier. This identifier must
// 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();
}

View file

@ -7,7 +7,6 @@ package org.eclipse.cdt.launch.ui;
import java.util.ArrayList;
import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.ICDebugConfiguration;
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.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@ -34,26 +33,29 @@ import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
public class CDebuggerTab extends CLaunchConfigurationTab {
ArrayList fDinfo;
int fDindex;
Combo fDCombo;
Button stopInMain;
protected Button fAttachButton;
protected Button fCoreButton;
protected Button fRunButton;
// Dynamic Debugger UI widgets
protected ILaunchConfigurationTab fDynamicTab;
protected Composite fDynamicTabHolder;
protected ICDebugConfiguration fCurrentDebugConfig;
protected ILaunchConfigurationWorkingCopy fWorkingCopy;
protected ILaunchConfiguration fLaunchConfiguration;
public void createControl(Composite parent) {
Composite comp= new Composite(parent, SWT.NONE);
Composite comp = new Composite(parent, SWT.NONE);
setControl(comp);
GridLayout topLayout = new GridLayout(3, false);
comp.setLayout(topLayout);
Label dlabel = new Label(comp, SWT.NONE);
dlabel.setText("Debugger:");
fDCombo = new Combo(comp, SWT.DROP_DOWN|SWT.READ_ONLY);
fDCombo = new Combo(comp, SWT.DROP_DOWN | SWT.READ_ONLY);
fDCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
handleDebuggerComboBoxModified();
@ -62,15 +64,27 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
stopInMain = new Button(comp, SWT.CHECK);
stopInMain.setText("Stop at main() on startup.");
GridData gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_END;
gd.horizontalIndent = 10;
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);
debuggerGroup.setText("Debugger Options");
setDynamicTabHolder(debuggerGroup);
GridLayout tabHolderLayout = new GridLayout();
tabHolderLayout.marginHeight= 0;
tabHolderLayout.marginWidth= 0;
tabHolderLayout.marginHeight = 0;
tabHolderLayout.marginWidth = 0;
tabHolderLayout.numColumns = 1;
getDynamicTabHolder().setLayout(tabHolderLayout);
gd = new GridData(GridData.FILL_BOTH);
@ -94,7 +108,13 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
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.
*/
@ -107,101 +127,98 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
// remove any debug specfic args from the config
if (wc == null) {
if (getLaunchConfiguration().isWorkingCopy()) {
wc = (ILaunchConfigurationWorkingCopy)getLaunchConfiguration();
wc = (ILaunchConfigurationWorkingCopy) getLaunchConfiguration();
}
}
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) {
try {
if (getLaunchConfiguration().isWorkingCopy()) {
// get a fresh copy to work on
wc = ((ILaunchConfigurationWorkingCopy)getLaunchConfiguration()).getOriginal().getWorkingCopy();
} else {
wc = ((ILaunchConfigurationWorkingCopy) getLaunchConfiguration()).getOriginal().getWorkingCopy();
}
else {
wc = getLaunchConfiguration().getWorkingCopy();
}
} catch (CoreException e) {
}
catch (CoreException e) {
return;
}
}
getDynamicTab().setDefaults(wc);
getDynamicTab().initializeFrom(wc);
}
updateLaunchConfigurationDialog();
}
protected void loadDebuggerComboBox(ILaunchConfiguration config) {
protected void loadDebuggerComboBox(ILaunchConfiguration config, String selection) {
ICDebugConfiguration[] debugConfigs;
String platform;
try {
platform = getPlatform(config);
}
catch (CoreException e) {
return;
}
String platform = getPlatform(config);
fDCombo.removeAll();
if ( fDinfo != null ) {
fDinfo.clear();
}
debugConfigs = CDebugCorePlugin.getDefault().getDebugConfigurations();
fDinfo = new ArrayList(debugConfigs.length);
for( int i = 0; i < debugConfigs.length; i++ ) {
int x = 0;
int selndx = 0;
for (int i = 0; i < debugConfigs.length; i++) {
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)) {
fDinfo.add(debugConfigs[i]);
fDCombo.add(debugConfigs[i].getName());
fDCombo.setData(Integer.toString(x), debugConfigs[i]);
if (selection.equals(debugConfigs[i].getID())) {
selndx = x;
}
x++;
break;
}
}
}
fDCombo.getParent().layout();
}
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;
}
}
fDCombo.select(selndx);
fDCombo.getParent().layout(true);
}
public void setDefaults(ILaunchConfigurationWorkingCopy 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();
if (dynamicTab != null) {
dynamicTab.setDefaults(config);
}
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) {
String id;
setLaunchConfiguration(config);
loadDebuggerComboBox(config);
try {
id = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, "");
setSelection(id);
loadDebuggerComboBox(config, id);
ILaunchConfigurationTab dynamicTab = getDynamicTab();
if (dynamicTab != null) {
dynamicTab.initializeFrom(config);
}
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);
}
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) {
return;
@ -209,16 +226,31 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
}
public void performApply(ILaunchConfigurationWorkingCopy config) {
if ( isValid(config) ) {
ICDebugConfiguration dbgCfg = (ICDebugConfiguration)fDinfo.get(fDCombo.getSelectionIndex());
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, dbgCfg.getID() );
if (isValid(config)) {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, getDebugConfig().getID());
ILaunchConfigurationTab dynamicTab = getDynamicTab();
if (dynamicTab == null) {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_SPECIFIC_ATTRS_MAP, (Map)null);
} else {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_SPECIFIC_ATTRS_MAP, (Map) null);
}
else {
dynamicTab.performApply(config);
}
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);
}
}
}
@ -226,7 +258,7 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
setErrorMessage(null);
setMessage(null);
if ( fDCombo.getSelectionIndex() == -1 ) {
if (fDCombo.getSelectionIndex() == -1) {
setErrorMessage("No debugger avalible");
return false;
}
@ -242,13 +274,9 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
* Return the class that implements <code>ILaunchConfigurationTab</code>
* that is registered against the debugger id of the currently selected debugger.
*/
protected ILaunchConfigurationTab getTabForCurrentDebugger() {
protected ICDebugConfiguration getConfigForCurrentDebugger() {
int selectedIndex = fDCombo.getSelectionIndex();
if (selectedIndex >= 0 && !fDinfo.isEmpty()) {
ICDebugConfiguration dbgCfg = (ICDebugConfiguration) fDinfo.get(selectedIndex);
return CDebugUIPlugin.getDefault().getDebuggerPage(dbgCfg.getID());
}
return null;
return (ICDebugConfiguration) fDCombo.getData(Integer.toString(selectedIndex));
}
/**
@ -263,16 +291,25 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
}
// 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) {
return;
}
setDebugConfig(debugConfig);
// Ask the dynamic UI to create its Control
getDynamicTab().setLaunchConfigurationDialog(getLaunchConfigurationDialog());
getDynamicTab().createControl(getDynamicTabHolder());
getDynamicTab().getControl().setVisible(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();
if ((super.getErrorMessage() != null) || (tab == null)) {
return super.getErrorMessage();
} else {
}
else {
return tab.getErrorMessage();
}
}

View file

@ -5,9 +5,7 @@ package org.eclipse.cdt.launch.ui;
* All Rights Reserved.
*/
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.cdt.core.CCorePlugin;
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.ICElement;
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.launch.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.launch.internal.ui.CLaunchConfigurationTab;
import org.eclipse.cdt.launch.internal.ui.LaunchImages;
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.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
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.ILaunchConfigurationWorkingCopy;
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.Text;
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
@ -86,7 +73,6 @@ public class CMainTab extends CLaunchConfigurationTab {
Composite comp = new Composite(parent, SWT.NONE);
setControl(comp);
// WorkbenchHelp.setHelp(getControl(), IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_MAIN_TAB);
GridLayout topLayout = new GridLayout();
comp.setLayout(topLayout);
@ -158,13 +144,10 @@ public class CMainTab extends CLaunchConfigurationTab {
* @see ILaunchConfigurationTab#initializeFrom(ILaunchConfiguration)
*/
public void initializeFrom(ILaunchConfiguration config) {
try {
filterPlatform = getPlatform(config);
}
catch (CoreException e) {
}
updateProjectFromConfig(config);
updateProgramFromConfig(config);
}
protected void updateProjectFromConfig(ILaunchConfiguration config) {
@ -197,26 +180,22 @@ public class CMainTab extends CLaunchConfigurationTab {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String) fProgText.getText());
}
/**
* @see ILaunchConfigurationTab#dispose()
*/
public void dispose() {
}
/**
* Show a dialog that lists all main types
*/
protected void handleSearchButtonSelected() {
String project = fProjText.getText();
if(project == null || project.length() == 0) {
MessageDialog.openInformation(getShell(), "Project required", "Project must first be entered before searching for a program");
if (getCProject() == null) {
MessageDialog.openInformation(
getShell(),
"Project required",
"Project must first be entered before searching for a program");
return;
}
IFile [] executables = getExeFiles(project);
IBinary[] executables = getBinaryFiles(getCProject());
ILabelProvider labelProvider = new WorkbenchLabelProvider();
ILabelProvider labelProvider = new CElementLabelProvider();
ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider);
dialog.setTitle("Program Selection");
dialog.setMessage("Choose a &program to run");
@ -229,8 +208,12 @@ public class CMainTab extends CLaunchConfigurationTab {
*/
if (dialog.open() == dialog.OK) {
IFile file = (IFile)dialog.getFirstResult();
fProgText.setText(file.getProjectRelativePath().toString());
IBinary binary = (IBinary) dialog.getFirstResult();
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
* we can find.
*/
protected IFile [] getExeFiles(String projectName) {
ArrayList exeList = new ArrayList(1);
IProject project;
project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if(project == null) {
return new IFile[0];
protected IBinary[] getBinaryFiles(ICProject cproject) {
return cproject.getBinaryContainer().getBinaries();
}
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
* context for the main type, allowing the user to key a main type name, or
@ -376,7 +320,7 @@ public class CMainTab extends CLaunchConfigurationTab {
setErrorMessage("Program not specified");
return false;
}
if (!project.getFile(name).exists() ) {
if (!project.getFile(name).exists()) {
setErrorMessage("Program does not exist");
return false;
}