diff options
author | Ken Ryall | 2007-11-03 15:58:34 +0000 |
---|---|---|
committer | Ken Ryall | 2007-11-03 15:58:34 +0000 |
commit | 8ee4b1941bd57dc695c53b0cc501867421991813 (patch) | |
tree | d503bb9587c13b231cbc16be8b55aef990b7da7a | |
parent | 4dea83bf905d907957fb046af5dc544e6c018938 (diff) | |
download | org.eclipse.cdt-8ee4b1941bd57dc695c53b0cc501867421991813.tar.gz org.eclipse.cdt-8ee4b1941bd57dc695c53b0cc501867421991813.tar.xz org.eclipse.cdt-8ee4b1941bd57dc695c53b0cc501867421991813.zip |
Bug 207231
6 files changed, 194 insertions, 30 deletions
diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.properties b/debug/org.eclipse.cdt.debug.ui/plugin.properties index dc1a1876dec..8644a1f5920 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.properties +++ b/debug/org.eclipse.cdt.debug.ui/plugin.properties @@ -35,6 +35,9 @@ ToggleInstructionStepModeAction.tooltip=Instruction Stepping Mode ShowDebuggerConsoleAction.label=Show Debugger Console ShowDebuggerConsoleAction.tooltip=Show Debugger Console On Target Selection +ViewMemoryAction.label=View Memory +ViewMemoryAction.tooltop=View Memory on Selected Variables + AddBreakpoint.label=Toggle &Breakpoint EnableBreakpoint.label=&Toggle Breakpoint Enabled BreakpointProperties.label=Breakpoint P&roperties... diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index e1d5bb22ba2..cbc05cb2ab5 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -357,6 +357,20 @@ 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="%ViewMemoryAction.label" + tooltip="%ViewMemoryAction.tooltip" + 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/CDebugUIUtils.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugUIUtils.java index a60d7288dc1..ea8af7872d4 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,33 @@ 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$ + + 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/ActionMessages.properties b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties index fb78360dabf..fb9f7aa62f4 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties @@ -118,3 +118,6 @@ ToggleDetailPaneAction.7=Hide the Detail Pane so that only the Main Tree View is AddRegisterGroupActionDelegate.0=Error AddRegisterGroupActionDelegate.1=Error(s) occurred adding register group. EditRegisterGroupActionDelegate.0=Unable to edit register group. +ViewMemoryActionDelegate.ErrorTitle=View Memory +ViewMemoryActionDelegate.CantOpenMemoryView=Can't open the Memory view +ViewMemoryActionDelegate.CantViewMemory=Can't view memory on variable 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..51f94bbe3e4 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ViewMemoryActionDelegate.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2007 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; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.cdt.debug.core.model.ICVariable; +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.ui.IDebugUIConstants; +import org.eclipse.debug.ui.memory.IMemoryRenderingSite; +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; +import org.eclipse.ui.PartInitException; + +public class ViewMemoryActionDelegate implements IObjectActionDelegate { + + private ICVariable[] variables; + + public ViewMemoryActionDelegate() {} + + public void setActivePart(IAction action, IWorkbenchPart targetPart) { + } + + public void run(IAction action) { + + 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$ + } + } + + 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 ) { + action.setEnabled( true ); + 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; + } + +} 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 852fbd88040..9f2106c7c1f 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 @@ -7,6 +7,7 @@ * * Contributors: * Freescale, Inc. - initial API and implementation + * Ken Ryall (Nokia) - Bug 207231 *******************************************************************************/ package org.eclipse.cdt.debug.internal.ui.views.memory; @@ -14,7 +15,9 @@ package org.eclipse.cdt.debug.internal.ui.views.memory; import java.util.ArrayList; 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.ui.CDebugUIUtils; import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; @@ -35,12 +38,10 @@ 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.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.progress.UIJob; /** * Adds memory blocks to the Memory view. @@ -194,16 +195,16 @@ public class AddMemoryBlocks implements IAddMemoryBlocksTarget { addDefaultRenderings(memBlock, memRendSite); } else { // open error if it failed to retrieve a memory block - openError(Messages.AddMemBlocks_title, + CDebugUIUtils.openError(Messages.AddMemBlocks_title, Messages.AddMemBlocks_noMemoryBlock, null); } } catch (DebugException e1) { - openError(Messages.AddMemBlocks_title, + CDebugUIUtils.openError(Messages.AddMemBlocks_title, Messages.AddMemBlocks_failed, e1); } catch (NumberFormatException e2) { String message = Messages.AddMemBlocks_failed + "\n" + Messages.AddMemBlocks_input_invalid; //$NON-NLS-1$ - openError(Messages.AddMemBlocks_title, message, + CDebugUIUtils.openError(Messages.AddMemBlocks_title, message, null); } } @@ -263,32 +264,52 @@ public class AddMemoryBlocks implements IAddMemoryBlocksTarget { container.addMemoryRendering(rendering); } - /** - * 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$ - - 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$ + 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()) + 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; - }}; - uiJob.setSystem(true); - uiJob.schedule(); + } + }; + job.setSystem(true); + job.schedule(); } } |