Skip to main content

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

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/ChangeLog,v
retrieving revision 1.161
diff -u -r1.161 ChangeLog
--- ChangeLog 8 Apr 2003 15:51:08 -0000 1.161
+++ ChangeLog 9 Apr 2003 22:00:51 -0000
@@ -1,3 +1,9 @@
+2003-04-09 Mikhail Khodjaiants
+ Core support of function breakpoints.
+ * CDebugModel.java
+ * ICFunctionBreakpoint.java
+ * CDebugTarget.java
+
 2003-04-07 Mikhail Khodjaiants
  Changed the message text in the 'getStackDepth' method.
  * CThread.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.41
diff -u -r1.41 CDebugModel.java
--- src/org/eclipse/cdt/debug/core/CDebugModel.java 29 Jan 2003 22:19:59 -0000 1.41
+++ src/org/eclipse/cdt/debug/core/CDebugModel.java 9 Apr 2003 22:00:52 -0000
@@ -9,6 +9,10 @@
 import java.text.MessageFormat;
 import java.util.HashMap;
 
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.IFunction;
+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;
@@ -21,12 +25,14 @@
 import org.eclipse.cdt.debug.core.model.ICAddressBreakpoint;
 import org.eclipse.cdt.debug.core.model.ICBreakpoint;
 import org.eclipse.cdt.debug.core.model.ICDebugTargetType;
+import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint;
 import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
 import org.eclipse.cdt.debug.core.model.ICWatchpoint;
 import org.eclipse.cdt.debug.core.model.IFormattedMemoryBlock;
 import org.eclipse.cdt.debug.internal.core.CDebugUtils;
 import org.eclipse.cdt.debug.internal.core.ICDebugInternalConstants;
 import org.eclipse.cdt.debug.internal.core.breakpoints.CAddressBreakpoint;
+import org.eclipse.cdt.debug.internal.core.breakpoints.CFunctionBreakpoint;
 import org.eclipse.cdt.debug.internal.core.breakpoints.CLineBreakpoint;
 import org.eclipse.cdt.debug.internal.core.breakpoints.CWatchpoint;
 import org.eclipse.cdt.debug.internal.core.model.CDebugTarget;
@@ -352,6 +358,7 @@
   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( ICAddressBreakpoint.ADDRESS, Long.toString( address ) );
   attributes.put( ICBreakpoint.ENABLED, new Boolean( enabled ) );
   attributes.put( ICBreakpoint.IGNORE_COUNT, new Integer( ignoreCount ) );
@@ -359,6 +366,70 @@
   return new CAddressBreakpoint( resource, attributes, add );
  }
 
+ public static ICFunctionBreakpoint functionBreakpointExists( IFunction function ) 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( getFunctionResource( function ) ) )
+    {
+     if ( breakpoint.getFunction() != null && breakpoint.getFunction().equals( function.getElementName() ) )
+     {
+      return breakpoint;
+     }
+    }
+   }
+  }
+  return null;
+ }
+
+ public static ICFunctionBreakpoint createFunctionBreakpoint( IFunction function,
+                 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 = function.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, function.getElementName() );
+  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 );
+ }
+
  public static ICWatchpoint watchpointExists( IResource resource, boolean write, boolean read, String _expression_ ) throws CoreException
  {
   String modelId = getPluginIdentifier();
@@ -526,5 +597,11 @@
                null ) );
    }
   }
+ }
+
+ private static IResource getFunctionResource( IFunction function )
+ {
+  ITranslationUnit tu = function.getTranslationUnit();
+  return ( tu != null ) ? tu.getResource() : null;
  }
 }
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.1
diff -u -r1.1 ICFunctionBreakpoint.java
--- src/org/eclipse/cdt/debug/core/model/ICFunctionBreakpoint.java 2 Dec 2002 23:22:22 -0000 1.1
+++ src/org/eclipse/cdt/debug/core/model/ICFunctionBreakpoint.java 9 Apr 2003 22:00:53 -0000
@@ -16,6 +16,13 @@
 public interface ICFunctionBreakpoint extends ICLineBreakpoint
 {
  /**
+  * Breakpoint attribute storing the function this breakpoint suspends
+  * execution at (value <code>"org.eclipse.cdt.debug.core.function"</code>).
+  * This attribute is a <code>String</code>.
+  */
+ public static final String FUNCTION = "org.eclipse.cdt.debug.core.function"; //$NON-NLS-1$ 
+
+ /**
   * Returns the function this breakpoint suspends execution in.
   *
   * @return the function this breakpoint suspends execution in
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.92
diff -u -r1.92 CDebugTarget.java
--- src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java 7 Apr 2003 22:36:57 -0000 1.92
+++ src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java 9 Apr 2003 22:00:56 -0000
@@ -61,6 +61,7 @@
 import org.eclipse.cdt.debug.core.model.ICDebugTarget;
 import org.eclipse.cdt.debug.core.model.ICDebugTargetType;
 import org.eclipse.cdt.debug.core.model.ICExpressionEvaluator;
+import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint;
 import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
 import org.eclipse.cdt.debug.core.model.ICWatchpoint;
 import org.eclipse.cdt.debug.core.model.IDebuggerProcessSupport;
@@ -697,7 +698,11 @@
   {
    try
    {
-    if ( breakpoint instanceof ICAddressBreakpoint )
+    if ( breakpoint instanceof ICFunctionBreakpoint )
+    {
+     setFunctionBreakpoint( (ICFunctionBreakpoint)breakpoint );
+    }
+    else if ( breakpoint instanceof ICAddressBreakpoint )
     {
      if ( supportsAddressBreakpoint( (ICAddressBreakpoint)breakpoint ) )
       setAddressBreakpoint( (ICAddressBreakpoint)breakpoint );
@@ -1933,6 +1938,45 @@
  {
   ICDIBreakpointManager bm = getCDISession().getBreakpointManager();
   ICDILocation location = bm.createLocation( Long.parseLong( breakpoint.getAddress() ) );
+  ICDICondition condition = bm.createCondition( breakpoint.getIgnoreCount(), breakpoint.getCondition() );
+  ICDIBreakpoint cdiBreakpoint = bm.setLocationBreakpoint( ICDIBreakpoint.REGULAR, location, condition, null );
+  getBreakpoints().put( breakpoint, cdiBreakpoint );
+  return cdiBreakpoint;
+ }

+ private void setFunctionBreakpoint( ICFunctionBreakpoint breakpoint ) throws DebugException
+ {
+  try
+  {
+   ICDIBreakpoint cdiBreakpoint = (ICDIBreakpoint)getBreakpoints().get( breakpoint );
+   if ( cdiBreakpoint == null )
+   {
+    cdiBreakpoint = setFunctionBreakpoint0( breakpoint );
+   }
+   ((CBreakpoint)breakpoint).incrementInstallCount();
+   if ( !breakpoint.isEnabled() )
+   {
+    cdiBreakpoint.setEnabled( false );
+   }
+  }
+  catch( CoreException ce )
+  {
+   requestFailed( "Operation failed. Reason: ", ce );
+  }
+  catch( CDIException e )
+  {
+   requestFailed( "Operation failed. Reason: ", e );
+  }
+  catch( NumberFormatException e )
+  {
+   requestFailed( "Operation failed. Reason: ", e );
+  }
+ }
+  
+ private synchronized ICDIBreakpoint setFunctionBreakpoint0( ICFunctionBreakpoint breakpoint ) throws CDIException, CoreException
+ {
+  ICDIBreakpointManager bm = getCDISession().getBreakpointManager();
+  ICDILocation location = bm.createLocation( null, breakpoint.getFunction(), -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