diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IDisassembly.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IDisassembly.java index 95c9b60ae10..46c83be5ce7 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IDisassembly.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IDisassembly.java @@ -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. * diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.properties b/debug/org.eclipse.cdt.debug.ui/plugin.properties index b8c407ca6b4..9bf8f79d7d7 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.properties +++ b/debug/org.eclipse.cdt.debug.ui/plugin.properties @@ -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 diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index f7e3a7eb235..9b1ed8c3bb2 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -1088,6 +1088,23 @@ tooltip="%AddEventBreakpoint.tooltip"> + + + + + + diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/GoToAddressActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/GoToAddressActionDelegate.java new file mode 100644 index 00000000000..daed395e825 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/GoToAddressActionDelegate.java @@ -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; + } + + +} +