1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Bug 468192 - Prevent creating a duplicate bp when modifying properties

- Have CBreakpointPropertyPage check if any CBreakpoint already exists
at the specified location
- Have GDBDynamicPrintfPropertyPage check if any CBreakpoint already
exists at the specified location
- Have GDBTracepointPropertyPage check if any CBreakpoint already exists
at the specified location

Change-Id: I67096343a7173a98a144e3577a6b8a05377759e3
Signed-off-by: Marc Khouzam <marc.khouzam@ericsson.com>
This commit is contained in:
Marc Khouzam 2015-05-22 16:41:05 -04:00 committed by Gerrit Code Review @ Eclipse.org
parent ed3e9cf973
commit 2b21405150
6 changed files with 260 additions and 34 deletions

View file

@ -27,6 +27,7 @@ CBreakpointPropertyPage.sourceHandle_label=File:
CBreakpointPropertyPage.breakpointType_line_label=C/C++ Line Breakpoint
CBreakpointPropertyPage.lineNumber_errorMessage=Enter a line number greater than 0
CBreakpointPropertyPage.lineNumber_label=Line number:
CBreakpointPropertyPage.breakpoint_already_exists_errorMessage=Breakpoint exists at this location
CBreakpointPropertyPage.breakpointType_event_label=C/C++ Event Breakpoint
CBreakpointPropertyPage.project_label=Project:
CBreakpointPropertyPage.breakpointType_watchpoint_label=C/C++ Watchpoint

View file

@ -45,6 +45,7 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IDebugModelProvider;
import org.eclipse.debug.core.model.ILineBreakpoint;
@ -57,6 +58,7 @@ import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
@ -535,10 +537,18 @@ public class CBreakpointPropertyPage extends FieldEditorPreferencePage implement
private Text fIgnoreCountTextControl;
private BreakpointFileNameFieldEditor fFileEditor;
private BreakpointIntegerFieldEditor fLineEditor;
private BreakpointIntegerFieldEditor fIgnoreCount;
private IAdaptable fElement;
/**
* Indicates if the page currently aims to create
* a breakpoint that already exits.
*/
private boolean fDuplicateBreakpoint;
/**
* The preference store used to interface between the breakpoint and the
* breakpoint preference page. This preference store is initialized only
@ -560,11 +570,6 @@ public class CBreakpointPropertyPage extends FieldEditorPreferencePage implement
// fCBreakpointPreferenceStore = new CBreakpointPreferenceStore();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
*/
@Override
protected void createFieldEditors() {
ICBreakpoint breakpoint = getBreakpoint();
@ -681,11 +686,11 @@ public class CBreakpointPropertyPage extends FieldEditorPreferencePage implement
boolean isFilenameEditable = fileName != null && fileName.isEmpty();
if (isNewBreakpoint && isFilenameEditable) {
BreakpointFileNameFieldEditor fileNameEditor = new BreakpointFileNameFieldEditor(
fFileEditor = new BreakpointFileNameFieldEditor(
ICLineBreakpoint.SOURCE_HANDLE, title, parent);
fileNameEditor.setErrorMessage(BreakpointsMessages.getString("CBreakpointPropertyPage.fileName_errorMessage")); //$NON-NLS-1$
fileNameEditor.setEmptyStringAllowed(false);
addField(fileNameEditor);
fFileEditor.setErrorMessage(BreakpointsMessages.getString("CBreakpointPropertyPage.fileName_errorMessage")); //$NON-NLS-1$
fFileEditor.setEmptyStringAllowed(false);
addField(fFileEditor);
} else {
if (fileName != null) {
addField(createLabelEditor(parent, title, fileName));
@ -704,10 +709,10 @@ public class CBreakpointPropertyPage extends FieldEditorPreferencePage implement
protected void createLineNumberEditor( Composite parent ) {
String title = BreakpointsMessages.getString( "CBreakpointPropertyPage.lineNumber_label" ); //$NON-NLS-1$
BreakpointIntegerFieldEditor labelFieldEditor =new BreakpointIntegerFieldEditor( IMarker.LINE_NUMBER ,title, parent);
labelFieldEditor.setValidRange( 1, Integer.MAX_VALUE );
labelFieldEditor.setErrorMessage(BreakpointsMessages.getString("CBreakpointPropertyPage.lineNumber_errorMessage")); //$NON-NLS-1$
addField( labelFieldEditor );
fLineEditor = new BreakpointIntegerFieldEditor(IMarker.LINE_NUMBER ,title, parent);
fLineEditor.setValidRange(1, Integer.MAX_VALUE);
fLineEditor.setErrorMessage(BreakpointsMessages.getString("CBreakpointPropertyPage.lineNumber_errorMessage")); //$NON-NLS-1$
addField(fLineEditor);
}
protected void createWatchExpressionEditor( Composite parent ) {
@ -807,6 +812,79 @@ public class CBreakpointPropertyPage extends FieldEditorPreferencePage implement
return new LabelFieldEditor( parent, title, value );
}
@Override
public boolean isValid() {
// Don't allow to create a duplicate breakpoint
return super.isValid() && !fDuplicateBreakpoint;
}
@Override
public void propertyChange(PropertyChangeEvent event) {
super.propertyChange(event);
ICBreakpoint currentBp = getBreakpoint();
if (!(currentBp instanceof ICFunctionBreakpoint) &&
!(currentBp instanceof ICAddressBreakpoint)) {
// Check for duplication of line breakpoints
if (event.getProperty().equals(FieldEditor.VALUE)) {
if (super.isValid()) {
// For every change, if all the fields are valid
// we then check if we are dealing with a duplicate
// breakpoint.
boolean oldValue = fDuplicateBreakpoint;
fDuplicateBreakpoint = isDuplicateBreakpoint();
if (oldValue != fDuplicateBreakpoint) {
if (fDuplicateBreakpoint) {
setErrorMessage(BreakpointsMessages.getString("CBreakpointPropertyPage.breakpoint_already_exists_errorMessage")); //$NON-NLS-1$
} else {
setErrorMessage(null);
}
// update container state
if (getContainer() != null) {
getContainer().updateButtons();
}
// update page state
updateApplyButton();
}
}
}
}
}
private boolean isDuplicateBreakpoint() {
String source = null;
if (fFileEditor != null) {
source = fFileEditor.getStringValue();
} else {
// If the source file is not editable, we should fetch
// it from the preference store
source = getPreferenceStore().getString(ICBreakpoint.SOURCE_HANDLE);
}
int line = fLineEditor.getIntValue();
// Look for any breakpoint that has the same source file and line number as what
// is currently being inputed. Careful not to compare with the current breakpoint
// in the case of modifying the breakpoint properties of an existing breakpoint; in
// that case we of course have this particular bp at this file and line.
ICBreakpoint currentBp = getBreakpoint();
IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints();
for (IBreakpoint bp : breakpoints) {
if (!bp.equals(currentBp) && bp instanceof ICBreakpoint) {
IMarker marker = bp.getMarker();
if (marker != null) {
String markerFile = marker.getAttribute(ICBreakpoint.SOURCE_HANDLE, ""); //$NON-NLS-1$
int markerLine = marker.getAttribute(IMarker.LINE_NUMBER, -1);
if (source.equals(markerFile) && line == markerLine) {
// Woops, we already have another breakpoint at this file:line
return true;
}
}
}
}
return false;
}
protected ICBreakpoint getBreakpoint() {
IAdaptable element = getElement();
if (element instanceof ICBreakpoint) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014 Ericsson and others.
* Copyright (c) 2014, 2015 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
@ -16,6 +16,7 @@ import org.eclipse.cdt.debug.core.model.ICBreakpoint;
import org.eclipse.cdt.debug.core.model.ICDynamicPrintf;
import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint;
import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
import org.eclipse.cdt.debug.internal.ui.breakpoints.BreakpointsMessages;
import org.eclipse.cdt.debug.internal.ui.breakpoints.CBreakpointContext;
import org.eclipse.cdt.debug.internal.ui.breakpoints.CBreakpointPreferenceStore;
import org.eclipse.cdt.debug.ui.breakpoints.ICBreakpointContext;
@ -25,6 +26,7 @@ import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IDebugModelProvider;
import org.eclipse.debug.ui.DebugUITools;
@ -35,6 +37,7 @@ import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Composite;
@ -177,8 +180,16 @@ public class GDBDynamicPrintfPropertyPage extends FieldEditorPreferencePage impl
private DynamicPrintfStringFieldEditor fCondition;
private Text fIgnoreCountTextControl;
private DynamicPrintfIntegerFieldEditor fLineEditor;
private DynamicPrintfIntegerFieldEditor fIgnoreCount;
/**
* Indicates if the page currently aims to create
* a breakpoint that already exits.
*/
private boolean fDuplicateBreakpoint;
private DynamicPrintfStringFieldEditor fPrintString;
private IAdaptable fElement;
@ -197,11 +208,6 @@ public class GDBDynamicPrintfPropertyPage extends FieldEditorPreferencePage impl
noDefaultAndApplyButton();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
*/
@Override
protected void createFieldEditors() {
ICDynamicPrintf dprintf = getDprintf();
@ -269,9 +275,10 @@ public class GDBDynamicPrintfPropertyPage extends FieldEditorPreferencePage impl
}
protected void createLineNumberEditor(Composite parent) {
String title = Messages.PropertyPage_LineNumber;
DynamicPrintfIntegerFieldEditor labelFieldEditor = new DynamicPrintfIntegerFieldEditor(IMarker.LINE_NUMBER, title, parent);
labelFieldEditor.setValidRange(1, Integer.MAX_VALUE);
addField(labelFieldEditor);
fLineEditor = new DynamicPrintfIntegerFieldEditor(IMarker.LINE_NUMBER, title, parent);
fLineEditor.setValidRange(1, Integer.MAX_VALUE);
fLineEditor.setErrorMessage(Messages.PropertyPage_lineNumber_errorMessage);
addField(fLineEditor);
}
protected void createEnabledField(Composite parent) {
@ -312,6 +319,71 @@ public class GDBDynamicPrintfPropertyPage extends FieldEditorPreferencePage impl
addField(fPrintString);
}
@Override
public boolean isValid() {
// Don't allow to create a duplicate breakpoint
return super.isValid() && !fDuplicateBreakpoint;
}
@Override
public void propertyChange(PropertyChangeEvent event) {
super.propertyChange(event);
ICBreakpoint currentBp = getDprintf();
if (!(currentBp instanceof ICFunctionBreakpoint) &&
!(currentBp instanceof ICAddressBreakpoint)) {
// Check for duplication of line dprintf
if (event.getProperty().equals(FieldEditor.VALUE)) {
if (super.isValid()) {
// For every change, if all the fields are valid
// we then check if we are dealing with a duplicate
// breakpoint.
boolean oldValue = fDuplicateBreakpoint;
fDuplicateBreakpoint = isDuplicateBreakpoint();
if (oldValue != fDuplicateBreakpoint) {
if (fDuplicateBreakpoint) {
setErrorMessage(BreakpointsMessages.getString("CBreakpointPropertyPage.breakpoint_already_exists_errorMessage")); //$NON-NLS-1$
} else {
setErrorMessage(null);
}
// update container state
if (getContainer() != null) {
getContainer().updateButtons();
}
// update page state
updateApplyButton();
}
}
}
}
}
private boolean isDuplicateBreakpoint() {
String source = getPreferenceStore().getString(ICBreakpoint.SOURCE_HANDLE);
int line = fLineEditor.getIntValue();
// Look for any breakpoint (base bp class) that has the same source file and line number as what
// is currently being inputed. Careful not to compare with the current dprintf
// in the case of modifying the properties of an existing dprintf; in
// that case we of course have this particular dprintf at this file and line.
ICBreakpoint currentBp = getDprintf();
IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints();
for (IBreakpoint bp : breakpoints) {
if (!bp.equals(currentBp) && bp instanceof ICBreakpoint) {
IMarker marker = bp.getMarker();
if (marker != null) {
String markerFile = marker.getAttribute(ICBreakpoint.SOURCE_HANDLE, ""); //$NON-NLS-1$
int markerLine = marker.getAttribute(IMarker.LINE_NUMBER, -1);
if (source.equals(markerFile) && line == markerLine) {
// Woops, we already have another breakpoint at this file:line
return true;
}
}
}
}
return false;
}
protected FieldEditor createLabelEditor(Composite parent, String title, String value) {
return new LabelFieldEditor(parent, title, value);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2014 Ericsson and others.
* Copyright (c) 2009, 2015 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
@ -19,6 +19,7 @@ import org.eclipse.cdt.debug.core.model.ICBreakpoint;
import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint;
import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
import org.eclipse.cdt.debug.core.model.ICTracepoint;
import org.eclipse.cdt.debug.internal.ui.breakpoints.BreakpointsMessages;
import org.eclipse.cdt.debug.internal.ui.breakpoints.CBreakpointContext;
import org.eclipse.cdt.debug.internal.ui.breakpoints.CBreakpointPreferenceStore;
import org.eclipse.cdt.debug.ui.breakpoints.ICBreakpointContext;
@ -27,6 +28,7 @@ import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IDebugModelProvider;
import org.eclipse.debug.ui.DebugUITools;
@ -37,6 +39,7 @@ import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Composite;
@ -179,8 +182,16 @@ public class GDBTracepointPropertyPage extends FieldEditorPreferencePage impleme
private TracepointStringFieldEditor fCondition;
private Text fIgnoreCountTextControl;
private TracepointIntegerFieldEditor fLineEditor;
private TracepointIntegerFieldEditor fIgnoreCount;
/**
* Indicates if the page currently aims to create
* a breakpoint that already exits.
*/
private boolean fDuplicateBreakpoint;
private Text fPassCountTextControl;
private TracepointIntegerFieldEditor fPassCount;
@ -204,11 +215,6 @@ public class GDBTracepointPropertyPage extends FieldEditorPreferencePage impleme
noDefaultAndApplyButton();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
*/
@Override
protected void createFieldEditors() {
ICTracepoint tracepoint = getTracepoint();
@ -277,9 +283,10 @@ public class GDBTracepointPropertyPage extends FieldEditorPreferencePage impleme
}
protected void createLineNumberEditor(Composite parent) {
String title = Messages.PropertyPage_LineNumber;
TracepointIntegerFieldEditor labelFieldEditor = new TracepointIntegerFieldEditor(IMarker.LINE_NUMBER, title, parent);
labelFieldEditor.setValidRange(1, Integer.MAX_VALUE);
addField(labelFieldEditor);
fLineEditor = new TracepointIntegerFieldEditor(IMarker.LINE_NUMBER, title, parent);
fLineEditor.setValidRange(1, Integer.MAX_VALUE);
fLineEditor.setErrorMessage(Messages.PropertyPage_lineNumber_errorMessage);
addField(fLineEditor);
}
protected void createEnabledField(Composite parent) {
@ -314,6 +321,72 @@ public class GDBTracepointPropertyPage extends FieldEditorPreferencePage impleme
return new LabelFieldEditor(parent, title, value);
}
@Override
public boolean isValid() {
// Don't allow to create a duplicate breakpoint
return super.isValid() && !fDuplicateBreakpoint;
}
@Override
public void propertyChange(PropertyChangeEvent event) {
super.propertyChange(event);
ICBreakpoint currentBp = getTracepoint();
if (!(currentBp instanceof ICFunctionBreakpoint) &&
!(currentBp instanceof ICAddressBreakpoint)) {
// Check for duplication of line tracepoints
if (event.getProperty().equals(FieldEditor.VALUE)) {
if (super.isValid()) {
// For every change, if all the fields are valid
// we then check if we are dealing with a duplicate
// breakpoint.
boolean oldValue = fDuplicateBreakpoint;
fDuplicateBreakpoint = isDuplicateBreakpoint();
if (oldValue != fDuplicateBreakpoint) {
if (fDuplicateBreakpoint) {
setErrorMessage(BreakpointsMessages.getString("CBreakpointPropertyPage.breakpoint_already_exists_errorMessage")); //$NON-NLS-1$
} else {
setErrorMessage(null);
}
// update container state
if (getContainer() != null) {
getContainer().updateButtons();
}
// update page state
updateApplyButton();
}
}
}
}
}
private boolean isDuplicateBreakpoint() {
String source = getPreferenceStore().getString(ICBreakpoint.SOURCE_HANDLE);
int line = fLineEditor.getIntValue();
// Look for any breakpoint (base class) that has the same source file and line number as what
// is currently being inputed. Careful not to compare with the current tracepoint
// in the case of modifying the properties of an existing tracepoint; in
// that case we of course have this particular tracepoint at this file and line.
ICBreakpoint currentBp = getTracepoint();
IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints();
for (IBreakpoint bp : breakpoints) {
if (!bp.equals(currentBp) && bp instanceof ICBreakpoint) {
IMarker marker = bp.getMarker();
if (marker != null) {
String markerFile = marker.getAttribute(ICBreakpoint.SOURCE_HANDLE, ""); //$NON-NLS-1$
int markerLine = marker.getAttribute(IMarker.LINE_NUMBER, -1);
if (source.equals(markerFile) && line == markerLine) {
// Woops, we already have another breakpoint at this file:line
return true;
}
}
}
}
return false;
}
protected ICTracepoint getTracepoint() {
IAdaptable element = getElement();
if (element instanceof ICTracepoint) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2014 Wind River Systems, Inc. and others.
* Copyright (c) 2009, 2015 Wind River Systems, Inc. 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
@ -35,6 +35,7 @@ public class Messages extends NLS {
public static String PropertyPage_function_value_errorMessage;
public static String PropertyPage_Class;
public static String PropertyPage_Enabled;
public static String PropertyPage_lineNumber_errorMessage;
public static String DynamicPrintfPropertyPage_PrintString;
public static String GdbThreadFilterEditor_Thread;

View file

@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2009, 2014 Wind River Systems and others.
# Copyright (c) 2009, 2015 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
@ -28,6 +28,7 @@ TracepointPropertyPage_PassCount=&Pass count:
PropertyPage_Class=Class:
PropertyPage_Enabled=Enabled
PropertyPage_function_value_errorMessage=Enter a function expression:
PropertyPage_lineNumber_errorMessage=Enter a line number greater than 0
DynamicPrintfPropertyPage_PrintString=&printf(
ToggleDynamicPrintfTargetFactory_description=Standard C/C++ Dynamic Printf type.