1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Use the asynchronous implementation for resume, suspend, step etc provided by eclipse 3.1.

This commit is contained in:
Mikhail Khodjaiants 2005-01-11 20:43:57 +00:00
parent dd9f4af843
commit 0a9d717f51
10 changed files with 196 additions and 230 deletions

View file

@ -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

View file

@ -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();

View file

@ -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 );

View file

@ -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}

View file

@ -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

View file

@ -215,12 +215,7 @@
menubarPath="stepGroup"
enablesFor="1"
id="org.eclipse.cdt.debug.internal.ui.actions.RestartActionDelegate">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui">
</pluginState>
</enablement>
<selection class="org.eclipse.cdt.debug.core.model.IRestart"/>
</action>
<action
state="false"
@ -240,6 +235,17 @@
</pluginState>
</enablement>
</action>
<action
helpContextId="signal_zero_action_context"
enablesFor="1"
label="%SignalZeroAction.label"
tooltip="%SignalZeroAction.tooltip"
icon="icons/full/clcl16/signal0_co.gif"
class="org.eclipse.cdt.debug.internal.ui.actions.SignalZeroWorkbenchActionDelegate"
menubarPath="threadGroup"
id="org.eclipse.cdt.debug.internal.ui.actions.SignalZeroWorkbenchActionDelegate">
<selection class="org.eclipse.cdt.debug.core.model.IResumeWithoutSignal"/>
</action>
</viewerContribution>
<viewerContribution
targetID="#CEditorRulerContext"
@ -514,21 +520,6 @@
<objectContribution
objectClass="org.eclipse.cdt.debug.core.model.IResumeWithoutSignal"
id="org.eclipse.cdt.debug.ui.DebugTargetActions">
<action
label="%SignalZeroAction.label"
icon="icons/full/clcl16/signal0_co.gif"
helpContextId="signal_zero_action_context"
class="org.eclipse.cdt.debug.internal.ui.actions.SignalZeroObjectActionDelegate"
menubarPath="threadGroup"
enablesFor="1"
id="org.eclipse.cdt.debug.internal.ui.actions.SignalZeroObjectActionDelegate">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui">
</pluginState>
</enablement>
</action>
</objectContribution>
<objectContribution
objectClass="org.eclipse.cdt.debug.core.model.ICastToType"
@ -749,12 +740,7 @@
helpContextId="restart_action_context"
label="%RestartAction.label"
tooltip="%RestartAction.tooltip">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui">
</pluginState>
</enablement>
<selection class="org.eclipse.cdt.debug.core.model.IRestart"/>
</action>
<action
state="false"

View file

@ -1,6 +1,6 @@
/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* 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
@ -10,18 +10,25 @@
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
import java.util.Iterator;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.IActionDelegate2;
import org.eclipse.ui.INullSelectionListener;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IViewActionDelegate;
@ -31,7 +38,7 @@ import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
public abstract class AbstractDebugActionDelegate implements IWorkbenchWindowActionDelegate, IViewActionDelegate, ISelectionListener, INullSelectionListener {
public abstract class AbstractDebugActionDelegate implements IWorkbenchWindowActionDelegate, IViewActionDelegate, IActionDelegate2, ISelectionListener, INullSelectionListener {
/**
* The underlying action for this delegate
@ -46,7 +53,7 @@ public abstract class AbstractDebugActionDelegate implements IWorkbenchWindowAct
/**
* Cache of the most recent seletion
*/
private IStructuredSelection fSelection;
private IStructuredSelection fSelection = StructuredSelection.EMPTY;
/**
* Whether this delegate has been initialized
@ -59,6 +66,54 @@ public abstract class AbstractDebugActionDelegate implements IWorkbenchWindowAct
*/
protected IWorkbenchWindow fWindow;
/**
* Background job for this action, or <code>null</code> 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.
* </p>
*
* @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) {
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}