1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 06:32:10 +02:00

[111711] - added go to address action to cdi dissasembly view

This commit is contained in:
Alena Laskavaia 2009-03-12 20:33:01 +00:00
parent 666c642f44
commit f38d981cc8
4 changed files with 155 additions and 0 deletions

View file

@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.debug.core.model;
import org.eclipse.cdt.core.IAddress;
import org.eclipse.cdt.core.IAddressFactory;
import org.eclipse.debug.core.DebugException;
@ -27,6 +28,16 @@ public interface IDisassembly extends ICDebugElement {
*/
IDisassemblyBlock getDisassemblyBlock( ICStackFrame frame ) throws DebugException;
/**
* Returns the disassembly block for given stack frame.
*
* @param address the address from which the disassembly starts
* @return the disassembly block for given memory address
* @throws DebugException if this method fails.
* @since 6.0
*/
IDisassemblyBlock getDisassemblyBlock( IAddress address ) throws DebugException;
/**
* Returns the address factory associated with this element.
*

View file

@ -29,6 +29,9 @@ DebugActionSet.label=C/C++ Debug
RestartAction.label=Restart
RestartAction.tooltip=Restart
DisassemblyViewAction.label=Go to address...
DisassemblyViewAction.tooltip=Enter memory address for the assembly code
ToggleInstructionStepModeAction.label=Instruction Stepping Mode
ToggleInstructionStepModeAction.tooltip=Instruction Stepping Mode

View file

@ -1088,6 +1088,23 @@
tooltip="%AddEventBreakpoint.tooltip">
</action>
</viewContribution>
<viewContribution
id="org.eclipse.cdt.debug.ui.disassemblyView.menu"
targetID="org.eclipse.cdt.debug.ui.DisassemblyView">
<menu
id="org.eclipse.cdt.debug.ui.disassemblyViewMenu"
label="disassemblyViewMenu">
</menu>
<action
class="org.eclipse.cdt.debug.internal.ui.views.disassembly.GoToAddressActionDelegate"
icon="icons/elcl16/show_ascii.gif"
id="org.eclipse.cdt.debug.internal.ui.actions.disassemblyViewAction"
label="%DisassemblyViewAction.label"
menubarPath="org.eclipse.cdt.debug.ui.disassemblyViewMenu"
style="push"
tooltip="%DisassemblyViewAction.tooltip">
</action>
</viewContribution>
<viewContribution
targetID="org.eclipse.debug.ui.VariableView"
id="org.eclipse.debug.ui.variablesView.toolbar">

View file

@ -0,0 +1,124 @@
package org.eclipse.cdt.debug.internal.ui.views.disassembly;
import org.eclipse.cdt.core.IAddress;
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.core.model.IDisassemblyBlock;
import org.eclipse.cdt.debug.internal.core.model.Disassembly;
import org.eclipse.cdt.debug.internal.ui.views.disassembly.DisassemblyEditorInput;
import org.eclipse.cdt.debug.internal.ui.views.disassembly.DisassemblyView;
import org.eclipse.cdt.utils.Addr32;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
public class GoToAddressActionDelegate implements IActionDelegate, IViewActionDelegate {
private IViewPart fView;
private IAction fAction;
private DisassemblyView fDisassemblyView;
public void init(IViewPart view) {
setView(view);
if (view instanceof DisassemblyView) {
fDisassemblyView = (DisassemblyView) view;
}
}
private void setView(IViewPart view) {
fView = view;
}
protected IViewPart getView() {
return fView;
}
public void run(IAction action) {
String address;
InputDialog dialog = new InputDialog(fView.getViewSite().getShell(), "Enter address", "Enter address to go to", "",
new IInputValidator() {
public String isValid(String in) {
try {
String input = in.trim();
if (input.length() == 0)
return "Cannot be empty address";
if (input.toLowerCase().startsWith("0x")) {
Long.parseLong(input.substring(2), 16);
} else {
Long.parseLong(input);
}
return null;
} catch (NumberFormatException ex) {
return "Must be a hexadecimal or decimal address";
}
}
});
if (dialog.open() == Window.OK) {
address = dialog.getValue();
gotoAddress(address);
}
}
protected void setAction(IAction action) {
fAction = action;
}
protected IAction getAction() {
return fAction;
}
public void selectionChanged(IAction action, ISelection selection) {
setAction(action);
}
private void gotoAddress(String addr) {
IAddress address = new Addr32(addr);
if (fDisassemblyView != null) {
ICDebugTarget target = null;
ISelection selection = fDisassemblyView.getSite().getPage().getSelection(IDebugUIConstants.ID_DEBUG_VIEW);
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof ICStackFrame) {
IDebugTarget tar = ((ICStackFrame) element).getDebugTarget();
if (tar instanceof ICDebugTarget) {
target = (ICDebugTarget) tar;
}
}
}
DisassemblyEditorInput input = null;
try {
input = create(target, address);
fDisassemblyView.setViewerInput(input);
} catch (DebugException e) {
MessageDialog dialog = new MessageDialog(fView.getViewSite().getShell(), "Wrong address", null,
"Cannot access memory at address " + addr, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL },
0);
dialog.open();
}
}
}
public static DisassemblyEditorInput create(ICDebugTarget target, IAddress address) throws DebugException {
DisassemblyEditorInput input = null;
IDisassembly disassembly = target.getDisassembly();
if (disassembly instanceof Disassembly) {
IDisassemblyBlock block = ((Disassembly) disassembly).getDisassemblyBlock(address);
input = DisassemblyEditorInput.create(block);
}
return input;
}
}