mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Core support of function and method breakpoints
This commit is contained in:
parent
0c47e3bed5
commit
ee742625a1
6 changed files with 143 additions and 12 deletions
|
@ -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
|
2003-04-09 Mikhail Khodjaiants
|
||||||
Core support of function breakpoints.
|
Core support of function breakpoints.
|
||||||
* CDebugModel.java
|
* CDebugModel.java
|
||||||
|
|
|
@ -11,8 +11,8 @@ import java.util.HashMap;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.IFunction;
|
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.ISourceRange;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
|
||||||
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
||||||
import org.eclipse.cdt.debug.core.cdi.ICDIConfiguration;
|
import org.eclipse.cdt.debug.core.cdi.ICDIConfiguration;
|
||||||
import org.eclipse.cdt.debug.core.cdi.ICDILocation;
|
import org.eclipse.cdt.debug.core.cdi.ICDILocation;
|
||||||
|
@ -381,9 +381,9 @@ public class CDebugModel
|
||||||
ICFunctionBreakpoint breakpoint = (ICFunctionBreakpoint)breakpoints[i];
|
ICFunctionBreakpoint breakpoint = (ICFunctionBreakpoint)breakpoints[i];
|
||||||
if ( breakpoint.getMarker().getType().equals( markerType ) )
|
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;
|
return breakpoint;
|
||||||
}
|
}
|
||||||
|
@ -423,11 +423,75 @@ public class CDebugModel
|
||||||
attributes.put( IMarker.CHAR_START, new Integer( charStart ) );
|
attributes.put( IMarker.CHAR_START, new Integer( charStart ) );
|
||||||
attributes.put( IMarker.CHAR_END, new Integer( charEnd ) );
|
attributes.put( IMarker.CHAR_END, new Integer( charEnd ) );
|
||||||
attributes.put( IMarker.LINE_NUMBER, new Integer( lineNumber ) );
|
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.ENABLED, new Boolean( enabled ) );
|
||||||
attributes.put( ICBreakpoint.IGNORE_COUNT, new Integer( ignoreCount ) );
|
attributes.put( ICBreakpoint.IGNORE_COUNT, new Integer( ignoreCount ) );
|
||||||
attributes.put( ICBreakpoint.CONDITION, condition );
|
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
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,4 +39,6 @@ public interface ICFunctionBreakpoint extends ICLineBreakpoint
|
||||||
* on this breakpoint's underlying marker
|
* on this breakpoint's underlying marker
|
||||||
*/
|
*/
|
||||||
public void setFunction( String function ) throws CoreException;
|
public void setFunction( String function ) throws CoreException;
|
||||||
|
|
||||||
|
public String getFileName() throws CoreException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,11 @@ import org.apache.xml.serialize.Method;
|
||||||
import org.apache.xml.serialize.OutputFormat;
|
import org.apache.xml.serialize.OutputFormat;
|
||||||
import org.apache.xml.serialize.Serializer;
|
import org.apache.xml.serialize.Serializer;
|
||||||
import org.apache.xml.serialize.SerializerFactory;
|
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.IProject;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.debug.core.DebugPlugin;
|
import org.eclipse.debug.core.DebugPlugin;
|
||||||
|
@ -289,4 +293,47 @@ public class CDebugUtils
|
||||||
serializer.asDOMSerializer().serialize( doc );
|
serializer.asDOMSerializer().serialize( doc );
|
||||||
return s.toString( "UTF8" ); //$NON-NLS-1$
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ package org.eclipse.cdt.debug.internal.core.breakpoints;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint;
|
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.IMarker;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -92,4 +93,17 @@ public class CFunctionBreakpoint extends CBreakpoint implements ICFunctionBreakp
|
||||||
{
|
{
|
||||||
return C_FUNCTION_BREAKPOINT;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1976,7 +1976,9 @@ public class CDebugTarget extends CDebugElement
|
||||||
private synchronized ICDIBreakpoint setFunctionBreakpoint0( ICFunctionBreakpoint breakpoint ) throws CDIException, CoreException
|
private synchronized ICDIBreakpoint setFunctionBreakpoint0( ICFunctionBreakpoint breakpoint ) throws CDIException, CoreException
|
||||||
{
|
{
|
||||||
ICDIBreakpointManager bm = getCDISession().getBreakpointManager();
|
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() );
|
ICDICondition condition = bm.createCondition( breakpoint.getIgnoreCount(), breakpoint.getCondition() );
|
||||||
ICDIBreakpoint cdiBreakpoint = bm.setLocationBreakpoint( ICDIBreakpoint.REGULAR, location, condition, null );
|
ICDIBreakpoint cdiBreakpoint = bm.setLocationBreakpoint( ICDIBreakpoint.REGULAR, location, condition, null );
|
||||||
getBreakpoints().put( breakpoint, cdiBreakpoint );
|
getBreakpoints().put( breakpoint, cdiBreakpoint );
|
||||||
|
|
Loading…
Add table
Reference in a new issue