diff options
author | Mikhail Khodjaiants | 2004-05-06 22:03:25 +0000 |
---|---|---|
committer | Mikhail Khodjaiants | 2004-05-06 22:03:25 +0000 |
commit | a19d23361a119a607fd40ef6fcc7963ce4464c20 (patch) | |
tree | 2c6b721fdf030edede5bd9b5e19cca1bc3444afc /debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug | |
parent | 8ca7329e88313627a94faa61c7e7f5a991fe7e61 (diff) | |
download | org.eclipse.cdt-a19d23361a119a607fd40ef6fcc7963ce4464c20.tar.gz org.eclipse.cdt-a19d23361a119a607fd40ef6fcc7963ce4464c20.tar.xz org.eclipse.cdt-a19d23361a119a607fd40ef6fcc7963ce4464c20.zip |
Implementation of mixed disassembly mode.
Diffstat (limited to 'debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug')
5 files changed, 178 insertions, 193 deletions
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java index 4bb8e7561fd..b5b2f126ab7 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java @@ -18,7 +18,6 @@ import org.eclipse.cdt.debug.internal.ui.views.disassembly.DisassemblyEditorInpu import org.eclipse.cdt.debug.internal.ui.views.disassembly.DisassemblyView; import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.cdt.debug.ui.ICDebugUIConstants; -import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; @@ -109,20 +108,25 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget { IResource resource = ResourcesPlugin.getWorkspace().getRoot(); String sourceHandle = getSourceHandle( input ); long address = ((DisassemblyEditorInput)input).getAddress( lineNumber ); - ICAddressBreakpoint breakpoint = CDIDebugModel.addressBreakpointExists( sourceHandle, resource, address ); - if ( breakpoint != null ) { - DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( breakpoint, true ); + if ( address != 0 ) { + ICAddressBreakpoint breakpoint = CDIDebugModel.addressBreakpointExists( sourceHandle, resource, address ); + if ( breakpoint != null ) { + DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( breakpoint, true ); + } + else { + CDIDebugModel.createAddressBreakpoint( sourceHandle, + resource, + address, + true, + 0, + "", //$NON-NLS-1$ + true ); + } + return; } else { - CDIDebugModel.createAddressBreakpoint( sourceHandle, - resource, - address, - true, - 0, - "", //$NON-NLS-1$ - true ); + errorMessage = ActionMessages.getString( "ToggleBreakpointAdapter.Invalid_line_1" ); //$NON-NLS-1$ } - return; } } } @@ -141,7 +145,7 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget { if ( !(input instanceof DisassemblyEditorInput) || ((DisassemblyEditorInput)input).equals( DisassemblyEditorInput.EMPTY_EDITOR_INPUT ) ) { return false; - } + } } return ( selection instanceof ITextSelection ); } @@ -258,8 +262,7 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget { return ((IStorageEditorInput)input).getStorage().getName(); } if ( input instanceof DisassemblyEditorInput ) { - IFile file = ((DisassemblyEditorInput)input).getModuleFile(); - return ( file != null ) ? file.getLocation().toOSString() : ""; //$NON-NLS-1$ + return ((DisassemblyEditorInput)input).getModuleFile(); } return ""; //$NON-NLS-1$ } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyAnnotationModel.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyAnnotationModel.java index 7f044c000ce..85e64a1f9e2 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyAnnotationModel.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyAnnotationModel.java @@ -137,10 +137,9 @@ public class DisassemblyAnnotationModel extends AnnotationModel { Position position = null; DisassemblyEditorInput input = getInput(); if ( input != null ) { - long address = input.getBreakpointAddress( breakpoint ); int start = -1; - if ( address > 0 && document != null ) { - int instrNumber = input.getInstructionNumber( address ); + if ( document != null ) { + int instrNumber = input.getInstructionLine( breakpoint ); if ( instrNumber > 0 ) { try { start = fDocument.getLineOffset( instrNumber - 1 ); 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 7c0af3cbb06..5c268b9d074 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 @@ -13,13 +13,14 @@ package org.eclipse.cdt.debug.internal.ui.views.disassembly; import java.util.Arrays; import org.eclipse.cdt.debug.core.model.IAsmInstruction; +import org.eclipse.cdt.debug.core.model.IAsmSourceLine; import org.eclipse.cdt.debug.core.model.IBreakpointTarget; +import org.eclipse.cdt.debug.core.model.ICDebugTarget; import org.eclipse.cdt.debug.core.model.ICLineBreakpoint; 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.core.model.IDisassemblyBlock; import org.eclipse.cdt.debug.internal.ui.CDebugUIUtils; -import org.eclipse.core.resources.IFile; import org.eclipse.debug.core.DebugException; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.IEditorInput; @@ -30,148 +31,6 @@ import org.eclipse.ui.IPersistableElement; */ public class DisassemblyEditorInput implements IEditorInput { - /** - * A storage object used by Disassembly view. - */ - private static class DisassemblyStorage { - - private IDisassembly fDisassembly; - private IAsmInstruction[] fInstructions; - protected String fContents; - protected long fStartAddress = 0; - protected long fEndAddress = 0; - - /** - * Constructor for DisassemblyStorage. - */ - public DisassemblyStorage( IDisassembly disassembly, IAsmInstruction[] instructions ) { - fDisassembly = disassembly; - fInstructions = ( instructions != null ) ? instructions : new IAsmInstruction[0]; - initializeAddresses(); - createContent(); - } - - public String getContents() { - return fContents; - } - - public IDisassembly getDisassembly() { - return this.fDisassembly; - } - - public boolean containsFrame( ICStackFrame frame ) { - if ( !getDisassembly().getDebugTarget().equals( frame.getDebugTarget() ) ) - return false; - long address = frame.getAddress(); - 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; - } - - public long getBreakpointAddress( ICLineBreakpoint breakpoint ) { - IDisassembly dis = getDisassembly(); - if ( dis != null ) { - IBreakpointTarget bt = (IBreakpointTarget)dis.getDebugTarget().getAdapter( IBreakpointTarget.class ); - if ( bt != null ) { - try { - return bt.getBreakpointAddress( breakpoint ); - } - catch( DebugException e ) { - } - } - } - return 0; - } - - private void createContent() { - StringBuffer lines = new StringBuffer(); - int maxFunctionName = 0; - int maxOpcodeLength = 0; - long maxOffset = 0; - for( int i = 0; i < fInstructions.length; ++i ) { - String functionName = fInstructions[i].getFunctionName(); - if ( functionName.length() > maxFunctionName ) { - maxFunctionName = functionName.length(); - } - String opcode = fInstructions[i].getOpcode(); - if ( opcode.length() > maxOpcodeLength ) - maxOpcodeLength = opcode.length(); - if ( fInstructions[i].getOffset() > maxOffset ) { - maxOffset = fInstructions[i].getOffset(); - } - } - int instrPos = calculateInstructionPosition( maxFunctionName, maxOffset ); - int argPosition = instrPos + maxOpcodeLength + 1; - for( int i = 0; i < fInstructions.length; ++i ) { - lines.append( getInstructionString( fInstructions[i], instrPos, argPosition ) ); - } - fContents = lines.toString(); - } - - private String getInstructionString( IAsmInstruction instruction, int instrPosition, int argPosition ) { - int worstCaseSpace = Math.max( instrPosition, argPosition ); - char[] spaces = new char[worstCaseSpace]; - Arrays.fill( spaces, ' ' ); - StringBuffer sb = new StringBuffer(); - if ( instruction != null ) { - sb.append( CDebugUIUtils.toHexAddressString( instruction.getAdress() ) ); - sb.append( ' ' ); - String functionName = instruction.getFunctionName(); - if ( functionName != null && functionName.length() > 0 ) { - sb.append( '<' ); - sb.append( functionName ); - if ( instruction.getOffset() != 0 ) { - sb.append( '+' ); - sb.append( instruction.getOffset() ); - } - sb.append( ">:" ); //$NON-NLS-1$ - sb.append( spaces, 0, instrPosition - sb.length() ); - } - sb.append( instruction.getOpcode() ); - sb.append( spaces, 0, argPosition - sb.length() ); - sb.append( instruction.getArguments() ); - sb.append( '\n' ); - } - return sb.toString(); - } - - private int calculateInstructionPosition( int maxFunctionName, long maxOffset ) { - return (16 + maxFunctionName + Long.toString( maxOffset ).length()); - } - - private void initializeAddresses() { - if ( fInstructions.length > 0 ) { - fStartAddress = fInstructions[0].getAdress(); - fEndAddress = fInstructions[fInstructions.length - 1].getAdress(); - } - } - - public int getLineNumber( long address ) { - for( int i = 0; i < fInstructions.length; ++i ) { - if ( fInstructions[i].getAdress() == address ) { - return i + 1; - } - } - return 0; - } - - public long getAddress( int lineNumber ) throws IllegalArgumentException { - if ( lineNumber > 0 && lineNumber <= fInstructions.length ) - return fInstructions[--lineNumber].getAdress(); - throw new IllegalArgumentException(); - } - } - public static final IEditorInput EMPTY_EDITOR_INPUT = new DisassemblyEditorInput(); public static final IEditorInput PENDING_EDITOR_INPUT = @@ -182,9 +41,11 @@ public class DisassemblyEditorInput implements IEditorInput { }; /** - * Storage associated with this editor input + * Disassembly block associated with this editor input */ - private DisassemblyStorage fStorage; + private IDisassemblyBlock fBlock; + + private String fContents = ""; //$NON-NLS-1$ /** * Constructor for DisassemblyEditorInput. @@ -198,8 +59,9 @@ public class DisassemblyEditorInput implements IEditorInput { * @param disassembly * @param instructions */ - public DisassemblyEditorInput( IDisassembly disassembly, IAsmInstruction[] instructions ) { - fStorage = new DisassemblyStorage( disassembly, instructions ); + private DisassemblyEditorInput( IDisassemblyBlock block ) { + fBlock = block; + createContents(); } /* (non-Javadoc) @@ -245,29 +107,158 @@ public class DisassemblyEditorInput implements IEditorInput { } public boolean contains( ICStackFrame frame ) { - if ( fStorage != null ) { - return fStorage.containsFrame( frame ); + if ( fBlock != null ) { + return fBlock.contains( frame ); } return false; } public String getContents() { - return ( fStorage != null ) ? fStorage.getContents() : ""; //$NON-NLS-1$ + return fContents; + } + + public int getInstructionLine( long address ) { + if ( fBlock != null ) { + IAsmSourceLine[] lines = fBlock.getSourceLines(); + int result = 0; + for ( int i = 0; i < lines.length; ++i ) { + IAsmInstruction[] instructions = lines[i].getInstructions(); + ++result; + for ( int j = 0; j < instructions.length; ++j ) { + ++result; + if ( instructions[j].getAdress() == address ) { + return result; + } + } + } + } + return 0; + } + + public int getInstructionLine( ICLineBreakpoint breakpoint ) { + if ( fBlock != null ) { + IDisassembly dis = fBlock.getDisassembly(); + if ( dis != null ) { + IBreakpointTarget bt = (IBreakpointTarget)dis.getDebugTarget().getAdapter( IBreakpointTarget.class ); + if ( bt != null ) { + try { + long address = bt.getBreakpointAddress( breakpoint ); + if ( address != 0 ) + return getInstructionLine( address ); + } + catch( DebugException e ) { + } + } + } + } + return 0; } - public int getInstructionNumber( long address ) { - return ( fStorage != null ) ? fStorage.getLineNumber( address ) : 0; + public long getAddress( int lineNumber ) { + if ( fBlock != null ) { + IAsmSourceLine[] lines = fBlock.getSourceLines(); + int current = 0; + for ( int i = 0; i < lines.length; ++i ) { + IAsmInstruction[] instructions = lines[i].getInstructions(); + ++current; + if ( lineNumber == current ) + return instructions[0].getAdress(); + if ( lineNumber > current && lineNumber <= current + instructions.length ) + return instructions[lineNumber - current - 1].getAdress(); + current += instructions.length; + } + } + return 0; } - public long getAddress( int lineNumber ) throws IllegalArgumentException { - return ( fStorage != null ) ? fStorage.getAddress( lineNumber ) : 0; + public String getModuleFile() { + return ( fBlock != null ) ? fBlock.getModuleFile() : null; } - public IFile getModuleFile() { - return ( fStorage != null ) ? fStorage.getModuleFile() : null; + public static DisassemblyEditorInput create( ICStackFrame frame ) throws DebugException { + DisassemblyEditorInput input = null; + IDisassembly disassembly = ((ICDebugTarget)frame.getDebugTarget()).getDisassembly(); + if ( disassembly != null ) { + IDisassemblyBlock block = disassembly.getDisassemblyBlock( frame ); + input = new DisassemblyEditorInput( block ); + } + return input; } - public long getBreakpointAddress( ICLineBreakpoint breakpoint ) { - return ( fStorage != null ) ? fStorage.getBreakpointAddress( breakpoint ) : 0; + private void createContents() { + StringBuffer lines = new StringBuffer(); + int maxFunctionName = 0; + int maxOpcodeLength = 0; + long maxOffset = 0; + if ( fBlock != null ) { + IAsmSourceLine[] mi = fBlock.getSourceLines(); + for ( int j = 0; j < mi.length; ++j ) { + IAsmInstruction[] instructions = mi[j].getInstructions(); + for( int i = 0; i < instructions.length; ++i ) { + String functionName = instructions[i].getFunctionName(); + if ( functionName.length() > maxFunctionName ) { + maxFunctionName = functionName.length(); + } + String opcode = instructions[i].getOpcode(); + if ( opcode.length() > maxOpcodeLength ) + maxOpcodeLength = opcode.length(); + if ( instructions[i].getOffset() > maxOffset ) { + maxOffset = instructions[i].getOffset(); + } + } + } + int instrPos = calculateInstructionPosition( maxFunctionName, maxOffset ); + int argPosition = instrPos + maxOpcodeLength + 1; + for ( int j = 0; j < mi.length; ++j ) { + if ( fBlock.isMixedMode() ) + lines.append( getSourceLineString( mi[j] ) ); + IAsmInstruction[] instructions = mi[j].getInstructions(); + for( int i = 0; i < instructions.length; ++i ) { +// if ( fBlock.isMixedMode() ) +// lines.append( "\t" ); //$NON-NLS-1$ + lines.append( getInstructionString( instructions[i], instrPos, argPosition ) ); + } + } + } + fContents = lines.toString(); + } + + private String getInstructionString( IAsmInstruction instruction, int instrPosition, int argPosition ) { + int worstCaseSpace = Math.max( instrPosition, argPosition ); + char[] spaces = new char[worstCaseSpace]; + Arrays.fill( spaces, ' ' ); + StringBuffer sb = new StringBuffer(); + if ( instruction != null ) { + sb.append( CDebugUIUtils.toHexAddressString( instruction.getAdress() ) ); + sb.append( ' ' ); + String functionName = instruction.getFunctionName(); + if ( functionName != null && functionName.length() > 0 ) { + sb.append( '<' ); + sb.append( functionName ); + if ( instruction.getOffset() != 0 ) { + sb.append( '+' ); + sb.append( instruction.getOffset() ); + } + sb.append( ">:" ); //$NON-NLS-1$ + sb.append( spaces, 0, instrPosition - sb.length() ); + } + sb.append( instruction.getOpcode() ); + sb.append( spaces, 0, argPosition - sb.length() ); + sb.append( instruction.getArguments() ); + sb.append( '\n' ); + } + return sb.toString(); + } + + private int calculateInstructionPosition( int maxFunctionName, long maxOffset ) { + return (16 + maxFunctionName + Long.toString( maxOffset ).length()); + } + + private String getSourceLineString( IAsmSourceLine line ) { + String text = line.toString(); + if ( text == null ) { + text = DisassemblyMessages.getString( "DisassemblyEditorInput.source_line_is_not_available_1" ) + '\n'; //$NON-NLS-1$ + } + return text; } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyMessages.properties b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyMessages.properties index 4e86da8ee13..89bca8d99d3 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyMessages.properties +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyMessages.properties @@ -4,3 +4,4 @@ DisassemblyInstructionPointerAnnotation.Secondary_Pointer_1=Secondary Disassembl DisassemblyAnnotationHover.Multiple_markers_at_this_line_1=Multiple markers at this line HTMLTextPresenter.ellipsis= HTML2TextReader.dash=- +DisassemblyEditorInput.source_line_is_not_available_1=<source line is not available> 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 2ef8f094e77..ec4f8267f66 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 @@ -10,14 +10,11 @@ ***********************************************************************/ package org.eclipse.cdt.debug.internal.ui.views.disassembly; +import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import java.util.HashMap; -import org.eclipse.cdt.debug.core.model.IAsmInstruction; -import org.eclipse.cdt.debug.core.model.ICDebugTarget; import org.eclipse.cdt.debug.core.model.ICStackFrame; -import org.eclipse.cdt.debug.core.model.IDisassembly; import org.eclipse.cdt.debug.internal.ui.ICDebugHelpContextIds; import org.eclipse.cdt.debug.internal.ui.IInternalCDebugUIConstants; import org.eclipse.cdt.debug.internal.ui.actions.CBreakpointPropertiesRulerAction; @@ -529,13 +526,8 @@ public class DisassemblyView extends AbstractDebugEventHandlerView input = (IEditorInput)current; } else { - IAsmInstruction[] instructions = new IAsmInstruction[0]; try { - IDisassembly disassembly = ((ICDebugTarget)frame.getDebugTarget()).getDisassembly(); - if ( disassembly != null ) { - instructions = disassembly.getInstructions( frame ); - input = new DisassemblyEditorInput( disassembly, instructions ); - } + input = DisassemblyEditorInput.create( frame ); } catch( DebugException e ) { status = new Status( IStatus.ERROR, @@ -553,8 +545,7 @@ public class DisassemblyView extends AbstractDebugEventHandlerView } protected void selectAndReveal( ICStackFrame frame, IEditorInput input ) { - long address = frame.getAddress(); - IRegion region = getLineInformation( address, input ); + IRegion region = getLineInformation( frame, input ); if ( region != null ) { int start = region.getOffset(); int length = region.getLength(); @@ -572,9 +563,9 @@ public class DisassemblyView extends AbstractDebugEventHandlerView /** * Returns the line information for the given line in the given editor */ - private IRegion getLineInformation( long address, IEditorInput input ) { + private IRegion getLineInformation( ICStackFrame frame, IEditorInput input ) { if ( input instanceof DisassemblyEditorInput ) { - int line = ((DisassemblyEditorInput)input).getInstructionNumber( address ); + int line = ((DisassemblyEditorInput)input).getInstructionLine( frame.getAddress() ); if ( line > 0 ) { try { return getSourceViewer().getDocument().getLineInformation( --line ); @@ -703,8 +694,8 @@ public class DisassemblyView extends AbstractDebugEventHandlerView Assert.isNotNull( model ); DisassemblyInstructionPointerAnnotation instrPointer = getCurrentInstructionPointer(); if ( instrPointer != null ) { - model.removeAnnotation( instrPointer ); - setCurrentInstructionPointer( null ); + model.removeAnnotation( instrPointer ); + setCurrentInstructionPointer( null ); } } |