mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
The core support of the prompting source locator.
This commit is contained in:
parent
55d70715c7
commit
9a7b5690eb
7 changed files with 157 additions and 122 deletions
|
@ -1,3 +1,12 @@
|
|||
2002-12-17 Mikhail Khodjaiants
|
||||
The core support of the prompting source locator.
|
||||
* ICSourceLocator.java
|
||||
* CDebugTarget.java
|
||||
* CDirectorySourceLocation.java
|
||||
* CSourceLocator.java
|
||||
* CSourceManager.java
|
||||
* DisassemblyManager.java
|
||||
|
||||
2002-12-17 Mikhail Khodjaiants
|
||||
The 'getLineNumber' method of CStackFrame should return the line number associated with the stack frame if the current source locator
|
||||
does not implement 'ICSourceLocator'.
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
*/
|
||||
package org.eclipse.cdt.debug.core.sourcelookup;
|
||||
|
||||
import org.eclipse.cdt.debug.core.model.IStackFrameInfo;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.debug.core.model.ISourceLocator;
|
||||
import org.eclipse.debug.core.model.IStackFrame;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -27,17 +27,8 @@ public interface ICSourceLocator extends ISourceLocator
|
|||
* @return line number of instruction pointer in this stack frame,
|
||||
* or -1 if line number information is unavailable
|
||||
*/
|
||||
int getLineNumber( IStackFrameInfo frameInfo );
|
||||
int getLineNumber( IStackFrame stackFrame );
|
||||
|
||||
/**
|
||||
* Returns a source element that corresponds to the given file name, or
|
||||
* <code>null</code> if a source element could not be located.
|
||||
*
|
||||
* @param fileName the file name for which to locate source
|
||||
* @return an object representing a source element.
|
||||
*/
|
||||
// Object getSourceElement( String fileName );
|
||||
|
||||
/**
|
||||
* Returns the source locations of this locator.
|
||||
*
|
||||
|
|
|
@ -68,14 +68,13 @@ import org.eclipse.cdt.debug.internal.core.CDebugUtils;
|
|||
import org.eclipse.cdt.debug.internal.core.CMemoryManager;
|
||||
import org.eclipse.cdt.debug.internal.core.ICDebugInternalConstants;
|
||||
import org.eclipse.cdt.debug.internal.core.breakpoints.CBreakpoint;
|
||||
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLocator;
|
||||
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceManager;
|
||||
import org.eclipse.cdt.debug.internal.core.sourcelookup.DisassemblyManager;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
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.IAdaptable;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.MultiStatus;
|
||||
|
@ -212,7 +211,12 @@ public class CDebugTarget extends CDebugElement
|
|||
private CMemoryManager fMemoryManager;
|
||||
|
||||
/**
|
||||
* A memory manager for this target.
|
||||
* A disassembly manager for this target.
|
||||
*/
|
||||
private DisassemblyManager fDisassemblyManager;
|
||||
|
||||
/**
|
||||
* Whether the debugger process is default.
|
||||
*/
|
||||
private boolean fIsDebuggerProcessDefault = false;
|
||||
|
||||
|
@ -244,14 +248,11 @@ public class CDebugTarget extends CDebugElement
|
|||
setCDITarget( cdiTarget );
|
||||
setBreakpoints( new HashMap( 5 ) );
|
||||
setExecFile( file );
|
||||
if ( getExecFile() != null )
|
||||
{
|
||||
getLaunch().setSourceLocator( createSourceLocator( getExecFile().getProject() ) );
|
||||
}
|
||||
setConfiguration( cdiTarget.getSession().getConfiguration() );
|
||||
fSupportsTerminate = allowsTerminate & getConfiguration().supportsTerminate();
|
||||
fSupportsDisconnect = allowsDisconnect & getConfiguration().supportsDisconnect();
|
||||
setThreadList( new ArrayList( 5 ) );
|
||||
setDisassemblyManager( new DisassemblyManager( this ) );
|
||||
initialize();
|
||||
DebugPlugin.getDefault().getLaunchManager().addLaunchListener( this );
|
||||
DebugPlugin.getDefault().getExpressionManager().addExpressionListener( this );
|
||||
|
@ -827,9 +828,9 @@ public class CDebugTarget extends CDebugElement
|
|||
return this;
|
||||
if ( adapter.equals( ISourceMode.class ) )
|
||||
{
|
||||
if ( getSourceLocator() instanceof ISourceMode )
|
||||
if ( getSourceLocator() instanceof IAdaptable )
|
||||
{
|
||||
return getSourceLocator();
|
||||
return ((IAdaptable)getSourceLocator()).getAdapter( ISourceMode.class );
|
||||
}
|
||||
}
|
||||
if ( adapter.equals( ICMemoryManager.class ) )
|
||||
|
@ -840,6 +841,8 @@ public class CDebugTarget extends CDebugElement
|
|||
return this;
|
||||
if ( adapter.equals( IRunToLine.class ) )
|
||||
return this;
|
||||
if ( adapter.equals( DisassemblyManager.class ) )
|
||||
return fDisassemblyManager;
|
||||
return super.getAdapter( adapter );
|
||||
}
|
||||
|
||||
|
@ -1832,12 +1835,6 @@ public class CDebugTarget extends CDebugElement
|
|||
return getLaunch().getSourceLocator();
|
||||
}
|
||||
|
||||
protected ISourceLocator createSourceLocator( IProject project )
|
||||
{
|
||||
return new CSourceManager( ( getLaunch().getSourceLocator() != null ) ? getLaunch().getSourceLocator() : new CSourceLocator( project ),
|
||||
new DisassemblyManager( this ) ) ;
|
||||
}
|
||||
|
||||
protected void setSourceSearchPath()
|
||||
{
|
||||
ICDISourceManager mgr = getCDISession().getSourceManager();
|
||||
|
@ -2020,4 +2017,14 @@ public class CDebugTarget extends CDebugElement
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected void setDisassemblyManager( DisassemblyManager dm )
|
||||
{
|
||||
fDisassemblyManager = dm;
|
||||
}
|
||||
|
||||
protected DisassemblyManager getDisassemblyManager()
|
||||
{
|
||||
return fDisassemblyManager;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,10 +26,15 @@ import org.eclipse.core.runtime.Path;
|
|||
public class CDirectorySourceLocation implements ICSourceLocation
|
||||
{
|
||||
/**
|
||||
* The directory associated with this source location
|
||||
* The root directory of this source location
|
||||
*/
|
||||
private IPath fDirectory;
|
||||
|
||||
/**
|
||||
* The associted path of this source location.
|
||||
*/
|
||||
private IPath fAssociation = null;
|
||||
|
||||
/**
|
||||
* Constructor for CDirectorySourceLocation.
|
||||
*/
|
||||
|
@ -38,6 +43,15 @@ public class CDirectorySourceLocation implements ICSourceLocation
|
|||
setDirectory( directory );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for CDirectorySourceLocation.
|
||||
*/
|
||||
public CDirectorySourceLocation( IPath directory, IPath association )
|
||||
{
|
||||
setDirectory( directory );
|
||||
setAssociation( association );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#findSourceElement(String)
|
||||
*/
|
||||
|
@ -67,19 +81,17 @@ public class CDirectorySourceLocation implements ICSourceLocation
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the directory in which source elements will
|
||||
* be searched for.
|
||||
* Sets the directory in which source elements will be searched for.
|
||||
*
|
||||
* @param directory a directory
|
||||
*/
|
||||
private void setDirectory( IPath directory )
|
||||
protected void setDirectory( IPath directory )
|
||||
{
|
||||
fDirectory = directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the directory associated with this source
|
||||
* location.
|
||||
* Returns the root directory of this source location.
|
||||
*
|
||||
* @return directory
|
||||
*/
|
||||
|
@ -88,29 +100,45 @@ public class CDirectorySourceLocation implements ICSourceLocation
|
|||
return fDirectory;
|
||||
}
|
||||
|
||||
protected void setAssociation( IPath association )
|
||||
{
|
||||
fAssociation = association;
|
||||
}
|
||||
|
||||
public IPath getAssociation()
|
||||
{
|
||||
return fAssociation;
|
||||
}
|
||||
|
||||
private Object findFileByAbsolutePath( String fileName )
|
||||
{
|
||||
IPath filePath = new Path( fileName );
|
||||
String name = filePath.lastSegment();
|
||||
filePath = filePath.removeLastSegments( 1 );
|
||||
IPath path = getDirectory();
|
||||
if ( path.equals( filePath ) )
|
||||
IPath association = getAssociation();
|
||||
if ( path.isPrefixOf( filePath ) )
|
||||
{
|
||||
path = path.append( name );
|
||||
|
||||
// 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 );
|
||||
}
|
||||
filePath = path.append( filePath.removeFirstSegments( path.segmentCount() ) );
|
||||
}
|
||||
else if ( association != null && association.isPrefixOf( filePath ) )
|
||||
{
|
||||
filePath = path.append( filePath.removeFirstSegments( association.segmentCount() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
// Try for a file in another workspace project
|
||||
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( filePath );
|
||||
if ( f != null )
|
||||
{
|
||||
return f;
|
||||
}
|
||||
|
||||
File file = filePath.toFile();
|
||||
if ( file.exists() )
|
||||
{
|
||||
return createExternalFileStorage( filePath );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,10 +15,9 @@ import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
|
|||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.debug.core.model.IPersistableSourceLocator;
|
||||
import org.eclipse.debug.core.model.IStackFrame;
|
||||
|
||||
/**
|
||||
|
@ -27,7 +26,7 @@ import org.eclipse.debug.core.model.IStackFrame;
|
|||
*
|
||||
* @since Aug 19, 2002
|
||||
*/
|
||||
public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocator
|
||||
public class CSourceLocator implements ICSourceLocator
|
||||
{
|
||||
/**
|
||||
* The array of source locations associated with this locator.
|
||||
|
@ -73,9 +72,10 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.debug.core.ICSourceLocator#getLineNumber(IStackFrameInfo)
|
||||
*/
|
||||
public int getLineNumber( IStackFrameInfo frameInfo )
|
||||
public int getLineNumber( IStackFrame frame )
|
||||
{
|
||||
return ( frameInfo != null ) ? frameInfo.getFrameLineNumber() : 0;
|
||||
IStackFrameInfo info = (IStackFrameInfo)frame.getAdapter( IStackFrameInfo.class );
|
||||
return ( info != null ) ? info.getFrameLineNumber() : 0;
|
||||
}
|
||||
|
||||
protected Object getInput( IStackFrameInfo info )
|
||||
|
@ -86,27 +86,23 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
|
|||
String fileName = info.getFile();
|
||||
if ( fileName != null && fileName.length() > 0 )
|
||||
{
|
||||
ICSourceLocation[] locations = getSourceLocations();
|
||||
for ( int i = 0; i < locations.length; ++i )
|
||||
result = findFileByAbsolutePath( fileName );
|
||||
if ( result == null )
|
||||
{
|
||||
try
|
||||
ICSourceLocation[] locations = getSourceLocations();
|
||||
for ( int i = 0; i < locations.length; ++i )
|
||||
{
|
||||
result = locations[i].findSourceElement( fileName );
|
||||
try
|
||||
{
|
||||
result = locations[i].findSourceElement( fileName );
|
||||
}
|
||||
catch( CoreException e )
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
if ( result != null )
|
||||
break;
|
||||
}
|
||||
catch( CoreException e )
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
if ( result != null )
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( result == null )
|
||||
{
|
||||
Path path = new Path( fileName );
|
||||
if ( path.isAbsolute() && path.toFile().exists() )
|
||||
{
|
||||
return new FileStorage( path );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -191,26 +187,20 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
|
|||
}
|
||||
return (ICSourceLocation[])list.toArray( new ICSourceLocation[list.size()] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
|
||||
*/
|
||||
public String getMemento() throws CoreException
|
||||
|
||||
private Object findFileByAbsolutePath( String fileName )
|
||||
{
|
||||
Path path = new Path( fileName );
|
||||
if ( path.isAbsolute() && path.toFile().exists() )
|
||||
{
|
||||
// Try for a file in another workspace project
|
||||
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( path );
|
||||
if ( f != null )
|
||||
{
|
||||
return f;
|
||||
}
|
||||
return new FileStorage( path );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(ILaunchConfiguration)
|
||||
*/
|
||||
public void initializeDefaults( ILaunchConfiguration configuration ) throws CoreException
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(String)
|
||||
*/
|
||||
public void initializeFromMemento( String memento ) throws CoreException
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
|
||||
package org.eclipse.cdt.debug.internal.core.sourcelookup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
|
||||
import org.eclipse.cdt.debug.core.ICDebugConstants;
|
||||
import org.eclipse.cdt.debug.core.model.IStackFrameInfo;
|
||||
|
@ -14,6 +17,7 @@ import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
|
|||
import org.eclipse.cdt.debug.core.sourcelookup.ISourceMode;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.debug.core.ILaunch;
|
||||
import org.eclipse.debug.core.model.ISourceLocator;
|
||||
import org.eclipse.debug.core.model.IStackFrame;
|
||||
|
||||
|
@ -24,52 +28,43 @@ import org.eclipse.debug.core.model.IStackFrame;
|
|||
*/
|
||||
public class CSourceManager implements ICSourceLocator, ISourceMode, IAdaptable
|
||||
{
|
||||
private ISourceLocator fSourceLocator;
|
||||
private DisassemblyManager fDisassemblyManager;
|
||||
private ISourceLocator fSourceLocator = null;
|
||||
private int fMode = ISourceMode.MODE_SOURCE;
|
||||
private int fRealMode = fMode;
|
||||
private ILaunch fLaunch = null;
|
||||
|
||||
/**
|
||||
* Constructor for CSourceManager.
|
||||
*/
|
||||
public CSourceManager( ISourceLocator sourceLocator, DisassemblyManager disassemblyManager )
|
||||
public CSourceManager( ISourceLocator sourceLocator )
|
||||
{
|
||||
setSourceLocator( sourceLocator );
|
||||
setDisassemblyManager( disassemblyManager );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#getLineNumber(IStackFrameInfo)
|
||||
*/
|
||||
public int getLineNumber( IStackFrameInfo frameInfo )
|
||||
public int getLineNumber( IStackFrame frame )
|
||||
{
|
||||
if ( getRealMode() == ISourceMode.MODE_SOURCE )
|
||||
{
|
||||
if ( getCSourceLocator() != null )
|
||||
{
|
||||
return getCSourceLocator().getLineNumber( frameInfo );
|
||||
return getCSourceLocator().getLineNumber( frame );
|
||||
}
|
||||
if ( frameInfo != null )
|
||||
IStackFrameInfo info = (IStackFrameInfo)frame.getAdapter( IStackFrameInfo.class );
|
||||
if ( info != null )
|
||||
{
|
||||
return frameInfo.getFrameLineNumber();
|
||||
return info.getFrameLineNumber();
|
||||
}
|
||||
}
|
||||
if ( getRealMode() == ISourceMode.MODE_DISASSEMBLY && getDisassemblyManager() != null )
|
||||
if ( getRealMode() == ISourceMode.MODE_DISASSEMBLY && getDisassemblyManager( frame ) != null )
|
||||
{
|
||||
return getDisassemblyManager().getLineNumber( frameInfo );
|
||||
return getDisassemblyManager( frame ).getLineNumber( frame );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#getSourceElement(String)
|
||||
*/
|
||||
/*
|
||||
public Object getSourceElement( String fileName )
|
||||
{
|
||||
return ( getCSourceLocator() != null ) ? getCSourceLocator().getSourceElement( fileName ) : null;
|
||||
}
|
||||
*/
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#getSourceLocations()
|
||||
*/
|
||||
|
@ -146,10 +141,10 @@ public class CSourceManager implements ICSourceLocator, ISourceMode, IAdaptable
|
|||
}
|
||||
if ( result == null &&
|
||||
( autoDisassembly || getMode() == ISourceMode.MODE_DISASSEMBLY ) &&
|
||||
getDisassemblyManager() != null )
|
||||
getDisassemblyManager( stackFrame ) != null )
|
||||
{
|
||||
setRealMode( ISourceMode.MODE_DISASSEMBLY );
|
||||
result = getDisassemblyManager().getSourceElement( stackFrame );
|
||||
result = getDisassemblyManager( stackFrame ).getSourceElement( stackFrame );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -167,7 +162,11 @@ public class CSourceManager implements ICSourceLocator, ISourceMode, IAdaptable
|
|||
|
||||
protected ISourceLocator getSourceLocator()
|
||||
{
|
||||
return fSourceLocator;
|
||||
if ( fSourceLocator != null )
|
||||
return fSourceLocator;
|
||||
else if ( fLaunch != null )
|
||||
return fLaunch.getSourceLocator();
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void setSourceLocator( ISourceLocator sl )
|
||||
|
@ -175,13 +174,20 @@ public class CSourceManager implements ICSourceLocator, ISourceMode, IAdaptable
|
|||
fSourceLocator = sl;
|
||||
}
|
||||
|
||||
protected void setDisassemblyManager( DisassemblyManager dm )
|
||||
protected DisassemblyManager getDisassemblyManager( IStackFrame stackFrame )
|
||||
{
|
||||
fDisassemblyManager = dm;
|
||||
if ( stackFrame != null )
|
||||
{
|
||||
return (DisassemblyManager)stackFrame.getDebugTarget().getAdapter( DisassemblyManager.class );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected DisassemblyManager getDisassemblyManager()
|
||||
|
||||
public void addSourceLocation( ICSourceLocation location )
|
||||
{
|
||||
return fDisassemblyManager;
|
||||
ICSourceLocation[] locations = getSourceLocations();
|
||||
ArrayList list = new ArrayList( Arrays.asList( locations ) );
|
||||
list.add( location );
|
||||
setSourceLocations( (ICSourceLocation[])list.toArray( new ICSourceLocation[list.size()] ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,12 +39,16 @@ public class DisassemblyManager
|
|||
setDebugTarget( target );
|
||||
}
|
||||
|
||||
public int getLineNumber( IStackFrameInfo frameInfo )
|
||||
public int getLineNumber( IStackFrame frame )
|
||||
{
|
||||
DisassemblyStorage storage = getSourceElement( frameInfo );
|
||||
if ( storage != null )
|
||||
IStackFrameInfo info = (IStackFrameInfo)frame.getAdapter( IStackFrameInfo.class );
|
||||
if ( info != null )
|
||||
{
|
||||
return storage.getLineNumber( frameInfo.getAddress() );
|
||||
DisassemblyStorage storage = getSourceElement( info );
|
||||
if ( storage != null )
|
||||
{
|
||||
return storage.getLineNumber( info.getAddress() );
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue