From 8fdc0ff5f8a6911eb3c5bd4ee64e2e429967ac19 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Mon, 27 Jan 2003 22:28:13 +0000 Subject: [PATCH] Managing breakpoints from the gdb console. --- debug/org.eclipse.cdt.debug.core/ChangeLog | 15 ++ .../cdt/debug/core/CDebugCorePlugin.java | 13 + .../eclipse/cdt/debug/core/CDebugModel.java | 62 ++++- .../cdt/debug/core/IAsyncExecutor.java | 16 ++ .../core/sourcelookup/ICSourceLocator.java | 2 + .../core/breakpoints/CAddressBreakpoint.java | 11 +- .../core/breakpoints/CBreakpoint.java | 43 ++++ .../core/breakpoints/CFunctionBreakpoint.java | 11 +- .../core/breakpoints/CLineBreakpoint.java | 9 + .../core/breakpoints/CWatchpoint.java | 14 +- .../internal/core/model/CDebugTarget.java | 229 +++++++++++++++--- .../core/sourcelookup/CSourceLocator.java | 30 +++ .../core/sourcelookup/CSourceManager.java | 12 + debug/org.eclipse.cdt.debug.ui/ChangeLog | 6 + .../AddAddressBreakpointActionDelegate.java | 1 - .../actions/ManageBreakpointRulerAction.java | 2 +- .../eclipse/cdt/debug/ui/CDebugUIPlugin.java | 21 +- 17 files changed, 452 insertions(+), 45 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IAsyncExecutor.java diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index b316f327cb2..02d5c6728c7 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,18 @@ +2003-01-27 Mikhail Khodjaiants + Managing breakpoints from the gdb console. + * CDebugCorePlugin.java + * CDebugModel.java + * IAsyncExecutor.java + * ICSourceLocator.java + * CAddressBreakpoint.java + * CBreakpoint.java + * CFunctionBreakpoint.java + * CLineBreakpoint.java + * CWatchpoint.java + * CDebugTarget.java + * CSourceLocator.java + * CSourceManager.java + 2003-01-27 Mikhail Khodjaiants Use 'equals' to compare CDI variables instead of names. * CStackFrame.java diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java index 981d4dd00b2..d4318a2df7c 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java @@ -39,6 +39,8 @@ public class CDebugCorePlugin extends Plugin private HashMap fDebugConfigurations; + private IAsyncExecutor fAsyncExecutor = null; + /** * The constructor. */ @@ -199,4 +201,15 @@ public class CDebugCorePlugin extends Plugin } } } + + public void setAsyncExecutor( IAsyncExecutor executor ) + { + fAsyncExecutor = executor; + } + + public void asyncExec( Runnable runnable ) + { + if ( fAsyncExecutor != null ) + fAsyncExecutor.asyncExec( runnable ); + } } 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 19a1a74adef..a5c33744d60 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 @@ -14,10 +14,12 @@ import org.eclipse.cdt.debug.core.cdi.ICDIConfiguration; import org.eclipse.cdt.debug.core.cdi.ICDILocation; import org.eclipse.cdt.debug.core.cdi.ICDISessionObject; import org.eclipse.cdt.debug.core.cdi.event.ICDISuspendedEvent; +import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint; import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression; import org.eclipse.cdt.debug.core.cdi.model.ICDIMemoryBlock; import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; +import org.eclipse.cdt.debug.core.cdi.model.ICDIWatchpoint; import org.eclipse.cdt.debug.core.model.ICAddressBreakpoint; import org.eclipse.cdt.debug.core.model.ICBreakpoint; import org.eclipse.cdt.debug.core.model.ICDebugTargetType; @@ -307,6 +309,23 @@ public class CDebugModel return new CLineBreakpoint( resource, attributes, add ); } + public static ICLineBreakpoint createLineBreakpoint( IResource resource, + int lineNumber, + boolean enabled, + int ignoreCount, + String condition, + ICDIBreakpoint cdiBreakpoint, + boolean add ) throws DebugException + { + HashMap attributes = new HashMap( 10 ); + attributes.put( ICBreakpoint.ID, getPluginIdentifier() ); + attributes.put( IMarker.LINE_NUMBER, new Integer( lineNumber ) ); + attributes.put( ICBreakpoint.ENABLED, new Boolean( enabled ) ); + attributes.put( ICBreakpoint.IGNORE_COUNT, new Integer( ignoreCount ) ); + attributes.put( ICBreakpoint.CONDITION, condition ); + return new CLineBreakpoint( resource, attributes, cdiBreakpoint, add ); + } + public static ICAddressBreakpoint addressBreakpointExists( IResource resource, long address ) throws CoreException { String modelId = getPluginIdentifier(); @@ -341,7 +360,6 @@ public class CDebugModel } public static ICAddressBreakpoint createAddressBreakpoint( IResource resource, - int lineNumber, long address, boolean enabled, int ignoreCount, @@ -350,7 +368,6 @@ public class CDebugModel { HashMap attributes = new HashMap( 10 ); attributes.put( ICBreakpoint.ID, getPluginIdentifier() ); -// attributes.put( IMarker.LINE_NUMBER, new Integer( lineNumber ) ); attributes.put( IMarker.CHAR_START, new Integer( 0 ) ); attributes.put( IMarker.CHAR_END, new Integer( 0 ) ); attributes.put( IMarker.LINE_NUMBER, new Integer( -1 ) ); @@ -361,6 +378,26 @@ public class CDebugModel return new CAddressBreakpoint( resource, attributes, add ); } + public static ICAddressBreakpoint createAddressBreakpoint( IResource resource, + long address, + boolean enabled, + int ignoreCount, + String condition, + ICDIBreakpoint breakpoint, + boolean add ) throws DebugException + { + HashMap attributes = new HashMap( 10 ); + attributes.put( ICBreakpoint.ID, getPluginIdentifier() ); + 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( ICAddressBreakpoint.ADDRESS, Long.toString( address ) ); + attributes.put( ICBreakpoint.ENABLED, new Boolean( enabled ) ); + attributes.put( ICBreakpoint.IGNORE_COUNT, new Integer( ignoreCount ) ); + attributes.put( ICBreakpoint.CONDITION, condition ); + return new CAddressBreakpoint( resource, attributes, breakpoint, add ); + } + public static ICWatchpoint watchpointExists( IResource resource, boolean write, boolean read, String expression ) throws CoreException { String modelId = getPluginIdentifier(); @@ -406,6 +443,27 @@ public class CDebugModel return new CWatchpoint( resource, attributes, add ); } + public static ICWatchpoint createWatchpoint( IResource resource, + boolean writeAccess, + boolean readAccess, + String expression, + boolean enabled, + int ignoreCount, + String condition, + ICDIWatchpoint watchpoint, + boolean add ) throws DebugException + { + HashMap attributes = new HashMap( 10 ); + attributes.put( ICBreakpoint.ID, getPluginIdentifier() ); + attributes.put( ICBreakpoint.ENABLED, new Boolean( enabled ) ); + attributes.put( ICBreakpoint.IGNORE_COUNT, new Integer( ignoreCount ) ); + attributes.put( ICBreakpoint.CONDITION, condition ); + attributes.put( ICWatchpoint.EXPRESSION, expression ); + attributes.put( ICWatchpoint.READ, new Boolean( readAccess ) ); + attributes.put( ICWatchpoint.WRITE, new Boolean( writeAccess ) ); + return new CWatchpoint( resource, attributes, watchpoint, add ); + } + public static IExpression createExpression( IDebugTarget target, String text ) throws DebugException { if ( target != null && target instanceof CDebugTarget ) diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IAsyncExecutor.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IAsyncExecutor.java new file mode 100644 index 00000000000..e4dce2e58a3 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IAsyncExecutor.java @@ -0,0 +1,16 @@ +/* + *(c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + * + */ +package org.eclipse.cdt.debug.core; + +/** + * Enter type comment. + * + * @since: Jan 27, 2003 + */ +public interface IAsyncExecutor +{ + void asyncExec( Runnable runnable ); +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocator.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocator.java index f7efa4c01c9..34bd8e97204 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocator.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocator.java @@ -50,4 +50,6 @@ public interface ICSourceLocator extends ISourceLocator * @return whether this locator is able to locate the given resource */ boolean contains( IResource resource ); + + Object findSourceElement( String fileName ); } \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CAddressBreakpoint.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CAddressBreakpoint.java index 6d630dc79ef..6d71cb1daa0 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CAddressBreakpoint.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CAddressBreakpoint.java @@ -7,6 +7,7 @@ package org.eclipse.cdt.debug.internal.core.breakpoints; import java.util.Map; +import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint; import org.eclipse.cdt.debug.core.model.ICAddressBreakpoint; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; @@ -35,7 +36,15 @@ public class CAddressBreakpoint extends CBreakpoint implements ICAddressBreakpoi */ public CAddressBreakpoint( IResource resource, Map attributes, boolean add ) throws DebugException { - super( resource, C_ADDRESS_BREAKPOINT, attributes, add ); + super( resource, getMarkerType(), attributes, add ); + } + + /** + * Constructor for CAddressBreakpoint. + */ + public CAddressBreakpoint( IResource resource, Map attributes, ICDIBreakpoint cdiBreakpoint, boolean add ) throws DebugException + { + super( resource, getMarkerType(), attributes, cdiBreakpoint, add ); } /* (non-Javadoc) 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 db4a50229f1..b936e672a2c 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 @@ -9,6 +9,7 @@ package org.eclipse.cdt.debug.internal.core.breakpoints; import java.util.Map; import org.eclipse.cdt.debug.core.CDebugModel; +import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint; import org.eclipse.cdt.debug.core.model.ICBreakpoint; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; @@ -32,6 +33,12 @@ public abstract class CBreakpoint extends Breakpoint implements ICBreakpoint, IDebugEventSetListener { + /** + * This field is used to pass a CDI breakpoint to the target if the breakpoint + * is created in gdb console. + */ + private ICDIBreakpoint fExternalBreakpoint = null; + /** * Constructor for CBreakpoint. */ @@ -64,6 +71,32 @@ public abstract class CBreakpoint extends Breakpoint run( wr ); } + /** + * Constructor for CBreakpoint. + */ + public CBreakpoint( final IResource resource, final String markerType, final Map attributes, final ICDIBreakpoint cdiBreakpoint, final boolean add ) throws DebugException + { + setExternalBreakpoint( cdiBreakpoint ); + IWorkspaceRunnable wr= new IWorkspaceRunnable() + { + public void run( IProgressMonitor monitor ) throws CoreException + { + // create the marker + setMarker( resource.createMarker( markerType ) ); + + // set attributes + ensureMarker().setAttributes( attributes ); + + //set the marker message + setAttribute( IMarker.MESSAGE, getMarkerMessage() ); + + // add to breakpoint manager if requested + register( add ); + } + }; + run( wr ); + } + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IBreakpoint#getModelIdentifier() */ @@ -224,4 +257,14 @@ public abstract class CBreakpoint extends Breakpoint { super.setAttribute( attributeName, value ); } + + public ICDIBreakpoint getExternalBreakpoint() + { + return fExternalBreakpoint; + } + + public void setExternalBreakpoint( ICDIBreakpoint cdiBreakpoint ) + { + fExternalBreakpoint = cdiBreakpoint; + } } 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 ae5a8a6178a..2e1c01ec69f 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 @@ -7,6 +7,7 @@ package org.eclipse.cdt.debug.internal.core.breakpoints; import java.util.Map; +import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint; import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; @@ -42,7 +43,15 @@ public class CFunctionBreakpoint extends CBreakpoint implements ICFunctionBreakp */ public CFunctionBreakpoint( IResource resource, Map attributes, boolean add ) throws DebugException { - super( resource, C_FUNCTION_BREAKPOINT, attributes, add ); + super( resource, getMarkerType(), attributes, add ); + } + + /** + * Constructor for CFunctionBreakpoint. + */ + public CFunctionBreakpoint( IResource resource, Map attributes, ICDIBreakpoint cdiBreakpoint, boolean add ) throws DebugException + { + super( resource, getMarkerType(), attributes, cdiBreakpoint, add ); } /* (non-Javadoc) diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CLineBreakpoint.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CLineBreakpoint.java index 6404205b9ba..f1cfe8aaf82 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CLineBreakpoint.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CLineBreakpoint.java @@ -7,6 +7,7 @@ package org.eclipse.cdt.debug.internal.core.breakpoints; import java.util.Map; +import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint; import org.eclipse.cdt.debug.core.model.ICLineBreakpoint; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; @@ -38,6 +39,14 @@ public class CLineBreakpoint extends CBreakpoint implements ICLineBreakpoint super( resource, getMarkerType(), attributes, add ); } + /** + * Constructor for CLineBreakpoint. + */ + public CLineBreakpoint( IResource resource, Map attributes, ICDIBreakpoint cdiBreakpoint, boolean add ) throws DebugException + { + super( resource, getMarkerType(), attributes, cdiBreakpoint, add ); + } + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ILineBreakpoint#getLineNumber() */ diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CWatchpoint.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CWatchpoint.java index effcaed6796..4361bb843a7 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CWatchpoint.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CWatchpoint.java @@ -7,6 +7,7 @@ package org.eclipse.cdt.debug.internal.core.breakpoints; import java.util.Map; +import org.eclipse.cdt.debug.core.cdi.model.ICDIWatchpoint; import org.eclipse.cdt.debug.core.model.ICWatchpoint; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; @@ -31,17 +32,20 @@ public class CWatchpoint extends CBreakpoint implements ICWatchpoint /** * Constructor for CWatchpoint. - * @param resource - * @param markerType - * @param attributes - * @param add - * @throws DebugException */ public CWatchpoint( IResource resource, Map attributes, boolean add ) throws DebugException { super( resource, getMarkerType(), attributes, add ); } + /** + * Constructor for CWatchpoint. + */ + public CWatchpoint( IResource resource, Map attributes, ICDIWatchpoint watchpoint, boolean add ) throws DebugException + { + super( resource, getMarkerType(), attributes, watchpoint, add ); + } + /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.ICWatchpoint#isWriteType() */ 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 8c5305fdb75..30b3c132ad6 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 @@ -74,6 +74,7 @@ import org.eclipse.cdt.debug.internal.core.CMemoryManager; import org.eclipse.cdt.debug.internal.core.CSharedLibraryManager; import org.eclipse.cdt.debug.internal.core.ICDebugInternalConstants; import org.eclipse.cdt.debug.internal.core.breakpoints.CBreakpoint; +import org.eclipse.cdt.debug.internal.core.breakpoints.CWatchpoint; import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceManager; import org.eclipse.cdt.debug.internal.core.sourcelookup.DisassemblyManager; import org.eclipse.core.resources.IFile; @@ -901,6 +902,14 @@ public class CDebugTarget extends CDebugElement if ( ((ICDISharedLibrary)source).areSymbolsLoaded() ) setRetryBreakpoints( true ); } + if ( source instanceof ICDILocationBreakpoint ) + { + handleLocationBreakpointCreatedEvent( (ICDILocationBreakpoint)source ); + } + if ( source instanceof ICDIWatchpoint ) + { + handleWatchpointCreatedEvent( (ICDIWatchpoint)source ); + } } else if ( event instanceof ICDISuspendedEvent ) { @@ -933,6 +942,10 @@ public class CDebugTarget extends CDebugElement { getSharedLibraryManager().sharedLibraryUnloaded( (ICDISharedLibrary)source ); } + if ( source instanceof ICDIBreakpoint ) + { + handleBreakpointDestroyedEvent( (ICDIBreakpoint)source ); + } } else if ( event instanceof ICDIDisconnectedEvent ) { @@ -1463,6 +1476,126 @@ public class CDebugTarget extends CDebugElement } } + private void handleLocationBreakpointCreatedEvent( final ICDILocationBreakpoint breakpoint ) + { + Runnable runnable = new Runnable() + { + public void run() + { + doHandleLocationBreakpointCreatedEvent( breakpoint ); + } + + }; + CDebugCorePlugin.getDefault().asyncExec( runnable ); + } + + protected void doHandleLocationBreakpointCreatedEvent( ICDILocationBreakpoint breakpoint ) + { + if ( breakpoint.isTemporary() || getBreakpoints().containsValue( breakpoint ) ) + return; + try + { + if ( breakpoint.getLocation().getFile() != null && breakpoint.getLocation().getFile().length() > 0 ) + { + if ( getSourceLocator() instanceof IAdaptable && ((IAdaptable)getSourceLocator()).getAdapter( ICSourceLocator.class ) != null ) + { + Object sourceElement = ((ICSourceLocator)((IAdaptable)getSourceLocator()).getAdapter( ICSourceLocator.class )).findSourceElement( breakpoint.getLocation().getFile() ); + if ( sourceElement != null && sourceElement instanceof IFile ) + { + CDebugModel.createLineBreakpoint( (IFile)sourceElement, + breakpoint.getLocation().getLineNumber(), + breakpoint.isEnabled(), + breakpoint.getCondition().getIgnoreCount(), + breakpoint.getCondition().getExpression(), + breakpoint, + true ); + } + } + } + else if ( breakpoint.getLocation().getAddress() > 0 ) + { + CDebugModel.createAddressBreakpoint( getExecFile(), + breakpoint.getLocation().getAddress(), + breakpoint.isEnabled(), + breakpoint.getCondition().getIgnoreCount(), + breakpoint.getCondition().getExpression(), + breakpoint, + true ); + } + } + catch( CDIException e ) + { + } + catch( DebugException e ) + { + } + } + + private void handleWatchpointCreatedEvent( final ICDIWatchpoint watchpoint ) + { + Runnable runnable = new Runnable() + { + public void run() + { + doHandleWatchpointCreatedEvent( watchpoint ); + } + + }; + CDebugCorePlugin.getDefault().asyncExec( runnable ); + } + + protected void doHandleWatchpointCreatedEvent( ICDIWatchpoint watchpoint ) + { + if ( getBreakpoints().containsValue( watchpoint ) ) + return; + try + { + CDebugModel.createWatchpoint( getExecFile().getProject(), + watchpoint.isWriteType(), + watchpoint.isReadType(), + watchpoint.getWatchExpression(), + watchpoint.isEnabled(), + watchpoint.getCondition().getIgnoreCount(), + watchpoint.getCondition().getExpression(), + watchpoint, + true ); + } + catch( CDIException e ) + { + } + catch( DebugException e ) + { + } + } + + private void handleBreakpointDestroyedEvent( final ICDIBreakpoint breakpoint ) + { + Runnable runnable = new Runnable() + { + public void run() + { + doHandleBreakpointDestroyedEvent( breakpoint ); + } + + }; + CDebugCorePlugin.getDefault().asyncExec( runnable ); + } + + protected void doHandleBreakpointDestroyedEvent( ICDIBreakpoint cdiBreakpoint ) + { + IBreakpoint breakpoint = findBreakpoint( cdiBreakpoint ); + if ( breakpoint != null ) + { + try + { + DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( breakpoint, true ); + } + catch( CoreException e ) + { + } + } + } + /** * Finds and returns the model thread for the associated CDI thread, * or null if not found. @@ -1615,20 +1748,21 @@ public class CDebugTarget extends CDebugElement private void setLineBreakpoint( ICLineBreakpoint breakpoint ) throws DebugException { - ICDIBreakpointManager bm = getCDISession().getBreakpointManager(); try { - ICDILocation location = bm.createLocation( breakpoint.getMarker().getResource().getLocation().lastSegment(), null, breakpoint.getLineNumber() ); - ICDICondition condition = bm.createCondition( breakpoint.getIgnoreCount(), breakpoint.getCondition() ); - ICDIBreakpoint cdiBreakpoint = bm.setLocationBreakpoint( ICDIBreakpoint.REGULAR, location, condition, null ); - if ( !getBreakpoints().containsKey( breakpoint ) ) + ICDIBreakpoint cdiBreakpoint = ((CBreakpoint)breakpoint).getExternalBreakpoint(); + if ( cdiBreakpoint == null ) + { + setLineBreakpoint0( breakpoint ); + } + else { getBreakpoints().put( breakpoint, cdiBreakpoint ); - ((CBreakpoint)breakpoint).incrementInstallCount(); - if ( !breakpoint.isEnabled() ) - { - cdiBreakpoint.setEnabled( false ); - } + } + ((CBreakpoint)breakpoint).incrementInstallCount(); + if ( !breakpoint.isEnabled() ) + { + cdiBreakpoint.setEnabled( false ); } } catch( CoreException ce ) @@ -1640,23 +1774,33 @@ public class CDebugTarget extends CDebugElement requestFailed( "Operation failed. Reason: ", e ); } } + + private synchronized void setLineBreakpoint0( ICLineBreakpoint breakpoint ) throws CDIException, CoreException + { + ICDIBreakpointManager bm = getCDISession().getBreakpointManager(); + ICDILocation location = bm.createLocation( breakpoint.getMarker().getResource().getLocation().lastSegment(), null, breakpoint.getLineNumber() ); + ICDICondition condition = bm.createCondition( breakpoint.getIgnoreCount(), breakpoint.getCondition() ); + ICDIBreakpoint cdiBreakpoint = bm.setLocationBreakpoint( ICDIBreakpoint.REGULAR, location, condition, null ); + getBreakpoints().put( breakpoint, cdiBreakpoint ); + } private void setAddressBreakpoint( ICAddressBreakpoint breakpoint ) throws DebugException { - ICDIBreakpointManager bm = getCDISession().getBreakpointManager(); try { - 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 ); - if ( !getBreakpoints().containsKey( breakpoint ) ) + ICDIBreakpoint cdiBreakpoint = ((CBreakpoint)breakpoint).getExternalBreakpoint(); + if ( cdiBreakpoint == null ) + { + setAddressBreakpoint0( breakpoint ); + } + else { getBreakpoints().put( breakpoint, cdiBreakpoint ); - ((CBreakpoint)breakpoint).incrementInstallCount(); - if ( !breakpoint.isEnabled() ) - { - cdiBreakpoint.setEnabled( false ); - } + } + ((CBreakpoint)breakpoint).incrementInstallCount(); + if ( !breakpoint.isEnabled() ) + { + cdiBreakpoint.setEnabled( false ); } } catch( CoreException ce ) @@ -1672,26 +1816,33 @@ public class CDebugTarget extends CDebugElement requestFailed( "Operation failed. Reason: ", e ); } } + + private synchronized void setAddressBreakpoint0( ICAddressBreakpoint breakpoint ) throws CDIException, CoreException + { + 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 ); + } private void setWatchpoint( ICWatchpoint watchpoint ) throws DebugException { - ICDIBreakpointManager bm = getCDISession().getBreakpointManager(); try { - ICDICondition condition = bm.createCondition( watchpoint.getIgnoreCount(), watchpoint.getCondition() ); - int accessType = 0; - accessType |= ( watchpoint.isWriteType() ) ? ICDIWatchpoint.WRITE : 0; - accessType |= ( watchpoint.isReadType() ) ? ICDIWatchpoint.READ : 0; - String expression = watchpoint.getExpression(); - ICDIWatchpoint cdiWatchpoint = bm.setWatchpoint( ICDIBreakpoint.REGULAR, accessType, expression, condition ); - if ( !getBreakpoints().containsKey( watchpoint ) ) + ICDIWatchpoint cdiWatchpoint = (ICDIWatchpoint)((CWatchpoint)watchpoint).getExternalBreakpoint(); + if ( cdiWatchpoint == null ) + { + setWatchpoint0( watchpoint ); + } + else { getBreakpoints().put( watchpoint, cdiWatchpoint ); - ((CBreakpoint)watchpoint).incrementInstallCount(); - if ( !watchpoint.isEnabled() ) - { - cdiWatchpoint.setEnabled( false ); - } + } + ((CBreakpoint)watchpoint).incrementInstallCount(); + if ( !watchpoint.isEnabled() ) + { + cdiWatchpoint.setEnabled( false ); } } catch( CoreException ce ) @@ -1704,6 +1855,18 @@ public class CDebugTarget extends CDebugElement } } + private synchronized void setWatchpoint0( ICWatchpoint watchpoint ) throws CDIException, CoreException + { + ICDIBreakpointManager bm = getCDISession().getBreakpointManager(); + ICDICondition condition = bm.createCondition( watchpoint.getIgnoreCount(), watchpoint.getCondition() ); + int accessType = 0; + accessType |= ( watchpoint.isWriteType() ) ? ICDIWatchpoint.WRITE : 0; + accessType |= ( watchpoint.isReadType() ) ? ICDIWatchpoint.READ : 0; + String expression = watchpoint.getExpression(); + ICDIWatchpoint cdiWatchpoint = bm.setWatchpoint( ICDIBreakpoint.REGULAR, accessType, expression, condition ); + getBreakpoints().put( watchpoint, cdiWatchpoint ); + } + private ICDIBreakpoint findCDIBreakpoint( IBreakpoint breakpoint ) { return (ICDIBreakpoint)getBreakpoints().get( breakpoint ); diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java index 574641bc52c..803cd4925b0 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java @@ -216,4 +216,34 @@ public class CSourceLocator implements ICSourceLocator } return null; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#findSourceElement(String) + */ + public Object findSourceElement( String fileName ) + { + Object result = null; + if ( fileName != null && fileName.length() > 0 ) + { + result = findFileByAbsolutePath( fileName ); + if ( result == null ) + { + ICSourceLocation[] locations = getSourceLocations(); + for ( int i = 0; i < locations.length; ++i ) + { + try + { + result = locations[i].findSourceElement( fileName ); + } + catch( CoreException e ) + { + // do nothing + } + if ( result != null ) + break; + } + } + } + return result; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java index 75c05d7cf0b..6c6236dd0e0 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java @@ -190,4 +190,16 @@ public class CSourceManager implements ICSourceLocator, ISourceMode, IAdaptable list.add( location ); setSourceLocations( (ICSourceLocation[])list.toArray( new ICSourceLocation[list.size()] ) ); } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#findSourceElement(String) + */ + public Object findSourceElement( String fileName ) + { + if ( getCSourceLocator() != null ) + { + return getCSourceLocator().findSourceElement( fileName ); + } + return null; + } } diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog index a663c95fc0b..ab0645850c3 100644 --- a/debug/org.eclipse.cdt.debug.ui/ChangeLog +++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog @@ -1,3 +1,9 @@ +2003-01-27 Mikhail Khodjaiants + Managing breakpoints from the gdb console. + * AddAddressBreakpointActionDelegate.java + * ManageBreakpointRulerAction.java + * CDebugUIPlugin.java + 2003-01-23 Mikhail Khodjaiants Ignore the text selection when hovering. * DebugTextHovering.java diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/AddAddressBreakpointActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/AddAddressBreakpointActionDelegate.java index 00312e65ef5..b106687f601 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/AddAddressBreakpointActionDelegate.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/AddAddressBreakpointActionDelegate.java @@ -71,7 +71,6 @@ public class AddAddressBreakpointActionDelegate extends AbstractListenerActionDe if ( dialog.open() == dialog.OK ) { CDebugModel.createAddressBreakpoint( ((IExecFileInfo)getDebugTarget( element ).getAdapter( IExecFileInfo.class )).getExecFile(), - -1, parseValue( dialog.getValue().trim() ), true, 0, diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageBreakpointRulerAction.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageBreakpointRulerAction.java index 2a752a153bc..e6f2a8349f9 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageBreakpointRulerAction.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageBreakpointRulerAction.java @@ -286,7 +286,7 @@ public class ManageBreakpointRulerAction extends Action implements IUpdate long address = ((IDisassemblyStorage)editorInput.getStorage()).getAddress( lineNumber ); if ( address != 0 && CDebugModel.addressBreakpointExists( resource, address ) == null ) { - CDebugModel.createAddressBreakpoint( resource, lineNumber, address, true, 0, "", true ); + CDebugModel.createAddressBreakpoint( resource, address, true, 0, "", true ); } } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java index f1a8ed54fcd..9dc917e7cff 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java @@ -5,6 +5,8 @@ import java.util.Map; import java.util.MissingResourceException; import java.util.ResourceBundle; +import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.cdt.debug.core.IAsyncExecutor; import org.eclipse.cdt.debug.core.model.ISwitchToFrame; import org.eclipse.cdt.debug.core.model.ISwitchToThread; import org.eclipse.cdt.debug.core.sourcelookup.IDisassemblyStorage; @@ -55,7 +57,10 @@ import org.eclipse.ui.plugin.AbstractUIPlugin; /** * The main plugin class to be used in the desktop. */ -public class CDebugUIPlugin extends AbstractUIPlugin implements ISelectionListener, IDebugEventSetListener +public class CDebugUIPlugin extends AbstractUIPlugin + implements ISelectionListener, + IDebugEventSetListener, + IAsyncExecutor { //The shared instance. private static CDebugUIPlugin plugin; @@ -313,6 +318,7 @@ public class CDebugUIPlugin extends AbstractUIPlugin implements ISelectionListen { fImageDescriptorRegistry.dispose(); } + CDebugCorePlugin.getDefault().setAsyncExecutor( null ); super.shutdown(); } @@ -327,6 +333,7 @@ public class CDebugUIPlugin extends AbstractUIPlugin implements ISelectionListen { ww.getSelectionService().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this ); } + CDebugCorePlugin.getDefault().setAsyncExecutor( this ); DebugPlugin.getDefault().addDebugEventListener( this ); } @@ -476,4 +483,16 @@ public class CDebugUIPlugin extends AbstractUIPlugin implements ISelectionListen fDisassemblyDocumentProvider = new DisassemblyDocumentProvider(); return fDisassemblyDocumentProvider; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.IAsyncExecutor#asyncExec(Runnable) + */ + public void asyncExec( Runnable runnable ) + { + Display display = getStandardDisplay(); + if ( display != null ) + { + display.asyncExec( runnable ); + } + } }