# HG changeset patch # User timkelly # Date 1268336701 21600 # Node ID 96e5879cd42d3d66b07b01561743d264b6b31a68 # Parent 02cf64aef5196a6f8986782b96072ff3d464b385 Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC. diff -r 02cf64aef519 -r 96e5879cd42d debuggercdi/com.nokia.cdt.debug.common/.classpath --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debuggercdi/com.nokia.cdt.debug.common/.classpath Thu Mar 11 13:45:01 2010 -0600 @@ -0,0 +1,7 @@ + + + + + + + diff -r 02cf64aef519 -r 96e5879cd42d debuggercdi/com.nokia.cdt.debug.common/.project --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debuggercdi/com.nokia.cdt.debug.common/.project Thu Mar 11 13:45:01 2010 -0600 @@ -0,0 +1,39 @@ + + + com.nokia.cdt.debug.common + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/org.eclipse.pde.api.tools.apiAnalysisBuilder.launch + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.eclipse.pde.api.tools.apiAnalysisNature + + diff -r 02cf64aef519 -r 96e5879cd42d debuggercdi/com.nokia.cdt.debug.common/.settings/org.eclipse.jdt.core.prefs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debuggercdi/com.nokia.cdt.debug.common/.settings/org.eclipse.jdt.core.prefs Thu Mar 11 13:45:01 2010 -0600 @@ -0,0 +1,8 @@ +#Tue Mar 09 15:31:12 CST 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff -r 02cf64aef519 -r 96e5879cd42d debuggercdi/com.nokia.cdt.debug.common/META-INF/MANIFEST.MF --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debuggercdi/com.nokia.cdt.debug.common/META-INF/MANIFEST.MF Thu Mar 11 13:45:01 2010 -0600 @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Carbide Common CDT Plugin +Bundle-SymbolicName: com.nokia.cdt.debug.common;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: com.nokia.cdt.debug.common.CarbideCommonDebuggerPlugin +Bundle-Vendor: Nokia +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.cdt.debug.core;bundle-version="7.0.0", + org.eclipse.debug.core;bundle-version="3.6.0" +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-ActivationPolicy: lazy +Export-Package: com.nokia.cdt.debug.common.internal.source.lookup diff -r 02cf64aef519 -r 96e5879cd42d debuggercdi/com.nokia.cdt.debug.common/build.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debuggercdi/com.nokia.cdt.debug.common/build.properties Thu Mar 11 13:45:01 2010 -0600 @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff -r 02cf64aef519 -r 96e5879cd42d debuggercdi/com.nokia.cdt.debug.common/plugin.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debuggercdi/com.nokia.cdt.debug.common/plugin.xml Thu Mar 11 13:45:01 2010 -0600 @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + diff -r 02cf64aef519 -r 96e5879cd42d debuggercdi/com.nokia.cdt.debug.common/src/com/nokia/cdt/debug/common/CarbideCommonDebuggerPlugin.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debuggercdi/com.nokia.cdt.debug.common/src/com/nokia/cdt/debug/common/CarbideCommonDebuggerPlugin.java Thu Mar 11 13:45:01 2010 -0600 @@ -0,0 +1,50 @@ +package com.nokia.cdt.debug.common; + +import org.eclipse.core.runtime.Plugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class CarbideCommonDebuggerPlugin extends Plugin { + + // The plug-in ID + public static final String PLUGIN_ID = "com.nokia.cdt.debug.common"; + + // The shared instance + private static CarbideCommonDebuggerPlugin plugin; + + /** + * The constructor + */ + public CarbideCommonDebuggerPlugin() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static CarbideCommonDebuggerPlugin getDefault() { + return plugin; + } + +} diff -r 02cf64aef519 -r 96e5879cd42d debuggercdi/com.nokia.cdt.debug.common/src/com/nokia/cdt/debug/common/internal/source/lookup/CarbideSourcePathComputerDelegate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debuggercdi/com.nokia.cdt.debug.common/src/com/nokia/cdt/debug/common/internal/source/lookup/CarbideSourcePathComputerDelegate.java Thu Mar 11 13:45:01 2010 -0600 @@ -0,0 +1,76 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +package com.nokia.cdt.debug.common.internal.source.lookup; + +import java.util.ArrayList; + +import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.debug.core.sourcelookup.AbsolutePathSourceContainer; +import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer; +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.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.sourcelookup.ISourceContainer; +import org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate; +import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer; + +import com.nokia.cdt.debug.common.CarbideCommonDebuggerPlugin; + +/** + * Computes the default source lookup path for a launch configuration. + */ +public class CarbideSourcePathComputerDelegate implements ISourcePathComputerDelegate { + + /** From legacy DE support. */ + public static final String PSC_FindSourceOutsideWorkspace = "com.freescale.cdt.debug.cw.PN_FindSourceOutsideWorkspace"; + + /** + * Constructor for CSourcePathComputerDelegate. + */ + public CarbideSourcePathComputerDelegate() { + super(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate#computeSourceContainers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.runtime.IProgressMonitor) + */ + public ISourceContainer[] computeSourceContainers( ILaunchConfiguration configuration, IProgressMonitor monitor ) throws CoreException { + ISourceContainer[] common = CDebugCorePlugin.getDefault().getCommonSourceLookupDirector().getSourceContainers(); + ArrayList containers = new ArrayList( common.length + 1 ); + for ( int i = 0; i < common.length; ++i ) { + ISourceContainer sc = common[i]; + if ( sc.getType().getId().equals( MappingSourceContainer.TYPE_ID ) ) + sc = ((MappingSourceContainer)sc).copy(); + containers.add( sc ); + } + String projectName = configuration.getAttribute( ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null ); + if (projectName != null && projectName.length() > 0) { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName ); + if ( project.exists() ) { + containers.add( 0, new ProjectSourceContainer( project, true ) ); + } + } + if (CarbideCommonDebuggerPlugin.getDefault().getPluginPreferences().getBoolean( + PSC_FindSourceOutsideWorkspace)) + containers.add( 0, new AbsolutePathSourceContainer() ); + return (ISourceContainer[])containers.toArray( new ISourceContainer[containers.size()] ); + } +} diff -r 02cf64aef519 -r 96e5879cd42d debuggercdi/com.nokia.cdt.debug.common/src/com/nokia/cdt/debug/common/internal/source/lookup/SourceMappingUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debuggercdi/com.nokia.cdt.debug.common/src/com/nokia/cdt/debug/common/internal/source/lookup/SourceMappingUtils.java Thu Mar 11 13:45:01 2010 -0600 @@ -0,0 +1,85 @@ +package com.nokia.cdt.debug.common.internal.source.lookup; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Path; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.core.model.ISourceLocator; +import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector; +import org.eclipse.debug.core.sourcelookup.ISourceContainer; + + +public class SourceMappingUtils { + + /** Name kept for legacy launch config settings purposes */ + private static final String EPOCROOT_SETTING = "com.nokia.cdt.debug.cw.symbian.Epoc_Root" ; //$NON-NLS-1$ + + /** + * Add the source mapping for the workign copy of the launch config. Clients should ensure to call doSave() after this call. + * @param configuration + * @throws CoreException + */ + public static void addSourceMappingToLaunch(ILaunchConfigurationWorkingCopy configuration) throws CoreException { + String memento = null; + String type = null; + + memento = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, (String) null); + type = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, (String) null); + if (type == null) { + type = configuration.getType().getSourceLocatorId(); + } + ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); + ISourceLocator locator = launchManager.newSourceLocator(type); + if (locator instanceof AbstractSourceLookupDirector) { + AbstractSourceLookupDirector director = (AbstractSourceLookupDirector) locator; + if (memento == null) { + director.initializeDefaults(configuration); + } else { + director.initializeFromMemento(memento, configuration); + } + + addSourceMappingToDirector(director, configuration); + + configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, director.getMemento()); + configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, director.getId()); + } + } + + private static void addSourceMappingToDirector(AbstractSourceLookupDirector director, ILaunchConfiguration configuration) throws CoreException { + + ArrayList containerList = new ArrayList(Arrays.asList(director.getSourceContainers())); + + boolean hasSymbianContainer = false; + + SymbianSourceContainer symbianContainer = null; + + for (Iterator iter = containerList.iterator(); iter.hasNext() && !hasSymbianContainer;) { + ISourceContainer container = (ISourceContainer) iter.next(); + if (container instanceof SymbianSourceContainer) + { + hasSymbianContainer = true; + } + } + + if (!hasSymbianContainer) { + + String epocRootPath = configuration.getAttribute( EPOCROOT_SETTING, (String)null ); + if (epocRootPath != null) + { + symbianContainer = new SymbianSourceContainer(new Path(epocRootPath)); + symbianContainer.init(director); + containerList.add(symbianContainer); + } + } + + director.setSourceContainers((ISourceContainer[]) containerList.toArray(new ISourceContainer[containerList.size()])); + } + + +} diff -r 02cf64aef519 -r 96e5879cd42d debuggercdi/com.nokia.cdt.debug.common/src/com/nokia/cdt/debug/common/internal/source/lookup/SymbianSourceContainer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debuggercdi/com.nokia.cdt.debug.common/src/com/nokia/cdt/debug/common/internal/source/lookup/SymbianSourceContainer.java Thu Mar 11 13:45:01 2010 -0600 @@ -0,0 +1,100 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +package com.nokia.cdt.debug.common.internal.source.lookup; + +import org.eclipse.cdt.debug.core.sourcelookup.AbsolutePathSourceContainer; +import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer; +import org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainer; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.sourcelookup.ISourceContainer; +import org.eclipse.debug.core.sourcelookup.ISourceContainerType; +import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; + +import com.nokia.cdt.debug.common.CarbideCommonDebuggerPlugin; + +/** + * Used to attempt to map missing files to ones in EPOCROOT. + * For example, if source files are built on drive M but + * the SDK and sources are on drive R then it will replace + * the source's device ID with the EPOCROOT path and see + * if the file exists. If so a path mapping entry will be + * created to map from that drive to EPOCROOT. + */ +public class SymbianSourceContainer extends MappingSourceContainer { + + private Path epocRoot; + public static final String TYPE_ID = CarbideCommonDebuggerPlugin.PLUGIN_ID + ".containerType.mapping"; //$NON-NLS-1$ + public static final String CONTAINER_NAME = "Symbian SDK Root Locator"; //$NON-NLS-1$ + + public SymbianSourceContainer(Path epocRoot) + { + super(CONTAINER_NAME); + this.epocRoot = epocRoot; + } + + @Override + public ISourceContainerType getType() { + return getSourceContainerType( TYPE_ID ); + } + + protected Object[] findSourceElements(String name, ISourceContainer[] containers) throws CoreException { + Object[] result = super.findSourceElements(name, containers); + if (result.length == 0) + { + Path sourcePath = new Path( name ); + MapEntrySourceContainer mapping = new MapEntrySourceContainer(sourcePath.uptoSegment(0), epocRoot); + ISourceLookupDirector director = this.getDirector(); + if (director != null) + mapping.init(director); + result = mapping.findSourceElements(name); + if (result.length > 0) + { + if (!mapping.getBackendPath().equals(mapping.getLocalPath())){ + addMapEntry(mapping); + } + if (director != null) + { + ILaunchConfigurationWorkingCopy configuration = director.getLaunchConfiguration().getWorkingCopy(); + configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, director.getMemento()); + configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, director.getId()); + configuration.doSave(); + } + } + else + { + // Check to see if this is an absolute path inside the SDK. + // Absolute paths are usually caught by the AbsolutePathSourceContainer but + // if there is not one present then this will work for files in the SDK. + if (epocRoot.isPrefixOf(sourcePath)) + { + result = new AbsolutePathSourceContainer().findSourceElements(name); + } + } + } + return result; + } + + public IPath getEpocRoot() { + return epocRoot; + } + +} diff -r 02cf64aef519 -r 96e5879cd42d debuggercdi/com.nokia.cdt.debug.common/src/com/nokia/cdt/debug/common/internal/source/lookup/SymbianSourceContainerType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debuggercdi/com.nokia.cdt.debug.common/src/com/nokia/cdt/debug/common/internal/source/lookup/SymbianSourceContainerType.java Thu Mar 11 13:45:01 2010 -0600 @@ -0,0 +1,99 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +package com.nokia.cdt.debug.common.internal.source.lookup; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.cdt.debug.internal.core.sourcelookup.InternalSourceLookupMessages; +import org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainer; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Path; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.sourcelookup.ISourceContainer; +import org.eclipse.debug.core.sourcelookup.ISourceContainerType; +import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainerTypeDelegate; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + + +public class SymbianSourceContainerType extends AbstractSourceContainerTypeDelegate { + + private final static String ELEMENT_MAPPING = "mapping"; //$NON-NLS-1$ + private final static String ELEMENT_MAP_ENTRY = "mapEntry"; //$NON-NLS-1$ + private final static String ATTR_EPOCROOT = "epocroot"; //$NON-NLS-1$ + private final static String ATTR_MEMENTO = "memento"; //$NON-NLS-1$ + + public ISourceContainer createSourceContainer( String memento ) throws CoreException { + Node node = parseDocument( memento ); + if ( node.getNodeType() == Node.ELEMENT_NODE ) { + Element element = (Element)node; + if ( ELEMENT_MAPPING.equals( element.getNodeName() ) ) { + String epocroot = element.getAttribute( ATTR_EPOCROOT ); + if ( epocroot == null ) + epocroot = ""; //$NON-NLS-1$ + List entries = new ArrayList(); + Node childNode = element.getFirstChild(); + while( childNode != null ) { + if ( childNode.getNodeType() == Node.ELEMENT_NODE ) { + Element child = (Element)childNode; + if ( ELEMENT_MAP_ENTRY.equals( child.getNodeName() ) ) { + String childMemento = child.getAttribute( ATTR_MEMENTO ); + if ( childMemento == null || childMemento.length() == 0 ) { + abort( InternalSourceLookupMessages.getString( "MappingSourceContainerType.0" ), null ); //$NON-NLS-1$ + } + ISourceContainerType type = DebugPlugin.getDefault().getLaunchManager().getSourceContainerType( MapEntrySourceContainer.TYPE_ID ); + MapEntrySourceContainer entry = (MapEntrySourceContainer)type.createSourceContainer( childMemento ); + entries.add( entry ); + } + } + childNode = childNode.getNextSibling(); + } + SymbianSourceContainer container = new SymbianSourceContainer( new Path( epocroot ) ); + Iterator it = entries.iterator(); + while( it.hasNext() ) { + container.addMapEntry( (MapEntrySourceContainer)it.next() ); + } + return container; + } + abort( InternalSourceLookupMessages.getString( "MappingSourceContainerType.1" ), null ); //$NON-NLS-1$ + } + abort( InternalSourceLookupMessages.getString( "MappingSourceContainerType.2" ), null ); //$NON-NLS-1$ + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate#getMemento(org.eclipse.debug.core.sourcelookup.ISourceContainer) + */ + public String getMemento( ISourceContainer container ) throws CoreException { + Document document = newDocument(); + Element element = document.createElement( ELEMENT_MAPPING ); + element.setAttribute( ATTR_EPOCROOT, ((SymbianSourceContainer)container).getEpocRoot().toOSString() ); + ISourceContainer[] entries = ((SymbianSourceContainer)container).getSourceContainers(); + for ( int i = 0; i < entries.length; ++i ) { + Element child = document.createElement( ELEMENT_MAP_ENTRY ); + child.setAttribute( ATTR_MEMENTO, entries[i].getType().getMemento( entries[i] ) ); + element.appendChild( child ); + } + document.appendChild( element ); + return serializeDocument( document ); + } + +}