diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index 8e14e284b7c..c1123ba9344 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,11 @@ +2003-04-11 Mikhail Khodjaiants + Core support of function and method breakpoints. + * CDebugModel.java + * ICFunctionBreakpoint.java + * CDebugUtils.java + * CFunctionBreakpoint.java + * CDebugTarget.java + 2003-04-09 Mikhail Khodjaiants Core support of function breakpoints. * CDebugModel.java diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugModel.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugModel.java index 2ea8b85f68a..e0b548fab7e 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugModel.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugModel.java @@ -11,8 +11,8 @@ import java.util.HashMap; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.IFunction; +import org.eclipse.cdt.core.model.IMethod; import org.eclipse.cdt.core.model.ISourceRange; -import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.ICDIConfiguration; import org.eclipse.cdt.debug.core.cdi.ICDILocation; @@ -381,9 +381,9 @@ public class CDebugModel ICFunctionBreakpoint breakpoint = (ICFunctionBreakpoint)breakpoints[i]; if ( breakpoint.getMarker().getType().equals( markerType ) ) { - if ( breakpoint.getMarker().getResource().equals( getFunctionResource( function ) ) ) + if ( breakpoint.getMarker().getResource().equals( CDebugUtils.getFunctionResource( function ) ) ) { - if ( breakpoint.getFunction() != null && breakpoint.getFunction().equals( function.getElementName() ) ) + if ( breakpoint.getFunction() != null && breakpoint.getFunction().equals( CDebugUtils.getFunctionName( function ) ) ) { return breakpoint; } @@ -423,11 +423,75 @@ public class CDebugModel 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( ICFunctionBreakpoint.FUNCTION, function.getElementName() ); + attributes.put( ICFunctionBreakpoint.FUNCTION, CDebugUtils.getFunctionName( function ) ); attributes.put( ICBreakpoint.ENABLED, new Boolean( enabled ) ); attributes.put( ICBreakpoint.IGNORE_COUNT, new Integer( ignoreCount ) ); attributes.put( ICBreakpoint.CONDITION, condition ); - return new CFunctionBreakpoint( getFunctionResource( function ), attributes, add ); + return new CFunctionBreakpoint( CDebugUtils.getFunctionResource( function ), attributes, add ); + } + + public static ICFunctionBreakpoint methodBreakpointExists( IMethod method ) throws CoreException + { + String modelId = getPluginIdentifier(); + String markerType = CFunctionBreakpoint.getMarkerType(); + IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager(); + IBreakpoint[] breakpoints = manager.getBreakpoints( modelId ); + for ( int i = 0; i < breakpoints.length; i++ ) + { + if ( !( breakpoints[i] instanceof ICFunctionBreakpoint ) ) + { + continue; + } + ICFunctionBreakpoint breakpoint = (ICFunctionBreakpoint)breakpoints[i]; + if ( breakpoint.getMarker().getType().equals( markerType ) ) + { + if ( breakpoint.getMarker().getResource().equals( CDebugUtils.getMethodResource( method ) ) ) + { + if ( breakpoint.getFunction() != null && breakpoint.getFunction().equals( CDebugUtils.getMethodQualifiedName( method ) ) ) + { + return breakpoint; + } + } + } + } + return null; + } + + public static ICFunctionBreakpoint createMethodBreakpoint( IMethod method, + boolean enabled, + int ignoreCount, + String condition, + boolean add ) throws DebugException + { + HashMap attributes = new HashMap( 10 ); + attributes.put( ICBreakpoint.ID, getPluginIdentifier() ); + int lineNumber = -1; + int charStart = -1; + int charEnd = -1; + try + { + ISourceRange sourceRange = method.getSourceRange(); + if ( sourceRange != null ) + { + charStart = sourceRange.getStartPos(); + charEnd = charStart + sourceRange.getLength(); + // for now + if ( charEnd == 0 ) + lineNumber = sourceRange.getStartLine(); + } + } + catch( CModelException e ) + { + CDebugCorePlugin.log( e.getStatus() ); + } + 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( ICFunctionBreakpoint.FUNCTION, CDebugUtils.getMethodQualifiedName( method ) ); + attributes.put( ICBreakpoint.ENABLED, new Boolean( enabled ) ); + attributes.put( ICBreakpoint.IGNORE_COUNT, new Integer( ignoreCount ) ); + attributes.put( ICBreakpoint.CONDITION, condition ); + return new CFunctionBreakpoint( CDebugUtils.getMethodResource( method ), attributes, add ); } public static ICWatchpoint watchpointExists( IResource resource, boolean write, boolean read, String expression ) throws CoreException @@ -598,10 +662,4 @@ public class CDebugModel } } } - - private static IResource getFunctionResource( IFunction function ) - { - ITranslationUnit tu = function.getTranslationUnit(); - return ( tu != null ) ? tu.getResource() : function.getCProject().getProject(); - } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICFunctionBreakpoint.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICFunctionBreakpoint.java index b5ecf9eea4d..8cd39de5304 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICFunctionBreakpoint.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICFunctionBreakpoint.java @@ -39,4 +39,6 @@ public interface ICFunctionBreakpoint extends ICLineBreakpoint * on this breakpoint's underlying marker */ public void setFunction( String function ) throws CoreException; + + public String getFileName() throws CoreException; } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java index a6d45d0d5d9..994dcc660da 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java @@ -14,7 +14,11 @@ import org.apache.xml.serialize.Method; import org.apache.xml.serialize.OutputFormat; import org.apache.xml.serialize.Serializer; import org.apache.xml.serialize.SerializerFactory; +import org.eclipse.cdt.core.model.IFunction; +import org.eclipse.cdt.core.model.IMethod; +import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.debug.core.DebugPlugin; @@ -289,4 +293,47 @@ public class CDebugUtils serializer.asDOMSerializer().serialize( doc ); return s.toString( "UTF8" ); //$NON-NLS-1$ } + + + public static IResource getFunctionResource( IFunction function ) + { + ITranslationUnit tu = function.getTranslationUnit(); + return ( tu != null ) ? tu.getResource() : function.getCProject().getProject(); + } + + public static IResource getMethodResource( IMethod method ) + { + ITranslationUnit tu = method.getTranslationUnit(); + return ( tu != null ) ? tu.getResource() : method.getCProject().getProject(); + } + + public static String getFunctionName( IFunction function ) + { + StringBuffer name = new StringBuffer( function.getElementName() ); + if ( name.indexOf( "::" ) != -1 ) + { + String[] params = function.getParameterTypes(); + name.append( '(' ); + if ( params.length == 0 ) + { + name.append( "void" ); + } + else + { + for ( int i = 0; i < params.length; ++i ) + { + name.append( params[i] ); + if ( i != params.length - 1 ) + name.append( ',' ); + } + } + name.append( ')' ); + } + return name.toString(); + } + + public static String getMethodQualifiedName( IMethod method ) + { + return null; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CFunctionBreakpoint.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CFunctionBreakpoint.java index 3858037c519..1867216bc5a 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CFunctionBreakpoint.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CFunctionBreakpoint.java @@ -8,6 +8,7 @@ package org.eclipse.cdt.debug.internal.core.breakpoints; import java.util.Map; import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; @@ -92,4 +93,17 @@ public class CFunctionBreakpoint extends CBreakpoint implements ICFunctionBreakp { return C_FUNCTION_BREAKPOINT; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint#getFileName() + */ + public String getFileName() throws CoreException + { + IResource resource = ensureMarker().getResource(); + if ( resource instanceof IFile ) + { + return ((IFile)resource).getLocation().lastSegment(); + } + return null; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java index 65d80c26f99..67d73dd798a 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java @@ -1976,7 +1976,9 @@ public class CDebugTarget extends CDebugElement private synchronized ICDIBreakpoint setFunctionBreakpoint0( ICFunctionBreakpoint breakpoint ) throws CDIException, CoreException { ICDIBreakpointManager bm = getCDISession().getBreakpointManager(); - ICDILocation location = bm.createLocation( null, breakpoint.getFunction(), -1 ); + String function = breakpoint.getFunction(); + String fileName = ( function != null && function.indexOf( "::" ) == -1 ) ? breakpoint.getFileName() : null; + ICDILocation location = bm.createLocation( fileName, function, -1 ); ICDICondition condition = bm.createCondition( breakpoint.getIgnoreCount(), breakpoint.getCondition() ); ICDIBreakpoint cdiBreakpoint = bm.setLocationBreakpoint( ICDIBreakpoint.REGULAR, location, condition, null ); getBreakpoints().put( breakpoint, cdiBreakpoint );