1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-14 03:35:37 +02:00

use new debugger configuartion page extension

added AbstractCLaunchTAb
This commit is contained in:
David Inglis 2002-08-15 14:43:02 +00:00
parent 54f5b7dadf
commit 6a2a614989
8 changed files with 306 additions and 242 deletions

View file

@ -8,6 +8,7 @@
<classpathentry kind="src" path="/org.eclipse.cdt.core"/> <classpathentry kind="src" path="/org.eclipse.cdt.core"/>
<classpathentry kind="src" path="/org.eclipse.cdt.ui"/> <classpathentry kind="src" path="/org.eclipse.cdt.ui"/>
<classpathentry kind="src" path="/org.eclipse.cdt.debug.core"/> <classpathentry kind="src" path="/org.eclipse.cdt.debug.core"/>
<classpathentry kind="src" path="/org.eclipse.cdt.debug.ui"/>
<classpathentry kind="src" path="/org.eclipse.core.runtime"/> <classpathentry kind="src" path="/org.eclipse.core.runtime"/>
<classpathentry kind="src" path="/org.eclipse.core.boot"/> <classpathentry kind="src" path="/org.eclipse.core.boot"/>
<classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/> <classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/>

View file

@ -5,6 +5,7 @@
<projects> <projects>
<project>org.eclipse.cdt.core</project> <project>org.eclipse.cdt.core</project>
<project>org.eclipse.cdt.debug.core</project> <project>org.eclipse.cdt.debug.core</project>
<project>org.eclipse.cdt.debug.ui</project>
<project>org.eclipse.cdt.ui</project> <project>org.eclipse.cdt.ui</project>
<project>org.eclipse.core.boot</project> <project>org.eclipse.core.boot</project>
<project>org.eclipse.core.resources</project> <project>org.eclipse.core.resources</project>

View file

@ -17,6 +17,7 @@
<import plugin="org.eclipse.cdt.core"/> <import plugin="org.eclipse.cdt.core"/>
<import plugin="org.eclipse.cdt.ui"/> <import plugin="org.eclipse.cdt.ui"/>
<import plugin="org.eclipse.cdt.debug.core"/> <import plugin="org.eclipse.cdt.debug.core"/>
<import plugin="org.eclipse.cdt.debug.ui"/>
</requires> </requires>

View file

@ -0,0 +1,212 @@
/*
* (c) Copyright QNX Software System Ltd. 2002.
* All Rights Reserved.
*/
package org.eclipse.cdt.launch;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Map.Entry;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
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;
protected String[] getEnvironmentArray(ILaunchConfiguration config) {
// Map env = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map) null);
// TODO create env array;
return null;
}
protected Properties getEnvironmentProperty(ILaunchConfiguration config) {
Properties prop = new Properties();
Map env = null;
try {
env = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map) null);
}
catch (CoreException e) {
}
if ( env == null )
return prop;
Iterator entries = env.entrySet().iterator();
Entry entry;
while( entries.hasNext() ) {
entry = (Entry) entries.next();
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);
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);
}
return dir;
}
/**
* Throws a core exception with an error status object built from
* the given message, lower level exception, and error code.
*
* @param message the status message
* @param exception lower level exception associated with the
* error, or <code>null</code> if none
* @param code error code
*/
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) {
projectName = projectName.trim();
if (projectName.length() > 0) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
ICProject cProject = CCorePlugin.getDefault().getCoreModel().create(project);
if (cProject != null && cProject.exists()) {
return cProject;
}
}
}
return null;
}
public String getProjectName(ILaunchConfiguration configuration) throws CoreException {
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);
}
/**
* 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);
}
/**
* Returns the program arguments as an array of individual arguments.
*
* @return the program arguments as an array of individual arguments
*/
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();
return res;
}
private static class ArgumentParser {
private String fArgs;
private int fIndex= 0;
private int ch= -1;
public ArgumentParser(String args) {
fArgs= args;
}
public String[] parseArguments() {
ArrayList v= new ArrayList();
ch= getNext();
while (ch > 0) {
while (Character.isWhitespace((char)ch))
ch= getNext();
if (ch == '"') {
v.add(parseString());
} else {
v.add(parseToken());
}
}
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();
while (ch > 0 && ch != '"') {
if (ch == '\\') {
ch= getNext();
if (ch != '"') { // Only escape double quotes
buf.append('\\');
}
}
if (ch > 0) {
buf.append((char)ch);
ch= getNext();
}
}
ch= getNext();
return buf.toString();
}
private String parseToken() {
StringBuffer buf= new StringBuffer();
while (ch > 0 && !Character.isWhitespace((char)ch)) {
if (ch == '\\') {
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('\\');
}
} else if (ch == '"') {
buf.append(parseString());
} else {
buf.append((char)ch);
ch= getNext();
}
}
return buf.toString();
}
}
}

