mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Contributing new disassembly.
This commit is contained in:
parent
996ff223bf
commit
19c364f589
3 changed files with 105 additions and 39 deletions
|
@ -128,11 +128,13 @@ public class DisassemblyRetrieval extends CDebugElement implements ICDIEventList
|
|||
else {
|
||||
fCurrentOffset += getDistance( fBaseElement, address );
|
||||
}
|
||||
fFlags = flags;
|
||||
fBaseElement = address;
|
||||
}
|
||||
}
|
||||
|
||||
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 showSource = ( (flags & FLAGS_SHOW_SOURCE) != 0 );
|
||||
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 {
|
||||
BigInteger startAddress = address;
|
||||
IDisassemblyLine[] lines = new IDisassemblyLine[0];
|
||||
while( lines.length < lineCount ) {
|
||||
BigInteger endAddress = address.add( BigInteger.valueOf( lineCount * getMaxInstructionSize() ) );
|
||||
IDisassemblyLine[] lines = new IDisassemblyLine[0];
|
||||
BigInteger endAddress = startAddress;
|
||||
if ( lines.length < lineCount && endAddress.compareTo( getGlobalEndAddress() ) < 0 ) {
|
||||
endAddress = address.add( BigInteger.valueOf( lineCount * getMaxInstructionSize() ) );
|
||||
if ( endAddress.compareTo( getGlobalEndAddress() ) > 0 )
|
||||
endAddress = getGlobalEndAddress();
|
||||
lines = disassemble( address, endAddress, mixed );
|
||||
IDisassemblyInstruction firstInstruction = getFirstInstruction( lines );
|
||||
if ( firstInstruction == null )
|
||||
break;
|
||||
IDisassemblyInstruction lastInstruction = getLastInstruction( lines );
|
||||
if ( lastInstruction == null )
|
||||
break;
|
||||
if ( startAddress.compareTo( firstInstruction.getAdress().getValue() ) < 0 ) {
|
||||
lines = appendLines( disassemble( startAddress, firstInstruction.getAdress().getValue(), mixed ), lines );
|
||||
}
|
||||
startAddress = lastInstruction.getAdress().getValue();
|
||||
if ( startAddress.compareTo( endAddress ) < 0 ) {
|
||||
lines = appendLines( lines, disassemble( startAddress, endAddress, mixed ) );
|
||||
if ( firstInstruction != null && lastInstruction != null ) {
|
||||
if ( startAddress.compareTo( firstInstruction.getAdress().getValue() ) < 0 ) {
|
||||
lines = appendLines( disassemble( startAddress, firstInstruction.getAdress().getValue(), mixed ), lines );
|
||||
}
|
||||
startAddress = lastInstruction.getAdress().getValue();
|
||||
if ( startAddress.compareTo( endAddress ) < 0 ) {
|
||||
IDisassemblyLine[] extraLines = new IDisassemblyLine[0];
|
||||
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 );
|
||||
|
|
|
@ -150,31 +150,33 @@ public class DocumentContentProvider implements IModelChangedListener {
|
|||
Object newBase = update.getBaseElement();
|
||||
int newOffset = update.getOffset();
|
||||
VirtualDocument document = getDocument();
|
||||
boolean needsUpdate = false;
|
||||
if ( newBase != getBase() ) {
|
||||
fBase = newBase;
|
||||
disposeBaseProxy();
|
||||
installBaseProxy( fBase );
|
||||
needsUpdate = true;
|
||||
}
|
||||
if ( newOffset != document.getCurrentOffset() ) {
|
||||
document.setCurrentOffset( newOffset );
|
||||
needsUpdate = true;
|
||||
}
|
||||
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)
|
||||
*/
|
||||
@Override
|
||||
public IStatus runInUIThread( IProgressMonitor monitor ) {
|
||||
getViewer().refresh( true );
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
};
|
||||
job.setSystem( true );
|
||||
job.schedule();
|
||||
if ( document != null ) {
|
||||
boolean needsUpdate = false;
|
||||
if ( newBase != getBase() ) {
|
||||
fBase = newBase;
|
||||
disposeBaseProxy();
|
||||
installBaseProxy( fBase );
|
||||
needsUpdate = true;
|
||||
}
|
||||
if ( newOffset != document.getCurrentOffset() ) {
|
||||
document.setCurrentOffset( newOffset );
|
||||
needsUpdate = true;
|
||||
}
|
||||
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)
|
||||
*/
|
||||
@Override
|
||||
public IStatus runInUIThread( IProgressMonitor monitor ) {
|
||||
getViewer().refresh( true );
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
};
|
||||
job.setSystem( true );
|
||||
job.schedule();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,12 @@
|
|||
|
||||
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.text.MessageFormat;
|
||||
|
||||
import org.eclipse.cdt.debug.core.CDebugUtils;
|
||||
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.ui.disassembly.IDocumentElementLabelProvider;
|
||||
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.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -80,9 +89,58 @@ public class DisassemblyElementLabelProvider implements IDocumentElementLabelPro
|
|||
sb.append( line.getLineNumber() );
|
||||
sb.append( '\t' );
|
||||
}
|
||||
sb.append( line.getFile().getPath() );
|
||||
sb.append( getSourceLineText( line ) );
|
||||
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() ) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue