import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Properties;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tizen.rt.ide.Messages;
+import org.tizen.rt.ide.util.MacroUtil;
import org.tizen.rt.ide.util.OSChecker;
+import org.tizen.rt.ide.util.ResourceUtil;
+import org.tizen.rt.ide.util.SDKUtil;
+import org.tizen.rt.ide.util.XMLUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import ilg.gnuarmeclipse.debug.gdbjtag.openocd.ConfigurationAttributes;
private static final String PATH_BUILD_OUTPUT = "build/output"; //$NON-NLS-1$
private static final String PATH_BUILD_CONFIGS = "build/configs"; //$NON-NLS-1$
private static final String PATH_OPENOCD = "openocd"; //$NON-NLS-1$
+ private static final String PATH_OPENOCD_SCRIPT = "tools/openocd"; //$NON-NLS-1$
+ // private static final String PATH_DEBUG_OPENOCD = "tools/openocd"; //$NON-NLS-1$
private static final String PROGRAM_NAME = PATH_BUILD_OUTPUT + "/bin/tinyara"; //$NON-NLS-1$
- private static final String OPENOCD_EXECUTABLE_32 = "openocd_0.10_linux32_t20"; //$NON-NLS-1$
- private static final String OPENOCD_EXECUTABLE_64 = "openocd_0.10_linux64_t20"; //$NON-NLS-1$
+ // private static final String OPENOCD_EXECUTABLE_32 = "openocd_0.10_linux32_t20"; //$NON-NLS-1$
+ // private static final String OPENOCD_EXECUTABLE_64 = "openocd_0.10_linux64_t20"; //$NON-NLS-1$
+ // private static final String OPENOCD_EXECUTABLE_32 = "linux32/openocd"; //$NON-NLS-1$
+ // private static final String OPENOCD_EXECUTABLE_64 = "linux64/openocd"; //$NON-NLS-1$
private static final String DEBUGGER_NAME = "arm-none-eabi-gdb"; //$NON-NLS-1$
+ private static final String FILE_NAME_DEBUG_SCRIPT = "debug.xml"; //$NON-NLS-1$
private final String OPENOCD_LAUNCHTYPE = "ilg.gnuarmeclipse.debug.gdbjtag.openocd.launchConfigurationType"; //$NON-NLS-1$
+ private class LaunchParam {
+ public String name;
+ public String prefix;
+ public String value;
+
+ public LaunchParam(String name, String prefix, String value) {
+ this.name = name;
+ this.prefix = prefix;
+ this.value = value;
+ }
+ }
+
+ private class LaunchExecute {
+ public String platform;
+ public String execute;
+ public List<LaunchParam> params;
+
+ public LaunchExecute(String platform, String execute, List<LaunchParam> params) {
+ this.platform = platform;
+ this.execute = execute;
+ this.params = params;
+ }
+
+ public String getFullParam() {
+ if (params == null) {
+ return null;
+ }
+
+ String fullParam = null;
+ for (LaunchParam param : params) {
+ if (fullParam != null && !fullParam.isEmpty()) {
+ fullParam += " ";
+ } else {
+ fullParam = "";
+ }
+ fullParam += param.prefix + " " + param.value;
+ }
+
+ return fullParam;
+ }
+ }
+
+ private class LaunchScript {
+ public String type;
+ public Map<String, LaunchExecute> executes;
+
+ public LaunchScript(String type, Map<String, LaunchExecute> executes) {
+ this.type = type;
+ this.executes = executes;
+ }
+
+ public LaunchExecute getExecute(String platformName) {
+ if (executes == null) {
+ return null;
+ }
+
+ return executes.get(platformName);
+ }
+ }
+
+ private Map<String, LaunchScript> getBuildScripts(File buildScriptFile, Map<String, String> macros) {
+ Document doc = XMLUtil.readXML(buildScriptFile);
+
+ NodeList commands = XMLUtil.getDOMNodes(doc.getDocumentElement(), "/launch/debug");
+ if (commands == null || commands.getLength() <= 0) {
+ return null;
+ }
+
+ Map<String, LaunchScript> scripts = new HashMap<String, LaunchScript>();
+
+ int len = commands.getLength();
+ for (int i = 0; i < len; i++) {
+ Node node = commands.item(i);
+ if (node instanceof Element) {
+ Element elm = (Element) node;
+
+ String name = elm.getAttribute("name");
+ String type = elm.getAttribute("type");
+
+ Map<String, LaunchExecute> executes = new HashMap<String, LaunchExecute>();
+
+ NodeList execNodes = XMLUtil.getDOMNodes(elm, "execute");
+ if (execNodes != null && execNodes.getLength() > 0) {
+ int len2 = execNodes.getLength();
+ for (int j = 0; j < len2; j++) {
+ Node execNode = execNodes.item(j);
+ if (execNode instanceof Element) {
+ Element execElm = (Element) execNode;
+
+ String platform = execElm.getAttribute("platform");
+ String execute = execElm.getAttribute("execute");
+ execute = MacroUtil.processMacro(execute, macros);
+
+ List<LaunchParam> params = new ArrayList<LaunchParam> ();
+ NodeList paramNodes = XMLUtil.getDOMNodes(execElm, "param");
+ if (paramNodes != null && paramNodes.getLength() > 0) {
+ int len3 = paramNodes.getLength();
+ for (int k = 0; k < len3; k++) {
+ Node paramNode = paramNodes.item(k);
+ if (paramNode instanceof Element) {
+ Element paramElm = (Element) paramNode;
+
+ String prefix = paramElm.getAttribute("prefix");
+ String value = paramElm.getAttribute("value");
+ value = MacroUtil.processMacro(value, macros);
+
+ params.add(new LaunchParam(name, prefix, value));
+ }
+ }
+ }
+
+ executes.put(platform, new LaunchExecute(platform, execute, params));
+ }
+ }
+ }
+
+ scripts.put(name, new LaunchScript(type, executes));
+ }
+ }
+
+ return scripts;
+ }
+
private ILaunchConfiguration createConfiguration(String projectName, IPath targetPath, String boardName, String debugCfg) throws CoreException {
- String openocdPath = targetPath.toOSString() + File.separator + PATH_BUILD_CONFIGS + File.separator + boardName + File.separator + PATH_OPENOCD;
- String openocdExec = null;
+ String sdkPath = SDKUtil.getSdkPath();
+ String homePath = ResourceUtil.getCurrentProject().getLocation().toString();
+ String boardPath = homePath + File.separator + "configs" + File.separator + boardName;
+
+ File launchScriptFile = new File(boardPath, FILE_NAME_DEBUG_SCRIPT);
+ if (!launchScriptFile.exists()) {
+ launchScriptFile = new File(sdkPath, "rt-ide" + File.separator + "resources" + File.separator + "scripts" + File.separator + FILE_NAME_DEBUG_SCRIPT);
+ if (!launchScriptFile.exists()) {
+ MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.RtosDebug_ERROR_DEBUGSCRIPT_NOT_EXIST); //$NON-NLS-1$
+ return null;
+ }
+ }
+
+ String scriptPath = new File(debugCfg).getParent();
+ debugCfg = new File(debugCfg).getName();
+
+ Map<String, String> macros = new HashMap<String, String>();
+ macros.put("PROJECT_PATH", homePath);
+ macros.put("BOARD", boardName);
+ macros.put("SCRIPT_PATH", scriptPath);
+ macros.put("SCRIPT_FILE", debugCfg);
+
+ // consoleManager.println("Launch project using " + launchScriptFile);
+
+ Map<String, LaunchScript> scripts = getBuildScripts(launchScriptFile, macros);
+ if (scripts == null) {
+ return null;
+ }
+ LaunchScript launch = scripts.get("openocd");
+ if (launch == null) {
+ return null;
+ }
+
+ String platformName;
if (OSChecker.is64bit()) {
- openocdExec = OPENOCD_EXECUTABLE_64;
+ platformName = "linux64";
} else {
- openocdExec = OPENOCD_EXECUTABLE_32;
+ platformName = "linux32";
}
- openocdExec = openocdPath + File.separator + openocdExec;
- if (!new File(openocdExec).exists()) {
+ LaunchExecute openocdExec = launch.getExecute(platformName);
+
+ // String openocdPath = targetPath.toOSString() + File.separator + PATH_BUILD_CONFIGS + File.separator + boardName + File.separator + PATH_DEBUG_OPENOCD;
+ // String openocdExec = null;
+ // if (OSChecker.is64bit()) {
+ // openocdExec = OPENOCD_EXECUTABLE_64;
+ // } else {
+ // openocdExec = OPENOCD_EXECUTABLE_32;
+ // }
+ // openocdExec = openocdPath + File.separator + openocdExec;
+
+ if (!new File(openocdExec.execute).exists()) {
MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.RtosDebug_ERROR_OPENOCD_NOT_EXIST); //$NON-NLS-1$
return null;
}
ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, manager.generateLaunchConfigurationName(targetPath.lastSegment()));
- wc.setAttribute(ConfigurationAttributes.GDB_SERVER_EXECUTABLE, openocdExec);
- wc.setAttribute(ConfigurationAttributes.GDB_SERVER_OTHER, "-f " + debugCfg); //$NON-NLS-1$
+ wc.setAttribute(ConfigurationAttributes.GDB_SERVER_EXECUTABLE, openocdExec.execute);
+ wc.setAttribute(ConfigurationAttributes.GDB_SERVER_OTHER, openocdExec.getFullParam()); // $NON-NLS-1$
wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, PROGRAM_NAME);
}
if (debugCfg == null || debugCfg.isEmpty()) {
FileDialog dialog = new FileDialog(Display.getDefault().getActiveShell(), SWT.SHEET);
- File home = new File(proj.getLocation().toString(), PATH_BUILD_CONFIGS + File.separator + board + File.separator + PATH_OPENOCD);
+ File home = new File(proj.getLocation().toString(), PATH_BUILD_CONFIGS + File.separator + board + File.separator + PATH_OPENOCD_SCRIPT);
dialog.setFilterPath(home.toString());
dialog.setFilterExtensions(new String[] { "*.cfg" }); //$NON-NLS-1$
debugCfg = dialog.open();