1 11 12 package org.eclipse.debug.internal.ui.views.memory.renderings; 13 14 import java.math.BigInteger ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.debug.core.DebugException; 18 import org.eclipse.debug.core.DebugPlugin; 19 import org.eclipse.debug.core.model.IDebugElement; 20 import org.eclipse.debug.core.model.IDebugTarget; 21 import org.eclipse.debug.core.model.IMemoryBlock; 22 import org.eclipse.debug.core.model.IMemoryBlockExtension; 23 import org.eclipse.debug.core.model.IMemoryBlockRetrievalExtension; 24 import org.eclipse.debug.internal.ui.DebugUIMessages; 25 import org.eclipse.debug.internal.ui.DebugUIPlugin; 26 import org.eclipse.debug.internal.ui.views.memory.MemoryViewUtil; 27 import org.eclipse.debug.ui.DebugUITools; 28 import org.eclipse.debug.ui.IDebugUIConstants; 29 import org.eclipse.debug.ui.memory.AbstractMemoryRendering; 30 import org.eclipse.debug.ui.memory.IMemoryRendering; 31 import org.eclipse.debug.ui.memory.IMemoryRenderingType; 32 import org.eclipse.debug.ui.memory.IRepositionableMemoryRendering; 33 import org.eclipse.jface.action.Action; 34 import org.eclipse.jface.window.Window; 35 import org.eclipse.swt.widgets.Shell; 36 import org.eclipse.ui.PlatformUI; 37 38 39 44 public class GoToAddressAction extends Action 45 { 46 private IRepositionableMemoryRendering fRendering; 47 48 public GoToAddressAction(IRepositionableMemoryRendering rendering) 49 { 50 super(DebugUIMessages.GoToAddressAction_title); 51 setToolTipText(DebugUIMessages.GoToAddressAction_title); 52 53 fRendering = rendering; 54 55 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugUIConstants.PLUGIN_ID + ".GoToAddressAction_context"); } 57 60 public void run() 61 { 62 try 63 { 64 Shell shell= DebugUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(); 65 66 GoToAddressDialog dialog = new GoToAddressDialog(shell); 68 dialog.open(); 69 70 int returnCode = dialog.getReturnCode(); 71 72 if (returnCode == Window.CANCEL) 73 { 74 return; 75 } 76 77 String expression = dialog.getExpression(); 79 80 expression = parseExpression(expression); 81 82 doGoToAddress(expression); 83 } 84 catch (DebugException e) 86 { 87 MemoryViewUtil.openError(DebugUIMessages.GoToAddressAction_Go_to_address_failed, 88 DebugUIMessages.GoToAddressAction_Go_to_address_failed, e); 89 } 90 catch (NumberFormatException e1) 91 { 92 MemoryViewUtil.openError(DebugUIMessages.GoToAddressAction_Go_to_address_failed, 93 DebugUIMessages.GoToAddressAction_Address_is_invalid, null); 94 } 95 } 96 100 public String parseExpression(String expression) { 101 expression = expression.toUpperCase(); 102 expression = expression.trim(); 103 104 if (expression.startsWith("0X")) { 106 expression = expression.substring(2); 107 } 108 return expression; 109 } 110 114 public void doGoToAddress(String expression) throws DebugException, NumberFormatException { 115 BigInteger address = new BigInteger (expression, 16); 117 118 IMemoryBlock mb = fRendering.getMemoryBlock(); 121 if (mb instanceof IMemoryBlockExtension) 122 { 123 IMemoryBlockExtension mbExt = (IMemoryBlockExtension)mb; 124 BigInteger mbStart = mbExt.getMemoryBlockStartAddress(); 125 BigInteger mbEnd = mbExt.getMemoryBlockEndAddress(); 126 127 if (mbStart != null) 128 { 129 if (address.compareTo(mbStart) < 0) 132 { 133 IMemoryBlockRetrievalExtension retrieval = (IMemoryBlockRetrievalExtension)mbExt.getAdapter(IMemoryBlockRetrievalExtension.class); 134 IDebugTarget dt = mbExt.getDebugTarget(); 135 136 if (retrieval == null && dt instanceof IMemoryBlockRetrievalExtension) 137 retrieval = (IMemoryBlockRetrievalExtension)dt; 138 139 if (retrieval != null) 142 { 143 addNewMemoryBlock(expression, retrieval); 144 return; 145 } 146 } 147 } 148 if (mbEnd != null) 149 { 150 if (address.compareTo(mbEnd) > 0) 153 { 154 IMemoryBlockRetrievalExtension retrieval = (IMemoryBlockRetrievalExtension)mbExt.getAdapter(IMemoryBlockRetrievalExtension.class); 155 IDebugTarget dt = mbExt.getDebugTarget(); 156 157 if (retrieval == null && dt instanceof IMemoryBlockRetrievalExtension) 158 retrieval = (IMemoryBlockRetrievalExtension)dt; 159 160 if (retrieval != null) 163 { 164 addNewMemoryBlock(expression, retrieval); 165 return; 166 } 167 } 168 } 169 } 170 171 fRendering.goToAddress(address); 173 } 174 175 private void addNewMemoryBlock(String expression, IMemoryBlockRetrievalExtension retrieval) 176 { 177 Object elem = DebugUITools.getDebugContext(); 178 179 if (!(elem instanceof IDebugElement)) 180 return; 181 182 try { 183 if (retrieval != null) 184 { 185 IMemoryBlockExtension mbext = retrieval.getExtendedMemoryBlock(expression, elem); 186 if (mbext != null) 187 { 188 IMemoryBlock[] memArray = new IMemoryBlock[]{mbext}; 189 DebugPlugin.getDefault().getMemoryBlockManager().addMemoryBlocks(memArray); 190 } 191 192 IMemoryRenderingType renderingType = DebugUITools.getMemoryRenderingManager().getRenderingType(fRendering.getRenderingId()); 193 194 if (renderingType != null) 195 { 196 IMemoryRendering rendering = renderingType.createRendering(); 197 198 if (rendering != null && fRendering instanceof AbstractMemoryRendering) 199 { 200 rendering.init(((AbstractMemoryRendering)fRendering).getMemoryRenderingContainer(), mbext); 201 ((AbstractMemoryRendering)fRendering).getMemoryRenderingContainer().addMemoryRendering(rendering); 202 } 203 } 204 } 205 } catch (DebugException e) { 206 MemoryViewUtil.openError(DebugUIMessages.GoToAddressAction_Go_to_address_failed, 207 DebugUIMessages.GoToAddressAction_Go_to_address_failed, e); 208 } catch (CoreException e) 209 { 210 MemoryViewUtil.openError(DebugUIMessages.GoToAddressAction_Go_to_address_failed, 211 DebugUIMessages.GoToAddressAction_Go_to_address_failed, e); 212 } 213 } 214 } 215 | Popular Tags |