diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugModel.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugModel.java index df948c44ca1..b37b50c113e 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugModel.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugModel.java @@ -6,19 +6,14 @@ package org.eclipse.cdt.debug.core; -import java.text.MessageFormat; import java.util.HashMap; import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.ICDILocation; -import org.eclipse.cdt.debug.core.cdi.ICDISourceManager; -import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint; import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression; import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; -import org.eclipse.cdt.debug.internal.core.CSourceLocator; import org.eclipse.cdt.debug.internal.core.breakpoints.CLineBreakpoint; import org.eclipse.cdt.debug.internal.core.breakpoints.CWatchpoint; -import org.eclipse.cdt.debug.internal.core.model.CDebugElement; import org.eclipse.cdt.debug.internal.core.model.CDebugTarget; import org.eclipse.cdt.debug.internal.core.model.CExpression; import org.eclipse.core.resources.IMarker; @@ -98,17 +93,6 @@ public class CDebugModel { final IDebugTarget[] target = new IDebugTarget[1]; - // Temporary - try - { - ICDISourceManager mgr = cdiTarget.getSession().getSourceManager(); - mgr.addSourcePaths( new String[] { project.getLocation().toOSString() }); - } - catch( CDIException e ) - { - CDebugCorePlugin.log( e ); - } - IWorkspaceRunnable r = new IWorkspaceRunnable() { public void run( IProgressMonitor m ) diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CDirectorySourceLocation.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CDirectorySourceLocation.java index 32f99fd9368..e30cab86afc 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CDirectorySourceLocation.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CDirectorySourceLocation.java @@ -116,20 +116,23 @@ public class CDirectorySourceLocation implements ICSourceLocation private Object findFileByRelativePath( String fileName ) { IPath path = getDirectory(); - path.append( fileName ); - - // Try for a file in another workspace project - IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( path ); - if ( f != null ) + if ( path != null ) { - return f; - } - - File file = path.toFile(); - if ( file.exists() ) - { - return createExternalFileStorage( path ); - } + path = path.append( fileName ); + + // Try for a file in another workspace project + IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( path ); + if ( f != null ) + { + return f; + } + + File file = path.toFile(); + if ( file.exists() ) + { + return createExternalFileStorage( path ); + } + } return null; } @@ -137,4 +140,12 @@ public class CDirectorySourceLocation implements ICSourceLocation { return new FileStorage( path ); } + + /** + * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#getPaths() + */ + public IPath[] getPaths() + { + return new IPath[] { fDirectory }; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CProjectSourceLocation.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CProjectSourceLocation.java index 229f0f6096e..99e807f64c6 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CProjectSourceLocation.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CProjectSourceLocation.java @@ -5,6 +5,8 @@ */ package org.eclipse.cdt.debug.core.sourcelookup; +import java.io.File; + import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -41,17 +43,11 @@ public class CProjectSourceLocation implements ICSourceLocation { if ( getProject() != null ) { - IPath path = new Path( name ); - String fileName = path.toOSString(); - - String pPath = new String( getProject().getLocation().toOSString() ); - int i = 0; - if ( (i = fileName.indexOf( pPath )) >= 0 ) - { - i += pPath.length() + 1; - if ( fileName.length() > i ) - return getProject().getFile( fileName.substring( i ) ); - } + File file = new File( name ); + if ( file.isAbsolute() ) + return findFileByAbsolutePath( name ); + else + return findFileByRelativePath( name ); } return null; } @@ -112,4 +108,38 @@ public class CProjectSourceLocation implements ICSourceLocation } return null; } + + private Object findFileByAbsolutePath( String name ) + { + IPath path = new Path( name ); + String fileName = path.toOSString(); + + String pPath = new String( getProject().getLocation().toOSString() ); + int i = 0; + if ( (i = fileName.indexOf( pPath )) >= 0 ) + { + i += pPath.length() + 1; + if ( fileName.length() > i ) + return getProject().getFile( fileName.substring( i ) ); + } + return null; + } + + private Object findFileByRelativePath( String fileName ) + { + return getProject().getFile( fileName ); + } + + /** + * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#getPaths() + */ + public IPath[] getPaths() + { + IPath[] result = new IPath[0]; + if ( getProject() != null ) + { + result = new IPath[] { getProject().getLocation() }; + } + return result; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CSourceLocator.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CSourceLocator.java similarity index 96% rename from debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CSourceLocator.java rename to debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CSourceLocator.java index 6c84284daf8..aacecfb1abf 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CSourceLocator.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CSourceLocator.java @@ -4,15 +4,12 @@ * */ -package org.eclipse.cdt.debug.internal.core; +package org.eclipse.cdt.debug.core.sourcelookup; import java.util.ArrayList; import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.IStackFrameInfo; -import org.eclipse.cdt.debug.core.sourcelookup.CProjectSourceLocation; -import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation; -import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator; import org.eclipse.cdt.debug.internal.core.model.*; import org.eclipse.core.internal.resources.File; import org.eclipse.core.resources.IContainer; diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocation.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocation.java index 4977f89bd5d..d407324c9fc 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocation.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocation.java @@ -7,6 +7,7 @@ package org.eclipse.cdt.debug.core.sourcelookup; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IPath; /** * @@ -35,4 +36,11 @@ public interface ICSourceLocation extends IAdaptable * @exception CoreException if an exception occurs while searching for the specified source element */ Object findSourceElement( String name ) throws CoreException; + + /** + * Returns the paths associated with this location. + * + * @return the paths associated with this location + */ + IPath[] getPaths(); } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java index d864f0ce5c2..480de7892e2 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java @@ -7,7 +7,6 @@ package org.eclipse.cdt.debug.internal.core.model; import java.text.MessageFormat; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -35,6 +34,7 @@ import org.eclipse.cdt.debug.core.cdi.ICDILocation; import org.eclipse.cdt.debug.core.cdi.ICDIRegisterObject; import org.eclipse.cdt.debug.core.cdi.ICDISessionObject; import org.eclipse.cdt.debug.core.cdi.ICDISignal; +import org.eclipse.cdt.debug.core.cdi.ICDISourceManager; import org.eclipse.cdt.debug.core.cdi.ICDIWatchpointScope; import org.eclipse.cdt.debug.core.cdi.ICDIWatchpointTrigger; import org.eclipse.cdt.debug.core.cdi.event.ICDIChangedEvent; @@ -53,16 +53,15 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; import org.eclipse.cdt.debug.core.cdi.model.ICDIThread; import org.eclipse.cdt.debug.core.cdi.model.ICDIWatchpoint; -import org.eclipse.cdt.debug.core.sourcelookup.CDirectorySourceLocation; +import org.eclipse.cdt.debug.core.sourcelookup.CSourceLocator; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator; -import org.eclipse.cdt.debug.internal.core.CSourceLocator; import org.eclipse.cdt.debug.internal.core.breakpoints.CBreakpoint; import org.eclipse.core.resources.IMarkerDelta; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.IPath; import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; @@ -235,6 +234,7 @@ public class CDebugTarget extends CDebugElement protected void initialize() { initializeState(); + setSourceSearchPath(); initializeBreakpoints(); initializeRegisters(); getLaunch().addDebugTarget( this ); @@ -1844,10 +1844,33 @@ public class CDebugTarget extends CDebugElement protected ISourceLocator createSourceLocator( IProject project ) { - CSourceLocator locator = new CSourceLocator( project ); - List list = Arrays.asList( locator.getSourceLocations() ); - list.add( new CDirectorySourceLocation( new Path( project.getLocation().toOSString() ) ) ); - locator.setSourceLocations( (ICSourceLocation[])list.toArray( new ICSourceLocation[list.size()] ) ); - return locator; + return new CSourceLocator( project ); + } + + protected void setSourceSearchPath() + { + ICDISourceManager mgr = getCDISession().getSourceManager(); + ISourceLocator locator = getLaunch().getSourceLocator(); + ArrayList list = new ArrayList(); + if ( locator != null && locator instanceof ICSourceLocator ) + { + ICSourceLocation[] locations = ((ICSourceLocator)locator).getSourceLocations(); + for ( int i = 0; i < locations.length; ++i ) + { + IPath[] paths = locations[i].getPaths(); + for ( int j = 0; j < paths.length; ++j ) + { + list.add( paths[j].toOSString() ); + } + } + } + try + { + mgr.addSourcePaths( (String[])list.toArray( new String[list.size()] ) ); + } + catch( CDIException e ) + { + CDebugCorePlugin.log( e ); + } } }