From 0a9d717f51ce63dac638777a1a7522a3cc759a6d Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Tue, 11 Jan 2005 20:43:57 +0000 Subject: [PATCH] Use the asynchronous implementation for resume, suspend, step etc provided by eclipse 3.1. --- debug/org.eclipse.cdt.debug.core/ChangeLog | 6 + .../internal/core/model/CDebugTarget.java | 54 ++---- .../debug/internal/core/model/CThread.java | 12 -- .../core/model/CoreModelMessages.properties | 6 - debug/org.eclipse.cdt.debug.ui/ChangeLog | 8 + debug/org.eclipse.cdt.debug.ui/plugin.xml | 40 ++-- .../actions/AbstractDebugActionDelegate.java | 181 ++++++++++++++---- .../ui/actions/RestartActionDelegate.java | 7 + .../SignalZeroObjectActionDelegate.java | 105 ---------- .../SignalZeroWorkbenchActionDelegate.java | 7 + 10 files changed, 196 insertions(+), 230 deletions(-) delete mode 100644 debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/SignalZeroObjectActionDelegate.java diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index b95216d93c1..98eb8ed025f 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,9 @@ +2005-01-11 Mikhail Khodjaiants + Use the asynchronous implementation for resume, suspend, step etc provided by eclipse 3.1. + * CDebugTarget.java + * CThread.java + * CoreModelMessages.properties + 2005-01-10 Mikhail Khodjaiants Use the asynchronous implementation for resume, suspend, step etc provided by eclipse 3.1. * CDebugTarget.java 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 4f0beafdb77..751f94fabc0 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 @@ -910,23 +910,13 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv changeState( CDebugElementState.RESTARTING ); ICDILocation location = getCDITarget().createLocation( "", "main", 0 ); //$NON-NLS-1$ //$NON-NLS-2$ setInternalTemporaryBreakpoint( location ); - DebugPlugin.getDefault().asyncExec( new Runnable() { - - public void run() { - try { - getCDITarget().restart(); - } - catch( CDIException e ) { - restoreOldState(); - try { - targetRequestFailed( e.getMessage(), e ); - } - catch( DebugException e1 ) { - failed( CoreModelMessages.getString( "CDebugTarget.6" ), e1 ); //$NON-NLS-1$ - } - } - } - } ); + try { + getCDITarget().restart(); + } + catch( CDIException e ) { + restoreOldState(); + targetRequestFailed( e.getMessage(), e ); + } } /** @@ -1498,23 +1488,13 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv if ( !canResume() ) return; changeState( CDebugElementState.RESUMING ); - DebugPlugin.getDefault().asyncExec( new Runnable() { - - public void run() { - try { - getCDITarget().resume( false ); - } - catch( CDIException e ) { - restoreOldState(); - try { - targetRequestFailed( e.getMessage(), e ); - } - catch( DebugException e1 ) { - failed( CoreModelMessages.getString( "CDebugTarget.7" ), e1 ); //$NON-NLS-1$ - } - } - } - } ); + try { + getCDITarget().resume( false ); + } + catch( CDIException e ) { + restoreOldState(); + targetRequestFailed( e.getMessage(), e ); + } } /* (non-Javadoc) @@ -1804,12 +1784,6 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv fMemoryBlockRetrieval = memoryBlockRetrieval; } - protected void failed( String message, Throwable e ) { - MultiStatus ms = new MultiStatus( CDebugModel.getPluginIdentifier(), ICDebugInternalConstants.STATUS_CODE_ERROR, message, null ); - 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(); 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 be49aebe8f7..039f06ae40d 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 @@ -15,8 +15,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; -import org.eclipse.cdt.debug.core.CDebugModel; -import org.eclipse.cdt.debug.core.CDebugUtils; import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.ICDIBreakpointHit; import org.eclipse.cdt.debug.core.cdi.ICDIEndSteppingRange; @@ -43,11 +41,7 @@ import org.eclipse.cdt.debug.core.model.IDummyStackFrame; import org.eclipse.cdt.debug.core.model.IRestart; import org.eclipse.cdt.debug.core.model.IResumeWithoutSignal; import org.eclipse.cdt.debug.core.model.IRunToLine; -import org.eclipse.cdt.debug.internal.core.ICDebugInternalConstants; import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.model.IBreakpoint; @@ -860,12 +854,6 @@ public class CThread extends CDebugElement implements ICThread, IRestart, IResum return ((CDebugTarget)getDebugTarget()).isInstructionSteppingEnabled(); } - protected void failed( String message, Throwable e ) { - MultiStatus ms = new MultiStatus( CDebugModel.getPluginIdentifier(), ICDebugInternalConstants.STATUS_CODE_ERROR, message, null ); - ms.add( new Status( IStatus.ERROR, CDebugModel.getPluginIdentifier(), ICDebugInternalConstants.STATUS_CODE_ERROR, e.getMessage(), e ) ); - CDebugUtils.error( ms, this ); - } - protected void suspendByTarget( ICDISessionObject reason, ICDIThread suspensionThread ) { setState( CDebugElementState.SUSPENDED ); setCurrentStateInfo( null ); 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 9e8f1157a02..eaf547eb911 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 @@ -12,12 +12,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.1=Execution is suspended because of error. -CDebugTarget.2=Terminate failed. -CDebugTarget.3=Resume failed. -CDebugTarget.4=Suspend failed. -CDebugTarget.5=Disconnect failed. -CDebugTarget.6=Restart failed. -CDebugTarget.7=Resume without signal failed. CModificationVariable.0=Unable to set value. CModificationVariable.1=Unable to set value. CStackFrame.0={0} at {1}: {2} diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog index f66b6bbf839..9d86ee69a9f 100644 --- a/debug/org.eclipse.cdt.debug.ui/ChangeLog +++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog @@ -1,3 +1,11 @@ +2005-01-11 Mikhail Khodjaiants + Use the asynchronous implementation for resume, suspend, step etc provided by eclipse 3.1. + * plugin.xml + * AbstractDebugActionDelegate.java + * RestartActionDelegate.java + * SignalZeroWorkbenchActionDelegate.java + * SignalZeroObjectActionDelegate.java: removed + 2005-01-04 Mikhail Khodjaiants Removed the disassembly editor extension. * plugin.xml diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index baec8776cc4..d0a51a72c70 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -215,12 +215,7 @@ menubarPath="stepGroup" enablesFor="1" id="org.eclipse.cdt.debug.internal.ui.actions.RestartActionDelegate"> - - - - + + + + - - - - - - - - - - + null if none. + */ + private DebugRequestJob fBackgroundJob = null; + + class DebugRequestJob extends Job { + + private Object[] fElements = null; + + /** + * Constructs a new job to perform a debug request (for example, step) + * in the background. + * + * @param name job name + */ + public DebugRequestJob(String name) { + super(name); + setPriority(Job.INTERACTIVE); + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + protected IStatus run(IProgressMonitor monitor) { + MultiStatus status= + new MultiStatus(CDebugUIPlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED, getStatusMessage(), null); + for (int i = 0; i < fElements.length; i++) { + Object element= fElements[i]; + try { + doAction(element); + } catch (DebugException e) { + status.merge(e.getStatus()); + } + } + return status; + } + + /** + * Sets the selection to operate on. + * + * @param elements + */ + public void setTargets(Object[] elements) { + fElements = elements; + } + + } + /** * It's crucial that delegate actions have a zero-arg constructor so that * they can be reflected into existence when referenced in an action set @@ -67,17 +122,19 @@ public abstract class AbstractDebugActionDelegate implements IWorkbenchWindowAct public AbstractDebugActionDelegate() { } - /** - * @see IWorkbenchWindowActionDelegate#dispose() + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() */ public void dispose(){ if (getWindow() != null) { getWindow().getSelectionService().removeSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this); } + fBackgroundJob = null; + fSelection= null; } - /** - * @see IWorkbenchWindowActionDelegate#init(IWorkbenchWindow) + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) */ public void init(IWorkbenchWindow window){ // listen to selection changes in the debug view @@ -85,36 +142,74 @@ public abstract class AbstractDebugActionDelegate implements IWorkbenchWindowAct window.getSelectionService().addSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this); } - /** - * @see IActionDelegate#run(IAction) + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ public void run(IAction action){ - IStructuredSelection selection= getSelection(); - - final Iterator enum= selection.iterator(); - String pluginId= DebugUIPlugin.getUniqueIdentifier(); - final MultiStatus ms= - new MultiStatus(pluginId, DebugException.REQUEST_FAILED, getStatusMessage(), null); + if (action.isEnabled()) { + IStructuredSelection selection = getSelection(); + // disable the action so it cannot be run again until an event or selection change + // updates the enablement + action.setEnabled(false); + if (isRunInBackground()) { + runInBackground(action, selection); + } else { + runInForeground(selection); + } + } + } + + /** + * Runs this action in a background job. + */ + private void runInBackground(IAction action, IStructuredSelection selection) { + if (fBackgroundJob == null) { + fBackgroundJob = new DebugRequestJob(action.getText()); + } + fBackgroundJob.setTargets(selection.toArray()); + fBackgroundJob.schedule(); + } + + /** + * Runs this action in the UI thread. + */ + private void runInForeground(final IStructuredSelection selection) { + final MultiStatus status= + new MultiStatus(CDebugUIPlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED, getStatusMessage(), null); BusyIndicator.showWhile(Display.getCurrent(), new Runnable() { public void run() { - while (enum.hasNext()) { - Object element= enum.next(); + Iterator selectionIter = selection.iterator(); + while (selectionIter.hasNext()) { + Object element= selectionIter.next(); try { doAction(element); } catch (DebugException e) { - ms.merge(e.getStatus()); + status.merge(e.getStatus()); } } } }); + reportErrors(status); + } + + private void reportErrors(final MultiStatus ms) { if (!ms.isOK()) { - IWorkbenchWindow window= DebugUIPlugin.getActiveWorkbenchWindow(); + IWorkbenchWindow window= CDebugUIPlugin.getActiveWorkbenchWindow(); if (window != null) { - DebugUIPlugin.errorDialog(window.getShell(), getErrorDialogTitle(), getErrorDialogMessage(), ms); + ErrorDialog.openError(window.getShell(), getErrorDialogTitle(), getErrorDialogMessage(), ms); } else { - DebugUIPlugin.log(ms); + CDebugUIPlugin.log(ms); } - } + } + } + + /** + * Returns whether or not this action should be run in the background. + * Subclasses may override. + * @return whether or not this action should be run in the background + */ + protected boolean isRunInBackground() { + return false; } /** @@ -133,7 +228,7 @@ public abstract class AbstractDebugActionDelegate implements IWorkbenchWindowAct * in the debug view only. *

