1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

Implementation of the source location.

This commit is contained in:
Mikhail Khodjaiants 2002-08-19 22:21:50 +00:00
parent 0c9803fd5d
commit 0307260c31
6 changed files with 349 additions and 24 deletions

View file

@ -14,6 +14,7 @@ import org.eclipse.cdt.debug.core.cdi.ICDILocation;
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
import org.eclipse.cdt.debug.internal.core.CDebugElement;
import org.eclipse.cdt.debug.internal.core.CDebugTarget;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
@ -77,6 +78,7 @@ public class CDebugModel
final ICDITarget cdiTarget,
final String name,
final IProcess process,
final IProject project,
final boolean allowTerminate,
final boolean allowDisconnect,
final boolean stopInMain ) throws DebugException
@ -90,6 +92,7 @@ public class CDebugModel
cdiTarget,
name,
process,
project,
allowTerminate,
allowDisconnect );
}

View file

@ -0,0 +1,49 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.core;
import org.eclipse.core.resources.IProject;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.ISourceLocator;
/**
*
* A C/C++ extension of <code>ISourceLocator</code>.
* Provides constants and methods to manage different source modes.
*
* @since Aug 19, 2002
*/
public interface ICSourceLocator extends ISourceLocator
{
static final public int MODE_SOURCE = 0;
static final public int MODE_DISASSEMBLY = 1;
static final public int MODE_MIXED = 2;
/**
* Returns the current source presentation mode.
*
* @return the current source presentation mode
*/
int getMode();
/**
* Sets the source presentation mode.
*
* @param the source presentation mode to set
*/
void setMode( int mode );
/**
* Returns the line number of the instruction pointer in the specified
* stack frame that corresponds to a line in an associated source element,
* or -1 if line number information is unavailable.
*
* @param frameInfo the frame data
* @return line number of instruction pointer in this stack frame,
* or -1 if line number information is unavailable
*/
int getLineNumber( IStackFrameInfo frameInfo );
}

View file

