From c52732cf99918e067d925aa0a85fe4ddaa04ae02 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Tue, 3 Sep 2002 14:37:25 +0000 Subject: [PATCH] More implementation of breakpoints. --- .../core/breakpoints/CBreakpoint.java | 30 ++++++++ .../internal/core/model/CDebugTarget.java | 68 ++++++++++++++++++- 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CBreakpoint.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CBreakpoint.java index 4eb3a7a081b..035e637f31d 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CBreakpoint.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CBreakpoint.java @@ -192,4 +192,34 @@ public abstract class CBreakpoint extends Breakpoint { return null; } + + /** + * Increments the install count of this breakpoint + */ + public void incrementInstallCount() throws CoreException + { + int count = getInstallCount(); + setAttribute( INSTALL_COUNT, count + 1 ); + } + + /** + * Returns the INSTALL_COUNT attribute of this breakpoint + * or 0 if the attribute is not set. + */ + public int getInstallCount() throws CoreException + { + return ensureMarker().getAttribute( INSTALL_COUNT, 0 ); + } + + /** + * Decrements the install count of this breakpoint. + */ + public void decrementInstallCount() throws CoreException + { + int count = getInstallCount(); + if ( count > 0 ) + { + setAttribute( INSTALL_COUNT, count - 1 ); + } + } } 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 1eee2a114d2..cb405c8e056 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 @@ -557,6 +557,15 @@ public class CDebugTarget extends CDebugElement */ public void breakpointRemoved( IBreakpoint breakpoint, IMarkerDelta delta ) { + try + { + if ( breakpoint instanceof CBreakpoint ) + removeBreakpoint( (CBreakpoint)breakpoint ); + } + catch( DebugException e ) + { + CDebugCorePlugin.log( e ); + } } /* (non-Javadoc) @@ -946,7 +955,14 @@ public class CDebugTarget extends CDebugElement getCDISession().getEventManager().removeEventListener( this ); DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener( this ); DebugPlugin.getDefault().getLaunchManager().removeLaunchListener( this ); - removeAllBreakpoints(); + try + { + removeAllBreakpoints(); + } + catch( DebugException e ) + { + CDebugCorePlugin.log( e ); + } } /** @@ -969,8 +985,50 @@ public class CDebugTarget extends CDebugElement * Removes all breakpoints from this target. * */ - protected void removeAllBreakpoints() + protected void removeAllBreakpoints() throws DebugException { + ICDIBreakpoint[] cdiBreakpoints = (ICDIBreakpoint[])getBreakpoints().values().toArray( new ICDIBreakpoint[0] ); + ICDIBreakpointManager bm = getCDISession().getBreakpointManager(); + try + { + bm.deleteBreakpoints( cdiBreakpoints ); + Iterator it = getBreakpoints().keySet().iterator(); + while( it.hasNext() ) + { + ((CBreakpoint)it.next()).decrementInstallCount(); + } + getBreakpoints().clear(); + } + catch( CoreException ce ) + { + requestFailed( "Operation failed. Reason: ", ce ); + } + catch( CDIException e ) + { + requestFailed( "Operation failed. Reason: ", e ); + } + } + + protected void removeBreakpoint( CBreakpoint breakpoint ) throws DebugException + { + ICDIBreakpoint cdiBreakpoint = findCDIBreakpoint( breakpoint ); + if ( cdiBreakpoint == null ) + return; + ICDIBreakpointManager bm = getCDISession().getBreakpointManager(); + try + { + bm.deleteBreakpoints( new ICDIBreakpoint[] { cdiBreakpoint } ); + getBreakpoints().remove( breakpoint ); + breakpoint.decrementInstallCount(); + } + catch( CoreException ce ) + { + requestFailed( "Operation failed. Reason: ", ce ); + } + catch( CDIException e ) + { + requestFailed( "Operation failed. Reason: ", e ); + } } /** @@ -1370,6 +1428,7 @@ public class CDebugTarget extends CDebugElement if ( !getBreakpoints().containsKey( breakpoint ) ) { getBreakpoints().put( breakpoint, cdiBreakpoint ); + ((CBreakpoint)breakpoint).incrementInstallCount(); } } catch( CoreException ce ) @@ -1381,4 +1440,9 @@ public class CDebugTarget extends CDebugElement requestFailed( "Operation failed. Reason: ", e ); } } + + private ICDIBreakpoint findCDIBreakpoint( IBreakpoint breakpoint ) + { + return (ICDIBreakpoint)getBreakpoints().get( breakpoint ); + } }