1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 418710 - Provide a way to disable "View memory" menu per expression

Add IViewInMemory interface to general CDT to make it available for CDI
also.
Use IViewInMemory in DSF, and override it for the GDB case.
No need to use IViewInMemory.viewInMemory() yet, but it is put in the
new interface to be future-proof.

Change-Id: Iba9abee6b9bb459b4ec3a4fd72378f77f417643a
Signed-off-by: Marc Khouzam <marc.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/18952
This commit is contained in:
Marc Khouzam 2013-11-27 04:47:42 -05:00
parent 0071f546d1
commit eb3b78ec86
4 changed files with 140 additions and 18 deletions

View file

@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2013 Ericsson 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:
* Marc Khouzam (Ericsson) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.core.model;
import org.eclipse.core.runtime.IAdaptable;
/**
* Provides the ability to view a variable in the memory view.
* @since 7.4
*/
public interface IViewInMemory extends IAdaptable {
/**
* Returns whether this element can currently be viewed in the memory view.
*
* @return whether this element can currently be viewed in the memory view.
*/
boolean canViewInMemory();
/**
* Displays the element in the memory view.
*/
void viewInMemory();
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010 Freescale Semiconductor. and others.
* Copyright (c) 2010, 2013 Freescale Semiconductor. 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
@ -8,6 +8,7 @@
* Contributors:
* Freescale Semiconductor - initial API and implementation
* Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121)
* Marc Khouzam (Ericsson) - Add support disable "View Memory" action (bug 418710)
*******************************************************************************/
package org.eclipse.cdt.dsf.gdb.internal.ui.viewmodel;
@ -184,8 +185,50 @@ public class GdbVariableVMNode extends VariableVMNode {
request.done();
}
}
@Override
public boolean canViewInMemory() {
String expr = getExpression();
if (isConvenienceVariable(expr) || isRegisterExpression(expr)) {
return false;
}
return super.canViewInMemory();
}
};
private static boolean isConvenienceVariable(String expr) {
// GDB convenience variables are variables that start with a $ followed
// by at least one digit.
// Note that registers also start with a $, so we need to make sure
// there is a digit immediately following the $.
// Also, the $ may not be at the start of the expression in cases
// where we are dealing with children of a convenience variable,
// such as ($1).myvar or ((class bar) $1).foo.
// So, we look for a $ followed by a number, anywhere in the expression.
// Convenience variables are used for return values of methods calls.
// see bug 341731
if (expr.matches(".*" + "\\$\\d" + ".*")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return true;
}
return false;
}
private static boolean isRegisterExpression(String expr) {
// Registers expressions start with a $ followed by a non-digit.
// We must check for the non-digit because we need to make sure
// we are not dealing with a convenience variable.
// Also, the $ may not be at the start of the expression in cases
// where we are dealing with a casted register, or children of a register
// such as (int)($eax)
// So, we look for a $ followed by a non-digit, anywhere in the expression.
if (expr.matches(".*" + "\\$\\D" + ".*")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return true;
}
return false;
}
/**
* The special context representing more children to be available.
*

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010 Nokia and others.
* Copyright (c) 2010, 2013 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
@ -7,6 +7,7 @@
*
* Contributors:
* Nokia - Initial API and implementation
* Marc Khouzam (Ericsson) - Allow to disable ViewMemory handler (bug 418710)
*******************************************************************************/
package org.eclipse.cdt.dsf.debug.internal.ui.viewmodel.actions;
@ -16,6 +17,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.concurrent.RejectedExecutionException;
import org.eclipse.cdt.debug.core.model.IViewInMemory;
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.DsfExecutor;
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
@ -32,6 +34,7 @@ import org.eclipse.cdt.dsf.service.DsfSession;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@ -50,12 +53,11 @@ 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.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISources;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
/**
* DSF version of handler for viewing variable in memory view command.
@ -63,25 +65,58 @@ import org.eclipse.ui.handlers.HandlerUtil;
*/
public class DsfViewMemoryHandler extends AbstractHandler {
private VariableExpressionVMC[] fMemoryViewables = new VariableExpressionVMC[0];
protected VariableExpressionVMC[] getMemoryViewables() {
return fMemoryViewables;
}
protected void setMemoryViewables(VariableExpressionVMC[] viewableMemoryITems) {
fMemoryViewables = viewableMemoryITems;
}
@Override
public void setEnabled(Object evaluationContext) {
VariableExpressionVMC[] viewableMemoryITems = getMemoryViewables(evaluationContext);
setBaseEnabled(viewableMemoryITems.length > 0);
setMemoryViewables(viewableMemoryITems);
}
/*
* (non-Javadoc)
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
List<Object> list = new ArrayList<Object>();
Iterator<?> iter = ((IStructuredSelection)selection).iterator();
if (getMemoryViewables() == null || getMemoryViewables().length == 0) {
return null;
}
showInMemoryView(getMemoryViewables());
return null;
}
private VariableExpressionVMC[] getMemoryViewables(Object evaluationContext) {
List<VariableExpressionVMC> viewableMemoryItems = new ArrayList<VariableExpressionVMC>();
if (evaluationContext instanceof IEvaluationContext) {
Object s = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
if (s instanceof IStructuredSelection) {
Iterator<?> iter = ((IStructuredSelection)s).iterator();
while(iter.hasNext()) {
Object obj = iter.next();
if (obj instanceof VariableExpressionVMC) {
list.add(obj);
Object element = DebugPlugin.getAdapter(obj, IViewInMemory.class);
if (element != null) {
if (((IViewInMemory)element).canViewInMemory()) {
viewableMemoryItems.add((VariableExpressionVMC)obj);
}
}
showInMemoryView(list.toArray(new VariableExpressionVMC[list.size()]));
}
return null;
}
}
}
return viewableMemoryItems.toArray(new VariableExpressionVMC[viewableMemoryItems.size()]);
}
private void addDefaultRenderings(IMemoryBlock memoryBlock, IMemoryRenderingSite memRendSite) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2010 Wind River Systems and others.
* Copyright (c) 2006, 2013 Wind River Systems 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
@ -7,6 +7,7 @@
*
* Contributors:
* Wind River Systems - initial API and implementation
* Marc Khouzam (Ericsson) - Add support disable "View Memory" action (bug 418710)
*******************************************************************************/
package org.eclipse.cdt.dsf.debug.ui.viewmodel.variable;
@ -19,6 +20,7 @@ import java.util.concurrent.RejectedExecutionException;
import org.eclipse.cdt.debug.core.model.ICastToArray;
import org.eclipse.cdt.debug.core.model.ICastToType;
import org.eclipse.cdt.debug.core.model.IViewInMemory;
import org.eclipse.cdt.debug.internal.ui.CDebugImages;
import org.eclipse.cdt.dsf.concurrent.ConfinedToDsfExecutor;
import org.eclipse.cdt.dsf.concurrent.CountingRequestMonitor;
@ -157,7 +159,7 @@ public class VariableVMNode extends AbstractExpressionVMNode
*/
private final FormattedValueRetriever fFormattedValueRetriever;
public class VariableExpressionVMC extends DMVMContext implements IFormattedValueVMContext {
public class VariableExpressionVMC extends DMVMContext implements IFormattedValueVMContext, IViewInMemory {
private IExpression fExpression;
@ -210,6 +212,16 @@ public class VariableVMNode extends AbstractExpressionVMNode
public int hashCode() {
return super.hashCode() + (fExpression != null ? fExpression.hashCode() : 0);
}
@Override
public boolean canViewInMemory() {
return true;
}
@Override
public void viewInMemory() {
assert false : "VariableExpressionVMC.viewInMemory() not implemented"; //$NON-NLS-1$
}
}
protected class VariableExpressionFactory implements IWatchExpressionFactoryAdapter2 {