From fdf2c99a70dd01cbf2fafcbb81a200bfad0e5e91 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Tue, 8 Oct 2002 22:03:22 +0000 Subject: [PATCH] Implementation of disassembly mode. --- .../cdt/debug/core/IDisassemblyStorage.java | 40 ++++++ .../core/sourcelookup/CSourceLocator.java | 90 +----------- .../core/sourcelookup/CSourceManager.java | 130 ++++++++++++++++++ .../core/sourcelookup/DisassemblyManager.java | 23 ++++ .../core/sourcelookup/ICSourceLocator.java | 45 ++---- .../debug/core/sourcelookup/ISourceMode.java | 33 +++++ .../internal/core/DisassemblyStorage.java | 122 ++++++++++++++++ .../internal/core/model/CDebugTarget.java | 9 +- .../icons/full/obj16/disassembly_obj.gif | Bin 0 -> 238 bytes .../cdt/debug/internal/ui/CDebugImages.java | 2 + .../ui/editors/DisassemblyEditorInput.java | 88 ++++++++++++ 11 files changed, 455 insertions(+), 127 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IDisassemblyStorage.java create mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CSourceManager.java create mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/DisassemblyManager.java create mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ISourceMode.java create mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/DisassemblyStorage.java create mode 100644 debug/org.eclipse.cdt.debug.ui/icons/full/obj16/disassembly_obj.gif create mode 100644 debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/editors/DisassemblyEditorInput.java diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IDisassemblyStorage.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IDisassemblyStorage.java new file mode 100644 index 00000000000..3f814faa79e --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IDisassemblyStorage.java @@ -0,0 +1,40 @@ +/* + *(c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + * + */ + +package org.eclipse.cdt.debug.core; + +import org.eclipse.core.resources.IStorage; +import org.eclipse.debug.core.model.IDebugTarget; + +/** + * Defines methods specific to disassembly. + * + * @since: Oct 8, 2002 + */ +public interface IDisassemblyStorage extends IStorage +{ + /** + * Returns the debug target of this disassembly. + * + * @return the debug target of this disassembly + */ + IDebugTarget getDebugTarget(); + + /** + * Returns whether this storage contains the instructions at given address. + * + * @param address - an address + * @return whether this storage contains the instructions at given address + */ + boolean containsAddress( long address ); + + /** + * Returns the line number for given address. + * @param address - an address + * @return the line number for given address + */ + int getLineNumber( long address ) ; +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CSourceLocator.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CSourceLocator.java index 41994cfee5f..ad1a33374d9 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CSourceLocator.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CSourceLocator.java @@ -8,13 +8,11 @@ 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.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.model.IPersistableSourceLocator; import org.eclipse.debug.core.model.IStackFrame; @@ -32,13 +30,6 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato */ private ICSourceLocation[] fSourceLocations; - /** - * The source presentation mode. - */ - private int fMode = ICSourceLocator.MODE_SOURCE; - - private int fInternalMode = MODE_SOURCE; - /** * Constructor for CSourceLocator. */ @@ -68,19 +59,11 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato */ 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 getInput( (IStackFrameInfo)stackFrame.getAdapter( IStackFrameInfo.class ) ); } - return result; + return null; } /* (non-Javadoc) @@ -88,58 +71,14 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato */ public int getLineNumber( IStackFrameInfo frameInfo ) { - int result = 0; - if ( getMode() == MODE_SOURCE ) - result = frameInfo.getFrameLineNumber(); - return result; + return ( frameInfo != null ) ? frameInfo.getFrameLineNumber() : 0; } - /* (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 ) + protected Object getInput( IStackFrameInfo info ) { Object result = null; if ( info != null ) { - setInternalMode( ICSourceLocator.MODE_SOURCE ); String fileName = info.getFile(); if ( fileName != null && fileName.length() > 0 ) { @@ -159,11 +98,6 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato } } } - // switch to assembly mode if source file not found -/* - if ( result == null ) - result = getDisassemblyInput( info ); -*/ return result; } @@ -193,22 +127,6 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato return result; } - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.ICSourceLocator#getSourceElementForAddress(long) - */ - public Object getSourceElementForAddress( long address ) - { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.ICSourceLocator#getSourceElementForFunction(String) - */ - public Object getSourceElementForFunction( String function ) - { - return null; - } - /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.ICSourceLocator#contains(IResource) */ diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CSourceManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CSourceManager.java new file mode 100644 index 00000000000..bcb06b60906 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CSourceManager.java @@ -0,0 +1,130 @@ +/* + *(c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + * + */ + +package org.eclipse.cdt.debug.core.sourcelookup; + +import org.eclipse.cdt.debug.core.IStackFrameInfo; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.debug.core.model.ISourceLocator; +import org.eclipse.debug.core.model.IStackFrame; + +/** + * Enter type comment. + * + * @since: Oct 8, 2002 + */ +public class CSourceManager implements ICSourceLocator, ISourceMode, IAdaptable +{ + protected ISourceLocator fSourceLocator; + protected int fMode = ISourceMode.MODE_SOURCE; + + /** + * Constructor for CSourceManager. + */ + public CSourceManager( ISourceLocator sourceLocator ) + { + fSourceLocator = sourceLocator; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#getLineNumber(IStackFrameInfo) + */ + public int getLineNumber( IStackFrameInfo frameInfo ) + { + if ( getMode() == ISourceMode.MODE_SOURCE ) + { + if ( getCSourceLocator() != null ) + { + return getCSourceLocator().getLineNumber( frameInfo ); + } + if ( frameInfo != null ) + { + return frameInfo.getFrameLineNumber(); + } + } + 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() + */ + public ICSourceLocation[] getSourceLocations() + { + return ( getCSourceLocator() != null ) ? getCSourceLocator().getSourceLocations() : new ICSourceLocation[0]; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#setSourceLocations(ICSourceLocation[]) + */ + public void setSourceLocations( ICSourceLocation[] locations ) + { + if ( getCSourceLocator() != null ) + { + getCSourceLocator().setSourceLocations( locations ); + } + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#contains(IResource) + */ + public boolean contains( IResource resource ) + { + return ( getCSourceLocator() != null ) ? getCSourceLocator().contains( resource ) : false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.sourcelookup.ISourceMode#getMode() + */ + public int getMode() + { + return fMode; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.sourcelookup.ISourceMode#setMode(int) + */ + public void setMode( int mode ) + { + fMode = mode; + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) + */ + public Object getAdapter( Class adapter ) + { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(IStackFrame) + */ + public Object getSourceElement( IStackFrame stackFrame ) + { + return ( getSourceLocator() != null ) ? getSourceLocator() : null; + } + + protected ICSourceLocator getCSourceLocator() + { + if ( getSourceLocator() instanceof ICSourceLocator ) + return (ICSourceLocator)getSourceLocator(); + return null; + } + + protected ISourceLocator getSourceLocator() + { + return fSourceLocator; + } +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/DisassemblyManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/DisassemblyManager.java new file mode 100644 index 00000000000..7c9a9eb9cb7 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/DisassemblyManager.java @@ -0,0 +1,23 @@ +/* + *(c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + * + */ + +package org.eclipse.cdt.debug.core.sourcelookup; + +/** + * Enter type comment. + * + * @since: Oct 8, 2002 + */ +public class DisassemblyManager +{ + /** + * Constructor for DisassemblyManager. + */ + public DisassemblyManager() + { + super(); + } +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocator.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocator.java index 86ec75aeae3..082c3414cf7 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocator.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocator.java @@ -6,6 +6,7 @@ package org.eclipse.cdt.debug.core.sourcelookup; import org.eclipse.cdt.debug.core.IStackFrameInfo; +import org.eclipse.core.resources.IResource; import org.eclipse.debug.core.model.ISourceLocator; /** @@ -17,24 +18,6 @@ import org.eclipse.debug.core.model.ISourceLocator; */ 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, @@ -55,24 +38,6 @@ public interface ICSourceLocator extends ISourceLocator */ Object getSourceElement( String fileName ); - /** - * Returns a source element that corresponds to the given function, or - * null if a source element could not be located. - * - * @param function the function name for which to locate source - * @return an object representing a source element. - */ - Object getSourceElementForFunction( String function ); - - /** - * Returns a source element that corresponds to the given address, or - * null if a source element could not be located. - * - * @param address the address for which to locate source - * @return an object representing a source element. - */ - Object getSourceElementForAddress( long address ); - /** * Returns the source locations of this locator. * @@ -86,4 +51,12 @@ public interface ICSourceLocator extends ISourceLocator * @param location - an array of source locations */ void setSourceLocations( ICSourceLocation[] locations ); + + /** + * Returns whether this locator is able to locate the given resource. + * + * @param resource the resource to locate + * @return whether this locator is able to locate the given resource + */ + boolean contains( IResource resource ); } \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ISourceMode.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ISourceMode.java new file mode 100644 index 00000000000..3e52c07fb24 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ISourceMode.java @@ -0,0 +1,33 @@ +/* + *(c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + * + */ + +package org.eclipse.cdt.debug.core.sourcelookup; + +/** + * Defines constatnts and methods to set the source presentation mode. + * + * @since: Oct 8, 2002 + */ +public interface ISourceMode +{ + 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 ); +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/DisassemblyStorage.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/DisassemblyStorage.java new file mode 100644 index 00000000000..9fd001eadd8 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/DisassemblyStorage.java @@ -0,0 +1,122 @@ +/* + *(c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + * + */ + +package org.eclipse.cdt.debug.internal.core; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import org.eclipse.cdt.debug.core.IDisassemblyStorage; +import org.eclipse.cdt.debug.core.cdi.model.ICDIInstruction; +import org.eclipse.core.resources.IStorage; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.debug.core.model.IDebugTarget; + +/** + * Enter type comment. + * + * @since: Oct 8, 2002 + */ +public class DisassemblyStorage implements IDisassemblyStorage +{ + protected ICDIInstruction[] fInstructions; + protected IDebugTarget fDebugTarget; + protected ByteArrayInputStream fInputStream = null; + protected long fStartAddress = 0; + protected long fEndAddress = 0; + + /** + * Constructor for DisassemblyStorage. + */ + public DisassemblyStorage( IDebugTarget target, ICDIInstruction[] instructions ) + { + setDebugTarget( target ); + setInstructions( instructions ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.IDisassemblyStorage#getDebugTarget() + */ + public IDebugTarget getDebugTarget() + { + return fDebugTarget; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.IDisassemblyStorage#containsAddress(Long) + */ + public boolean containsAddress( long address ) + { + return ( address >= fStartAddress && address <= fEndAddress ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.IDisassemblyStorage#getLineNumber(Long) + */ + public int getLineNumber( long address ) + { + return 0; + } + + /* (non-Javadoc) + * @see org.eclipse.core.resources.IStorage#getContents() + */ + public InputStream getContents() throws CoreException + { + if ( fInputStream != null ) + fInputStream.reset(); + return fInputStream; + } + + /* (non-Javadoc) + * @see org.eclipse.core.resources.IStorage#getFullPath() + */ + public IPath getFullPath() + { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.core.resources.IStorage#getName() + */ + public String getName() + { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.core.resources.IStorage#isReadOnly() + */ + public boolean isReadOnly() + { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) + */ + public Object getAdapter( Class adapter ) + { + if ( adapter.equals( IStorage.class ) ) + return this; + if ( adapter.equals( IDisassemblyStorage.class ) ) + return this; + if ( adapter.equals( DisassemblyStorage.class ) ) + return this; + return null; + } + + protected void setDebugTarget( IDebugTarget target ) + { + fDebugTarget = target; + } + + protected void setInstructions( ICDIInstruction[] intructions ) + { + fInstructions = intructions; + } +} 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 68c32570676..a168446f1b6 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 @@ -217,8 +217,7 @@ public class CDebugTarget extends CDebugElement setCDITarget( cdiTarget ); setBreakpoints( new HashMap( 5 ) ); setTemporaryBreakpoints( new ArrayList() ); - if ( getLaunch().getSourceLocator() == null ) - getLaunch().setSourceLocator( createSourceLocator( project ) ); + getLaunch().setSourceLocator( createSourceLocator( project ) ); setConfiguration( cdiTarget.getSession().getConfiguration() ); fSupportsTerminate = allowsTerminate & getConfiguration().supportsTerminate(); fSupportsDisconnect = allowsDisconnect & getConfiguration().supportsDisconnect(); @@ -353,9 +352,9 @@ public class CDebugTarget extends CDebugElement if ( breakpoint instanceof ICBreakpoint ) { ISourceLocator sl = getSourceLocator(); - if ( sl != null && sl instanceof CSourceLocator ) + if ( sl != null && sl instanceof ICSourceLocator ) { - return ((CSourceLocator)sl).contains( breakpoint.getMarker().getResource() ); + return ((ICSourceLocator)sl).contains( breakpoint.getMarker().getResource() ); } return true; } @@ -1803,7 +1802,7 @@ public class CDebugTarget extends CDebugElement protected ISourceLocator createSourceLocator( IProject project ) { - return new CSourceLocator( project ); + return ( getLaunch().getSourceLocator() != null ) ? getLaunch().getSourceLocator() : new CSourceLocator( project ); } protected void setSourceSearchPath() diff --git a/debug/org.eclipse.cdt.debug.ui/icons/full/obj16/disassembly_obj.gif b/debug/org.eclipse.cdt.debug.ui/icons/full/obj16/disassembly_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..546c93c42d15fa850d0a11aa4d08a80556b0eabb GIT binary patch literal 238 zcmV!>eG;q zf{TPfs-s%Lxo*e6e6_A~+0>`s+qCQH)amEa=jG7u?APe#((CEf#J`zJNkU3VL;L#n z|Ns930|Nj60RR90A^8LW0018VEC2ui01yBW000GR;3tk`DFSG!ngHj%E(VlsW#83< z%wugQH^ySY`}itATg1@_^f~12pt0oZMo?K>U0HxfI8%oZjE#