From 021e8976990d462841b028f91fa19e4ead72e8d7 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Mon, 30 Apr 2007 00:28:45 +0000 Subject: [PATCH] Bug 179755 - Introduced mechanism to allow debuggers to specify a regex pattern specifying supported build configurations. This is used to set the defaults in the CDebuggerTab as well as the CApplicationLauchShortcut. A new debugger MinGW is introduced to take advantage of this and set the appropriate paths to the MinGW debugger. --- .../internal/CApplicationLaunchShortcut.java | 48 ++++++++++++----- .../LocalRunLaunchConfigurationTabGroup.java | 3 +- .../internal/ui/MigratingCEnvironmentTab.java | 52 ------------------- .../eclipse/cdt/launch/ui/CDebuggerTab.java | 40 ++++++++++++-- 4 files changed, 73 insertions(+), 70 deletions(-) delete mode 100644 launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/MigratingCEnvironmentTab.java diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/CApplicationLaunchShortcut.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/CApplicationLaunchShortcut.java index 20fafaf7cbf..42a1b615aad 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/CApplicationLaunchShortcut.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/CApplicationLaunchShortcut.java @@ -19,13 +19,18 @@ import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDebugConfiguration; +import org.eclipse.cdt.debug.ui.CDebugUIPlugin; +import org.eclipse.cdt.debug.ui.ICDebuggerPage; import org.eclipse.cdt.launch.AbstractCLaunchDelegate; import org.eclipse.cdt.launch.internal.ui.LaunchMessages; import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; import org.eclipse.cdt.ui.CElementLabelProvider; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; @@ -106,23 +111,31 @@ public class CApplicationLaunchShortcut implements ILaunchShortcut { // user to choose one. int candidateCount = candidateConfigs.size(); if (candidateCount < 1) { - String programCPU = bin.getCPU(); - // Try default debugger first - ICDebugConfiguration defaultConfig = CDebugCorePlugin.getDefault().getDefaultDebugConfiguration(); - String os = Platform.getOS(); + // Set the default debugger based on the active toolchain on the project (if possible) ICDebugConfiguration debugConfig = null; - if ( defaultConfig != null ) { - String platform = defaultConfig.getPlatform(); - if (defaultConfig.supportsMode(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { - if (platform.equals("*") || platform.equals(os)) { //$NON-NLS-1$ - if (defaultConfig.supportsCPU(programCPU)) - debugConfig = defaultConfig; - } - } + IProject project = bin.getResource().getProject(); + ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project); + ICConfigurationDescription configDesc = projDesc.getActiveConfiguration(); + String configId = configDesc.getId(); + ICDebugConfiguration[] debugConfigs = CDebugCorePlugin.getDefault().getActiveDebugConfigurations(); + outer: for (int i = 0; i < debugConfigs.length; ++i) { + ICDebugConfiguration dc = debugConfigs[i]; + String[] patterns = dc.getSupportedBuildConfigPatterns(); + if (patterns != null) { + for (int j = 0; j < patterns.length; ++j) { + if (configId.matches(patterns[j])) { + debugConfig = dc; + break outer; + } + } + } } + if ( debugConfig == null ) { // Prompt the user if more then 1 debugger. - ICDebugConfiguration[] debugConfigs = CDebugCorePlugin.getDefault().getActiveDebugConfigurations(); + String programCPU = bin.getCPU(); + String os = Platform.getOS(); + debugConfigs = CDebugCorePlugin.getDefault().getActiveDebugConfigurations(); List debugList = new ArrayList(debugConfigs.length); for (int i = 0; i < debugConfigs.length; i++) { String platform = debugConfigs[i].getPlatform(); @@ -140,6 +153,7 @@ public class CApplicationLaunchShortcut implements ILaunchShortcut { debugConfig = chooseDebugConfig(debugConfigs, mode); } } + if (debugConfig != null) { configuration = createConfiguration(bin, debugConfig); } @@ -168,13 +182,19 @@ public class CApplicationLaunchShortcut implements ILaunchShortcut { configType.newInstance(null, getLaunchManager().generateUniqueLaunchConfigurationNameFrom(bin.getElementName())); wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, projectName); wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, bin.getCProject().getElementName()); - wc.setMappedResources(new IResource[] {bin.getCProject().getProject()}); + wc.setMappedResources(new IResource[] {bin.getResource()}); wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null); wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, true); wc.setAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN); wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, debugConfig.getID()); + + // Load up the debugger page to set the defaults. There should probably be a separate + // extension point for this. + ICDebuggerPage page = CDebugUIPlugin.getDefault().getDebuggerPage(debugConfig.getID()); + page.setDefaults(wc); + config = wc.doSave(); } catch (CoreException ce) { LaunchUIPlugin.log(ce); diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LocalRunLaunchConfigurationTabGroup.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LocalRunLaunchConfigurationTabGroup.java index db5cdc2a8dd..9ca477a889a 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LocalRunLaunchConfigurationTabGroup.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LocalRunLaunchConfigurationTabGroup.java @@ -15,6 +15,7 @@ import org.eclipse.cdt.launch.ui.CDebuggerTab; import org.eclipse.cdt.launch.ui.CMainTab; import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup; import org.eclipse.debug.ui.CommonTab; +import org.eclipse.debug.ui.EnvironmentTab; import org.eclipse.debug.ui.ILaunchConfigurationDialog; import org.eclipse.debug.ui.ILaunchConfigurationTab; import org.eclipse.debug.ui.sourcelookup.SourceLookupTab; @@ -28,7 +29,7 @@ public class LocalRunLaunchConfigurationTabGroup extends AbstractLaunchConfigura ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { new CMainTab(true), new CArgumentsTab(), - new MigratingCEnvironmentTab(), + new EnvironmentTab(), new CDebuggerTab(false), new SourceLookupTab(), new CommonTab() diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/MigratingCEnvironmentTab.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/MigratingCEnvironmentTab.java deleted file mode 100644 index 693cb75b1ec..00000000000 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/MigratingCEnvironmentTab.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * QNX Software Systems - initial API and implementation - *******************************************************************************/ -/* - * Created on Oct 21, 2004 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package org.eclipse.cdt.launch.internal.ui; - -import java.util.Map; - -import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; -import org.eclipse.debug.core.ILaunchManager; -import org.eclipse.debug.ui.EnvironmentTab; - - -/** - * @deprecated - temporary class for while configs are migrated to new EnvironmentTab - */ -public class MigratingCEnvironmentTab extends EnvironmentTab { - - - /* (non-Javadoc) - * @see org.eclipse.cdt.launch.ui.CEnvironmentTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration) - */ - public void initializeFrom(ILaunchConfiguration config) { - if (config instanceof ILaunchConfigurationWorkingCopy) { - ILaunchConfigurationWorkingCopy wc = (ILaunchConfigurationWorkingCopy) config; - try { - Map map = wc.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null); - if (map != null) { - wc.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map); - wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null); - } - } catch (CoreException e) { - } - } - super.initializeFrom(config); - } -} 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 d008480c25e..b9ed77cd101 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 @@ -24,6 +24,9 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.ICExtensionReference; import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDebugConfiguration; @@ -223,10 +226,41 @@ public class CDebuggerTab extends AbstractCDebuggerTab { } config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ENABLE_VARIABLE_BOOKKEEPING, false); config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ENABLE_REGISTER_BOOKKEEPING, false); - ICDebugConfiguration dc = CDebugCorePlugin.getDefault().getDefaultDebugConfiguration(); - if (dc != null) { - config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, dc.getID()); + + // Set the default debugger based on the active toolchain on the project (if possible) + String defaultDebugger = null; + try { + String projectName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); + if (projectName.length() > 0) { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project); + ICConfigurationDescription configDesc = projDesc.getActiveConfiguration(); + String configId = configDesc.getId(); + ICDebugConfiguration[] debugConfigs = CDebugCorePlugin.getDefault().getActiveDebugConfigurations(); + outer: for (int i = 0; i < debugConfigs.length; ++i) { + ICDebugConfiguration debugConfig = debugConfigs[i]; + String[] patterns = debugConfig.getSupportedBuildConfigPatterns(); + if (patterns != null) { + for (int j = 0; j < patterns.length; ++j) { + if (configId.matches(patterns[j])) { + defaultDebugger = debugConfig.getID(); + break outer; + } + } + } + } + } + } catch (CoreException e) { } + + if (defaultDebugger == null) { + ICDebugConfiguration dc = CDebugCorePlugin.getDefault().getDefaultDebugConfiguration(); + if (dc != null) { + defaultDebugger = dc.getID(); + } + } + + config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, defaultDebugger); } public void initializeFrom(ILaunchConfiguration config) {