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

Contributing new disassembly.

This commit is contained in:
Mikhail Khodjaiants 2008-04-22 16:49:52 +00:00
parent 996ff223bf
commit 19c364f589
3 changed files with 105 additions and 39 deletions

View file

@ -128,11 +128,13 @@ public class DisassemblyRetrieval extends CDebugElement implements ICDIEventList
else { else {
fCurrentOffset += getDistance( fBaseElement, address ); fCurrentOffset += getDistance( fBaseElement, address );
} }
fFlags = flags;
fBaseElement = address; fBaseElement = address;
} }
} }
public void retrieveDisassembly( Object input, Object base, int offset, int lineCount, boolean reveal, int flags ) throws DebugException { public void retrieveDisassembly( Object input, Object base, int offset, int lineCount, boolean reveal, int flags ) throws DebugException {
fFlags = flags;
boolean showInstructions = ( (flags & FLAGS_SHOW_INSTRUCTIONS) != 0 ); boolean showInstructions = ( (flags & FLAGS_SHOW_INSTRUCTIONS) != 0 );
boolean showSource = ( (flags & FLAGS_SHOW_SOURCE) != 0 ); boolean showSource = ( (flags & FLAGS_SHOW_SOURCE) != 0 );
List<IDisassemblyLine> lines = new ArrayList<IDisassemblyLine>( lineCount ); List<IDisassemblyLine> lines = new ArrayList<IDisassemblyLine>( lineCount );
@ -195,24 +197,28 @@ public class DisassemblyRetrieval extends CDebugElement implements ICDIEventList
private IDisassemblyLine[] disassembleDown( BigInteger address, int lineCount, boolean mixed ) throws DebugException { private IDisassemblyLine[] disassembleDown( BigInteger address, int lineCount, boolean mixed ) throws DebugException {
BigInteger startAddress = address; BigInteger startAddress = address;
IDisassemblyLine[] lines = new IDisassemblyLine[0]; IDisassemblyLine[] lines = new IDisassemblyLine[0];
while( lines.length < lineCount ) { BigInteger endAddress = startAddress;
BigInteger endAddress = address.add( BigInteger.valueOf( lineCount * getMaxInstructionSize() ) ); if ( lines.length < lineCount && endAddress.compareTo( getGlobalEndAddress() ) < 0 ) {
endAddress = address.add( BigInteger.valueOf( lineCount * getMaxInstructionSize() ) );
if ( endAddress.compareTo( getGlobalEndAddress() ) > 0 ) if ( endAddress.compareTo( getGlobalEndAddress() ) > 0 )
endAddress = getGlobalEndAddress(); endAddress = getGlobalEndAddress();
lines = disassemble( address, endAddress, mixed ); lines = disassemble( address, endAddress, mixed );
IDisassemblyInstruction firstInstruction = getFirstInstruction( lines ); IDisassemblyInstruction firstInstruction = getFirstInstruction( lines );
if ( firstInstruction == null )
break;
IDisassemblyInstruction lastInstruction = getLastInstruction( lines ); IDisassemblyInstruction lastInstruction = getLastInstruction( lines );
if ( lastInstruction == null ) if ( firstInstruction != null && lastInstruction != null ) {
break; if ( startAddress.compareTo( firstInstruction.getAdress().getValue() ) < 0 ) {
if ( startAddress.compareTo( firstInstruction.getAdress().getValue() ) < 0 ) { lines = appendLines( disassemble( startAddress, firstInstruction.getAdress().getValue(), mixed ), lines );
lines = appendLines( disassemble( startAddress, firstInstruction.getAdress().getValue(), mixed ), lines ); }
} startAddress = lastInstruction.getAdress().getValue();
startAddress = lastInstruction.getAdress().getValue(); if ( startAddress.compareTo( endAddress ) < 0 ) {
if ( startAddress.compareTo( endAddress ) < 0 ) { IDisassemblyLine[] extraLines = new IDisassemblyLine[0];
lines = appendLines( lines, disassemble( startAddress, endAddress, mixed ) ); while( extraLines.length == 0 && endAddress.compareTo( getGlobalEndAddress() ) < 0 ) {
endAddress = endAddress.add( BigInteger.valueOf( getMaxInstructionSize() ) );
extraLines = disassemble( startAddress, endAddress, mixed );
}
lines = appendLines( lines, extraLines );
}
} }
} }
int size = Math.min( lineCount, lines.length ); int size = Math.min( lineCount, lines.length );

View file

@ -150,31 +150,33 @@ public class DocumentContentProvider implements IModelChangedListener {
Object newBase = update.getBaseElement(); Object newBase = update.getBaseElement();
int newOffset = update.getOffset(); int newOffset = update.getOffset();
VirtualDocument document = getDocument(); VirtualDocument document = getDocument();
boolean needsUpdate = false; if ( document != null ) {
if ( newBase != getBase() ) { boolean needsUpdate = false;
fBase = newBase; if ( newBase != getBase() ) {
disposeBaseProxy(); fBase = newBase;
installBaseProxy( fBase ); disposeBaseProxy();
needsUpdate = true; installBaseProxy( fBase );
} needsUpdate = true;
if ( newOffset != document.getCurrentOffset() ) { }
document.setCurrentOffset( newOffset ); if ( newOffset != document.getCurrentOffset() ) {
needsUpdate = true; document.setCurrentOffset( newOffset );
} needsUpdate = true;
if ( needsUpdate ) { }
WorkbenchJob job = new WorkbenchJob( "refresh content" ) { //$NON-NLS-1$ if ( needsUpdate ) {
WorkbenchJob job = new WorkbenchJob( "refresh content" ) { //$NON-NLS-1$
/* (non-Javadoc)
* @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) /* (non-Javadoc)
*/ * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
@Override */
public IStatus runInUIThread( IProgressMonitor monitor ) { @Override
getViewer().refresh( true ); public IStatus runInUIThread( IProgressMonitor monitor ) {
return Status.OK_STATUS; getViewer().refresh( true );
} return Status.OK_STATUS;
}; }
job.setSystem( true ); };
job.schedule(); job.setSystem( true );
job.schedule();
}
} }
} }

View file

@ -11,7 +11,12 @@
package org.eclipse.cdt.debug.internal.ui.elements.adapters; package org.eclipse.cdt.debug.internal.ui.elements.adapters;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.text.MessageFormat;
import org.eclipse.cdt.debug.core.CDebugUtils; import org.eclipse.cdt.debug.core.CDebugUtils;
import org.eclipse.cdt.debug.core.model.IDisassemblyInstruction; import org.eclipse.cdt.debug.core.model.IDisassemblyInstruction;
@ -19,10 +24,14 @@ import org.eclipse.cdt.debug.core.model.IDisassemblySourceLine;
import org.eclipse.cdt.debug.internal.ui.disassembly.editor.DisassemblyEditorPresentation; import org.eclipse.cdt.debug.internal.ui.disassembly.editor.DisassemblyEditorPresentation;
import org.eclipse.cdt.debug.ui.disassembly.IDocumentElementLabelProvider; import org.eclipse.cdt.debug.ui.disassembly.IDocumentElementLabelProvider;
import org.eclipse.cdt.debug.ui.disassembly.IDocumentElementLabelUpdate; import org.eclipse.cdt.debug.ui.disassembly.IDocumentElementLabelUpdate;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.model.ISourceLocator;
import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
/** /**
@ -80,9 +89,58 @@ public class DisassemblyElementLabelProvider implements IDocumentElementLabelPro
sb.append( line.getLineNumber() ); sb.append( line.getLineNumber() );
sb.append( '\t' ); sb.append( '\t' );
} }
sb.append( line.getFile().getPath() ); sb.append( getSourceLineText( line ) );
update.setLabel( DisassemblyEditorPresentation.ATTR_LINE_LABEL, sb.toString() ); update.setLabel( DisassemblyEditorPresentation.ATTR_LINE_LABEL, sb.toString() );
} }
} }
} }
private String getSourceLineText( IDisassemblySourceLine line ) {
File file = line.getFile();
String text = MessageFormat.format( "File {0} not found.", file.getPath() );
ISourceLocator locator = line.getDebugTarget().getLaunch().getSourceLocator();
if ( locator instanceof ISourceLookupDirector ) {
ISourceLookupDirector director = (ISourceLookupDirector)locator;
Object sourceElement = director.getSourceElement( file.getPath() );
if ( sourceElement != null ) {
File lookupFile = null;
if ( sourceElement instanceof IFile ) {
lookupFile = ((IFile)sourceElement).getLocation().toFile();
}
else if ( sourceElement instanceof IStorage ) {
lookupFile = ((IStorage)sourceElement).getFullPath().toFile();
}
if ( lookupFile != null ) {
try {
text = readLine( lookupFile, line.getLineNumber() - 1 );
}
catch( IOException e ) {
text = e.getLocalizedMessage();
}
}
}
}
return text;
}
private String readLine( File file, int lineNumber ) throws IOException {
FileReader fr = new FileReader( file );
BufferedReader br = new BufferedReader( fr );
try {
int count = 0;
String result = null;
do {
result = br.readLine();
if ( count++ == lineNumber )
return result;
}
while( result != null );
}
finally {
br.close();
}
throw new IOException( MessageFormat.format( "Line {0} doesn't exist in {1}.", Integer.valueOf( lineNumber ), file.getPath() ) );
}
} }