Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Core support of function and method breakpoints

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/ChangeLog,v
retrieving revision 1.162
diff -u -r1.162 ChangeLog
--- ChangeLog 9 Apr 2003 22:01:39 -0000 1.162
+++ ChangeLog 11 Apr 2003 22:28:12 -0000
@@ -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
Index: src/org/eclipse/cdt/debug/core/CDebugModel.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugModel.java,v
retrieving revision 1.43
diff -u -r1.43 CDebugModel.java
--- src/org/eclipse/cdt/debug/core/CDebugModel.java 10 Apr 2003 22:09:26 -0000 1.43
+++ src/org/eclipse/cdt/debug/core/CDebugModel.java 11 Apr 2003 22:28:12 -0000
@@ -11,8 +11,8 @@
 
 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 @@
    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 @@
   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
@@ -597,11 +661,5 @@
                null ) );
    }
   }
- }
-
- private static IResource getFunctionResource( IFunction function )
- {
-  ITranslationUnit tu = function.getTranslationUnit();
-  return ( tu != null ) ? tu.getResource() : function.getCProject().getProject();
  }
 }
Index: src/org/eclipse/cdt/debug/core/model/ICFunctionBreakpoint.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICFunctionBreakpoint.java,v
retrieving revision 1.2
diff -u -r1.2 ICFunctionBreakpoint.java
--- src/org/eclipse/cdt/debug/core/model/ICFunctionBreakpoint.java 9 Apr 2003 22:01:39 -0000 1.2
+++ src/org/eclipse/cdt/debug/core/model/ICFunctionBreakpoint.java 11 Apr 2003 22:28:12 -0000
@@ -39,4 +39,6 @@
   *  on this breakpoint's underlying marker
   */
  public void setFunction( String function ) throws CoreException;

+ public String getFileName() throws CoreException;
 }
Index: src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java,v
retrieving revision 1.9
diff -u -r1.9 CDebugUtils.java
--- src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java 18 Feb 2003 19:24:08 -0000 1.9
+++ src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java 11 Apr 2003 22:28:12 -0000
@@ -14,7 +14,11 @@
 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;
@@ -288,5 +292,48 @@
   Serializer serializer = SerializerFactory.getSerializerFactory( Method.XML ).makeSerializer( new OutputStreamWriter( s, "UTF8" ), format );
   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;
  }
 }
Index: src/org/eclipse/cdt/debug/internal/core/breakpoints/CFunctionBreakpoint.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CFunctionBreakpoint.java,v
retrieving revision 1.7
diff -u -r1.7 CFunctionBreakpoint.java
--- src/org/eclipse/cdt/debug/internal/core/breakpoints/CFunctionBreakpoint.java 29 Jan 2003 22:19:59 -0000 1.7
+++ src/org/eclipse/cdt/debug/internal/core/breakpoints/CFunctionBreakpoint.java 11 Apr 2003 22:28:12 -0000
@@ -8,6 +8,7 @@
 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;
@@ -91,5 +92,18 @@
  public static String getMarkerType()
  {
   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;
  }
 }
Index: src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java,v
retrieving revision 1.93
diff -u -r1.93 CDebugTarget.java
--- src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java 9 Apr 2003 22:01:39 -0000 1.93
+++ src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java 11 Apr 2003 22:28:13 -0000
@@ -1976,7 +1976,9 @@
  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 );

Back to the top