From 252e01a8368092cf26794bb5f2a68fd7e0f4d211 Mon Sep 17 00:00:00 2001 From: John Cortell Date: Mon, 21 Jul 2008 19:41:42 +0000 Subject: [PATCH] Added ICDIDisposable, as discussed in the mailing list. Most of these changes are adjustments to protect against an NPE since we now null out the CDI members when we dispose them. --- .../debug/core/cdi/model/ICDIDisposable.java | 35 +++++ .../internal/core/model/CDebugTarget.java | 125 +++++++++++++----- .../internal/core/model/CStackFrame.java | 55 ++++++-- .../debug/internal/core/model/CThread.java | 70 +++++++--- 4 files changed, 225 insertions(+), 60 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIDisposable.java diff --git a/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIDisposable.java b/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIDisposable.java new file mode 100644 index 00000000000..a51ba6fb906 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIDisposable.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2008 Freescale Semiconductor and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Freescale Semiconductor - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.debug.core.cdi.model; + +/** + * Some CDI interfaces have a dispose method, but a number of others don't (and + * should). E.g., ICDIVariable does, but ICDIStackFrame doesn't. This interface + * was created to introduce a dispose capability to CDI objects that call for it + * without breaking existing interfaces. + * + * CDT uses instanceof to check whether a CDI object supports this interface and + * if so calls the dispose method when it has no further need for the object. This + * does not apply to all CDI object; just ones for which it makes sense. The list + * is subject to grow: + * + */ +public interface ICDIDisposable { + /** + * Called when the object is no longer needed by CDT. + */ + public void dispose(); +} 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 e8dfd5594ce..4b8eb43c4cf 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 @@ -56,6 +56,7 @@ import org.eclipse.cdt.debug.core.cdi.event.ICDIRestartedEvent; import org.eclipse.cdt.debug.core.cdi.event.ICDIResumedEvent; import org.eclipse.cdt.debug.core.cdi.event.ICDISuspendedEvent; import org.eclipse.cdt.debug.core.cdi.model.ICDIAddressFactoryManagement; +import org.eclipse.cdt.debug.core.cdi.model.ICDIDisposable; import org.eclipse.cdt.debug.core.cdi.model.ICDIGlobalVariableDescriptor; import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; import org.eclipse.cdt.debug.core.cdi.model.ICDISharedLibrary; @@ -320,9 +321,14 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv * Adds all of the pre-existing threads to this debug target. */ protected void initializeThreads( List debugEvents ) { + final ICDITarget cdiTarget = getCDITarget(); + if (cdiTarget == null) { + return; + } + ICDIThread[] cdiThreads = new ICDIThread[0]; try { - cdiThreads = getCDITarget().getThreads(); + cdiThreads = cdiTarget.getThreads(); } catch( CDIException e ) { // ignore @@ -332,7 +338,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv CThread thread = createThread( cdiThreads[i] ); debugEvents.add( thread.createCreateEvent() ); try { - if ( cdiThreads[i].equals( getCDITarget().getCurrentThread() ) && thread.isSuspended() ) { + if ( cdiThreads[i].equals( cdiTarget.getCurrentThread() ) && thread.isSuspended() ) { // Use BREAKPOINT as a detail to force perspective switch suspendEvent = thread.createSuspendEvent( DebugEvent.BREAKPOINT ); } @@ -379,9 +385,14 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv } protected void initializeModuleManager() { + final ICDITarget cdiTarget = getCDITarget(); + if (cdiTarget == null) { + return; + } + ICDISharedLibrary[] slibs = new ICDISharedLibrary[0]; try { - slibs = getCDITarget().getSharedLibraries(); + slibs = cdiTarget.getSharedLibraries(); } catch( CDIException e ) { DebugPlugin.log( e ); @@ -517,7 +528,10 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv final CDebugElementState newState = CDebugElementState.TERMINATING; changeState( newState ); try { - getCDITarget().terminate(); + final ICDITarget cdiTarget = getCDITarget(); + if (cdiTarget != null) { + cdiTarget.terminate(); + } } catch( CDIException e ) { if ( getState() == newState ) { @@ -569,7 +583,10 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv final CDebugElementState newState = CDebugElementState.RESUMING; changeState( newState ); try { - getCDITarget().resume( false ); + final ICDITarget cdiTarget = getCDITarget(); + if (cdiTarget != null) { + cdiTarget.resume( false ); + } } catch( CDIException e ) { if ( getState() == newState ) { @@ -588,7 +605,10 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv final CDebugElementState newState = CDebugElementState.SUSPENDING; changeState( newState ); try { - getCDITarget().suspend(); + final ICDITarget cdiTarget = getCDITarget(); + if (cdiTarget != null) { + cdiTarget.suspend(); + } } catch( CDIException e ) { if ( getState() == newState ) { @@ -611,7 +631,10 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv CThread thread = (CThread)it.next(); ICDIThread suspensionThread = null; try { - suspensionThread = getCDITarget().getCurrentThread(); + final ICDITarget cdiTarget = getCDITarget(); + if (cdiTarget != null) { + suspensionThread = cdiTarget.getCurrentThread(); + } } catch( CDIException e ) { // ignore @@ -631,8 +654,11 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv ICDIThread[] cdiThreads = new ICDIThread[0]; ICDIThread currentCDIThread = null; try { - cdiThreads = getCDITarget().getThreads(); - currentCDIThread = getCDITarget().getCurrentThread(); + final ICDITarget cdiTarget = getCDITarget(); + if (cdiTarget != null) { + cdiThreads = cdiTarget.getThreads(); + currentCDIThread = cdiTarget.getCurrentThread(); + } } catch( CDIException e ) { } @@ -727,7 +753,10 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv final CDebugElementState newState = CDebugElementState.DISCONNECTING; changeState( newState ); try { - getCDITarget().disconnect(); + final ICDITarget cdiTarget = getCDITarget(); + if (cdiTarget != null) { + cdiTarget.disconnect(); + } } catch( CDIException e ) { if ( getState() == newState ) { @@ -848,10 +877,11 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv for( int i = 0; i < events.length; i++ ) { ICDIEvent event = events[i]; ICDIObject source = event.getSource(); + final ICDITarget cdiTarget = getCDITarget(); if ( source == null && event instanceof ICDIDestroyedEvent ) { handleTerminatedEvent( (ICDIDestroyedEvent)event ); } - else if ( source != null && source.getTarget().equals( getCDITarget() ) ) { + else if ( source != null && cdiTarget != null && source.getTarget().equals( cdiTarget ) ) { if ( event instanceof ICDICreatedEvent ) { if ( source instanceof ICDIThread ) { handleThreadCreatedEvent( (ICDICreatedEvent)event ); @@ -922,6 +952,11 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv if ( !canRestart() ) { return; } + final ICDITarget cdiTarget = getCDITarget(); + if (cdiTarget == null) { + return; + } + try { ILaunchConfiguration launchConfig = getLaunch().getLaunchConfiguration(); if ( launchConfig.getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_DEFAULT ) ) { @@ -930,10 +965,10 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv // See if the expression is a numeric address try { IAddress address = getAddressFactory().createAddress(mainSymbol); - location = getCDITarget().createAddressLocation( address.getValue() ); + location = cdiTarget.createAddressLocation( address.getValue() ); } catch (NumberFormatException nfexc) { // OK, expression is not a simple, absolute numeric value; keep trucking and try to resolve as expression - location = getCDITarget().createFunctionLocation( "", mainSymbol ); //$NON-NLS-1$ + location = cdiTarget.createFunctionLocation( "", mainSymbol ); //$NON-NLS-1$ } setInternalTemporaryBreakpoint( location ); @@ -946,7 +981,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv final CDebugElementState newState = CDebugElementState.RESTARTING; changeState( newState ); try { - getCDITarget().restart(); + cdiTarget.restart(); } catch( CDIException e ) { if ( getState() == newState ) { @@ -1031,6 +1066,12 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv disposeBreakpointManager(); removeAllExpressions(); disposePreferences(); + + ICDITarget cdiTarget = getCDITarget(); + setCDITarget(null); + if (cdiTarget instanceof ICDIDisposable) { + ((ICDIDisposable)cdiTarget).dispose(); + } } /** @@ -1308,12 +1349,16 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv public void setInternalTemporaryBreakpoint( ICDILocation location ) throws DebugException { try { + final ICDITarget cdiTarget = getCDITarget(); + if (cdiTarget == null) { + return; + } if (location instanceof ICDIFunctionLocation) { - getCDITarget().setFunctionBreakpoint( ICBreakpointType.TEMPORARY, (ICDIFunctionLocation)location, null, false ); + cdiTarget.setFunctionBreakpoint( ICBreakpointType.TEMPORARY, (ICDIFunctionLocation)location, null, false ); } else if (location instanceof ICDILineLocation) { - getCDITarget().setLineBreakpoint( ICBreakpointType.TEMPORARY, (ICDILineLocation)location, null, false ); + cdiTarget.setLineBreakpoint( ICBreakpointType.TEMPORARY, (ICDILineLocation)location, null, false ); } else if (location instanceof ICDIAddressLocation) { - getCDITarget().setAddressBreakpoint( ICBreakpointType.TEMPORARY, (ICDIAddressLocation)location, null, false ); + cdiTarget.setAddressBreakpoint( ICBreakpointType.TEMPORARY, (ICDIAddressLocation)location, null, false ); } else { // ??? targetRequestFailed("not_a_location", null); //$NON-NLS-1$ @@ -1481,7 +1526,10 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv final CDebugElementState newState = CDebugElementState.RESUMING; changeState( newState ); try { - getCDITarget().resume( false ); + final ICDITarget cdiTarget = getCDITarget(); + if (cdiTarget != null) { + cdiTarget.resume( false ); + } } catch( CDIException e ) { if ( getState() == newState ) { @@ -1685,8 +1733,9 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv public IAddressFactory getAddressFactory() { if ( fAddressFactory == null ) { // Ask CDI plug-in for the default AddressFactory. - if (fCDITarget instanceof ICDIAddressFactoryManagement) { - fAddressFactory = ((ICDIAddressFactoryManagement) fCDITarget).getAddressFactory(); + final ICDITarget cdiTarget = getCDITarget(); + if (cdiTarget instanceof ICDIAddressFactoryManagement) { + fAddressFactory = ((ICDIAddressFactoryManagement) cdiTarget).getAddressFactory(); } // And if that doesn't work, use the one from the file. if ( fAddressFactory == null ){ @@ -1733,7 +1782,10 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv public ICGlobalVariable createGlobalVariable( IGlobalVariableDescriptor info ) throws DebugException { ICDIVariableDescriptor vo = null; try { - vo = getCDITarget().getGlobalVariableDescriptors( info.getPath().lastSegment(), null, info.getName() ); + final ICDITarget cdiTarget = getCDITarget(); + if (cdiTarget != null) { + vo = cdiTarget.getGlobalVariableDescriptors( info.getPath().lastSegment(), null, info.getName() ); + } } catch( CDIException e ) { throw new DebugException( new Status( IStatus.ERROR, CDIDebugModel.getPluginIdentifier(), DebugException.TARGET_REQUEST_FAILED, e.getMessage(), null ) ); @@ -1749,7 +1801,10 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv ArrayList list = new ArrayList( containers.length ); getSourceLookupPath( list, containers ); try { - getCDITarget().setSourcePaths( (String[])list.toArray( new String[list.size()] ) ); + final ICDITarget cdiTarget = getCDITarget(); + if (cdiTarget != null) { + cdiTarget.setSourcePaths( (String[])list.toArray( new String[list.size()] ) ); + } } catch( CDIException e ) { CDebugCorePlugin.log( e ); @@ -1835,7 +1890,8 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv setInternalTemporaryBreakpoint( location ); } catch( CoreException e ) { - boolean isTerminated = getCDITarget().isTerminated(); + final ICDITarget cdiTarget = getCDITarget(); + boolean isTerminated = cdiTarget != null && cdiTarget.isTerminated(); if ( isTerminated ) { String message = MessageFormat.format( CoreModelMessages.getString( "CDebugTarget.0" ), new String[]{ stopExpression } ); //$NON-NLS-1$ MultiStatus status = new MultiStatus( CDebugCorePlugin.getUniqueIdentifier(), IStatus.OK, message, null ); @@ -1851,21 +1907,30 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv } protected void stopAtSymbol( String stopSymbol ) throws DebugException { - ICDILocation location = getCDITarget().createFunctionLocation( "", stopSymbol ); //$NON-NLS-1$ - stopAtLocation(location, stopSymbol); + final ICDITarget cdiTarget = getCDITarget(); + if (cdiTarget != null) { + ICDILocation location = cdiTarget.createFunctionLocation( "", stopSymbol ); //$NON-NLS-1$ + stopAtLocation(location, stopSymbol); + } } protected void stopAtAddress( IAddress address ) throws DebugException { - ICDIAddressLocation location = getCDITarget().createAddressLocation(address.getValue()); - stopAtLocation(location, address.toHexAddressString()); + final ICDITarget cdiTarget = getCDITarget(); + if (cdiTarget != null) { + ICDIAddressLocation location = cdiTarget.createAddressLocation(address.getValue()); + stopAtLocation(location, address.toHexAddressString()); + } } protected void stopInMain() throws DebugException { String mainSymbol = new String( ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT ); try { - mainSymbol = getLaunch().getLaunchConfiguration().getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT ); - ICDILocation location = getCDITarget().createFunctionLocation( "", mainSymbol ); //$NON-NLS-1$ - setInternalTemporaryBreakpoint( location ); + final ICDITarget cdiTarget = getCDITarget(); + if (cdiTarget != null) { + mainSymbol = getLaunch().getLaunchConfiguration().getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT ); + ICDILocation location = cdiTarget.createFunctionLocation( "", mainSymbol ); //$NON-NLS-1$ + setInternalTemporaryBreakpoint( location ); + } } catch( CoreException e ) { String message = MessageFormat.format( CoreModelMessages.getString( "CDebugTarget.2" ), new String[]{ mainSymbol, e.getStatus().getMessage() } ); //$NON-NLS-1$ diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java index 838a8c138c2..22b6d9fa877 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java @@ -26,6 +26,7 @@ import org.eclipse.cdt.debug.core.cdi.ICDILocation; import org.eclipse.cdt.debug.core.cdi.ICDILocator; import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener; +import org.eclipse.cdt.debug.core.cdi.model.ICDIDisposable; import org.eclipse.cdt.debug.core.cdi.model.ICDIExecuteMoveInstructionPointer; import org.eclipse.cdt.debug.core.cdi.model.ICDIExecuteResume; import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression; @@ -197,8 +198,10 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart ISourceLocator locator = ((CDebugTarget)getDebugTarget()).getSourceLocator(); if ( locator != null && locator instanceof IAdaptable && ((IAdaptable)locator).getAdapter( ICSourceLocator.class ) != null ) return ((ICSourceLocator)((IAdaptable)locator).getAdapter( ICSourceLocator.class )).getLineNumber( this ); - if ( getCDIStackFrame() != null && getCDIStackFrame().getLocator() != null ) - return getCDIStackFrame().getLocator().getLineNumber(); + + final ICDIStackFrame cdiFrame = getCDIStackFrame(); + if ( cdiFrame != null && cdiFrame.getLocator() != null ) + return cdiFrame.getLocator().getLineNumber(); } return -1; } @@ -221,7 +224,12 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart * @see org.eclipse.debug.core.model.IStackFrame#getName() */ public String getName() throws DebugException { - ICDILocator locator = getCDIStackFrame().getLocator(); + final ICDIStackFrame cdiFrame = getCDIStackFrame(); + if (cdiFrame == null) { + return ""; //$NON-NLS-1$ + } + + ICDILocator locator = cdiFrame.getLocator(); String func = ""; //$NON-NLS-1$ String file = ""; //$NON-NLS-1$ String line = ""; //$NON-NLS-1$ @@ -515,6 +523,12 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart getCDISession().getEventManager().removeEventListener( this ); disposeAllVariables(); disposeExpressions(); + + final ICDIStackFrame cdiFrame = getCDIStackFrame(); + setCDIStackFrame(null); + if (cdiFrame instanceof ICDIDisposable) { + ((ICDIDisposable)cdiFrame).dispose(); + } } /** @@ -524,7 +538,10 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart protected List getCDILocalVariableObjects() throws DebugException { List list = new ArrayList(); try { - list.addAll( Arrays.asList( getCDIStackFrame().getLocalVariableDescriptors( ) ) ); + final ICDIStackFrame cdiFrame = getCDIStackFrame(); + if (cdiFrame != null) { + list.addAll( Arrays.asList( cdiFrame.getLocalVariableDescriptors( ) ) ); + } } catch( CDIException e ) { targetRequestFailed( e.getMessage(), null ); @@ -539,7 +556,10 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart protected List getCDIArgumentObjects() throws DebugException { List list = new ArrayList(); try { - list.addAll( Arrays.asList( getCDIStackFrame().getArgumentDescriptors() ) ); + final ICDIStackFrame cdiFrame = getCDIStackFrame(); + if (cdiFrame != null) { + list.addAll( Arrays.asList( cdiFrame.getArgumentDescriptors() ) ); + } } catch( CDIException e ) { targetRequestFailed( e.getMessage(), null ); @@ -586,35 +606,40 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart */ public IAddress getAddress() { IAddressFactory factory = ((CDebugTarget)getDebugTarget()).getAddressFactory(); - return factory.createAddress( getCDIStackFrame().getLocator().getAddress() ); + final ICDIStackFrame cdiFrame = getCDIStackFrame(); + return cdiFrame != null ? factory.createAddress( cdiFrame.getLocator().getAddress() ) : null; } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.model.ICStackFrame#getFile() */ public String getFile() { - return getCDIStackFrame().getLocator().getFile(); + final ICDIStackFrame cdiFrame = getCDIStackFrame(); + return cdiFrame != null ? cdiFrame.getLocator().getFile() : ""; } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.model.ICStackFrame#getFunction() */ public String getFunction() { - return getCDIStackFrame().getLocator().getFunction(); + final ICDIStackFrame cdiFrame = getCDIStackFrame(); + return cdiFrame != null ? cdiFrame.getLocator().getFunction() : ""; } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.model.ICStackFrame#getLevel() */ public int getLevel() { - return getCDIStackFrame().getLevel(); + final ICDIStackFrame cdiFrame = getCDIStackFrame(); + return cdiFrame != null ? cdiFrame.getLevel() : -1; } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.model.ICStackFrame#getFrameLineNumber() */ public int getFrameLineNumber() { - return getCDIStackFrame().getLocator().getLineNumber(); + final ICDIStackFrame cdiFrame = getCDIStackFrame(); + return cdiFrame != null ? cdiFrame.getLocator().getLineNumber() : -1; } protected synchronized void preserve() { @@ -730,7 +755,10 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart */ public String evaluateExpressionToString( String expression ) throws DebugException { try { - return getCDITarget().evaluateExpressionToString( getCDIStackFrame(), expression ); + final ICDIStackFrame cdiFrame = getCDIStackFrame(); + if (cdiFrame != null) { + return getCDITarget().evaluateExpressionToString( cdiFrame, expression ); + } } catch( CDIException e ) { targetRequestFailed( e.getMessage(), null ); @@ -748,7 +776,10 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart protected void doStepReturn() throws DebugException { try { - getCDIStackFrame().stepReturn(); + final ICDIStackFrame cdiFrame = getCDIStackFrame(); + if (cdiFrame != null) { + cdiFrame.stepReturn(); + } } catch( CDIException e ) { targetRequestFailed( e.getMessage(), null ); diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CThread.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CThread.java index 5312b6a292b..8b7132fa5c2 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CThread.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CThread.java @@ -35,6 +35,7 @@ import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener; import org.eclipse.cdt.debug.core.cdi.event.ICDIResumedEvent; import org.eclipse.cdt.debug.core.cdi.event.ICDISuspendedEvent; +import org.eclipse.cdt.debug.core.cdi.model.ICDIDisposable; import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; import org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame; import org.eclipse.cdt.debug.core.cdi.model.ICDITargetConfiguration; @@ -265,7 +266,10 @@ public class CThread extends CDebugElement implements ICThread, IRestart, IResum */ protected ICDIStackFrame[] getCDIStackFrames( int lowFrame, int highFrame ) throws DebugException { try { - return getCDIThread().getStackFrames( lowFrame, highFrame ); + final ICDIThread cdiThread = getCDIThread(); + if (cdiThread != null) { + return cdiThread.getStackFrames( lowFrame, highFrame ); + } } catch( CDIException e ) { setStatus( ICDebugElementStatus.WARNING, MessageFormat.format( CoreModelMessages.getString( "CThread.0" ), new String[]{ e.getMessage() } ) ); //$NON-NLS-1$ @@ -373,7 +377,8 @@ public class CThread extends CDebugElement implements ICThread, IRestart, IResum * @see org.eclipse.debug.core.model.IThread#getName() */ public String getName() throws DebugException { - return getCDIThread().toString(); + final ICDIThread cdiThread = getCDIThread(); + return cdiThread != null ? cdiThread.toString() : ""; } /* (non-Javadoc) @@ -402,7 +407,8 @@ public class CThread extends CDebugElement implements ICThread, IRestart, IResum for( int i = 0; i < events.length; i++ ) { ICDIEvent event = events[i]; ICDIObject source = event.getSource(); - if ( source instanceof ICDIThread && source.equals( getCDIThread() ) ) { + final ICDIThread cdiThread = getCDIThread(); + if ( source instanceof ICDIThread && cdiThread != null && source.equals( cdiThread ) ) { if ( event instanceof ICDISuspendedEvent ) { handleSuspendedEvent( (ICDISuspendedEvent)event ); } @@ -467,7 +473,10 @@ public class CThread extends CDebugElement implements ICThread, IRestart, IResum CDebugElementState oldState = getState(); setState( CDebugElementState.RESUMING ); try { - getCDIThread().resume( false ); + final ICDIThread cdiThread = getCDIThread(); + if (cdiThread != null) { + cdiThread.resume( false ); + } } catch( CDIException e ) { setState( oldState ); @@ -497,7 +506,9 @@ public class CThread extends CDebugElement implements ICThread, IRestart, IResum try { final ICDIThread cdiThread = getCDIThread(); - cdiThread.stepUntil( location ); + if (cdiThread != null) { + cdiThread.stepUntil( location ); + } } catch( CDIException e ) { setState( oldState ); @@ -517,7 +528,10 @@ public class CThread extends CDebugElement implements ICThread, IRestart, IResum CDebugElementState oldState = getState(); setState( CDebugElementState.SUSPENDING ); try { - getCDIThread().suspend(); + final ICDIThread cdiThread = getCDIThread(); + if (cdiThread != null) { + cdiThread.suspend(); + } } catch( CDIException e ) { setState( oldState ); @@ -577,11 +591,14 @@ public class CThread extends CDebugElement implements ICThread, IRestart, IResum CDebugElementState oldState = getState(); setState( CDebugElementState.STEPPING ); try { - if ( !isInstructionsteppingEnabled() ) { - getCDIThread().stepInto( 1 ); - } - else { - getCDIThread().stepIntoInstruction( 1 ); + final ICDIThread cdiThread = getCDIThread(); + if (cdiThread != null) { + if ( !isInstructionsteppingEnabled() ) { + cdiThread.stepInto( 1 ); + } + else { + cdiThread.stepIntoInstruction( 1 ); + } } } catch( CDIException e ) { @@ -599,11 +616,14 @@ public class CThread extends CDebugElement implements ICThread, IRestart, IResum CDebugElementState oldState = getState(); setState( CDebugElementState.STEPPING ); try { - if ( !isInstructionsteppingEnabled() ) { - getCDIThread().stepOver( 1 ); - } - else { - getCDIThread().stepOverInstruction( 1 ); + final ICDIThread cdiThread = getCDIThread(); + if (cdiThread != null) { + if ( !isInstructionsteppingEnabled() ) { + cdiThread.stepOver( 1 ); + } + else { + cdiThread.stepOverInstruction( 1 ); + } } } catch( CDIException e ) { @@ -828,6 +848,12 @@ public class CThread extends CDebugElement implements ICThread, IRestart, IResum protected void cleanup() { getCDISession().getEventManager().removeEventListener( this ); disposeStackFrames(); + + final ICDIThread cdiThread = getCDIThread(); + setCDIThread(null); + if (cdiThread instanceof ICDIDisposable) { + ((ICDIDisposable)cdiThread).dispose(); + } } private void setRefreshChildren( boolean refresh ) { @@ -872,7 +898,10 @@ public class CThread extends CDebugElement implements ICThread, IRestart, IResum protected int getStackDepth() throws DebugException { int depth = 0; try { - depth = getCDIThread().getStackFrameCount(); + final ICDIThread cdiThread = getCDIThread(); + if (cdiThread != null) { + depth = cdiThread.getStackFrameCount(); + } } catch( CDIException e ) { setStatus( ICDebugElementStatus.WARNING, MessageFormat.format( CoreModelMessages.getString( "CThread.1" ), new String[]{ e.getMessage() } ) ); //$NON-NLS-1$ @@ -997,7 +1026,8 @@ public class CThread extends CDebugElement implements ICThread, IRestart, IResum protected void suspendByTarget( ICDISessionObject reason, ICDIThread suspensionThread ) { setState( CDebugElementState.SUSPENDED ); setCurrentStateInfo( null ); - if ( getCDIThread().equals( suspensionThread ) ) { + final ICDIThread cdiThread = getCDIThread(); + if ( cdiThread != null && cdiThread.equals( suspensionThread ) ) { setCurrent( true ); setCurrentStateInfo( reason ); if ( reason instanceof ICDIEndSteppingRange ) { @@ -1022,6 +1052,10 @@ public class CThread extends CDebugElement implements ICThread, IRestart, IResum private void syncWithBackend() { ICDIThread cdiThread = getCDIThread(); + if (cdiThread == null) { + return; + } + ICDIThread currentThread = null; try { currentThread = cdiThread.getTarget().getCurrentThread();