View file

@ -54,18 +54,22 @@ public interface ICDTLaunchConfigurationConstants {
* 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_CDT_DEBUGGER_ID = LaunchUIPlugin.getUniqueIdentifier() + ".CDT_DEBUGGER"; //$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 * Launch configuration attribute key. The value is the platform string of the launch configuration
*/ */
public static final String ATTR_CDT_PLATFORM = LaunchUIPlugin.getUniqueIdentifier() + ".CDT_PLATFFORM"; //$NON-NLS-1$ 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() + ".CDT_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
*/
public static final String ATTR_DEBUGGER_STOP_AT_MAIN = LaunchUIPlugin.getUniqueIdentifier() + ".DEBUGGER_STOP_AT_MAIN"; //$NON-NLS-1$
/** /**
* 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

@ -13,19 +13,17 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.CDebugModel; import org.eclipse.cdt.debug.core.CDebugModel;
import org.eclipse.cdt.debug.core.ICDebugConfiguration;
import org.eclipse.cdt.debug.core.ICDebugger; import org.eclipse.cdt.debug.core.ICDebugger;
import org.eclipse.cdt.debug.core.ICDebuggerManager;
import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDIRuntimeOptions; import org.eclipse.cdt.debug.core.cdi.ICDIRuntimeOptions;
import org.eclipse.cdt.debug.core.cdi.ICDISession; import org.eclipse.cdt.debug.core.cdi.ICDISession;
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
import org.eclipse.cdt.launch.AbstractCLaunchDelegate;
import org.eclipse.cdt.launch.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.launch.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
@ -36,46 +34,33 @@ 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.Platform;
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;
import org.eclipse.debug.core.ILaunchConfiguration; 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.ILaunchConfigurationDelegate;
import org.eclipse.debug.core.model.IProcess; import org.eclipse.debug.core.model.IProcess;
/** /**
* Insert the type's description here. * Insert the type's description here.
* @see ILaunchConfigurationDelegate * @see ILaunchConfigurationDelegate
*/ */
public class LocalCLaunchConfigurationDelegate implements ILaunchConfigurationDelegate { public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
protected String renderDebugTarget(ICDISession session) { /*
// String format= "{0} at localhost {1}"; protected String renderDebugTarget(ICDISession session) {
// return MessageFormat.format(format, new String[] { classToRun, String.valueOf(host) }); String format= "{0} at localhost {1}";
return "session -- TODO"; return MessageFormat.format(format, new String[] { classToRun, String.valueOf(host) });
} }
*/
public static String renderProcessLabel(String[] commandLine) { public String renderProcessLabel(String[] commandLine) {
String format= "{0} ({1})"; String format= "{0} ({1})";
String timestamp= DateFormat.getInstance().format(new Date(System.currentTimeMillis())); String timestamp= DateFormat.getInstance().format(new Date(System.currentTimeMillis()));
return MessageFormat.format(format, new String[] { commandLine[0], timestamp }); return MessageFormat.format(format, new String[] { commandLine[0], timestamp });
} }
protected static String renderCommandLine(String[] commandLine) { public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
if (commandLine.length < 1)
return "";
StringBuffer buf= new StringBuffer(commandLine[0]);
for (int i= 1; i < commandLine.length; i++) {
buf.append(' ');
buf.append(commandLine[i]);
}
return buf.toString();
}
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
if (monitor == null) { if (monitor == null) {
monitor = new NullProgressMonitor(); monitor = new NullProgressMonitor();
} }
@ -85,19 +70,18 @@ public class LocalCLaunchConfigurationDelegate implements ILaunchConfigurationDe
if (monitor.isCanceled()) { if (monitor.isCanceled()) {
return; return;
} }
ICProject cproject = getCProject(configuration); ICProject cproject = getCProject(config);
IPath projectPath = Platform.getLocation().append(cproject.getResource().getFullPath()); IPath projectPath = ((IProject)cproject.getResource()).getFile(getProgramName(config)).getLocation();
projectPath = projectPath.append(getProgramName(configuration)); String arguments[] = getProgramArgumentsArray(config);
String arguments[] = getProgramArgumentsArray(configuration);
ArrayList command = new ArrayList(1+arguments.length); ArrayList command = new ArrayList(1+arguments.length);
command.add(projectPath.toOSString()); command.add(projectPath.toOSString());
command.addAll(Arrays.asList(arguments)); command.addAll(Arrays.asList(arguments));
if (mode.equals(ILaunchManager.DEBUG_MODE)) { if (mode.equals(ILaunchManager.DEBUG_MODE)) {
ICDebuggerManager dbgmanager = CDebugCorePlugin.getDefault().getDebuggerManager(); ICDebugConfiguration dbgCfg = CDebugCorePlugin.getDefault().getDebugConfiguration(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, ""));
ICDebugger cdebugger = null; ICDebugger cdebugger = null;
try { try {
cdebugger = dbgmanager.createDebugger(configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_CDT_DEBUGGER_ID, "")); 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);
@ -113,67 +97,32 @@ public class LocalCLaunchConfigurationDelegate implements ILaunchConfigurationDe
IFile exe = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(projectPath); IFile exe = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(projectPath);
ICDISession dsession = null; ICDISession dsession = null;
try { try {
dsession = cdebugger.createLaunchSession(configuration, exe); dsession = cdebugger.createLaunchSession(config, exe);
} }
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();
opt.setArguments(configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "")); opt.setArguments(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, ""));
File wd = getWorkingDir(configuration); File wd = getWorkingDir(config);
if ( wd != null ) { if ( wd != null ) {
opt.setWorkingDirectory(wd.toString()); opt.setWorkingDirectory(wd.toString());
} }
opt.setEnvironment(getEnvironmentProperty(configuration)); 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()])));
CDebugModel.newDebugTarget(launch, dsession.getTargets()[0], renderDebugTarget(dsession), iprocess, true, false, false ); boolean stopInMain = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false);
CDebugModel.newDebugTarget(launch, dsession.getTargets()[0], dbgCfg.getName(), iprocess, true, false, stopInMain );
} }
else { else {
Process process = exec((String [])command.toArray(new String[command.size()]), getEnvironmentArray(configuration), getWorkingDir(configuration)); Process process = exec((String [])command.toArray(new String[command.size()]), getEnvironmentArray(config), getWorkingDir(config));
DebugPlugin.getDefault().newProcess(launch, process, "label"); DebugPlugin.getDefault().newProcess(launch, process, "label");
} }
monitor.done(); monitor.done();
} }
private String[] getEnvironmentArray(ILaunchConfiguration configuration) {
// Map env = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map) null);
// TODO create env array;
return null;
}
private Properties getEnvironmentProperty(ILaunchConfiguration configuration) {
// Map env = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map) null);
return new Properties();
}
protected File getWorkingDir(ILaunchConfiguration config) throws CoreException {
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);
}
return dir;
}
/**
* Throws a core exception with an error status object built from
* the given message, lower level exception, and error code.
*
* @param message the status message
* @param exception lower level exception associated with the
* error, or <code>null</code> if none
* @param code error code
*/
protected void abort(String message, Throwable exception, int code) throws CoreException {
throw new CoreException(new Status(IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(), code, message, exception));
}
/** /**
* Performs a runtime exec on the given command line in the context * Performs a runtime exec on the given command line in the context
@ -220,130 +169,4 @@ public class LocalCLaunchConfigurationDelegate implements ILaunchConfigurationDe
} }
return p; return p;
} }
public ICProject getCProject(ILaunchConfiguration configuration) throws CoreException {
String projectName = getCProjectName(configuration);
if (projectName != null) {
projectName = projectName.trim();
if (projectName.length() > 0) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
ICProject cProject = CCorePlugin.getDefault().getCoreModel().create(project);
if (cProject != null && cProject.exists()) {
return cProject;
}
}
}
return null;
}
public String getCProjectName(ILaunchConfiguration configuration) throws CoreException {
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);
}
/**
* Returns the program arguments as an array of individual arguments.
*
* @return the program arguments as an array of individual arguments
*/
public String[] getProgramArgumentsArray(ILaunchConfiguration configuration) throws CoreException {
String args = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null);
return parseArguments(args);
}
private static class ArgumentParser {
private String fArgs;
private int fIndex= 0;
private int ch= -1;
public ArgumentParser(String args) {
fArgs= args;
}
public String[] parseArguments() {
List v= new ArrayList();
ch= getNext();
while (ch > 0) {
while (Character.isWhitespace((char)ch))
ch= getNext();
if (ch == '"') {
v.add(parseString());
} else {
v.add(parseToken());
}
}
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();
while (ch > 0 && ch != '"') {
if (ch == '\\') {
ch= getNext();
if (ch != '"') { // Only escape double quotes
buf.append('\\');
}
}
if (ch > 0) {
buf.append((char)ch);
ch= getNext();
}
}
ch= getNext();
return buf.toString();
}
private String parseToken() {
StringBuffer buf= new StringBuffer();
while (ch > 0 && !Character.isWhitespace((char)ch)) {
if (ch == '\\') {
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('\\');
}
} else if (ch == '"') {
buf.append(parseString());
} else {
buf.append((char)ch);
ch= getNext();
}
}
return buf.toString();
}
}
private static String[] parseArguments(String args) {
if (args == null)
return new String[0];
ArgumentParser parser= new ArgumentParser(args);
String[] res= parser.parseArguments();
return res;
}
} }

View file

@ -83,6 +83,6 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
protected String getPlatform(ILaunchConfiguration config) throws CoreException { protected String getPlatform(ILaunchConfiguration config) throws CoreException {
String platform = BootLoader.getOS(); String platform = BootLoader.getOS();
return config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_CDT_PLATFORM, platform); return config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PLATFORM, platform);
} }
} }

View file

@ -9,7 +9,8 @@ import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin; 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.ICDebuggerInfo; import org.eclipse.cdt.debug.core.ICDebugConfiguration;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
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;
@ -25,6 +26,7 @@ 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;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Control;
@ -35,6 +37,7 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
ArrayList fDinfo; ArrayList fDinfo;
int fDindex; int fDindex;
Combo fDlist; Combo fDlist;
Button stopInMain;
// Dynamic Debugger UI widgets // Dynamic Debugger UI widgets
protected ILaunchConfigurationTab fDynamicTab; protected ILaunchConfigurationTab fDynamicTab;
@ -42,13 +45,11 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
protected ILaunchConfigurationWorkingCopy fWorkingCopy; protected ILaunchConfigurationWorkingCopy fWorkingCopy;
protected ILaunchConfiguration fLaunchConfiguration; protected ILaunchConfiguration fLaunchConfiguration;
public void createControl(Composite parent) { public void createControl(Composite parent) {
Composite comp= new Composite(parent, SWT.NONE); Composite comp= new Composite(parent, SWT.NONE);
setControl(comp); setControl(comp);
GridLayout topLayout = new GridLayout(2, false); GridLayout topLayout = new GridLayout(3, false);
comp.setLayout(topLayout); comp.setLayout(topLayout);
Label dlabel = new Label(comp, SWT.NONE); Label dlabel = new Label(comp, SWT.NONE);
dlabel.setText("Debugger:"); dlabel.setText("Debugger:");
@ -58,9 +59,15 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
handleDebuggerComboBoxModified(); handleDebuggerComboBoxModified();
} }
}); });
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;
stopInMain.setLayoutData(gd);
Group debuggerGroup = new Group(comp, SWT.SHADOW_ETCHED_IN); Group debuggerGroup = new Group(comp, SWT.SHADOW_ETCHED_IN);
GridData gd = new GridData(GridData.FILL_BOTH); gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 2; gd.horizontalSpan = 3;
debuggerGroup.setLayoutData(gd); debuggerGroup.setLayoutData(gd);
debuggerGroup.setText("Debugger Options"); debuggerGroup.setText("Debugger Options");
setDynamicTabHolder(new Composite(debuggerGroup, SWT.NONE)); setDynamicTabHolder(new Composite(debuggerGroup, SWT.NONE));
@ -71,7 +78,6 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
getDynamicTabHolder().setLayout(tabHolderLayout); getDynamicTabHolder().setLayout(tabHolderLayout);
gd = new GridData(GridData.FILL_BOTH); gd = new GridData(GridData.FILL_BOTH);
getDynamicTabHolder().setLayoutData(gd); getDynamicTabHolder().setLayoutData(gd);
} }
protected void setDynamicTabHolder(Composite tabHolder) { protected void setDynamicTabHolder(Composite tabHolder) {
@ -100,7 +106,7 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
// always set the newly created area with defaults // always set the newly created area with defaults
ILaunchConfigurationWorkingCopy wc = getLaunchConfigurationWorkingCopy(); ILaunchConfigurationWorkingCopy wc = getLaunchConfigurationWorkingCopy();
if (getDynamicTab() == null) { if (getDynamicTab() == null) {
// remove any VM specfic args from the config // remove any debug specfic args from the config
if (wc == null) { if (wc == null) {
if (getLaunchConfiguration().isWorkingCopy()) { if (getLaunchConfiguration().isWorkingCopy()) {
wc = (ILaunchConfigurationWorkingCopy)getLaunchConfiguration(); wc = (ILaunchConfigurationWorkingCopy)getLaunchConfiguration();
@ -130,28 +136,37 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
} }
protected void loadDebuggerComboBox(ILaunchConfiguration config) { protected void loadDebuggerComboBox(ILaunchConfiguration config) {
ICDebuggerInfo[] debuggerInfo = null; ICDebugConfiguration[] debugConfigs;
if ( fDinfo != null ) { String platform;
fDinfo.clear();
}
fDlist.removeAll();
try { try {
debuggerInfo = CDebugCorePlugin.getDefault().getDebuggerManager().queryDebuggers(getPlatform(config)); platform = getPlatform(config);
} }
catch (CoreException e) { catch (CoreException e) {
return; return;
} }
fDinfo = new ArrayList(debuggerInfo.length); if ( fDinfo != null ) {
for( int i = 0; i < debuggerInfo.length; i++ ) { fDinfo.clear();
fDinfo.add(debuggerInfo[i]);
fDlist.add(debuggerInfo[i].getName());
} }
fDlist.removeAll();
debugConfigs = CDebugCorePlugin.getDefault().getDebugConfigurations();
fDinfo = new ArrayList(debugConfigs.length);
for( int i = 0; i < debugConfigs.length; i++ ) {
String supported[] = debugConfigs[i].getPlatforms();
for( int j = 0; j < supported.length; j++ ) {
if (supported[j].equals("*") || supported[j].equalsIgnoreCase(platform)) {
fDinfo.add(debugConfigs[i]);
fDlist.add(debugConfigs[i].getName());
break;
}
}
}
fDlist.getParent().layout();
} }
protected void setSelection(String id) { protected void setSelection(String id) {
for (int i = 0; i < fDinfo.size(); i++ ) { for (int i = 0; i < fDinfo.size(); i++ ) {
ICDebuggerInfo dinfo = (ICDebuggerInfo) fDinfo.get(i); ICDebugConfiguration debugConfig = (ICDebugConfiguration) fDinfo.get(i);
if ( dinfo != null && dinfo.getID().equals(id) ) { if ( debugConfig != null && debugConfig.getID().equals(id) ) {
fDlist.select(i); fDlist.select(i);
return; return;
} }
@ -162,16 +177,17 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
setLaunchConfigurationWorkingCopy(config); setLaunchConfigurationWorkingCopy(config);
loadDebuggerComboBox(config); loadDebuggerComboBox(config);
if ( fDinfo.size() > 0 ) { if ( fDinfo.size() > 0 ) {
ICDebuggerInfo info = (ICDebuggerInfo) fDinfo.get(0); ICDebugConfiguration dbgCfg = (ICDebugConfiguration) fDinfo.get(0);
if ( info != null ) { if ( dbgCfg != null ) {
setSelection(info.getID()); setSelection(dbgCfg.getID());
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_CDT_DEBUGGER_ID, info.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);
} }
public void initializeFrom(ILaunchConfiguration config) { public void initializeFrom(ILaunchConfiguration config) {
@ -179,29 +195,32 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
setLaunchConfiguration(config); setLaunchConfiguration(config);
loadDebuggerComboBox(config); loadDebuggerComboBox(config);
try { try {
id = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_CDT_DEBUGGER_ID, ""); id = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, "");
setSelection(id);
ILaunchConfigurationTab dynamicTab = getDynamicTab();
if (dynamicTab != null) {
dynamicTab.initializeFrom(config);
}
if ( config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false) == true ) {
stopInMain.setSelection(true);
}
} }
catch (CoreException e) { catch (CoreException e) {
return; return;
} }
setSelection(id);
ILaunchConfigurationTab dynamicTab = getDynamicTab();
if (dynamicTab != null) {
dynamicTab.initializeFrom(config);
}
} }
public void performApply(ILaunchConfigurationWorkingCopy config) { public void performApply(ILaunchConfigurationWorkingCopy config) {
if ( isValid(config) ) { if ( isValid(config) ) {
ICDebuggerInfo dinfo = (ICDebuggerInfo)fDinfo.get(fDlist.getSelectionIndex()); ICDebugConfiguration dbgCfg = (ICDebugConfiguration)fDinfo.get(fDlist.getSelectionIndex());
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_CDT_DEBUGGER_ID, dinfo.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());
} }
} }
@ -223,18 +242,20 @@ 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 install type of the currently selected VM. * that is registered against the debugger id of the currently selected debugger.
*/ */
protected ILaunchConfigurationTab getTabForCurrentDebugger() { protected ILaunchConfigurationTab getTabForCurrentDebugger() {
int selectedIndex = fDlist.getSelectionIndex(); int selectedIndex = fDlist.getSelectionIndex();
if (selectedIndex > 0) { if (selectedIndex > 0) {
ICDebugConfiguration dbgCfg = (ICDebugConfiguration) fDinfo.get(selectedIndex);
return CDebugUIPlugin.getDefault().getDebuggerPage(dbgCfg.getID());
} }
return null; return null;
} }
/** /**
* Show the contributed piece of UI that was registered for the install type * Show the contributed piece of UI that was registered for the debugger id
* of the currently selected VM. * of the currently selected debugger.
*/ */
protected void loadDynamicDebugArea() { protected void loadDynamicDebugArea() {
// Dispose of any current child widgets in the tab holder area // Dispose of any current child widgets in the tab holder area
@ -243,7 +264,7 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
children[i].dispose(); children[i].dispose();
} }
// Retrieve the dynamic UI for the current JRE // Retrieve the dynamic UI for the current Debugger
setDynamicTab(getTabForCurrentDebugger()); setDynamicTab(getTabForCurrentDebugger());
if (getDynamicTab() == null) { if (getDynamicTab() == null) {
return; return;
@ -252,7 +273,8 @@ public class CDebuggerTab extends CLaunchConfigurationTab {
// 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());
getDynamicTabHolder().layout(); getDynamicTab().getControl().setVisible(true);
getDynamicTabHolder().layout(true);
} }
/** /**