Skip to main content
summaryrefslogtreecommitdiffstats
path: root/debug
diff options
context:
space:
mode:
authorKen Ryall2008-05-21 16:41:48 -0400
committerKen Ryall2008-05-21 16:41:48 -0400
commit5297afa058c14b8a674c3dc5dc55b9ce31310107 (patch)
tree123ddc28a02122c93af4382ea656caae95fcdc16 /debug
parent7a7891d1b41e58ed2859c19574d13e412af6eef8 (diff)
downloadorg.eclipse.cdt-5297afa058c14b8a674c3dc5dc55b9ce31310107.tar.gz
org.eclipse.cdt-5297afa058c14b8a674c3dc5dc55b9ce31310107.tar.xz
org.eclipse.cdt-5297afa058c14b8a674c3dc5dc55b9ce31310107.zip
Merge changes from CDT 4.0.x.
Diffstat (limited to 'debug')
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CMemoryBlockRetrievalExtension.java7
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugUIUtils.java37
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ViewMemoryActionDelegate.java168
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/AddMemoryBlocks.java51
4 files changed, 125 insertions, 138 deletions
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CMemoryBlockRetrievalExtension.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CMemoryBlockRetrievalExtension.java
index d13cb37198..cb56447806 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CMemoryBlockRetrievalExtension.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CMemoryBlockRetrievalExtension.java
@@ -257,14 +257,15 @@ public class CMemoryBlockRetrievalExtension extends PlatformObject implements IM
// OK, expression is not a simple literal address; keep trucking and try to resolve as expression
CStackFrame frame = getStackFrame( debugElement );
if ( frame != null ) {
- // We need to provide a better way for retrieving the address of expression
+ // Get the address of the expression
ICDIExpression cdiExpression = frame.getCDITarget().createExpression( expression );
exp = new CExpression( frame, cdiExpression, null );
IValue value = exp.getValue();
if ( value instanceof ICValue ) {
ICType type = ((ICValue)value).getType();
- if ( type != null && (type.isPointer() || type.isIntegralType() || type.isArray()) ) {
- address = value.getValueString();
+ if ( type != null ) {
+ // get the address for the expression, allow all types
+ address = frame.evaluateExpressionToString(exp.getExpressionString());
if ( address != null ) {
// ???
BigInteger a = ( address.startsWith( "0x" ) ) ? new BigInteger( address.substring( 2 ), 16 ) : new BigInteger( address ); //$NON-NLS-1$
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugUIUtils.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugUIUtils.java
index a60d7288dc..ed0730cb84 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugUIUtils.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugUIUtils.java
@@ -20,23 +20,30 @@ import org.eclipse.cdt.debug.core.model.ICType;
import org.eclipse.cdt.debug.core.model.ICValue;
import org.eclipse.cdt.debug.core.model.IEnableDisableTarget;
import org.eclipse.cdt.debug.internal.ui.views.disassembly.DisassemblyEditorInput;
+import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IValue;
import org.eclipse.debug.core.model.IVariable;
import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IPathEditorInput;
import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.IURIEditorInput;
+import org.eclipse.ui.progress.UIJob;
/**
* Utility methods for C/C++ Debug UI.
@@ -215,4 +222,34 @@ public class CDebugUIUtils {
}
return baseText.toString();
}
+
+ /**
+ * Helper function to open an error dialog.
+ * @param title
+ * @param message
+ * @param e
+ */
+ static public void openError (final String title, final String message, final Exception e)
+ {
+ UIJob uiJob = new UIJob("open error"){ //$NON-NLS-1$
+
+ @Override
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ // open error for the exception
+ String detail = ""; //$NON-NLS-1$
+ if (e != null)
+ detail = e.getMessage();
+
+ Shell shell = CDebugUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
+
+ MessageDialog.openError(
+ shell,
+ title,
+ message + "\n" + detail); //$NON-NLS-1$
+ return Status.OK_STATUS;
+ }};
+ uiJob.setSystem(true);
+ uiJob.schedule();
+ }
+
}
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
index 80e08148ff..5bb8e00a1f 100644
--- 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
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ken Ryall (Nokia) - initial API and implementation (207231)
+ *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
import java.util.ArrayList;
@@ -5,24 +15,12 @@ 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.cdt.debug.internal.ui.CDebugUIUtils;
+import org.eclipse.cdt.debug.internal.ui.views.memory.AddMemoryBlocks;
+import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
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;
@@ -30,148 +28,48 @@ import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
public class ViewMemoryActionDelegate implements IObjectActionDelegate {
private ICVariable[] variables;
- public ViewMemoryActionDelegate() {
- // TODO Auto-generated constructor stub
- }
+ public ViewMemoryActionDelegate() {}
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 ) {
+ IWorkbenchPage page = CDebugUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IViewPart newView;
+ try {
+ newView = page.showView(IDebugUIConstants.ID_MEMORY_VIEW, null, IWorkbenchPage.VIEW_ACTIVATE);
+ IMemoryRenderingSite memSite = (IMemoryRenderingSite) newView;
+ new AddMemoryBlocks().addMemoryBlocksForVariables(variables, memSite);
+ } catch (ClassCastException e) {
+ CDebugUIUtils.openError(ActionMessages.getString("ViewMemoryActionDelegate.ErrorTitle"), ActionMessages.getString("ViewMemoryActionDelegate.CantOpenMemoryView"), e); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (PartInitException e) {
+ CDebugUIUtils.openError(ActionMessages.getString("ViewMemoryActionDelegate.ErrorTitle"), ActionMessages.getString("ViewMemoryActionDelegate.CantOpenMemoryView"), e); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (DebugException e) {
+ CDebugUIUtils.openError(ActionMessages.getString("ViewMemoryActionDelegate.ErrorTitle"), ActionMessages.getString("ViewMemoryActionDelegate.CantViewMemory"), e); //$NON-NLS-1$ //$NON-NLS-2$
}
}
+ @SuppressWarnings("unchecked")
public void selectionChanged(IAction action, ISelection selection) {
if ( selection instanceof IStructuredSelection ) {
- List list = new ArrayList();
+ List<Object> list = new ArrayList<Object>();
IStructuredSelection ssel = (IStructuredSelection)selection;
- Iterator i = ssel.iterator();
+ Iterator<Object> 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 );
- }
+ action.setEnabled( true );
+ list.add( o );
}
}
- setVariables( (ICVariable[])list.toArray( new ICVariable[list.size()] ) );
+ setVariables( list.toArray( new ICVariable[list.size()] ) );
}
else {
action.setChecked( false );
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/AddMemoryBlocks.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/AddMemoryBlocks.java
index c30488230d..56c2237b5a 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/AddMemoryBlocks.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/AddMemoryBlocks.java
@@ -15,7 +15,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
+import org.eclipse.cdt.debug.core.model.ICVariable;
import org.eclipse.cdt.debug.internal.core.CMemoryBlockRetrievalExtension;
+import org.eclipse.cdt.debug.internal.core.model.CRegister;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
@@ -265,6 +267,55 @@ public class AddMemoryBlocks implements IAddMemoryBlocksTarget {
container.addMemoryRendering(rendering);
}
+ public void addMemoryBlocksForVariables(ICVariable[] variables, IMemoryRenderingSite memSite) throws DebugException {
+
+ IAdaptable debugViewElement = DebugUITools.getDebugContext();
+
+
+ CMemoryBlockRetrievalExtension cdtRetrieval = null;
+
+ {
+ IMemoryBlockRetrieval retrieval = (IMemoryBlockRetrieval)debugViewElement.getAdapter(IMemoryBlockRetrieval.class);
+
+ if (retrieval == null && debugViewElement instanceof IDebugElement)
+ retrieval = ((IDebugElement)debugViewElement).getDebugTarget();
+
+ if (retrieval == null || !(retrieval instanceof CMemoryBlockRetrievalExtension))
+ return;
+
+ cdtRetrieval = (CMemoryBlockRetrievalExtension) retrieval;
+ }
+
+ String[] expressions = new String[variables.length];
+ for (int i = 0; i < variables.length; i++) {
+
+ String exp = variables[i].getExpressionString();
+
+ if (variables[i].getType().isPointer() || variables[i].getType().isArray() ||
+ variables[i].getType().isReference() || variables[i] instanceof CRegister)
+ expressions[i] = exp;
+ else
+ expressions[i] = "&" + exp;
+ }
+
+ ParamHolder params;
+ params = new ExpressionsHolder(expressions);
+
+ final IAdaptable debugViewElement_f = debugViewElement;
+ final CMemoryBlockRetrievalExtension retrieval_f = cdtRetrieval;
+ final ParamHolder params_f = params;
+ final IMemoryRenderingSite memRendSite = memSite;
+ Job job = new Job("Add Memory Block") { //$NON-NLS-1$
+ protected IStatus run(IProgressMonitor monitor) {
+ addMemoryBlocks(debugViewElement_f, retrieval_f, params_f,
+ memRendSite);
+ return Status.OK_STATUS;
+ }
+ };
+ job.setSystem(true);
+ job.schedule();
+ }
+
/**
* Helper function to open an error dialog.
* @param title

Back to the top