mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-10 09:45:39 +02:00
Contributing new disassembly.
This commit is contained in:
parent
0a10b91cca
commit
501ebcad7f
7 changed files with 122 additions and 32 deletions
|
@ -105,9 +105,11 @@ public class DisassemblyRetrieval extends CDebugElement implements ICDIEventList
|
||||||
BigInteger address = null;
|
BigInteger address = null;
|
||||||
if ( startAddress != null ) {
|
if ( startAddress != null ) {
|
||||||
if ( getCurrentOffset() > offset ) {
|
if ( getCurrentOffset() > offset ) {
|
||||||
|
// scrolling up
|
||||||
address = startAddress.subtract( BigInteger.valueOf( getMinInstructionSize() * (getCurrentOffset() - offset) ) );
|
address = startAddress.subtract( BigInteger.valueOf( getMinInstructionSize() * (getCurrentOffset() - offset) ) );
|
||||||
}
|
}
|
||||||
else if ( getCurrentOffset() < offset ) {
|
else if ( getCurrentOffset() < offset ) {
|
||||||
|
// scrolling down
|
||||||
IDisassemblyInstruction next = getNextInstruction( startAddress, fLines );
|
IDisassemblyInstruction next = getNextInstruction( startAddress, fLines );
|
||||||
if ( next != null )
|
if ( next != null )
|
||||||
address = next.getAdress().getValue();
|
address = next.getAdress().getValue();
|
||||||
|
@ -157,10 +159,27 @@ 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;
|
||||||
|
IDisassemblyLine[] lines = new IDisassemblyLine[0];
|
||||||
|
while( lines.length < lineCount ) {
|
||||||
BigInteger endAddress = address.add( BigInteger.valueOf( lineCount * getMaxInstructionSize() ) );
|
BigInteger endAddress = address.add( BigInteger.valueOf( lineCount * getMaxInstructionSize() ) );
|
||||||
if ( endAddress.compareTo( getGlobalEndAddress() ) > 0 )
|
if ( endAddress.compareTo( getGlobalEndAddress() ) > 0 )
|
||||||
endAddress = getGlobalEndAddress();
|
endAddress = getGlobalEndAddress();
|
||||||
IDisassemblyLine[] lines = disassemble( address, endAddress, mixed );
|
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 ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
int size = Math.min( lineCount, lines.length );
|
int size = Math.min( lineCount, lines.length );
|
||||||
IDisassemblyLine[] result = new IDisassemblyLine[size];
|
IDisassemblyLine[] result = new IDisassemblyLine[size];
|
||||||
int start = getIndexForAddress( address, lines );
|
int start = getIndexForAddress( address, lines );
|
||||||
|
@ -189,13 +208,15 @@ public class DisassemblyRetrieval extends CDebugElement implements ICDIEventList
|
||||||
}
|
}
|
||||||
if ( mixedInstructions != null ) {
|
if ( mixedInstructions != null ) {
|
||||||
for ( ICDIMixedInstruction mi : mixedInstructions ) {
|
for ( ICDIMixedInstruction mi : mixedInstructions ) {
|
||||||
list.add( new DisassemblySourceLine( (CDebugTarget)getDebugTarget(), fBaseElement, mi ) );
|
|
||||||
ICDIInstruction[] instructions = mi.getInstructions();
|
ICDIInstruction[] instructions = mi.getInstructions();
|
||||||
|
if ( instructions.length > 0 ) {
|
||||||
|
list.add( new DisassemblySourceLine( (CDebugTarget)getDebugTarget(), fBaseElement, mi ) );
|
||||||
for ( ICDIInstruction i : instructions ) {
|
for ( ICDIInstruction i : instructions ) {
|
||||||
list.add( new DisassemblyInstruction( (CDebugTarget)getDebugTarget(), fBaseElement, i ) );
|
list.add( new DisassemblyInstruction( (CDebugTarget)getDebugTarget(), fBaseElement, i ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if ( asmInstructions != null ) {
|
else if ( asmInstructions != null ) {
|
||||||
for ( ICDIInstruction i : asmInstructions ) {
|
for ( ICDIInstruction i : asmInstructions ) {
|
||||||
list.add( new DisassemblyInstruction( (CDebugTarget)getDebugTarget(), fBaseElement, i ) );
|
list.add( new DisassemblyInstruction( (CDebugTarget)getDebugTarget(), fBaseElement, i ) );
|
||||||
|
@ -240,6 +261,22 @@ public class DisassemblyRetrieval extends CDebugElement implements ICDIEventList
|
||||||
return ( index > 0 ) ? (IDisassemblyInstruction)lines[index - 1] : null;
|
return ( index > 0 ) ? (IDisassemblyInstruction)lines[index - 1] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IDisassemblyInstruction getFirstInstruction( IDisassemblyLine[] lines ) {
|
||||||
|
for ( IDisassemblyLine l : lines ) {
|
||||||
|
if ( l instanceof IDisassemblyInstruction )
|
||||||
|
return (IDisassemblyInstruction)l;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IDisassemblyInstruction getLastInstruction( IDisassemblyLine[] lines ) {
|
||||||
|
for ( int i = lines.length - 1; i >= 0; --i ) {
|
||||||
|
if ( lines[i] instanceof IDisassemblyInstruction )
|
||||||
|
return (IDisassemblyInstruction)lines[i];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private BigInteger getGlobalStartAddress() {
|
private BigInteger getGlobalStartAddress() {
|
||||||
return getAddressFactory().getZero().getValue();
|
return getAddressFactory().getZero().getValue();
|
||||||
}
|
}
|
||||||
|
@ -251,4 +288,14 @@ public class DisassemblyRetrieval extends CDebugElement implements ICDIEventList
|
||||||
private IAddressFactory getAddressFactory() {
|
private IAddressFactory getAddressFactory() {
|
||||||
return ((CDebugTarget)getDebugTarget()).getAddressFactory();
|
return ((CDebugTarget)getDebugTarget()).getAddressFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IDisassemblyLine[] appendLines( IDisassemblyLine[] lines1, IDisassemblyLine[] lines2 ) {
|
||||||
|
List<IDisassemblyLine> list = new ArrayList<IDisassemblyLine>( lines1.length + lines2.length );
|
||||||
|
list.addAll( Arrays.asList( lines1 ) );
|
||||||
|
for ( IDisassemblyLine l : lines2 ) {
|
||||||
|
if ( !list.contains( l ) )
|
||||||
|
list.add( l );
|
||||||
|
}
|
||||||
|
return list.toArray( new IDisassemblyLine[list.size()] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,4 +65,19 @@ public class DisassemblySourceLine extends CDebugElement implements IDisassembly
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return fCDIMixedInstruction.getFileName() + ' ' + getLineNumber();
|
return fCDIMixedInstruction.getFileName() + ' ' + getLineNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#equals(java.lang.Object)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals( Object obj ) {
|
||||||
|
if ( !(obj instanceof IDisassemblySourceLine) )
|
||||||
|
return false;
|
||||||
|
IDisassemblySourceLine other = (IDisassemblySourceLine)obj;
|
||||||
|
if ( !getFile().equals( other.getFile() ) )
|
||||||
|
return false;
|
||||||
|
if ( getLineNumber() != other.getLineNumber() )
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,6 @@ public class CDebugUIPreferenceInitializer extends AbstractPreferenceInitializer
|
||||||
CDebugPreferencePage.initDefaults( pstore );
|
CDebugPreferencePage.initDefaults( pstore );
|
||||||
pstore.setDefault( ICDebugPreferenceConstants.PREF_OPEN_DISASSEMBLY_MODE, MessageDialogWithToggle.PROMPT );
|
pstore.setDefault( ICDebugPreferenceConstants.PREF_OPEN_DISASSEMBLY_MODE, MessageDialogWithToggle.PROMPT );
|
||||||
pstore.setDefault( ICDebugPreferenceConstants.PREF_DISASM_SHOW_INSTRUCTIONS, true );
|
pstore.setDefault( ICDebugPreferenceConstants.PREF_DISASM_SHOW_INSTRUCTIONS, true );
|
||||||
pstore.setDefault( ICDebugPreferenceConstants.PREF_DISASM_SHOW_SOURCE, false );
|
pstore.setDefault( ICDebugPreferenceConstants.PREF_DISASM_SHOW_SOURCE, true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,31 +17,26 @@ import org.eclipse.cdt.debug.internal.ui.IInternalCDebugUIConstants;
|
||||||
import org.eclipse.cdt.debug.internal.ui.disassembly.editor.DisassemblyEditorInput;
|
import org.eclipse.cdt.debug.internal.ui.disassembly.editor.DisassemblyEditorInput;
|
||||||
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.internal.ui.disassembly.viewer.DisassemblyDocumentProvider;
|
import org.eclipse.cdt.debug.internal.ui.disassembly.viewer.DisassemblyDocumentProvider;
|
||||||
import org.eclipse.cdt.debug.internal.ui.preferences.ICDebugPreferenceConstants;
|
|
||||||
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
|
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
|
||||||
|
import org.eclipse.cdt.debug.ui.disassembly.IDocumentPresentation;
|
||||||
import org.eclipse.core.commands.AbstractHandler;
|
import org.eclipse.core.commands.AbstractHandler;
|
||||||
import org.eclipse.core.commands.ExecutionEvent;
|
import org.eclipse.core.commands.ExecutionEvent;
|
||||||
import org.eclipse.core.commands.ExecutionException;
|
import org.eclipse.core.commands.ExecutionException;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
|
import org.eclipse.ui.IEditorInput;
|
||||||
|
import org.eclipse.ui.IWorkbenchPart;
|
||||||
|
import org.eclipse.ui.IWorkbenchPartSite;
|
||||||
import org.eclipse.ui.commands.IElementUpdater;
|
import org.eclipse.ui.commands.IElementUpdater;
|
||||||
import org.eclipse.ui.handlers.HandlerUtil;
|
import org.eclipse.ui.handlers.HandlerUtil;
|
||||||
import org.eclipse.ui.menus.UIElement;
|
import org.eclipse.ui.menus.UIElement;
|
||||||
import org.eclipse.ui.texteditor.IDocumentProvider;
|
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||||
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
|
||||||
public class DisassemblyDisplayModeHandler extends AbstractHandler implements IElementUpdater {
|
public class DisassemblyDisplayModeHandler extends AbstractHandler implements IElementUpdater {
|
||||||
|
|
||||||
private static final String ID_PARAMETER_MODE = "org.eclipse.cdt.debug.command.disassemblyDisplayMode.parameterMode"; //$NON-NLS-1$
|
private static final String ID_PARAMETER_MODE = "org.eclipse.cdt.debug.command.disassemblyDisplayMode.parameterMode"; //$NON-NLS-1$
|
||||||
|
|
||||||
private boolean fShowInstructions = false;
|
|
||||||
private boolean fShowSource = false;
|
|
||||||
|
|
||||||
public DisassemblyDisplayModeHandler() {
|
|
||||||
super();
|
|
||||||
fShowInstructions = CDebugUIPlugin.getDefault().getPreferenceStore().getBoolean( ICDebugPreferenceConstants.PREF_DISASM_SHOW_INSTRUCTIONS );
|
|
||||||
fShowSource = CDebugUIPlugin.getDefault().getPreferenceStore().getBoolean( ICDebugPreferenceConstants.PREF_DISASM_SHOW_SOURCE );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
||||||
*/
|
*/
|
||||||
|
@ -51,12 +46,10 @@ public class DisassemblyDisplayModeHandler extends AbstractHandler implements IE
|
||||||
if ( presentation != null ) {
|
if ( presentation != null ) {
|
||||||
String param = event.getParameter( ID_PARAMETER_MODE );
|
String param = event.getParameter( ID_PARAMETER_MODE );
|
||||||
if ( IInternalCDebugUIConstants.DISASM_DISPLAY_MODE_INSTRUCTIONS.equals( param ) ) {
|
if ( IInternalCDebugUIConstants.DISASM_DISPLAY_MODE_INSTRUCTIONS.equals( param ) ) {
|
||||||
fShowInstructions = !fShowInstructions;
|
presentation.setShowIntstructions( !presentation.showIntstructions() );
|
||||||
presentation.setShowIntstructions( fShowInstructions );
|
|
||||||
}
|
}
|
||||||
else if ( IInternalCDebugUIConstants.DISASM_DISPLAY_MODE_SOURCE.equals( param ) ) {
|
else if ( IInternalCDebugUIConstants.DISASM_DISPLAY_MODE_SOURCE.equals( param ) ) {
|
||||||
fShowSource = !fShowSource;
|
presentation.setShowSource( !presentation.showSource() );
|
||||||
presentation.setShowSource( fShowSource );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -67,12 +60,28 @@ public class DisassemblyDisplayModeHandler extends AbstractHandler implements IE
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void updateElement( UIElement element, Map parameters ) {
|
public void updateElement( UIElement element, Map parameters ) {
|
||||||
|
IWorkbenchPartSite site = (IWorkbenchPartSite)element.getServiceLocator().getService( IWorkbenchPartSite.class );
|
||||||
|
if ( site != null ) {
|
||||||
|
IWorkbenchPart part = site.getPart();
|
||||||
|
if ( part instanceof ITextEditor ) {
|
||||||
|
IEditorInput input = ((ITextEditor)part).getEditorInput();
|
||||||
|
if ( input instanceof DisassemblyEditorInput ) {
|
||||||
|
IDocumentProvider dp = ((ITextEditor)part).getDocumentProvider();
|
||||||
|
if ( dp instanceof DisassemblyDocumentProvider ) {
|
||||||
|
IDocumentPresentation p = ((DisassemblyDocumentProvider)dp).getDocumentPresentation( input );
|
||||||
|
if ( p instanceof DisassemblyEditorPresentation ) {
|
||||||
|
DisassemblyEditorPresentation presentation = (DisassemblyEditorPresentation)p;
|
||||||
String param = (String)parameters.get( ID_PARAMETER_MODE );
|
String param = (String)parameters.get( ID_PARAMETER_MODE );
|
||||||
if ( IInternalCDebugUIConstants.DISASM_DISPLAY_MODE_INSTRUCTIONS.equals( param ) ) {
|
if ( IInternalCDebugUIConstants.DISASM_DISPLAY_MODE_INSTRUCTIONS.equals( param ) ) {
|
||||||
element.setChecked( fShowInstructions );
|
element.setChecked( presentation.showIntstructions() );
|
||||||
}
|
}
|
||||||
else if ( IInternalCDebugUIConstants.DISASM_DISPLAY_MODE_SOURCE.equals( param ) ) {
|
else if ( IInternalCDebugUIConstants.DISASM_DISPLAY_MODE_SOURCE.equals( param ) ) {
|
||||||
element.setChecked( fShowSource );
|
element.setChecked( presentation.showSource() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,6 @@ public class DisassemblyEditorPresentation extends PresentationContext implement
|
||||||
public static final String PROPERTY_SHOW_ADDRESSES = "PROPERTY_SHOW_ADDRESSES"; //$NON-NLS-1$
|
public static final String PROPERTY_SHOW_ADDRESSES = "PROPERTY_SHOW_ADDRESSES"; //$NON-NLS-1$
|
||||||
public static final String PROPERTY_SHOW_LINE_NUMBERS = "PROPERTY_SHOW_LINE_NUMBERS"; //$NON-NLS-1$
|
public static final String PROPERTY_SHOW_LINE_NUMBERS = "PROPERTY_SHOW_LINE_NUMBERS"; //$NON-NLS-1$
|
||||||
|
|
||||||
private boolean fShowInstructions = true;
|
|
||||||
private boolean fShowSource = false;
|
|
||||||
|
|
||||||
private boolean fShowAddresses = true;
|
private boolean fShowAddresses = true;
|
||||||
private boolean fShowLineNumbers = true;
|
private boolean fShowLineNumbers = true;
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class DisassemblyElementLabelProvider implements IDocumentElementLabelPro
|
||||||
sb.append( line.getLineNumber() );
|
sb.append( line.getLineNumber() );
|
||||||
sb.append( '\t' );
|
sb.append( '\t' );
|
||||||
}
|
}
|
||||||
sb.append( line.getFile().getAbsolutePath() );
|
sb.append( line.getFile().getPath() );
|
||||||
update.setLabel( DisassemblyEditorPresentation.ATTR_LINE_LABEL, sb.toString() );
|
update.setLabel( DisassemblyEditorPresentation.ATTR_LINE_LABEL, sb.toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,15 @@
|
||||||
package org.eclipse.cdt.debug.internal.ui.preferences;
|
package org.eclipse.cdt.debug.internal.ui.preferences;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
|
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
|
||||||
|
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
|
||||||
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
|
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
|
||||||
|
import org.eclipse.jface.preference.BooleanFieldEditor;
|
||||||
|
import org.eclipse.jface.preference.FieldEditor;
|
||||||
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
||||||
import org.eclipse.jface.preference.IPreferenceStore;
|
import org.eclipse.jface.preference.IPreferenceStore;
|
||||||
import org.eclipse.jface.preference.RadioGroupFieldEditor;
|
import org.eclipse.jface.preference.RadioGroupFieldEditor;
|
||||||
|
import org.eclipse.swt.widgets.Composite;
|
||||||
|
import org.eclipse.swt.widgets.Group;
|
||||||
import org.eclipse.ui.IWorkbench;
|
import org.eclipse.ui.IWorkbench;
|
||||||
import org.eclipse.ui.IWorkbenchPreferencePage;
|
import org.eclipse.ui.IWorkbenchPreferencePage;
|
||||||
|
|
||||||
|
@ -45,6 +50,23 @@ public class DisassemblyPreferencePage extends FieldEditorPreferencePage impleme
|
||||||
},
|
},
|
||||||
getFieldEditorParent(),
|
getFieldEditorParent(),
|
||||||
true ) );
|
true ) );
|
||||||
|
|
||||||
|
Group group = ControlFactory.createGroup( getFieldEditorParent(), "Display settings", 1 );
|
||||||
|
Composite spacer = ControlFactory.createComposite( group, 1 );
|
||||||
|
|
||||||
|
FieldEditor edit = new BooleanFieldEditor(
|
||||||
|
ICDebugPreferenceConstants.PREF_DISASM_SHOW_INSTRUCTIONS,
|
||||||
|
"Show instructions",
|
||||||
|
spacer );
|
||||||
|
edit.fillIntoGrid( spacer, 2 );
|
||||||
|
addField( edit );
|
||||||
|
|
||||||
|
edit = new BooleanFieldEditor(
|
||||||
|
ICDebugPreferenceConstants.PREF_DISASM_SHOW_SOURCE,
|
||||||
|
"Show source",
|
||||||
|
spacer );
|
||||||
|
edit.fillIntoGrid( spacer, 2 );
|
||||||
|
addField( edit );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
Loading…
Add table
Reference in a new issue