From 476100749932568f347ed5aa8e7491ee4b0c0449 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Thu, 21 Oct 2004 20:19:08 +0000 Subject: [PATCH] Pass the target state to threads on terminate, disconnect, resume, suspend and restart. --- debug/org.eclipse.cdt.debug.core/ChangeLog | 7 +++ .../internal/core/model/CDebugElement.java | 14 +++++- .../internal/core/model/CDebugTarget.java | 49 +++++++++++-------- .../debug/internal/core/model/CThread.java | 4 -- .../core/model/CoreModelMessages.properties | 1 - 5 files changed, 47 insertions(+), 28 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index bf1f0b15fb1..3b8473d1845 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,10 @@ +2004-10-21 Mikhail Khodjaiants + Pass the target state to threads on terminate, disconnect, resume, suspend and restart. + * CoreModelMessages.properties + * CDebugElement.java + * CDebugTarget.java + * CThread.java + 2004-10-19 Mikhail Khodjaiants Set the initial state of a thread according to the state of the underlying CDI thread. * CThread.java diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugElement.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugElement.java index d2582d4d19a..02d85ab39bc 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugElement.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugElement.java @@ -52,10 +52,15 @@ abstract public class CDebugElement extends PlatformObject implements ICDebugEle private String fMessage = null; /** - * The state of this element. + * The current state of this element. */ private CDebugElementState fState = CDebugElementState.UNDEFINED; + /** + * The previous state of this element. + */ + private CDebugElementState fOldState = CDebugElementState.UNDEFINED; + /** * The current state info. */ @@ -336,10 +341,15 @@ abstract public class CDebugElement extends PlatformObject implements ICDebugEle return fState; } - protected void setState( CDebugElementState state ) throws IllegalArgumentException { + protected synchronized void setState( CDebugElementState state ) throws IllegalArgumentException { + fOldState = fState; fState = state; } + protected synchronized void restoreState() { + fState = fOldState; + } + /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.model.ICDebugElement#getCurrentStateInfo() */ 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 e9de71ba66d..c1cefc01ffc 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 @@ -440,8 +440,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv if ( !canTerminate() ) { return; } - final CDebugElementState oldState = getState(); - setState( CDebugElementState.TERMINATING ); + changeState( CDebugElementState.TERMINATING ); DebugPlugin.getDefault().asyncExec( new Runnable() { public void run() { @@ -449,7 +448,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv getCDITarget().terminate(); } catch( CDIException e ) { - setState( oldState ); + restoreOldState(); try { targetRequestFailed( e.getMessage(), e ); } @@ -500,8 +499,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv public void resume() throws DebugException { if ( !canResume() ) return; - final CDebugElementState oldState = getState(); - setState( CDebugElementState.RESUMING ); + changeState( CDebugElementState.RESUMING ); DebugPlugin.getDefault().asyncExec( new Runnable() { public void run() { @@ -509,7 +507,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv getCDITarget().resume( false ); } catch( CDIException e ) { - setState( oldState ); + restoreOldState(); try { targetRequestFailed( e.getMessage(), e ); } @@ -527,8 +525,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv public void suspend() throws DebugException { if ( !canSuspend() ) return; - final CDebugElementState oldState = getState(); - setState( CDebugElementState.SUSPENDING ); + changeState( CDebugElementState.SUSPENDING ); DebugPlugin.getDefault().asyncExec( new Runnable() { public void run() { @@ -536,7 +533,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv getCDITarget().suspend(); } catch( CDIException e ) { - setState( oldState ); + restoreOldState(); try { targetRequestFailed( e.getMessage(), e ); } @@ -731,11 +728,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv if ( isDisconnecting() ) { return; } - if ( !supportsDisconnect() ) { - notSupported( CoreModelMessages.getString( "CDebugTarget.0" ) ); //$NON-NLS-1$ - } - final CDebugElementState oldState = getState(); - setState( CDebugElementState.DISCONNECTING ); + changeState( CDebugElementState.DISCONNECTING ); DebugPlugin.getDefault().asyncExec( new Runnable() { public void run() { @@ -743,7 +736,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv getCDITarget().disconnect(); } catch( CDIException e ) { - setState( oldState ); + restoreOldState(); try { targetRequestFailed( e.getMessage(), e ); } @@ -949,8 +942,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv if ( !canRestart() ) { return; } - final CDebugElementState oldState = getState(); - setState( CDebugElementState.RESTARTING ); + changeState( CDebugElementState.RESTARTING ); ICDILocation location = getCDITarget().createLocation( "", "main", 0 ); //$NON-NLS-1$ //$NON-NLS-2$ setInternalTemporaryBreakpoint( location ); DebugPlugin.getDefault().asyncExec( new Runnable() { @@ -960,7 +952,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv getCDITarget().restart(); } catch( CDIException e ) { - setState( oldState ); + restoreOldState(); try { targetRequestFailed( e.getMessage(), e ); } @@ -1540,8 +1532,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv public void resumeWithoutSignal() throws DebugException { if ( !canResume() ) return; - final CDebugElementState oldState = getState(); - setState( CDebugElementState.RESUMING ); + changeState( CDebugElementState.RESUMING ); DebugPlugin.getDefault().asyncExec( new Runnable() { public void run() { @@ -1549,7 +1540,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv getCDITarget().resume( false ); } catch( CDIException e ) { - setState( oldState ); + restoreOldState(); try { targetRequestFailed( e.getMessage(), e ); } @@ -1877,4 +1868,20 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv ms.add( new Status( IStatus.ERROR, CDebugModel.getPluginIdentifier(), ICDebugInternalConstants.STATUS_CODE_ERROR, e.getMessage(), e ) ); CDebugUtils.error( ms, this ); } + + private void changeState( CDebugElementState state ) { + setState( state ); + Iterator it = getThreadList().iterator(); + while( it.hasNext() ) { + ((CThread)it.next()).setState( state ); + } + } + + protected void restoreOldState() { + restoreState(); + Iterator it = getThreadList().iterator(); + while( it.hasNext() ) { + ((CThread)it.next()).restoreState(); + } + } } 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 11daf7747d9..099b3384067 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 @@ -910,10 +910,6 @@ public class CThread extends CDebugElement implements ICThread, IRestart, IResum } protected void suspendByTarget( ICDISessionObject reason, ICDIThread suspensionThread ) { - if ( !(getState().equals( CDebugElementState.RESUMED ) || - getState().equals( CDebugElementState.STEPPED ) || - getState().equals( CDebugElementState.SUSPENDING )) ) - return; setState( CDebugElementState.SUSPENDED ); setCurrentStateInfo( null ); if ( getCDIThread().equals( suspensionThread ) ) { diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CoreModelMessages.properties b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CoreModelMessages.properties index 793345ac2f0..fb96f8bf88a 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CoreModelMessages.properties +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CoreModelMessages.properties @@ -11,7 +11,6 @@ CDebugTarget.Unable_to_get_globals_1=Unable to get globals. Reason: CArrayPartition.0=Type is not available. CArrayPartition.1=Qualified name is not available. -CDebugTarget.0=Session does not support 'disconnect'. CDebugTarget.1=Execution is suspended because of error. CDebugTarget.2=Terminate failed. CDebugTarget.3=Resume failed.