diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IRestart.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IRestart.java index a6b26e8d464..b9f9ea25c76 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IRestart.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IRestart.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 QNX Software Systems and others. + * Copyright (c) 2000, 2010 QNX Software Systems 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 @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Navid Mehregani (TI) - Bug 289526 - Migrate the Restart feature to the new one, as supported by the platform *******************************************************************************/ package org.eclipse.cdt.debug.core.model; @@ -15,6 +16,8 @@ import org.eclipse.debug.core.DebugException; /** * Provides the ability to restart a debug target. * + * @deprecated Use org.eclipse.debug.core.commands.IRestartHandler instead. IRestartHandler + * handles the call in an asynchronous fashion. */ public interface IRestart { diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index 166ced8fd9b..1853b0395c2 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -372,12 +372,14 @@ - - + + id="org.eclipse.cdt.debug.ui.debugview.popupMenu2"> + + + + + + + + + + - - - canRestart = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { + public void canExecute(final IEnabledStateRequest request) { + if (request.getElements().length != 1) { + request.setEnabled(false); + request.done(); + return; + } + + fExecutor.submit(new DsfCommandRunnable(fTracker, request.getElements()[0], request) { + @Override public void doExecute() { IGDBControl gdbControl = fTracker.getService(IGDBControl.class); if (gdbControl != null) { - rm.setData(gdbControl.canRestart()); + request.setEnabled(gdbControl.canRestart()); } else { - rm.setData(false); - } - - rm.done(); - } - }; - - fExecutor.execute(canRestart); - try { - return canRestart.get(); - } catch (InterruptedException e1) { - } catch (ExecutionException e1) { - } - return false; + request.setEnabled(false); + } + request.done(); + } + }); } + + private class UpdateLaunchJob extends Job { + private final AtomicReference fExecPathRef; + + UpdateLaunchJob(IPath path) { + super(""); //$NON-NLS-1$ + setSystem(true); + fExecPathRef = new AtomicReference(path); + } + @Override + protected IStatus run(IProgressMonitor monitor) { + // Now that we restarted the inferior, we must add it to our launch + // we must do this here because we cannot do it in the executor, or else + // it deadlocks + // We must first remove the old inferior from our launch (since it uses + // the same name and we use that name to find the old one) + // + // Remove + String inferiorLabel = fExecPathRef.get().lastSegment(); - public void restart() throws DebugException - { - final AtomicReference execPathRef = new AtomicReference(); - Query restartQuery = new Query() { - @Override - protected void execute(final DataRequestMonitor rm) { + IProcess[] launchProcesses = fLaunch.getProcesses(); + for (IProcess p : launchProcesses) { + if (p.getLabel().equals(inferiorLabel)) { + fLaunch.removeProcess(p); + break; + } + } + // Add + try { + fLaunch.addInferiorProcess(inferiorLabel); + } catch (CoreException e) { + } + return Status.OK_STATUS; + } + } + + public boolean execute(final IDebugCommandRequest request) { + if (request.getElements().length != 1) { + request.done(); + return false; + } + + fExecutor.submit(new DsfCommandRunnable(fTracker, request.getElements()[0], request) { + @Override public void doExecute() { final IGDBControl gdbControl = fTracker.getService(IGDBControl.class); final IGDBBackend backend = fTracker.getService(IGDBBackend.class); - if (gdbControl != null && backend != null) { - execPathRef.set(backend.getProgramPath()); - gdbControl.initInferiorInputOutput(new RequestMonitor(fExecutor, rm) { + if (gdbControl != null && backend != null) { + gdbControl.initInferiorInputOutput(new RequestMonitor(fExecutor, null) { @Override - protected void handleSuccess() { - gdbControl.createInferiorProcess(); - gdbControl.restart(fLaunch, rm); + protected void handleCompleted() { + if (isSuccess()) { + gdbControl.createInferiorProcess(); + gdbControl.restart(fLaunch, new RequestMonitor(fExecutor, null)); + + // Update the launch outside the executor + new UpdateLaunchJob(backend.getProgramPath()).schedule(); + } } }); - } else { - rm.done(); } - } - }; - - fExecutor.execute(restartQuery); - try { - restartQuery.get(); - } catch (InterruptedException e1) { - } catch (ExecutionException e1) { - } - - // Now that we restarted the inferior, we must add it to our launch - // we must do this here because we cannot do it in the executor, or else - // it deadlocks - // We must first remove the old inferior from our launch (since it uses - // the same name and we use that name to find the old one) - // - // Remove - String inferiorLabel = execPathRef.get().lastSegment(); - - IProcess[] launchProcesses = fLaunch.getProcesses(); - for (IProcess p : launchProcesses) { - if (p.getLabel().equals(inferiorLabel)) { - fLaunch.removeProcess(p); - break; - } - } - // Add - try { - fLaunch.addInferiorProcess(inferiorLabel); - } catch (CoreException e) { - throw new DebugException(e.getStatus()); - } - } + } + }); + return false; + } }