From 07dc15fa9c8142c374cf7ec3372c01c52962d614 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Wed, 21 Apr 2004 23:10:49 +0000 Subject: [PATCH] Implementing the Disassembly view. New annotation model is added to show breakpoint markers. --- debug/org.eclipse.cdt.debug.ui/ChangeLog | 9 +++ .../DisassemblyDocumentProvider.java | 28 +++----- .../disassembly/DisassemblyEditorInput.java | 18 +++++ ...sassemblyInstructionPointerAnnotation.java | 45 ++++-------- .../DisassemblyMarkerAnnotationModel.java | 69 +++++++++++++++++++ .../ui/views/disassembly/DisassemblyView.java | 53 ++++++-------- 6 files changed, 140 insertions(+), 82 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyMarkerAnnotationModel.java diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog index 1539c3998d3..45ff532bdd9 100644 --- a/debug/org.eclipse.cdt.debug.ui/ChangeLog +++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog @@ -1,3 +1,12 @@ +2004-04-15 Mikhail Khodjaiants + Implementing the Disassembly view. + New annotation model is added to show breakpoint markers. + * DisassemblyDocumentProvider.java + * DisassemblyEditorInput.java + * DisassemblyInstructionPointerAnnotation.java + * DisassemblyMarkerAnnotationModel.java: new + * DisassemblyView.java + 2004-04-19 Mikhail Khodjaiants Fix for bug 58711: Breakpoint race condition. To avoid race condition all breakpoint marker updates (like increment/decrement the install count, diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyDocumentProvider.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyDocumentProvider.java index 714b68d85b8..41b524b5b47 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyDocumentProvider.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyDocumentProvider.java @@ -10,7 +10,6 @@ ***********************************************************************/ package org.eclipse.cdt.debug.internal.ui.views.disassembly; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.text.Document; @@ -18,8 +17,6 @@ import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.IElementStateListener; -import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel; - /** * Document provider for disassembly view. @@ -28,8 +25,8 @@ public class DisassemblyDocumentProvider implements IDocumentProvider { private IDocument fDocument; - private IAnnotationModel fAnnotationModel; - + private DisassemblyMarkerAnnotationModel fAnnotationModel; + /** * Constructor for DisassemblyDocumentProvider. */ @@ -40,17 +37,12 @@ public class DisassemblyDocumentProvider implements IDocumentProvider { * @see org.eclipse.ui.texteditor.IDocumentProvider#connect(java.lang.Object) */ public void connect( Object element ) throws CoreException { - if ( element instanceof IDocument ) { - IAnnotationModel model = getAnnotationModel( null ); - model.connect( (IDocument)element ); - } } /* (non-Javadoc) * @see org.eclipse.ui.texteditor.IDocumentProvider#disconnect(java.lang.Object) */ public void disconnect( Object element ) { - // TODO Auto-generated method stub } /* (non-Javadoc) @@ -59,12 +51,13 @@ public class DisassemblyDocumentProvider implements IDocumentProvider { public IDocument getDocument( Object element ) { if ( fDocument == null ) { fDocument = new Document(); - try { - connect( fDocument ); - } - catch( CoreException e ) { - fDocument = null; - } + } + if ( element instanceof DisassemblyEditorInput ) { + String contents = ((DisassemblyEditorInput)element).getContents(); + fDocument.set( contents ); + } + else { + fDocument.set( "" ); //$NON-NLS-1$ } return fDocument; } @@ -128,8 +121,9 @@ public class DisassemblyDocumentProvider implements IDocumentProvider { */ public IAnnotationModel getAnnotationModel( Object element ) { if ( fAnnotationModel == null ) { - fAnnotationModel = new ResourceMarkerAnnotationModel( ResourcesPlugin.getWorkspace().getRoot() ); + fAnnotationModel = new DisassemblyMarkerAnnotationModel(); } + fAnnotationModel.setInput( ( element instanceof DisassemblyEditorInput ) ? (DisassemblyEditorInput)element : null ); return fAnnotationModel; } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyEditorInput.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyEditorInput.java index a806c439b87..8aaab2ff4ba 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyEditorInput.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyEditorInput.java @@ -15,7 +15,9 @@ import java.util.Arrays; import org.eclipse.cdt.debug.core.model.IAsmInstruction; import org.eclipse.cdt.debug.core.model.ICStackFrame; import org.eclipse.cdt.debug.core.model.IDisassembly; +import org.eclipse.cdt.debug.core.model.IExecFileInfo; import org.eclipse.cdt.debug.internal.ui.CDebugUIUtils; +import org.eclipse.core.resources.IFile; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IPersistableElement; @@ -58,6 +60,18 @@ public class DisassemblyEditorInput implements IEditorInput { return (address >= fStartAddress && address <= fEndAddress); } + public IFile getModuleFile() { + IDisassembly d = getDisassembly(); + IFile result = null; + if ( d != null ) { + IExecFileInfo info = (IExecFileInfo)d.getAdapter( IExecFileInfo.class ); + if ( info != null ) { + result = info.getExecFile(); + } + } + return result; + } + private void createContent() { StringBuffer lines = new StringBuffer(); int maxFunctionName = 0; @@ -227,4 +241,8 @@ public class DisassemblyEditorInput implements IEditorInput { public long getAddress( int lineNumber ) throws IllegalArgumentException { return ( fStorage != null ) ? fStorage.getAddress( lineNumber ) : 0; } + + public IFile getModuleFile() { + return ( fStorage != null ) ? fStorage.getModuleFile() : null; + } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyInstructionPointerAnnotation.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyInstructionPointerAnnotation.java index 3e3ba8d9c40..dd331f9d2f7 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyInstructionPointerAnnotation.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyInstructionPointerAnnotation.java @@ -24,11 +24,7 @@ import org.eclipse.jface.text.source.Annotation; */ public class DisassemblyInstructionPointerAnnotation extends Annotation { - /** - * The frame for this instruction pointer annotation. This is necessary only so that - * instances of this class can be distinguished by equals(). - */ - private ICStackFrame fStackFrame; + private int fHashCode = 0; /** * Construct an instruction pointer annotation for the given stack frame. @@ -40,16 +36,7 @@ public class DisassemblyInstructionPointerAnnotation extends Annotation { super( isTopFrame ? IInternalCDebugUIConstants.ANN_DISASM_INSTR_POINTER_CURRENT : IInternalCDebugUIConstants.ANN_DISASM_INSTR_POINTER_SECONDARY, false, isTopFrame ? DisassemblyMessages.getString( "DisassemblyInstructionPointerAnnotation.Current_Pointer_1" ) : DisassemblyMessages.getString( "DisassemblyInstructionPointerAnnotation.Secondary_Pointer_1" ) ); //$NON-NLS-1$ //$NON-NLS-2$ - fStackFrame = stackFrame; - } - - /** - * Returns the stack frame associated with this annotation - * - * @return the stack frame associated with this annotation - */ - public ICStackFrame getStackFrame() { - return fStackFrame; + fHashCode = getHashCode( stackFrame ); } private IDisassembly getDisassembly( ICStackFrame frame ) { @@ -64,28 +51,15 @@ public class DisassemblyInstructionPointerAnnotation extends Annotation { return null; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals( Object other ) { - if ( other instanceof DisassemblyInstructionPointerAnnotation ) { - ICStackFrame otherFrame = ((DisassemblyInstructionPointerAnnotation)other).getStackFrame(); - IDisassembly otherDisassembly = getDisassembly( otherFrame ); - if ( otherDisassembly != null && otherDisassembly.equals( getDisassembly( getStackFrame() ) ) ) { - return ( otherFrame.getAddress() == getStackFrame().getAddress() ); - } - } - return false; - } - /* (non-Javadoc) * @see java.lang.Object#hashCode() */ public int hashCode() { + return fHashCode; + } + + private int getHashCode( ICStackFrame frame ) { int hashCode = 17; - ICStackFrame frame = getStackFrame(); IDisassembly disassembly = getDisassembly( frame ); hashCode = 37*hashCode + (( disassembly != null ) ? disassembly.hashCode() : 0); if ( frame != null ) { @@ -94,4 +68,11 @@ public class DisassemblyInstructionPointerAnnotation extends Annotation { } return hashCode; } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals( Object obj ) { + return ( obj != null ? obj.hashCode() == hashCode() : false ); + } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyMarkerAnnotationModel.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyMarkerAnnotationModel.java new file mode 100644 index 00000000000..f873efa6bcc --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyMarkerAnnotationModel.java @@ -0,0 +1,69 @@ +/********************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.debug.internal.ui.views.disassembly; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.text.Position; +import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel; + +/** + * Marker annotation model for disassembly. + */ +public class DisassemblyMarkerAnnotationModel extends ResourceMarkerAnnotationModel { + + private DisassemblyEditorInput fInput; + + public DisassemblyMarkerAnnotationModel() { + super( ResourcesPlugin.getWorkspace().getRoot() ); + } + + protected DisassemblyEditorInput getInput() { + return this.fInput; + } + + protected void setInput( DisassemblyEditorInput input ) { + this.fInput = input; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel#deleteMarkers(org.eclipse.core.resources.IMarker[]) + */ + protected void deleteMarkers( IMarker[] markers ) throws CoreException { + // TODO Auto-generated method stub + super.deleteMarkers( markers ); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel#isAcceptable(org.eclipse.core.resources.IMarker) + */ + protected boolean isAcceptable( IMarker marker ) { + // TODO Auto-generated method stub + return super.isAcceptable( marker ); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel#retrieveMarkers() + */ + protected IMarker[] retrieveMarkers() throws CoreException { + // TODO Auto-generated method stub + return super.retrieveMarkers(); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel#createPositionFromMarker(org.eclipse.core.resources.IMarker) + */ + protected Position createPositionFromMarker( IMarker marker ) { + // TODO Auto-generated method stub + return super.createPositionFromMarker( marker ); + } +} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyView.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyView.java index 2d5f2a478ab..75cb50d687f 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyView.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyView.java @@ -32,7 +32,6 @@ import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.source.IAnnotationAccess; @@ -42,6 +41,7 @@ import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.IVerticalRuler; import org.eclipse.jface.text.source.SourceViewer; import org.eclipse.jface.text.source.VerticalRuler; +import org.eclipse.jface.util.Assert; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.ISelection; @@ -217,7 +217,8 @@ public class DisassemblyView extends AbstractDebugEventHandlerView * @return the vertical ruler */ private IVerticalRuler createVerticalRuler() { - return new VerticalRuler( VERTICAL_RULER_WIDTH, getAnnotationAccess() ); + IVerticalRuler ruler = new VerticalRuler( VERTICAL_RULER_WIDTH, getAnnotationAccess() ); + return ruler; } /** @@ -283,12 +284,9 @@ public class DisassemblyView extends AbstractDebugEventHandlerView } setInput( input ); - showViewer(); - IDocument document = viewer.getDocument(); - String contents = ((DisassemblyEditorInput)input).getContents(); - document.set( contents ); - + getSourceViewer().setDocument( getDocumentProvider().getDocument( input ), + getDocumentProvider().getAnnotationModel( input ) ); updateObjects(); } @@ -395,7 +393,7 @@ public class DisassemblyView extends AbstractDebugEventHandlerView getSourceViewer().setSelectedRange( start, 0 ); } widget.setRedraw( true ); - setInstructionPointer( frame, start, length ); + setInstructionPointer( frame, start, length, getDocumentProvider().getAnnotationModel( input ) ); } } @@ -496,22 +494,15 @@ public class DisassemblyView extends AbstractDebugEventHandlerView return this.fDocumentProvider; } - protected void setInstructionPointer( ICStackFrame frame, int start, int length ) { + protected void setInstructionPointer( ICStackFrame frame, int start, int length, IAnnotationModel model ) { + Assert.isNotNull( model ); boolean tos = isTopStackFrame( frame ); DisassemblyInstructionPointerAnnotation instPtrAnnotation = new DisassemblyInstructionPointerAnnotation( frame, tos ); - - Position position = new Position( start, length ); - - // Add the annotation at the position to the editor's annotation model. - // If there is no annotation model, there's nothing more to do - IAnnotationModel annModel = getDocumentProvider().getAnnotationModel( null ); - if ( annModel == null ) { - return; - } - DisassemblyInstructionPointerAnnotation currentPointer = getCurrentInstructionPointer(); - if ( currentPointer != null ) - removeCurrentInstructionPointer(); - annModel.addAnnotation( instPtrAnnotation, position ); + Position position = new Position( start, length ); + DisassemblyInstructionPointerAnnotation oldPointer = getCurrentInstructionPointer(); + if ( oldPointer != null ) + model.removeAnnotation( oldPointer ); + model.addAnnotation( instPtrAnnotation, position ); setCurrentInstructionPointer( instPtrAnnotation ); } @@ -534,14 +525,12 @@ public class DisassemblyView extends AbstractDebugEventHandlerView fInstrPointerAnnotation = instrPointer; } - protected void removeCurrentInstructionPointer() { + protected void removeCurrentInstructionPointer( IAnnotationModel model ) { + Assert.isNotNull( model ); DisassemblyInstructionPointerAnnotation instrPointer = getCurrentInstructionPointer(); if ( instrPointer != null ) { - IAnnotationModel annModel = getDocumentProvider().getAnnotationModel( null ); - if ( annModel != null ) { - annModel.removeAnnotation( instrPointer ); + model.removeAnnotation( instrPointer ); setCurrentInstructionPointer( null ); - } } } @@ -550,14 +539,12 @@ public class DisassemblyView extends AbstractDebugEventHandlerView if ( viewer == null ) return; - IEditorInput input = DisassemblyEditorInput.EMPTY_EDITOR_INPUT; + IEditorInput input = DisassemblyEditorInput.EMPTY_EDITOR_INPUT; setInput( input ); - showViewer(); - IDocument document = getSourceViewer().getDocument(); - String contents = ((DisassemblyEditorInput)input).getContents(); - document.set( contents ); - removeCurrentInstructionPointer(); + IAnnotationModel model = getDocumentProvider().getAnnotationModel( input ); + getSourceViewer().setDocument( getDocumentProvider().getDocument( input ), model ); + removeCurrentInstructionPointer( model ); updateObjects(); }