* - * @see IActionDelegate#selectionChanged(IAction, ISelection) + * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) */ public void selectionChanged(IAction action, ISelection s) { boolean wasInitialized= initialize(action, s); @@ -186,8 +281,8 @@ public abstract class AbstractDebugActionDelegate implements IWorkbenchWindowAct return ""; //$NON-NLS-1$ } - /** - * @see IViewActionDelegate#init(IViewPart) + /* (non-Javadoc) + * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) */ public void init(IViewPart view) { fViewPart = view; @@ -238,13 +333,6 @@ public abstract class AbstractDebugActionDelegate implements IWorkbenchWindowAct * @return structured selection */ protected IStructuredSelection getSelection() { - if (getView() != null) { - //cannot used the cached selection in a view - //as the selection can be out of date for context menu - //actions. See bug 14556 - ISelection s= getView().getViewSite().getSelectionProvider().getSelection(); - return (s instanceof IStructuredSelection)? (IStructuredSelection)s : StructuredSelection.EMPTY; - } return fSelection; } @@ -256,9 +344,9 @@ public abstract class AbstractDebugActionDelegate implements IWorkbenchWindowAct private void setSelection(IStructuredSelection selection) { fSelection = selection; } - - /** - * @see ISelectionListener#selectionChanged(IWorkbenchPart, ISelection) + + /* (non-Javadoc) + * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) */ public void selectionChanged(IWorkbenchPart part, ISelection selection) { update(getAction(), selection); @@ -299,9 +387,9 @@ public abstract class AbstractDebugActionDelegate implements IWorkbenchWindowAct if (selection.size() == 0) { return false; } - Iterator enum= selection.iterator(); - while (enum.hasNext()) { - Object element= enum.next(); + Iterator itr= selection.iterator(); + while (itr.hasNext()) { + Object element= itr.next(); if (!isEnabledFor(element)) { return false; } @@ -312,4 +400,17 @@ public abstract class AbstractDebugActionDelegate implements IWorkbenchWindowAct protected boolean isEnabledFor(Object element) { return true; } -} + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event) + */ + public void runWithEvent(IAction action, Event event) { + run(action); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction) + */ + public void init(IAction action) { + } +} \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestartActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestartActionDelegate.java index 42421d6016e..f9c89a842e1 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestartActionDelegate.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestartActionDelegate.java @@ -72,4 +72,11 @@ public class RestartActionDelegate extends AbstractListenerActionDelegate { protected String getErrorDialogTitle() { return ActionMessages.getString( "RestartActionDelegate.2" ); //$NON-NLS-1$ } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.internal.ui.actions.AbstractDebugActionDelegate#isRunInBackground() + */ + protected boolean isRunInBackground() { + return true; + } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/SignalZeroObjectActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/SignalZeroObjectActionDelegate.java deleted file mode 100644 index 6992ca0ff5b..00000000000 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/SignalZeroObjectActionDelegate.java +++ /dev/null @@ -1,105 +0,0 @@ -/********************************************************************** - * Copyright (c) 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - ***********************************************************************/ -package org.eclipse.cdt.debug.internal.ui.actions; - -import org.eclipse.cdt.debug.core.model.IResumeWithoutSignal; -import org.eclipse.cdt.debug.ui.CDebugUIPlugin; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.debug.core.DebugException; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.actions.ActionDelegate; - -/** - * The object contribution delegate of the "Resume Without Signal" action. - */ -public class SignalZeroObjectActionDelegate extends ActionDelegate implements IObjectActionDelegate { - - private IResumeWithoutSignal fTarget = null; - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) - */ - public void setActivePart( IAction action, IWorkbenchPart targetPart ) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.IActionDelegate#run(IAction) - */ - public void run( IAction action ) { - if ( getTarget() != null ) { - final MultiStatus ms = new MultiStatus( CDebugUIPlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED, ActionMessages.getString( "SignalZeroObjectActionDelegate.0" ), null ); //$NON-NLS-1$ - BusyIndicator.showWhile( Display.getCurrent(), new Runnable() { - - public void run() { - try { - doAction( getTarget() ); - } - catch( DebugException e ) { - ms.merge( e.getStatus() ); - } - } - } ); - if ( !ms.isOK() ) { - IWorkbenchWindow window = CDebugUIPlugin.getActiveWorkbenchWindow(); - if ( window != null ) { - CDebugUIPlugin.errorDialog( ActionMessages.getString( "SignalZeroObjectActionDelegate.1" ), ms ); //$NON-NLS-1$ - } - else { - CDebugUIPlugin.log( ms ); - } - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection) - */ - public void selectionChanged( IAction action, ISelection selection ) { - if ( selection instanceof IStructuredSelection ) { - Object element = ((IStructuredSelection)selection).getFirstElement(); - if ( element instanceof IResumeWithoutSignal ) { - boolean enabled = ((IResumeWithoutSignal)element).canResumeWithoutSignal(); - action.setEnabled( enabled ); - if ( enabled ) { - setTarget( (IResumeWithoutSignal)element ); - return; - } - } - } - action.setEnabled( false ); - setTarget( null ); - } - - protected void doAction( IResumeWithoutSignal target ) throws DebugException { - target.resumeWithoutSignal(); - } - - protected IResumeWithoutSignal getTarget() { - return fTarget; - } - - protected void setTarget( IResumeWithoutSignal target ) { - fTarget = target; - } -} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/SignalZeroWorkbenchActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/SignalZeroWorkbenchActionDelegate.java index f602d593d8d..7bf23cbc95b 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/SignalZeroWorkbenchActionDelegate.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/SignalZeroWorkbenchActionDelegate.java @@ -61,4 +61,11 @@ public class SignalZeroWorkbenchActionDelegate extends AbstractListenerActionDel protected String getErrorDialogTitle() { return ActionMessages.getString( "SignalZeroWorkbenchActionDelegate.2" ); //$NON-NLS-1$ } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.internal.ui.actions.AbstractDebugActionDelegate#isRunInBackground() + */ + protected boolean isRunInBackground() { + return true; + } }