diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java index 5b43e567762..4d1794a68a8 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java @@ -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; } @@ -77,7 +81,7 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel protected void abort(String message, Throwable exception, int code) throws CoreException { throw new CoreException(new Status(IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(), code, message, exception)); } - + public ICProject getCProject(ILaunchConfiguration configuration) throws CoreException { String projectName = getProjectName(configuration); if (projectName != null) { @@ -94,21 +98,21 @@ 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); } - + /** * Returns the program arguments as a String. * * @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); + } /** * Returns the program arguments as an array of individual arguments. @@ -117,96 +121,100 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel */ public String[] getProgramArgumentsArray(ILaunchConfiguration config) throws CoreException { return parseArguments(getProgramArguments(config)); - } - + } + 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(); - - ch= getNext(); + ArrayList v = new ArrayList(); + + 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; } - + private int getNext() { if (fIndex < fArgs.length()) return fArgs.charAt(fIndex++); return -1; } - + private String parseString() { - StringBuffer buf= new StringBuffer(); - ch= getNext(); + StringBuffer buf = new StringBuffer(); + ch = getNext(); while (ch > 0 && ch != '"') { if (ch == '\\') { - ch= getNext(); - if (ch != '"') { // Only escape double quotes - buf.append('\\'); + 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(); - - while (ch > 0 && !Character.isWhitespace((char)ch)) { + StringBuffer buf = new StringBuffer(); + + while (ch > 0 && !Character.isWhitespace((char) ch)) { if (ch == '\\') { - ch= getNext(); + ch = getNext(); if (ch > 0) { - if (ch != '"') { // Only escape double quotes - buf.append('\\'); + 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(); } - } + } } diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ICDTLaunchConfigurationConstants.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ICDTLaunchConfigurationConstants.java index 598f09d398b..9c06129b563 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ICDTLaunchConfigurationConstants.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ICDTLaunchConfigurationConstants.java @@ -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 diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalCLaunchConfigurationDelegate.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalCLaunchConfigurationDelegate.java index 5f7335f518f..e4c230701f6 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalCLaunchConfigurationDelegate.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalCLaunchConfigurationDelegate.java @@ -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,18 +53,18 @@ 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) }); - } -*/ + /* + 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 }); } - + public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { if (monitor == null) { monitor = new NullProgressMonitor(); @@ -71,21 +76,29 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate { return; } ICProject cproject = getCProject(config); - IPath projectPath = ((IProject)cproject.getResource()).getFile(getProgramName(config)).getLocation(); - String arguments[] = getProgramArgumentsArray(config); - ArrayList command = new ArrayList(1+arguments.length); + IPath projectPath = ((IProject) cproject.getResource()).getFile(getProgramName(config)).getLocation(); + String arguments[] = getProgramArgumentsArray(config); + ArrayList command = new ArrayList(1 + arguments.length); command.add(projectPath.toOSString()); command.addAll(Arrays.asList(arguments)); if (mode.equals(ILaunchManager.DEBUG_MODE)) { ICDebugConfiguration dbgCfg = null; - ICDebugger cdebugger = 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 { - dsession = cdebugger.createLaunchSession(config, exe); + 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) { diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/CLaunchConfigurationTab.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/CLaunchConfigurationTab.java index 42f71c844d5..6948b1f5351 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/CLaunchConfigurationTab.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/CLaunchConfigurationTab.java @@ -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; } } @@ -78,11 +80,16 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio name = cProject.getElementName(); } config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, name); - + } - - protected String getPlatform(ILaunchConfiguration config) throws CoreException { + + protected String getPlatform(ILaunchConfiguration config) { String platform = BootLoader.getOS(); - return config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PLATFORM, platform); - } + try { + return config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PLATFORM, platform); + } + catch (CoreException e) { + return platform; + } + } } diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LaunchUIPlugin.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LaunchUIPlugin.java index 53c6578c0ba..9749a628b38 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LaunchUIPlugin.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LaunchUIPlugin.java @@ -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(); } diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CDebuggerTab.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CDebuggerTab.java index d238bcf9295..7586ffce5ae 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CDebuggerTab.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CDebuggerTab.java @@ -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); - setControl(comp); + 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,22 +64,34 @@ 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); gd.horizontalSpan = 3; getDynamicTabHolder().setLayoutData(gd); } - + protected void setDynamicTabHolder(Composite tabHolder) { this.fDynamicTabHolder = tabHolder; } @@ -94,114 +108,117 @@ 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. */ protected void handleDebuggerComboBoxModified() { loadDynamicDebugArea(); - + // always set the newly created area with defaults ILaunchConfigurationWorkingCopy wc = getLaunchConfigurationWorkingCopy(); if (getDynamicTab() == null) { // 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 = getLaunchConfiguration().getWorkingCopy(); + wc = ((ILaunchConfigurationWorkingCopy) getLaunchConfiguration()).getOriginal().getWorkingCopy(); } - } catch (CoreException e) { + else { + wc = getLaunchConfiguration().getWorkingCopy(); + } + } + catch (CoreException e) { return; } } getDynamicTab().setDefaults(wc); getDynamicTab().initializeFrom(wc); } - - updateLaunchConfigurationDialog(); + 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(); + 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) { 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,24 +226,39 @@ 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); + } } } - + public boolean isValid(ILaunchConfiguration config) { 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 ILaunchConfigurationTab * 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)); } /** @@ -261,18 +289,27 @@ public class CDebuggerTab extends CLaunchConfigurationTab { for (int i = 0; i < children.length; i++) { children[i].dispose(); } - + // 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(); } } diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java index 898e696fd22..25a64054a5a 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java @@ -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) { - } + filterPlatform = getPlatform(config); updateProjectFromConfig(config); updateProgramFromConfig(config); + } protected void updateProjectFromConfig(ILaunchConfiguration config) { @@ -197,89 +180,50 @@ 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); - - ILabelProvider labelProvider = new WorkbenchLabelProvider(); + IBinary[] executables = getBinaryFiles(getCProject()); + + ILabelProvider labelProvider = new CElementLabelProvider(); ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider); dialog.setTitle("Program Selection"); dialog.setMessage("Choose a &program to run"); dialog.setElements(executables); - + /* if (cProject != null) { dialog.setInitialSelections(new Object[] { cProject }); } */ - + if (dialog.open() == dialog.OK) { - IFile file = (IFile)dialog.getFirstResult(); - fProgText.setText(file.getProjectRelativePath().toString()); - } - } - - /** - * 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]; - } - - 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 */ } + IBinary binary = (IBinary) dialog.getFirstResult(); + try { + fProgText.setText(binary.getResource().getProjectRelativePath().toString()); + } + catch (CModelException e) { } } - - return (IFile [])exeList.toArray(new IFile[0]); } - + + /** + * Iterate through and suck up all of the executable files that + * we can find. + */ + protected IBinary[] getBinaryFiles(ICProject cproject) { + return cproject.getBinaryContainer().getBinaries(); + } /** * Show a dialog that lets the user select a project. This in turn provides @@ -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; }