mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 09:16:02 +02:00
Bug 445375 : Watchpoints cannot be disabled for targets that do not
support it - add canPerformAction abstract method in base object action delegate class - add CToggleWatchpointActionDelegate that would also trigger interactive triggering of watchpoints vs non-interactive. - Check in each method & watchpoint delegates if IToggleBreakpointsTarget does support the action - Do not create duplicate watchpoints/breakpoints when toggling them interactively Change-Id: Idb1baaf171173b2d824a7cc50c8fe65e613f81aa Signed-off-by: Teodor Madan <teodor.madan@freescale.com> Reviewed-on: https://git.eclipse.org/r/34061 Tested-by: Hudson CI
This commit is contained in:
parent
7fda3c26d0
commit
afa28a8945
6 changed files with 120 additions and 15 deletions
|
@ -1358,7 +1358,6 @@ public class CDIDebugModel {
|
|||
public static ICFunctionBreakpoint functionBreakpointExists(String sourceHandle, IResource resource, String function)
|
||||
throws CoreException {
|
||||
String modelId = getPluginIdentifier();
|
||||
String markerType = ICFunctionBreakpoint.C_FUNCTION_BREAKPOINT_MARKER;
|
||||
IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
|
||||
IBreakpoint[] breakpoints = manager.getBreakpoints(modelId);
|
||||
for (int i = 0; i < breakpoints.length; i++) {
|
||||
|
@ -1366,12 +1365,10 @@ public class CDIDebugModel {
|
|||
continue;
|
||||
}
|
||||
ICFunctionBreakpoint breakpoint = (ICFunctionBreakpoint) breakpoints[i];
|
||||
if (breakpoint.getMarker().getType().equals(markerType)) {
|
||||
if (sameSourceHandle(sourceHandle, breakpoint.getSourceHandle())) {
|
||||
if (breakpoint.getMarker().getResource().equals(resource)) {
|
||||
if (breakpoint.getFunction() != null && breakpoint.getFunction().equals(function)) {
|
||||
return breakpoint;
|
||||
}
|
||||
if (sameSourceHandle(sourceHandle, breakpoint.getSourceHandle())) {
|
||||
if (breakpoint.getMarker().getResource().equals(resource)) {
|
||||
if (breakpoint.getFunction() != null && breakpoint.getFunction().equals(function)) {
|
||||
return breakpoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -679,7 +679,7 @@
|
|||
enablesFor="1"
|
||||
label="%ToggleWatchpointAction.label"
|
||||
icon="icons/elcl16/watchpoint_co.gif"
|
||||
class="org.eclipse.debug.ui.actions.ToggleWatchpointActionDelegate"
|
||||
class="org.eclipse.cdt.debug.internal.ui.actions.breakpoints.CToggleWatchpointActionDelegate"
|
||||
tooltip="%ToggleWatchpointAction.tooltip"
|
||||
menubarPath="additions"
|
||||
id="org.eclipse.cdt.debug.ui.actions.ToggleWatchpointAction"/>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2010 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2014 IBM Corporation 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:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Wind River Systems - added support for IToggleBreakpointsTargetFactory
|
||||
* Freescale - Add support for conditionally activating an action
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.internal.ui.actions.breakpoints;
|
||||
|
||||
|
@ -71,6 +72,16 @@ public abstract class CToggleBreakpointObjectActionDelegate implements IObjectAc
|
|||
protected abstract void performAction(IToggleBreakpointsTarget target, IWorkbenchPart part, ISelection selection, Event event)
|
||||
throws CoreException;
|
||||
|
||||
/**
|
||||
* Returns whether the specific operation is supported.
|
||||
*
|
||||
* @param target the target adapter
|
||||
* @param selection the selection to verify the operation on
|
||||
* @param part the part the operation has been requested on
|
||||
* @return whether the operation can be performed
|
||||
*/
|
||||
protected abstract boolean canPerformAction(IToggleBreakpointsTarget target, IWorkbenchPart part, ISelection selection);
|
||||
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
boolean enabled = false;
|
||||
if (selection instanceof IStructuredSelection) {
|
||||
|
@ -81,7 +92,7 @@ public abstract class CToggleBreakpointObjectActionDelegate implements IObjectAc
|
|||
if (fPart != null) {
|
||||
IToggleBreakpointsTarget target =
|
||||
DebugUITools.getToggleBreakpointsTargetManager().getToggleBreakpointsTarget(fPart, fSelection);
|
||||
enabled = target != null;
|
||||
enabled = target != null && canPerformAction(target, fPart, fSelection);
|
||||
}
|
||||
}
|
||||
action.setEnabled(enabled);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2014 IBM Corporation 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:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Freescale - Add support for conditionally activating an action
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.internal.ui.actions.breakpoints;
|
||||
|
||||
|
@ -45,4 +46,10 @@ public class CToggleMethodBreakpointActionDelegate extends CToggleBreakpointObje
|
|||
target.toggleMethodBreakpoints(part, selection);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canPerformAction(IToggleBreakpointsTarget target,
|
||||
IWorkbenchPart part, ISelection selection) {
|
||||
return target.canToggleMethodBreakpoints(part, selection);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2014 IBM Corporation 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:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Freescale - add support for conditionally activating action
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.internal.ui.actions.breakpoints;
|
||||
|
||||
import org.eclipse.cdt.debug.ui.breakpoints.IToggleBreakpointsTargetCExtension;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
|
||||
/**
|
||||
* A toggle watchpoint action that can be contributed an object
|
||||
* contribution. The action will toggle watchpoints on objects
|
||||
* that provide an <code>IToggleBreakpointsTarget</code> adapter.
|
||||
* <p>
|
||||
* This class is based on {@link org.eclipse.debug.ui.actions.ToggleWatchpointActionDelegate }
|
||||
* class. In addition to the copied functionality, it adds the handling of
|
||||
* action-triggering event.
|
||||
* </p>
|
||||
*
|
||||
* @since 7.5
|
||||
*/
|
||||
public class CToggleWatchpointActionDelegate extends CToggleBreakpointObjectActionDelegate {
|
||||
|
||||
protected void performAction(IToggleBreakpointsTarget target, IWorkbenchPart part, ISelection selection, Event event)
|
||||
throws CoreException
|
||||
{
|
||||
if ((event.stateMask & SWT.MOD1) != 0 &&
|
||||
target instanceof IToggleBreakpointsTargetCExtension &&
|
||||
((IToggleBreakpointsTargetCExtension)target).canCreateWatchpointsInteractive(part, selection))
|
||||
{
|
||||
((IToggleBreakpointsTargetCExtension)target).createWatchpointsInteractive(part, selection);
|
||||
}
|
||||
else {
|
||||
target.toggleWatchpoints(part, selection);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canPerformAction(IToggleBreakpointsTarget target,
|
||||
IWorkbenchPart part, ISelection selection) {
|
||||
return target.canToggleWatchpoints(part, selection);
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* Mentor Graphics - Initial API and implementation
|
||||
* Marc Khouzam (Ericsson) - Don't allow to set two bps at same line (bug 432503)
|
||||
* Teodor Madan (Freescale) - Do not create multiple watchpoints /method breakpoints at same location ( 445375 )
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.debug.ui.breakpoints;
|
||||
|
@ -184,8 +185,7 @@ abstract public class AbstractToggleBreakpointAdapter
|
|||
|
||||
@Override
|
||||
public boolean canCreateWatchpointsInteractive(IWorkbenchPart part, ISelection selection) {
|
||||
// Gather all input from user if needed.
|
||||
return true;
|
||||
return canToggleWatchpoints(part, selection) && !hasWatchpoint(part, selection);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -229,7 +229,7 @@ abstract public class AbstractToggleBreakpointAdapter
|
|||
|
||||
@Override
|
||||
public boolean canCreateFunctionBreakpointInteractive(IWorkbenchPart part, ISelection selection) {
|
||||
return true;
|
||||
return canToggleMethodBreakpoints(part, selection) && !hasMethodBreakpoints(part, selection);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -256,6 +256,40 @@ abstract public class AbstractToggleBreakpointAdapter
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean hasWatchpoint(IWorkbenchPart part, ISelection selection) {
|
||||
ICElement element = getCElementFromSelection( part, selection );
|
||||
if (element instanceof IVariable) {
|
||||
IVariable variable = (IVariable) element;
|
||||
String sourceHandle = getSourceHandle(variable );
|
||||
IResource resource = getElementResource(variable);
|
||||
String expression = getVariableName(variable);
|
||||
try {
|
||||
return null != findWatchpoint(sourceHandle, resource, expression);
|
||||
} catch (CoreException e) {
|
||||
DebugPlugin.log(e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean hasMethodBreakpoints(IWorkbenchPart part, ISelection selection) {
|
||||
ICElement element = getCElementFromSelection( part, selection );
|
||||
if ( element instanceof IFunction || element instanceof IMethod ) {
|
||||
IDeclaration declaration = (IDeclaration) element;
|
||||
String sourceHandle = getSourceHandle(declaration);
|
||||
IResource resource = getElementResource(declaration);
|
||||
String functionName = (declaration instanceof IFunction) ?
|
||||
getFunctionName((IFunction) declaration)
|
||||
: getMethodName((IMethod) declaration);
|
||||
try {
|
||||
return null != findFunctionBreakpoint(sourceHandle, resource, functionName);
|
||||
} catch (CoreException e) {
|
||||
DebugPlugin.log(e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the breakpoint for given part and selection.
|
||||
* Depending on the flags and on whether a breakpoint exists, this method
|
||||
|
@ -607,7 +641,8 @@ abstract public class AbstractToggleBreakpointAdapter
|
|||
return null;
|
||||
}
|
||||
|
||||
protected ICWatchpointTarget getWatchpointTarget( IWorkbenchPart part, ISelection selection ) {
|
||||
@SuppressWarnings("deprecation")
|
||||
protected ICWatchpointTarget getWatchpointTarget( IWorkbenchPart part, ISelection selection ) {
|
||||
if (selection != null && selection instanceof IStructuredSelection && !selection.isEmpty()) {
|
||||
Object obj = ((IStructuredSelection)selection).getFirstElement();
|
||||
if (obj != null) {
|
||||
|
|
Loading…
Add table
Reference in a new issue