Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKen Ryall2007-11-05 10:42:32 -0500
committerKen Ryall2007-11-05 10:42:32 -0500
commitf4a85817e6885961deba3a7ac65a0236d45a1bb4 (patch)
treed18ff0eaa56a634f82556fd13bd23cf0cb27b9f5
parent66cbf5bea76ae03baf9d4b487dfa3473b980cfb2 (diff)
downloadorg.eclipse.cdt-f4a85817e6885961deba3a7ac65a0236d45a1bb4.tar.gz
org.eclipse.cdt-f4a85817e6885961deba3a7ac65a0236d45a1bb4.tar.xz
org.eclipse.cdt-f4a85817e6885961deba3a7ac65a0236d45a1bb4.zip
Bug 207231, view memory on variables.
-rw-r--r--debug/org.eclipse.cdt.debug.ui/plugin.xml13
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ViewMemoryActionDelegate.java190
2 files changed, 203 insertions, 0 deletions
diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml
index 74e7b2148e2..1ebe6501976 100644
--- a/debug/org.eclipse.cdt.debug.ui/plugin.xml
+++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml
@@ -357,6 +357,19 @@
id="org.eclipse.cdt.debug.ui.actions.popup.RunToLine">
</action>
</viewerContribution>
+
+ <objectContribution
+ objectClass="org.eclipse.cdt.debug.core.model.ICVariable"
+ id="org.eclipse.cdt.debug.ui.CVariableActions">
+ <action
+ label="View Memory"
+ helpContextId="view_memory_context"
+ class="org.eclipse.cdt.debug.internal.ui.actions.ViewMemoryActionDelegate"
+ menubarPath="variableGroup"
+ enablesFor="+"
+ id="org.eclipse.cdt.debug.ui.actions.ViewMemoryAction">
+ </action>
+ </objectContribution>
<objectContribution
objectClass="org.eclipse.cdt.debug.core.model.ICVariable"
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ViewMemoryActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ViewMemoryActionDelegate.java
new file mode 100644
index 00000000000..80e08148ff8
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ViewMemoryActionDelegate.java
@@ -0,0 +1,190 @@
+package org.eclipse.cdt.debug.internal.ui.actions;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.cdt.debug.core.model.ICVariable;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.model.IDebugElement;
+import org.eclipse.debug.core.model.IMemoryBlock;
+import org.eclipse.debug.core.model.IMemoryBlockExtension;
+import org.eclipse.debug.core.model.IMemoryBlockRetrieval;
+import org.eclipse.debug.core.model.IMemoryBlockRetrievalExtension;
+import org.eclipse.debug.internal.ui.DebugUIMessages;
+import org.eclipse.debug.internal.ui.DebugUIPlugin;
+import org.eclipse.debug.internal.ui.views.memory.MemoryViewUtil;
+import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.debug.ui.IDebugUIConstants;
+import org.eclipse.debug.ui.memory.IMemoryRendering;
+import org.eclipse.debug.ui.memory.IMemoryRenderingContainer;
+import org.eclipse.debug.ui.memory.IMemoryRenderingSite;
+import org.eclipse.debug.ui.memory.IMemoryRenderingType;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+
+public class ViewMemoryActionDelegate implements IObjectActionDelegate {
+
+ private ICVariable[] variables;
+
+ public ViewMemoryActionDelegate() {
+ // TODO Auto-generated constructor stub
+ }
+
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ // TODO Auto-generated method stub
+
+ }
+
+ private IMemoryBlockRetrieval getMemoryBlockRetrieval(Object object)
+ {
+ IMemoryBlockRetrieval retrieval = null;
+
+ if (object instanceof IAdaptable)
+ {
+ IAdaptable adaptable = (IAdaptable)object;
+ retrieval = (IMemoryBlockRetrieval)adaptable.getAdapter(IMemoryBlockRetrieval.class);
+ }
+
+ if (retrieval == null && object instanceof IDebugElement)
+ {
+ IDebugElement de = (IDebugElement)object;
+ retrieval = de.getDebugTarget();
+ }
+
+ return retrieval;
+ }
+
+ /**
+ * @param memoryBlock
+ * @param primaryType
+ * @throws CoreException
+ */
+ private void createRenderingInContainer(IMemoryBlock memoryBlock, IMemoryRenderingType primaryType, String paneId) throws CoreException {
+
+ IWorkbenchPage page = DebugUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IViewPart newView = page.showView(IDebugUIConstants.ID_MEMORY_VIEW, null, IWorkbenchPage.VIEW_ACTIVATE);
+
+ IMemoryRenderingSite memSite = (IMemoryRenderingSite) newView.getSite();
+
+ IMemoryRendering rendering = primaryType.createRendering();
+ IMemoryRenderingContainer container = memSite.getContainer(paneId);
+ rendering.init(container, memoryBlock);
+ container.addMemoryRendering(rendering);
+ }
+
+ private void addDefaultRenderings(IMemoryBlock memoryBlock)
+ {
+ IMemoryRenderingType primaryType = DebugUITools.getMemoryRenderingManager().getPrimaryRenderingType(memoryBlock);
+ IMemoryRenderingType renderingTypes[] = DebugUITools.getMemoryRenderingManager().getDefaultRenderingTypes(memoryBlock);
+
+ // create primary rendering
+ try {
+ if (primaryType != null)
+ {
+ createRenderingInContainer(memoryBlock, primaryType, IDebugUIConstants.ID_RENDERING_VIEW_PANE_1);
+ }
+ else if (renderingTypes.length > 0)
+ {
+ primaryType = renderingTypes[0];
+ createRenderingInContainer(memoryBlock, renderingTypes[0], IDebugUIConstants.ID_RENDERING_VIEW_PANE_1);
+ }
+ } catch (CoreException e1) {
+ DebugUIPlugin.log(e1);
+ }
+
+ for (int i = 0; i<renderingTypes.length; i++)
+ {
+ try {
+ boolean create = true;
+ if (primaryType != null)
+ {
+ if (primaryType.getId().equals(renderingTypes[i].getId()))
+ create = false;
+ }
+ if (create)
+ createRenderingInContainer(memoryBlock, renderingTypes[i], IDebugUIConstants.ID_RENDERING_VIEW_PANE_2);
+ } catch (CoreException e) {
+ DebugUIPlugin.log(e);
+ }
+ }
+ }
+
+ private void addMemoryBlock() throws DebugException
+ { // if the debug session supports IMemoryBlockExtensionRetrieval
+
+ Object elem = DebugUITools.getDebugContext();
+
+ IMemoryBlockRetrieval retrieval = getMemoryBlockRetrieval(elem);
+
+ if (retrieval == null)
+ return;
+
+ IMemoryBlockRetrievalExtension memRetrieval = (IMemoryBlockRetrievalExtension)retrieval;
+
+ // get extended memory block with the expression entered
+ IMemoryBlockExtension memBlock = memRetrieval.getExtendedMemoryBlock("0x12345678", elem);
+
+ // add block to memory block manager
+ if (memBlock != null)
+ {
+ IMemoryBlock[] memArray = new IMemoryBlock[]{memBlock};
+
+ DebugPlugin.getDefault().getMemoryBlockManager().addMemoryBlocks(memArray);
+ addDefaultRenderings(memBlock);
+ }
+ else
+ {
+ // open error if it failed to retrieve a memory block
+ MemoryViewUtil.openError(DebugUIMessages.AddMemoryBlockAction_title, DebugUIMessages.AddMemoryBlockAction_noMemoryBlock, null);
+ }
+}
+
+ public void run(IAction action) {
+ ICVariable[] vars = getVariables();
+ if ( vars != null && vars.length > 0 ) {
+
+ }
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ if ( selection instanceof IStructuredSelection ) {
+ List list = new ArrayList();
+ IStructuredSelection ssel = (IStructuredSelection)selection;
+ Iterator i = ssel.iterator();
+ while( i.hasNext() ) {
+ Object o = i.next();
+ if ( o instanceof ICVariable ) {
+ ICVariable var = (ICVariable)o;
+ boolean enabled = true;
+ action.setEnabled( enabled );
+ if ( enabled ) {
+ list.add( o );
+ }
+ }
+ }
+ setVariables( (ICVariable[])list.toArray( new ICVariable[list.size()] ) );
+ }
+ else {
+ action.setChecked( false );
+ action.setEnabled( false );
+ }
+ }
+
+ protected ICVariable[] getVariables() {
+ return variables;
+ }
+
+ private void setVariables( ICVariable[] variables ) {
+ this.variables = variables;
+ }
+
+}

Back to the top