mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 338319: First step to allow terminating individual processes
This commit is contained in:
parent
cbb43fd93b
commit
3a6830d2ea
2 changed files with 42 additions and 25 deletions
|
@ -13,17 +13,15 @@ package org.eclipse.cdt.dsf.gdb.internal.ui.actions;
|
||||||
|
|
||||||
import java.util.concurrent.RejectedExecutionException;
|
import java.util.concurrent.RejectedExecutionException;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
|
||||||
import org.eclipse.cdt.dsf.concurrent.DsfExecutor;
|
import org.eclipse.cdt.dsf.concurrent.DsfExecutor;
|
||||||
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
|
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
|
||||||
import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor;
|
import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor;
|
||||||
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
|
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
|
||||||
import org.eclipse.cdt.dsf.datamodel.DMContexts;
|
import org.eclipse.cdt.dsf.datamodel.DMContexts;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IRunControl.IExecutionDMContext;
|
import org.eclipse.cdt.dsf.debug.service.IProcesses;
|
||||||
import org.eclipse.cdt.dsf.debug.ui.actions.DsfCommandRunnable;
|
import org.eclipse.cdt.dsf.debug.service.IProcesses.IProcessDMContext;
|
||||||
import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin;
|
import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin;
|
||||||
import org.eclipse.cdt.dsf.gdb.service.IGDBBackend;
|
|
||||||
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl;
|
|
||||||
import org.eclipse.cdt.dsf.mi.service.IMIBackend;
|
|
||||||
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
|
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
|
||||||
import org.eclipse.cdt.dsf.service.DsfSession;
|
import org.eclipse.cdt.dsf.service.DsfSession;
|
||||||
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
|
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
|
||||||
|
@ -54,11 +52,11 @@ public class DsfTerminateCommand implements ITerminateHandler {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Javac doesn't like the cast to "(AbstractDMVMLayoutNode<?>.DMVMContext)" need to use the
|
|
||||||
// construct below and suppress warnings.
|
|
||||||
IDMVMContext vmc = (IDMVMContext)request.getElements()[0];
|
IDMVMContext vmc = (IDMVMContext)request.getElements()[0];
|
||||||
final IExecutionDMContext dmc = DMContexts.getAncestorOfType(vmc.getDMContext(), IExecutionDMContext.class);
|
|
||||||
if (dmc == null) {
|
// First check if there is an ancestor process to terminate. This is the smallest entity we can terminate
|
||||||
|
final IProcessDMContext processDmc = DMContexts.getAncestorOfType(vmc.getDMContext(), IProcessDMContext.class);
|
||||||
|
if (processDmc == null) {
|
||||||
request.setEnabled(false);
|
request.setEnabled(false);
|
||||||
request.done();
|
request.done();
|
||||||
return;
|
return;
|
||||||
|
@ -69,15 +67,19 @@ public class DsfTerminateCommand implements ITerminateHandler {
|
||||||
new DsfRunnable() {
|
new DsfRunnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
// Get the processes service and the exec context.
|
// Get the processes service and the exec context.
|
||||||
IGDBBackend gdbBackend = fTracker.getService(IGDBBackend.class);
|
IProcesses procService = fTracker.getService(IProcesses.class);
|
||||||
if (gdbBackend == null || dmc == null) {
|
if (procService == null) {
|
||||||
// Context or service already invalid.
|
// Service already invalid.
|
||||||
request.setEnabled(false);
|
request.setEnabled(false);
|
||||||
request.done();
|
request.done();
|
||||||
} else {
|
} else {
|
||||||
// Check the terminate.
|
procService.canTerminate(processDmc, new DataRequestMonitor<Boolean>(ImmediateExecutor.getInstance(), null) {
|
||||||
request.setEnabled(gdbBackend.getState() == IMIBackend.State.STARTED);
|
@Override
|
||||||
request.done();
|
protected void handleCompleted() {
|
||||||
|
request.setEnabled(isSuccess() && getData());
|
||||||
|
request.done();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -88,17 +90,27 @@ public class DsfTerminateCommand implements ITerminateHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean execute(final IDebugCommandRequest request) {
|
public boolean execute(final IDebugCommandRequest request) {
|
||||||
if (request.getElements().length != 1) {
|
if (request.getElements().length != 1 ||
|
||||||
request.done();
|
!(request.getElements()[0] instanceof IDMVMContext)) {
|
||||||
return false;
|
request.done();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
IDMVMContext vmc = (IDMVMContext)request.getElements()[0];
|
||||||
|
|
||||||
|
// First check if there is an ancestor process to terminate. This is the smallest entity we can terminate
|
||||||
|
final IProcessDMContext processDmc = DMContexts.getAncestorOfType(vmc.getDMContext(), IProcessDMContext.class);
|
||||||
|
if (processDmc == null) {
|
||||||
|
request.done();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fExecutor.submit(new DsfCommandRunnable(fTracker, request.getElements()[0], request) {
|
fExecutor.execute(new DsfRunnable() {
|
||||||
@Override public void doExecute() {
|
public void run() {
|
||||||
IGDBControl gdbControl = fTracker.getService(IGDBControl.class);
|
IProcesses procService = fTracker.getService(IProcesses.class);
|
||||||
if (gdbControl != null) {
|
if (procService != null) {
|
||||||
gdbControl.terminate(new RequestMonitor(ImmediateExecutor.getInstance(), null) {
|
procService.terminate(processDmc, new RequestMonitor(ImmediateExecutor.getInstance(), null) {
|
||||||
@Override
|
@Override
|
||||||
protected void handleCompleted() {
|
protected void handleCompleted() {
|
||||||
request.setStatus(getStatus());
|
request.setStatus(getStatus());
|
||||||
|
|
|
@ -1097,7 +1097,12 @@ public class GDBProcesses_7_0 extends AbstractDsfService
|
||||||
}
|
}
|
||||||
|
|
||||||
public void terminate(IThreadDMContext thread, RequestMonitor rm) {
|
public void terminate(IThreadDMContext thread, RequestMonitor rm) {
|
||||||
fCommandControl.terminate(rm);
|
if (thread instanceof IMIProcessDMContext) {
|
||||||
|
fCommandControl.terminate(rm);
|
||||||
|
} else {
|
||||||
|
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Invalid process context.", null)); //$NON-NLS-1$
|
||||||
|
rm.done();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @since 4.0 */
|
/** @since 4.0 */
|
||||||
|
|
Loading…
Add table
Reference in a new issue