@ -12,6 +12,7 @@ import java.util.List;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.CDebugModel;
import org.eclipse.cdt.debug.core.ICSourceLocator;
import org.eclipse.cdt.debug.core.IFormattedMemoryBlock;
import org.eclipse.cdt.debug.core.IFormattedMemoryRetrieval;
import org.eclipse.cdt.debug.core.IRestart;
@ -24,6 +25,7 @@ import org.eclipse.cdt.debug.core.cdi.ICDISessionObject;
import org.eclipse.cdt.debug.core.cdi.ICDISignal;
import org.eclipse.cdt.debug.core.cdi.event.ICDIChangedEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDICreatedEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDIDestroyedEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDIDisconnectedEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener;
@ -31,13 +33,12 @@ import org.eclipse.cdt.debug.core.cdi.event.ICDIExitedEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDILoadedEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDIRestartedEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDIResumedEvent;
//import org.eclipse.cdt.debug.core.cdi.event.ICDISteppingEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDISuspendedEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDIDestroyedEvent;
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.core.resources.IMarkerDelta;
import org.eclipse.core.resources.IProject;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
@ -48,6 +49,7 @@ import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IMemoryBlock;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.ISourceLocator;
import org.eclipse.debug.core.model.IThread;
/**
@ -146,6 +148,11 @@ public class CDebugTarget extends CDebugElement
*/
private int fSuspendCount = 0;
/**
* The source locator for this target.
*/
private ICSourceLocator fSourceLocator = null;
/**
* Constructor for CDebugTarget.
* @param target
@ -154,6 +161,7 @@ public class CDebugTarget extends CDebugElement
ICDITarget cdiTarget,
String name,
IProcess process,
IProject project,
boolean allowsTerminate,
boolean allowsDisconnect )
{
@ -166,6 +174,8 @@ public class CDebugTarget extends CDebugElement
fConfig = cdiTarget.getSession().getConfiguration();
fSupportsTerminate = allowsTerminate & fConfig.supportsTerminate();
fSupportsDisconnect = allowsDisconnect & fConfig.supportsDisconnect();
fSourceLocator = createSourceLocator( project );
launch.setSourceLocator( fSourceLocator );
setThreadList( new ArrayList( 5 ) );
initialize();
DebugPlugin.getDefault().getLaunchManager().addLaunchListener( this );
@ -341,7 +351,7 @@ public class CDebugTarget extends CDebugElement
try
{
setTerminating( true );
getCDITarget().terminate();
getCDISession().terminate();
}
catch( CDIException e )
{
@ -453,9 +463,10 @@ public class CDebugTarget extends CDebugElement
* Refreshes the thread list.
*
*/
protected synchronized void refreshThreads()
protected synchronized List refreshThreads()
{
ArrayList list = new ArrayList( 5 );
ArrayList newThreads = new ArrayList( 5 );
try
{
ICDIThread[] cdiThreads = getCDITarget().getThreads();
@ -464,7 +475,8 @@ public class CDebugTarget extends CDebugElement
CThread thread = findThread( cdiThreads[i] );
if ( thread == null )
{
thread = createThread( cdiThreads[i] );
thread = new CThread( this, cdiThreads[i] );
newThreads.add( thread );
}
else
{
@ -479,11 +491,17 @@ public class CDebugTarget extends CDebugElement
}
getThreadList().clear();
setThreadList( list );
it = newThreads.iterator();
while( it.hasNext() )
{
((CThread)it.next()).fireCreationEvent();
}
}
catch( CDIException e )
{
CDebugCorePlugin.log( e );
}
return newThreads;
}
/**
@ -939,12 +957,7 @@ public class CDebugTarget extends CDebugElement
*/
protected CThread createThread( ICDIThread cdiThread )
{
CThread thread = null;
thread = new CThread( this, cdiThread );
if ( isDisconnected() )
{
return null;
}
CThread thread = new CThread( this, cdiThread );
getThreadList().add( thread );
thread.fireCreationEvent();
return thread;
@ -958,12 +971,7 @@ public class CDebugTarget extends CDebugElement
*/
protected CThread createRunningThread( ICDIThread cdiThread )
{
CThread thread = null;
thread = new CThread( this, cdiThread );
if ( isDisconnected() )
{
return null;
}
CThread thread = new CThread( this, cdiThread );
thread.setRunning( true );
getThreadList().add( thread );
thread.fireCreationEvent();
@ -996,13 +1004,15 @@ public class CDebugTarget extends CDebugElement
setCurrentStateId( IState.SUSPENDED );
ICDISessionObject reason = event.getReason();
setCurrentStateInfo( reason );
refreshThreads();
List newThreads = refreshThreads();
if ( event.getSource() instanceof ICDIThread )
{
CThread thread = findThread( (ICDIThread)event.getSource() );
if ( thread != null )
if ( thread != null && newThreads.contains( thread ) )
{
thread.handleDebugEvent( event );
}
}
if ( reason instanceof ICDIEndSteppingRange )
{
handleEndSteppingRange( (ICDIEndSteppingRange)reason );
@ -1216,4 +1226,19 @@ public class CDebugTarget extends CDebugElement
incrementSuspendCount();
super.fireSuspendEvent( detail );
}
/**
* Creates the source locator for this target.
*
* @return the source locator for this target
*/
private ICSourceLocator createSourceLocator( IProject project )
{
return new CSourceLocator( this, project );
}
protected ICSourceLocator getSourceLocator()
{
return fSourceLocator;
}
}

View file

@ -0,0 +1,217 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.internal.core;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.ICSourceLocator;
import org.eclipse.cdt.debug.core.IStackFrameInfo;
import org.eclipse.core.internal.resources.File;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IStackFrame;
/**
*
* Locates source for a C/C++ debug session.
*
* @since Aug 19, 2002
*/
public class CSourceLocator implements ICSourceLocator
{
/**
* The project in which to look for source.
*/
private IProject fProject;
/**
* The debug target this source locator is associated with.
*/
private CDebugTarget fTarget;
/**
* The source presentation mode.
*/
private int fMode = ICSourceLocator.MODE_SOURCE;
private int fInternalMode = MODE_SOURCE;
/**
* Constructor for CSourceLocator.
*/
public CSourceLocator( CDebugTarget target, IProject project )
{
fProject = project;
fTarget = target;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(IStackFrame)
*/
public Object getSourceElement( IStackFrame stackFrame )
{
Object result = null;
if ( stackFrame != null && stackFrame.getAdapter( IStackFrameInfo.class ) != null )
{
try
{
result = getInput( (IStackFrameInfo)stackFrame.getAdapter( IStackFrameInfo.class ) );
}
catch( DebugException e )
{
CDebugCorePlugin.log( e );
}
}
return result;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.ICSourceLocator#getLineNumber(IStackFrameInfo)
*/
public int getLineNumber( IStackFrameInfo frameInfo )
{
int result = 0;
if ( getMode() == MODE_SOURCE )
result = frameInfo.getFrameLineNumber();
return result;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.ICSourceLocator#getMode()
*/
public int getMode()
{
return fMode;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.ICSourceLocator#setMode(int)
*/
public void setMode( int mode )
{
}
protected void setInternalMode( int mode )
{
fInternalMode = mode;
}
protected Object getInput( IStackFrameInfo frameInfo ) throws DebugException
{
Object result = null;
switch( getMode() )
{
case ICSourceLocator.MODE_SOURCE:
result = getSourceInput( frameInfo );
break;
/*
case ICSourceLocator.MODE_DISASSEMBLY:
result = getDisassemblyInput( frameInfo );
break;
case ICSourceLocator.MODE_MIXED:
result = getMixedInput( frameInfo );
break;
*/
}
return result;
}
private Object getSourceInput( IStackFrameInfo info )
{
Object result = null;
if ( info != null )
{
setInternalMode( ICSourceLocator.MODE_SOURCE );
String fileName = info.getFile();
if ( fileName != null && fileName.length() > 0 )
result = findFile( fProject, fileName );
}
// switch to assembly mode if source file not found
/*
if ( result == null )
result = getDisassemblyInput( info );
*/
return result;
}
private Object findFile( IProject project, String fileName )
{
IPath path = new Path( fileName );
fileName = path.toOSString();
/*
* We have a few possible cases: either we get a source file name with no path,
* or we get a fully-qualified filename from the debugger.
*/
String pPath = new String( project.getLocation().toOSString() );
int i;
if ( (i = fileName.indexOf( pPath )) >= 0 )
{
i += pPath.length() + 1;
if ( fileName.length() > i )
return project.getFile( fileName.substring( i ) );
}
// Then just do a search on our project, and if that fails, any dependent projects
IFile f = null;
try
{
f = findFile( (IContainer)project, path );
if ( f != null )
return f;
if ( f == null )
{
IProject[] p = project.getReferencedProjects();
for ( int j= 0; j < p.length; j++ )
{
if ( (f = findFile( (IContainer)p[j], new Path( fileName ) )) != null )
{
return f;
}
}
}
}
catch( CoreException e )
{
}
if ( f != null )
return f;
// Search for an external file
// return findExternalFile( fileName );
return null;
}
private IFile findFile( IContainer parent, IPath name ) throws CoreException
{
if ( name.isAbsolute() )
{
if ( name.toOSString().startsWith( parent.getLocation().toOSString() ) )
{
name = new Path( name.toOSString().substring( parent.getLocation().toOSString().length() + 1 ) );
}
}
IResource found = parent.findMember( name );
if ( found != null && found.getType() == IResource.FILE )
{
return (IFile)found;
}
IResource[] children= parent.members();
for ( int i= 0; i < children.length; i++ )
{
if ( children[i] instanceof IContainer )
{
return findFile( (IContainer)children[i], name );
}
}
return null;
}
}

View file

@ -170,11 +170,7 @@ public class CStackFrame extends CDebugElement
{
if ( isSuspended() )
{
ICDILocation location = getCDIStackFrame().getLocation();
if ( location != null )
{
return location.getLineNumber();
}
return ((CDebugTarget)getDebugTarget()).getSourceLocator().getLineNumber( this );
}
return -1;
}

View file

@ -11,6 +11,9 @@ import java.util.HashMap;
import org.eclipse.cdt.debug.core.IStackFrameInfo;
import org.eclipse.cdt.debug.core.IState;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.DebugException;
@ -24,7 +27,11 @@ import org.eclipse.debug.ui.IDebugModelPresentation;
import org.eclipse.debug.ui.IValueDetailListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorRegistry;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.FileEditorInput;
/**
*
@ -87,6 +94,27 @@ public class CDTDebugModelPresentation extends LabelProvider
*/
public IEditorInput getEditorInput( Object element )
{
IFile file = null;
if ( element instanceof IMarker )
{
IResource resource = ((IMarker)element).getResource();
if ( resource instanceof IFile )
file = (IFile)resource;
}
if ( element instanceof IFile )
file = (IFile)element;
if ( file != null )
return new FileEditorInput( file );
/*
if ( element instanceof IFileStorage )
{
return new FileStorageEditorInput( (IFileStorage)element );
}
if ( element instanceof IDisassemblyStorage )
{
return new DisassemblyEditorInput( (IStorage)element );
}
*/
return null;
}
@ -95,6 +123,13 @@ public class CDTDebugModelPresentation extends LabelProvider
*/
public String getEditorId( IEditorInput input, Object element )
{
if ( input != null )
{
IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
IEditorDescriptor descriptor = registry.getDefaultEditor( input.getName() );
if ( descriptor != null )
return descriptor.getId();
}
return null;
}