Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Khodjaiants2005-02-03 20:13:18 +0000
committerMikhail Khodjaiants2005-02-03 20:13:18 +0000
commit00539a0ad363975f78ff570bb9a556393a9163ec (patch)
treea74d1dec8cf1123305e70df16735ea3ffa9b8c9d
parent53de71abf42aa7eae37379180e5355ab5b21f819 (diff)
downloadorg.eclipse.cdt-00539a0ad363975f78ff570bb9a556393a9163ec.tar.gz
org.eclipse.cdt-00539a0ad363975f78ff570bb9a556393a9163ec.tar.xz
org.eclipse.cdt-00539a0ad363975f78ff570bb9a556393a9163ec.zip
Fix for bug 84187: "Toggle Watchpoint" and "Toggle Method Breakpoint" don't work with C editor.
-rw-r--r--debug/org.eclipse.cdt.debug.core/ChangeLog15
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java48
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICWatchpoint.java3
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CWatchpoint.java45
-rw-r--r--debug/org.eclipse.cdt.debug.ui/ChangeLog10
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AbstractBreakpointRulerAction.java17
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java242
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/propertypages/CBreakpointPropertyPage.java46
8 files changed, 279 insertions, 147 deletions
diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog
index 562b6d6c740..8f576ef2f9c 100644
--- a/debug/org.eclipse.cdt.debug.core/ChangeLog
+++ b/debug/org.eclipse.cdt.debug.core/ChangeLog
@@ -1,3 +1,18 @@
+2005-02-03 Mikhail Khodjaiants
+ Fix for bug 84187: "Toggle Watchpoint" and "Toggle Method Breakpoint" don't work with C editor.
+ ICWatchpoint should extend ILineBreakpoint to allow watchpoints to be shown in editors.
+ * ICWatchpoint.java
+ * CWatchpoint.java
+
+2005-02-03 Mikhail Khodjaiants
+ Fix for bug 84187: "Toggle Watchpoint" and "Toggle Method Breakpoint" don't work with C editor.
+ * CDIDebugModel.java
+
+2005-02-02 Mikhail Khodjaiants
+ Fix for bug 84187: "Toggle Watchpoint" and "Toggle Method Breakpoint" don't work with C editor.
+ Added new "createWatchpoint" method that accepts position information.
+ * CDIDebugModel.java
+
2005-01-27 Mikhail Khodjaiants
Fix for bug 82825: "Internal" error when trying to launch a debug session.
* CDebugTarget.java
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java
index 2327eb3a86c..fb205fcdbd2 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java
@@ -195,7 +195,6 @@ public class CDIDebugModel {
attributes.put( IMarker.CHAR_START, new Integer( 0 ) );
attributes.put( IMarker.CHAR_END, new Integer( 0 ) );
attributes.put( IMarker.LINE_NUMBER, new Integer( -1 ) );
- attributes.put( IMarker.LINE_NUMBER, new Integer( -1 ) );
attributes.put( ICLineBreakpoint.ADDRESS, address.toHexAddressString() );
attributes.put( IBreakpoint.ENABLED, new Boolean( enabled ) );
attributes.put( ICBreakpoint.IGNORE_COUNT, new Integer( ignoreCount ) );
@@ -240,6 +239,53 @@ public class CDIDebugModel {
}
/**
+ * Creates and returns a watchpoint for the source defined by the given
+ * source handle, at the given expression. The marker associated with the
+ * watchpoint will be created on the specified resource.
+ *
+ * @param sourceHandle the handle to the watchpoint source
+ * @param resource the resource on which to create the associated watchpoint marker
+ * @param charStart the first character index associated with the watchpoint, or
+ * -1 if unspecified, in the source file in which the watchpoint
+ * is set
+ * @param charEnd the last character index associated with the watchpoint, or -1
+ * if unspecified, in the source file in which the watchpoint is
+ * set
+ * @param lineNumber the lineNumber on which the watchpoint is set, or -1 if
+ * unspecified - line numbers are 1 based, associated with the
+ * source file in which the watchpoint is set
+ * @param writeAccess whether this is write watchpoint
+ * @param readAccess whether this is read watchpoint
+ * @param expression the expression on which the watchpoint is set
+ * @param enabled whether to enable or disable this breakpoint
+ * @param ignoreCount the number of times this breakpoint will be ignored
+ * @param condition the breakpoint condition
+ * @param register whether to add this breakpoint to the breakpoint manager
+ * @return a watchpoint
+ * @throws CoreException if this method fails. Reasons include:
+ * <ul>
+ * <li>Failure creating underlying marker. The exception's
+ * status contains the underlying exception responsible for the
+ * failure.</li>
+ * </ul>
+ */
+ public static ICWatchpoint createWatchpoint( String sourceHandle, IResource resource, int charStart, int charEnd, int lineNumber, boolean writeAccess, boolean readAccess, String expression, boolean enabled, int ignoreCount, String condition, boolean register ) throws CoreException {
+ HashMap attributes = new HashMap( 10 );
+ attributes.put( IBreakpoint.ID, getPluginIdentifier() );
+ attributes.put( IMarker.CHAR_START, new Integer( charStart ) );
+ attributes.put( IMarker.CHAR_END, new Integer( charEnd ) );
+ attributes.put( IMarker.LINE_NUMBER, new Integer( lineNumber ) );
+ attributes.put( IBreakpoint.ENABLED, new Boolean( enabled ) );
+ attributes.put( ICBreakpoint.IGNORE_COUNT, new Integer( ignoreCount ) );
+ attributes.put( ICBreakpoint.CONDITION, condition );
+ attributes.put( ICBreakpoint.SOURCE_HANDLE, sourceHandle );
+ attributes.put( ICWatchpoint.EXPRESSION, expression );
+ attributes.put( ICWatchpoint.READ, new Boolean( readAccess ) );
+ attributes.put( ICWatchpoint.WRITE, new Boolean( writeAccess ) );
+ return new CWatchpoint( resource, attributes, register );
+ }
+
+ /**
* Creates and returns a breakpoint for the function defined by the given
* name. The marker associated with the breakpoint will be created on the
* specified resource.
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICWatchpoint.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICWatchpoint.java
index ab3d07f9f7a..b125727b267 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICWatchpoint.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICWatchpoint.java
@@ -11,11 +11,12 @@
package org.eclipse.cdt.debug.core.model;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.model.ILineBreakpoint;
/**
* A watchpoint specific to the C/C++ debug model.
*/
-public interface ICWatchpoint extends ICBreakpoint {
+public interface ICWatchpoint extends ICBreakpoint, ILineBreakpoint {
/**
* Watchpoint attribute storing the expression associated with this
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CWatchpoint.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CWatchpoint.java
index 5a3b59a16ab..c9750725d8c 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CWatchpoint.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CWatchpoint.java
@@ -12,8 +12,8 @@ package org.eclipse.cdt.debug.internal.core.breakpoints;
import java.text.MessageFormat;
import java.util.Map;
-
import org.eclipse.cdt.debug.core.model.ICWatchpoint;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
@@ -37,28 +37,22 @@ public class CWatchpoint extends CBreakpoint implements ICWatchpoint {
super( resource, getMarkerType(), attributes, add );
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.debug.core.ICWatchpoint#isWriteType()
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.model.ICWatchpoint#isWriteType()
*/
public boolean isWriteType() throws CoreException {
return ensureMarker().getAttribute( WRITE, true );
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.debug.core.ICWatchpoint#isReadType()
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.model.ICWatchpoint#isReadType()
*/
public boolean isReadType() throws CoreException {
return ensureMarker().getAttribute( READ, false );
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.debug.core.ICWatchpoint#getExpression()
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.model.ICWatchpoint#getExpression()
*/
public String getExpression() throws CoreException {
return ensureMarker().getAttribute( EXPRESSION, "" ); //$NON-NLS-1$
@@ -71,9 +65,7 @@ public class CWatchpoint extends CBreakpoint implements ICWatchpoint {
return C_WATCHPOINT;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.core.breakpoints.CBreakpoint#getMarkerMessage()
*/
protected String getMarkerMessage() throws CoreException {
@@ -99,4 +91,25 @@ public class CWatchpoint extends CBreakpoint implements ICWatchpoint {
sb.append( getConditionText() );
return sb.toString();
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ILineBreakpoint#getLineNumber()
+ */
+ public int getLineNumber() throws CoreException {
+ return ensureMarker().getAttribute( IMarker.LINE_NUMBER, -1 );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ILineBreakpoint#getCharStart()
+ */
+ public int getCharStart() throws CoreException {
+ return ensureMarker().getAttribute( IMarker.CHAR_START, -1 );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ILineBreakpoint#getCharEnd()
+ */
+ public int getCharEnd() throws CoreException {
+ return ensureMarker().getAttribute( IMarker.CHAR_END, -1 );
+ }
} \ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog
index 48e86bc28cf..e8c0f09d073 100644
--- a/debug/org.eclipse.cdt.debug.ui/ChangeLog
+++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog
@@ -1,3 +1,13 @@
+2005-02-03 Mikhail Khodjaiants
+ Fix for bug 84187: "Toggle Watchpoint" and "Toggle Method Breakpoint" don't work with C editor.
+ ICWatchpoint should extend ILineBreakpoint to allow watchpoints to be shown in editors.
+ * AbstractBreakpointRulerAction.java
+ * CBreakpointPropertyPage.java
+
+2005-02-02 Mikhail Khodjaiants
+ Fix for bug 84187: "Toggle Watchpoint" and "Toggle Method Breakpoint" don't work with C editor.
+ * ToggleBreakpointAdapter.java
+
2005-02-01 Mikhail Khodjaiants
Fix for bug 84165: Resurrect the "Add Watchpoint (C/C++)" Code.
* plugin.properties
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AbstractBreakpointRulerAction.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AbstractBreakpointRulerAction.java
index ef83a0448d9..97368972ee0 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AbstractBreakpointRulerAction.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AbstractBreakpointRulerAction.java
@@ -11,13 +11,12 @@
package org.eclipse.cdt.debug.internal.ui.actions;
import java.util.Iterator;
-
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
-import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
import org.eclipse.cdt.debug.internal.ui.views.disassembly.DisassemblyView;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IBreakpoint;
+import org.eclipse.debug.core.model.ILineBreakpoint;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
@@ -47,10 +46,10 @@ public abstract class AbstractBreakpointRulerAction extends Action implements IU
IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints( CDebugCorePlugin.getUniqueIdentifier() );
for( int i = 0; i < breakpoints.length; i++ ) {
IBreakpoint breakpoint = breakpoints[i];
- if ( breakpoint instanceof ICLineBreakpoint ) {
- ICLineBreakpoint cBreakpoint = (ICLineBreakpoint)breakpoint;
- if ( breakpointAtRulerLine( cBreakpoint ) ) {
- return cBreakpoint;
+ if ( breakpoint instanceof ILineBreakpoint ) {
+ ILineBreakpoint lineBreakpoint = (ILineBreakpoint)breakpoint;
+ if ( breakpointAtRulerLine( lineBreakpoint ) ) {
+ return lineBreakpoint;
}
}
}
@@ -80,13 +79,13 @@ public abstract class AbstractBreakpointRulerAction extends Action implements IU
fBreakpoint = breakpoint;
}
- protected boolean breakpointAtRulerLine( ICLineBreakpoint cBreakpoint ) {
+ protected boolean breakpointAtRulerLine( ILineBreakpoint cBreakpoint ) {
int lineNumber = getBreakpointLine( cBreakpoint );
int rulerLine = getInfo().getLineOfLastMouseButtonActivity();
return ( rulerLine == lineNumber );
}
- private int getBreakpointLine( ICLineBreakpoint breakpoint ) {
+ private int getBreakpointLine( ILineBreakpoint breakpoint ) {
if ( getTargetPart() instanceof ISaveablePart && ((ISaveablePart)getTargetPart()).isDirty() ) {
try {
return breakpoint.getLineNumber();
@@ -112,7 +111,7 @@ public abstract class AbstractBreakpointRulerAction extends Action implements IU
return -1;
}
- private Position getBreakpointPosition( ICLineBreakpoint breakpoint ) {
+ private Position getBreakpointPosition( ILineBreakpoint breakpoint ) {
IAnnotationModel model = getAnnotationModel();
if ( model != null ) {
Iterator it = model.getAnnotationIterator();
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java
index bd5894ef543..5293dc8a849 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java
@@ -12,6 +12,7 @@ package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.core.IAddress;
import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IDeclaration;
import org.eclipse.cdt.core.model.IFunction;
@@ -28,6 +29,7 @@ import org.eclipse.cdt.debug.internal.ui.views.disassembly.DisassemblyEditorInpu
import org.eclipse.cdt.debug.internal.ui.views.disassembly.DisassemblyView;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.debug.ui.ICDebugUIConstants;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
@@ -162,48 +164,30 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
* @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
*/
public void toggleMethodBreakpoints( IWorkbenchPart part, ISelection selection ) throws CoreException {
- if ( selection instanceof IStructuredSelection ) {
- IStructuredSelection ss = (IStructuredSelection)selection;
- if ( ss.size() == 1 && (ss.getFirstElement() instanceof IFunction || ss.getFirstElement() instanceof IMethod) ) {
- IDeclaration declaration = (IDeclaration)ss.getFirstElement();
- String sourceHandle = getSourceHandle( declaration );
- IResource resource = getElementResource( declaration );
- String functionName = ( declaration instanceof IFunction ) ? getFunctionName( (IFunction)declaration ) : getMethodName( (IMethod)declaration );
- ICFunctionBreakpoint breakpoint = CDIDebugModel.functionBreakpointExists( sourceHandle, resource, functionName );
- if ( breakpoint != null ) {
- DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( breakpoint, true );
- }
- else {
- int lineNumber = -1;
- int charStart = -1;
- int charEnd = -1;
- try {
- ISourceRange sourceRange = declaration.getSourceRange();
- if ( sourceRange != null ) {
- charStart = sourceRange.getStartPos();
- charEnd = charStart + sourceRange.getLength();
- if ( charEnd <= 0 ) {
- charStart = -1;
- charEnd = -1;
+ if ( selection instanceof ITextSelection ) {
+ String text = ((ITextSelection)selection).getText();
+ if ( text != null ) {
+ IResource resource = getResource( part );
+ if ( resource instanceof IFile ) {
+ ITranslationUnit tu = getTranslationUnit( (IFile)resource );
+ if ( tu != null ) {
+ try {
+ ICElement element = tu.getElement( text.trim() );
+ if ( element instanceof IFunction || element instanceof IMethod ) {
+ toggleMethodBreakpoints0( (IDeclaration)element );
}
- lineNumber = sourceRange.getStartLine();
+ }
+ catch( CModelException e ) {
}
}
- catch( CModelException e ) {
- DebugPlugin.log( e );
- }
- CDIDebugModel.createFunctionBreakpoint( sourceHandle,
- resource,
- functionName,
- charStart,
- charEnd,
- lineNumber,
- true,
- 0,
- "", //$NON-NLS-1$
- true );
}
}
+ }
+ else if ( selection instanceof IStructuredSelection ) {
+ IStructuredSelection ss = (IStructuredSelection)selection;
+ if ( ss.size() == 1 && (ss.getFirstElement() instanceof IFunction || ss.getFirstElement() instanceof IMethod) ) {
+ toggleMethodBreakpoints0( (IDeclaration)ss.getFirstElement() );
+ }
}
}
@@ -211,7 +195,24 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
* @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
*/
public boolean canToggleMethodBreakpoints( IWorkbenchPart part, ISelection selection ) {
- if ( selection instanceof IStructuredSelection ) {
+ if ( selection instanceof ITextSelection ) {
+ String text = ((ITextSelection)selection).getText();
+ if ( text != null ) {
+ IResource resource = getResource( part );
+ if ( resource instanceof IFile ) {
+ ITranslationUnit tu = getTranslationUnit( (IFile)resource );
+ if ( tu != null ) {
+ try {
+ ICElement element = tu.getElement( text.trim() );
+ return ( element instanceof IFunction || element instanceof IMethod );
+ }
+ catch( CModelException e ) {
+ }
+ }
+ }
+ }
+ }
+ else if ( selection instanceof IStructuredSelection ) {
IStructuredSelection ss = (IStructuredSelection)selection;
if ( ss.size() == 1 ) {
return ( ss.getFirstElement() instanceof IFunction || ss.getFirstElement() instanceof IMethod );
@@ -224,81 +225,59 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
* @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
*/
public void toggleWatchpoints( IWorkbenchPart part, ISelection selection ) throws CoreException {
- if ( selection instanceof IStructuredSelection ) {
+ if ( selection instanceof ITextSelection ) {
+ String text = ((ITextSelection)selection).getText();
+ if ( text != null ) {
+ IResource resource = getResource( part );
+ if ( resource instanceof IFile ) {
+ ITranslationUnit tu = getTranslationUnit( (IFile)resource );
+ if ( tu != null ) {
+ try {
+ ICElement element = tu.getElement( text.trim() );
+ if ( element instanceof IVariable ) {
+ toggleVariableWatchpoint( part, (IVariable)element );
+ }
+ }
+ catch( CModelException e ) {
+ }
+ }
+ }
+ }
+ }
+ else if ( selection instanceof IStructuredSelection ) {
IStructuredSelection ss = (IStructuredSelection)selection;
if ( ss.size() == 1 && ss.getFirstElement() instanceof IVariable ) {
toggleVariableWatchpoint( part, (IVariable)ss.getFirstElement() );
}
}
-// String errorMessage = null;
-// if ( part instanceof IEditorPart ) {
-// IEditorPart editorPart = (IEditorPart)part;
-// IEditorInput input = editorPart.getEditorInput();
-// if ( input == null ) {
-// errorMessage = ActionMessages.getString( "ToggleBreakpointAdapter.Empty_editor_2" ); //$NON-NLS-1$
-// }
-// else {
-// ITextEditor textEditor = (ITextEditor)editorPart;
-// IDocument document = textEditor.getDocumentProvider().getDocument( input );
-// if ( document == null ) {
-// errorMessage = ActionMessages.getString( "ToggleBreakpointAdapter.Missing_document_2" ); //$NON-NLS-1$
-// }
-// else {
-// IResource resource = getResource( textEditor );
-// if ( resource == null ) {
-// errorMessage = ActionMessages.getString( "ToggleBreakpointAdapter.Missing_resource_2" ); //$NON-NLS-1$
-// }
-// else {
-// if ( !(resource instanceof IWorkspaceRoot) )
-// resource = resource.getProject();
-// String expression = ( selection instanceof TextSelection ) ? ((TextSelection)selection).getText().trim() : ""; //$NON-NLS-1$
-// String sourceHandle = getSourceHandle( input );
-// ICWatchpoint watchpoint = CDIDebugModel.watchpointExists( sourceHandle, resource, expression );
-// if ( watchpoint != null ) {
-// DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( watchpoint, true );
-// }
-// else {
-// AddWatchpointDialog dlg = new AddWatchpointDialog( textEditor.getSite().getShell(), true, false, expression );
-// if ( dlg.open() != Window.OK )
-// return;
-// expression = dlg.getExpression();
-// WatchpointExpressionVerifier wev = new WatchpointExpressionVerifier();
-// if ( !wev.isValidExpression( document, expression ) ) {
-// errorMessage = ActionMessages.getString( "ToggleBreakpointAdapter.Invalid_expression_1" ) + expression; //$NON-NLS-1$
-// }
-// else {
-// CDIDebugModel.createWatchpoint( sourceHandle,
-// resource,
-// dlg.getWriteAccess(),
-// dlg.getReadAccess(),
-// expression,
-// true,
-// 0,
-// "", //$NON-NLS-1$
-// true );
-// }
-// }
-// return;
-// }
-// }
-// }
-// }
-// throw new CoreException( new Status( IStatus.ERROR, CDebugUIPlugin.getUniqueIdentifier(), ICDebugUIConstants.INTERNAL_ERROR, errorMessage, null ) );
}
/* (non-Javadoc)
* @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
*/
public boolean canToggleWatchpoints( IWorkbenchPart part, ISelection selection ) {
- if ( selection instanceof IStructuredSelection ) {
+ if ( selection instanceof ITextSelection ) {
+ String text = ((ITextSelection)selection).getText();
+ if ( text != null ) {
+ IResource resource = getResource( part );
+ if ( resource instanceof IFile ) {
+ ITranslationUnit tu = getTranslationUnit( (IFile)resource );
+ if ( tu != null ) {
+ try {
+ return ( tu.getElement( text.trim() ) instanceof IVariable );
+ }
+ catch( CModelException e ) {
+ }
+ }
+ }
+ }
+ }
+ else if ( selection instanceof IStructuredSelection ) {
IStructuredSelection ss = (IStructuredSelection)selection;
if ( ss.size() == 1 ) {
return ( ss.getFirstElement() instanceof IVariable );
}
}
-// if ( selection instanceof ITextSelection ) {
-// return true;
-// }
return false;
}
@@ -353,8 +332,29 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
if ( dlg.open() != Window.OK )
return;
expression = dlg.getExpression();
+ int lineNumber = -1;
+ int charStart = -1;
+ int charEnd = -1;
+ try {
+ ISourceRange sourceRange = variable.getSourceRange();
+ if ( sourceRange != null ) {
+ charStart = sourceRange.getStartPos();
+ charEnd = charStart + sourceRange.getLength();
+ if ( charEnd <= 0 ) {
+ charStart = -1;
+ charEnd = -1;
+ }
+ lineNumber = sourceRange.getStartLine();
+ }
+ }
+ catch( CModelException e ) {
+ DebugPlugin.log( e );
+ }
CDIDebugModel.createWatchpoint( sourceHandle,
resource,
+ charStart,
+ charEnd,
+ lineNumber,
dlg.getWriteAccess(),
dlg.getReadAccess(),
expression,
@@ -417,4 +417,52 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
private String getVariableName( IVariable variable ) {
return variable.getElementName();
}
+
+ private ITranslationUnit getTranslationUnit( IFile file ) {
+ Object element = CoreModel.getDefault().create( file );
+ if ( element instanceof ITranslationUnit ) {
+ return (ITranslationUnit)element;
+ }
+ return null;
+ }
+
+ private void toggleMethodBreakpoints0( IDeclaration declaration ) throws CoreException {
+ String sourceHandle = getSourceHandle( declaration );
+ IResource resource = getElementResource( declaration );
+ String functionName = ( declaration instanceof IFunction ) ? getFunctionName( (IFunction)declaration ) : getMethodName( (IMethod)declaration );
+ ICFunctionBreakpoint breakpoint = CDIDebugModel.functionBreakpointExists( sourceHandle, resource, functionName );
+ if ( breakpoint != null ) {
+ DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( breakpoint, true );
+ }
+ else {
+ int lineNumber = -1;
+ int charStart = -1;
+ int charEnd = -1;
+ try {
+ ISourceRange sourceRange = declaration.getSourceRange();
+ if ( sourceRange != null ) {
+ charStart = sourceRange.getStartPos();
+ charEnd = charStart + sourceRange.getLength();
+ if ( charEnd <= 0 ) {
+ charStart = -1;
+ charEnd = -1;
+ }
+ lineNumber = sourceRange.getStartLine();
+ }
+ }
+ catch( CModelException e ) {
+ DebugPlugin.log( e );
+ }
+ CDIDebugModel.createFunctionBreakpoint( sourceHandle,
+ resource,
+ functionName,
+ charStart,
+ charEnd,
+ lineNumber,
+ true,
+ 0,
+ "", //$NON-NLS-1$
+ true );
+ }
+ }
}
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/propertypages/CBreakpointPropertyPage.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/propertypages/CBreakpointPropertyPage.java
index c04843f626e..6428175d7f3 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/propertypages/CBreakpointPropertyPage.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/propertypages/CBreakpointPropertyPage.java
@@ -301,6 +301,29 @@ public class CBreakpointPropertyPage extends FieldEditorPreferencePage implement
addField( createLabelEditor( getFieldEditorParent(), PropertyPageMessages.getString( "CBreakpointPropertyPage.5" ), address ) ); //$NON-NLS-1$
}
}
+ else if ( breakpoint instanceof ICWatchpoint ) {
+ ICWatchpoint watchpoint = (ICWatchpoint)breakpoint;
+ String type = ""; //$NON-NLS-1$
+ String expression = ""; //$NON-NLS-1$
+ try {
+ if ( watchpoint.isReadType() && !watchpoint.isWriteType() )
+ type = PropertyPageMessages.getString( "CBreakpointPropertyPage.11" ); //$NON-NLS-1$
+ else if ( !watchpoint.isReadType() && watchpoint.isWriteType() )
+ type = PropertyPageMessages.getString( "CBreakpointPropertyPage.12" ); //$NON-NLS-1$
+ else
+ type = PropertyPageMessages.getString( "CBreakpointPropertyPage.13" ); //$NON-NLS-1$
+ expression = watchpoint.getExpression();
+ }
+ catch( CoreException ce ) {
+ CDebugUIPlugin.log( ce );
+ }
+ addField( createLabelEditor( getFieldEditorParent(), PropertyPageMessages.getString( "CBreakpointPropertyPage.18" ), type ) ); //$NON-NLS-1$
+ String projectName = breakpoint.getMarker().getResource().getLocation().toOSString();
+ if ( projectName != null ) {
+ addField( createLabelEditor( getFieldEditorParent(), PropertyPageMessages.getString( "CBreakpointPropertyPage.10" ), projectName ) ); //$NON-NLS-1$
+ }
+ addField( createLabelEditor( getFieldEditorParent(), PropertyPageMessages.getString( "CBreakpointPropertyPage.14" ), expression ) ); //$NON-NLS-1$
+ }
else if ( breakpoint instanceof ILineBreakpoint ) {
addField( createLabelEditor( getFieldEditorParent(), PropertyPageMessages.getString( "CBreakpointPropertyPage.18" ), PropertyPageMessages.getString( "CBreakpointPropertyPage.8" ) ) ); //$NON-NLS-1$//$NON-NLS-2$
String fileName = null;
@@ -327,29 +350,6 @@ public class CBreakpointPropertyPage extends FieldEditorPreferencePage implement
addField( createLabelEditor( getFieldEditorParent(), PropertyPageMessages.getString( "CBreakpointPropertyPage.9" ), lineNumber.toString() ) ); //$NON-NLS-1$
}
}
- else if ( breakpoint instanceof ICWatchpoint ) {
- ICWatchpoint watchpoint = (ICWatchpoint)breakpoint;
- String type = ""; //$NON-NLS-1$
- String expression = ""; //$NON-NLS-1$
- try {
- if ( watchpoint.isReadType() && !watchpoint.isWriteType() )
- type = PropertyPageMessages.getString( "CBreakpointPropertyPage.11" ); //$NON-NLS-1$
- else if ( !watchpoint.isReadType() && watchpoint.isWriteType() )
- type = PropertyPageMessages.getString( "CBreakpointPropertyPage.12" ); //$NON-NLS-1$
- else
- type = PropertyPageMessages.getString( "CBreakpointPropertyPage.13" ); //$NON-NLS-1$
- expression = watchpoint.getExpression();
- }
- catch( CoreException ce ) {
- CDebugUIPlugin.log( ce );
- }
- addField( createLabelEditor( getFieldEditorParent(), PropertyPageMessages.getString( "CBreakpointPropertyPage.18" ), type ) ); //$NON-NLS-1$
- String projectName = breakpoint.getMarker().getResource().getLocation().toOSString();
- if ( projectName != null ) {
- addField( createLabelEditor( getFieldEditorParent(), PropertyPageMessages.getString( "CBreakpointPropertyPage.10" ), projectName ) ); //$NON-NLS-1$
- }
- addField( createLabelEditor( getFieldEditorParent(), PropertyPageMessages.getString( "CBreakpointPropertyPage.14" ), expression ) ); //$NON-NLS-1$
- }
}
protected void createEnabledField( Composite parent ) {

Back to the top