1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 335528: Add method to allow overriding which StartOrRestart and DebugNewProcess sequences to use.

This commit is contained in:
Marc Khouzam 2011-02-16 11:39:41 +00:00
parent 54a25cca18
commit b9d2bc1e13
6 changed files with 97 additions and 44 deletions

View file

@ -20,6 +20,7 @@ import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants;
import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor; import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor;
import org.eclipse.cdt.dsf.concurrent.ReflectionSequence; import org.eclipse.cdt.dsf.concurrent.ReflectionSequence;
import org.eclipse.cdt.dsf.concurrent.RequestMonitor; import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
import org.eclipse.cdt.dsf.concurrent.Sequence;
import org.eclipse.cdt.dsf.datamodel.DMContexts; import org.eclipse.cdt.dsf.datamodel.DMContexts;
import org.eclipse.cdt.dsf.datamodel.IDMContext; import org.eclipse.cdt.dsf.datamodel.IDMContext;
import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext; import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext;
@ -68,7 +69,7 @@ public class DebugNewProcessSequence extends ReflectionSequence {
fContainerCtx = ctx; fContainerCtx = ctx;
} }
public DebugNewProcessSequence(DsfExecutor executor, IDMContext dmc, String file, Map<String, Object> attributes, DataRequestMonitor<IDMContext> rm) { public DebugNewProcessSequence(DsfExecutor executor, boolean isInitial, IDMContext dmc, String file, Map<String, Object> attributes, DataRequestMonitor<IDMContext> rm) {
super(executor, rm); super(executor, rm);
fContext = dmc; fContext = dmc;
fBinaryName = file; fBinaryName = file;
@ -94,7 +95,7 @@ public class DebugNewProcessSequence extends ReflectionSequence {
} }
/** /**
* Initialize the members of the {@link StartOrRestartProcessSequence_7_0} class. * Initialize the members of the DebugNewProcessSequence class.
* This step is mandatory for the rest of the sequence to complete. * This step is mandatory for the rest of the sequence to complete.
*/ */
@Execute @Execute
@ -267,7 +268,7 @@ public class DebugNewProcessSequence extends ReflectionSequence {
public void stepStartExecution(final RequestMonitor rm) { public void stepStartExecution(final RequestMonitor rm) {
if (fBackend.getSessionType() != SessionType.CORE) { if (fBackend.getSessionType() != SessionType.CORE) {
ImmediateExecutor.getInstance().execute( ImmediateExecutor.getInstance().execute(
new StartOrRestartProcessSequence_7_0( getStartOrRestartProcessSequence(
getExecutor(), getContainerContext(), fAttributes, false, getExecutor(), getContainerContext(), fAttributes, false,
new DataRequestMonitor<IContainerDMContext>(ImmediateExecutor.getInstance(), rm) { new DataRequestMonitor<IContainerDMContext>(ImmediateExecutor.getInstance(), rm) {
@Override @Override
@ -299,4 +300,14 @@ public class DebugNewProcessSequence extends ReflectionSequence {
fTracker = null; fTracker = null;
rm.done(); rm.done();
} }
/**
* Return the sequence that is to be used to start or restart the specified process.
* Allows others to extend more easily.
*/
protected Sequence getStartOrRestartProcessSequence(DsfExecutor executor, IContainerDMContext containerDmc,
Map<String, Object> attributes, boolean restart,
DataRequestMonitor<IContainerDMContext> rm) {
return new StartOrRestartProcessSequence_7_0(executor, containerDmc, attributes, restart, rm);
}
} }

View file

@ -41,13 +41,13 @@ public class DebugNewProcessSequence_7_2 extends DebugNewProcessSequence {
private IGDBControl fGdbControl; private IGDBControl fGdbControl;
private IGDBProcesses fProcService; private IGDBProcesses fProcService;
private String fSessionId; private String fSessionId;
private boolean fInitialProcess; private final boolean fInitialProcess;
public DebugNewProcessSequence_7_2(DsfExecutor executor, boolean initialProcess, IDMContext dmc, String file, public DebugNewProcessSequence_7_2(DsfExecutor executor, boolean isInitial, IDMContext dmc, String file,
Map<String, Object> attributes, DataRequestMonitor<IDMContext> rm) { Map<String, Object> attributes, DataRequestMonitor<IDMContext> rm) {
super(executor, dmc, file, attributes, rm); super(executor, isInitial, dmc, file, attributes, rm);
fSessionId = dmc.getSessionId(); fSessionId = dmc.getSessionId();
fInitialProcess = initialProcess; fInitialProcess = isInitial;
} }
@Override @Override
@ -68,7 +68,7 @@ public class DebugNewProcessSequence_7_2 extends DebugNewProcessSequence {
} }
/** /**
* Initialize the members of the {@link DebugNewProcessSequence_7_2} class. * Initialize the members of the DebugNewProcessSequence_7_2 class.
* This step is mandatory for the rest of the sequence to complete. * This step is mandatory for the rest of the sequence to complete.
*/ */
@Execute @Execute

View file

@ -20,8 +20,10 @@ import org.eclipse.cdt.core.IProcessList;
import org.eclipse.cdt.debug.core.CDebugUtils; import org.eclipse.cdt.debug.core.CDebugUtils;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.DsfExecutor;
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.concurrent.Sequence;
import org.eclipse.cdt.dsf.datamodel.DMContexts; import org.eclipse.cdt.dsf.datamodel.DMContexts;
import org.eclipse.cdt.dsf.datamodel.IDMContext; import org.eclipse.cdt.dsf.datamodel.IDMContext;
import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext; import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext;
@ -279,7 +281,17 @@ public class GDBProcesses extends MIProcesses implements IGDBProcesses {
public void debugNewProcess(IDMContext dmc, String file, public void debugNewProcess(IDMContext dmc, String file,
Map<String, Object> attributes, DataRequestMonitor<IDMContext> rm) { Map<String, Object> attributes, DataRequestMonitor<IDMContext> rm) {
ImmediateExecutor.getInstance().execute( ImmediateExecutor.getInstance().execute(
new DebugNewProcessSequence(getExecutor(), dmc, file, attributes, rm)); getDebugNewProcessSequence(getExecutor(), true, dmc, file, attributes, rm));
}
/**
* Return the sequence that is to be used to create a new process.
* Allows others to extend more easily.
* @since 4.0
*/
protected Sequence getDebugNewProcessSequence(DsfExecutor executor, boolean isInitial, IDMContext dmc, String file,
Map<String, Object> attributes, DataRequestMonitor<IDMContext> rm) {
return new DebugNewProcessSequence(executor, isInitial, dmc, file, attributes, rm);
} }
@Override @Override

View file

@ -24,6 +24,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IProcessInfo; import org.eclipse.cdt.core.IProcessInfo;
import org.eclipse.cdt.core.IProcessList; import org.eclipse.cdt.core.IProcessList;
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.DsfExecutor;
import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor; import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor;
import org.eclipse.cdt.dsf.concurrent.Immutable; import org.eclipse.cdt.dsf.concurrent.Immutable;
import org.eclipse.cdt.dsf.concurrent.RequestMonitor; import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
@ -435,6 +436,9 @@ public class GDBProcesses_7_0 extends AbstractDsfService
private static final String FAKE_THREAD_ID = "0"; //$NON-NLS-1$ private static final String FAKE_THREAD_ID = "0"; //$NON-NLS-1$
/**
* Keeps track if we are dealing with the very first process of GDB.
*/
private boolean fInitialProcess = true; private boolean fInitialProcess = true;
public GDBProcesses_7_0(DsfSession session) { public GDBProcesses_7_0(DsfSession session) {
@ -538,6 +542,16 @@ public class GDBProcesses_7_0 extends AbstractDsfService
return fGroupToPidMap; return fGroupToPidMap;
} }
/** @since 4.0 */
protected boolean isInitialProcess() {
return fInitialProcess;
}
/** @since 4.0 */
protected void setIsInitialProcess(boolean isInitial) {
fInitialProcess = isInitial;
}
/** /**
* Returns the groupId that is associated with the provided pId * Returns the groupId that is associated with the provided pId
* @since 4.0 * @since 4.0
@ -736,6 +750,13 @@ public class GDBProcesses_7_0 extends AbstractDsfService
new Step() { new Step() {
@Override @Override
public void execute(RequestMonitor rm) { public void execute(RequestMonitor rm) {
if (isInitialProcess()) {
// To be proper, set the initialProcess variable to false
// it may be necessary for a class that extends this class
setIsInitialProcess(false);
}
// There is no groupId until we attach, so we can use the default groupId // There is no groupId until we attach, so we can use the default groupId
fContainerDmc = createContainerContext(procCtx, MIProcesses.UNIQUE_GROUP_ID); fContainerDmc = createContainerContext(procCtx, MIProcesses.UNIQUE_GROUP_ID);
@ -857,20 +878,35 @@ public class GDBProcesses_7_0 extends AbstractDsfService
public void debugNewProcess(IDMContext dmc, String file, public void debugNewProcess(IDMContext dmc, String file,
Map<String, Object> attributes, DataRequestMonitor<IDMContext> rm) { Map<String, Object> attributes, DataRequestMonitor<IDMContext> rm) {
if (!fInitialProcess) {
// If we have already dealt with the initial process, check if we are allowed to create another one // Store the current value of the initialProcess variable because we will use it later
// and we are about to change it.
boolean isInitial = isInitialProcess();
if (isInitialProcess()) {
setIsInitialProcess(false);
} else {
// If we are trying to create another process than the initial one, see if we are allowed
if (!doIsDebugNewProcessSupported()) { if (!doIsDebugNewProcessSupported()) {
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Cannot start a new process", null)); //$NON-NLS-1$ rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INVALID_STATE, "Not allowed to create a new process", null)); //$NON-NLS-1$
rm.done(); rm.done();
return; return;
} }
} }
fInitialProcess = false;
ImmediateExecutor.getInstance().execute( ImmediateExecutor.getInstance().execute(
new DebugNewProcessSequence(getExecutor(), dmc, file, attributes, rm)); getDebugNewProcessSequence(getExecutor(), isInitial, dmc, file, attributes, rm));
} }
/**
* Return the sequence that is to be used to create a new process the specified process.
* Allows others to extend more easily.
* @since 4.0
*/
protected Sequence getDebugNewProcessSequence(DsfExecutor executor, boolean isInitial, IDMContext dmc, String file,
Map<String, Object> attributes, DataRequestMonitor<IDMContext> rm) {
return new DebugNewProcessSequence(executor, isInitial, dmc, file, attributes, rm);
}
public void getProcessesBeingDebugged(final IDMContext dmc, final DataRequestMonitor<IDMContext[]> rm) { public void getProcessesBeingDebugged(final IDMContext dmc, final DataRequestMonitor<IDMContext[]> rm) {
final ICommandControlDMContext controlDmc = DMContexts.getAncestorOfType(dmc, ICommandControlDMContext.class); final ICommandControlDMContext controlDmc = DMContexts.getAncestorOfType(dmc, ICommandControlDMContext.class);
final IMIContainerDMContext containerDmc = DMContexts.getAncestorOfType(dmc, IMIContainerDMContext.class); final IMIContainerDMContext containerDmc = DMContexts.getAncestorOfType(dmc, IMIContainerDMContext.class);
@ -1088,11 +1124,22 @@ public class GDBProcesses_7_0 extends AbstractDsfService
/** @since 4.0 */ /** @since 4.0 */
public void restart(IContainerDMContext containerDmc, Map<String, Object> attributes, RequestMonitor rm) { public void restart(IContainerDMContext containerDmc, Map<String, Object> attributes, RequestMonitor rm) {
ImmediateExecutor.getInstance().execute( ImmediateExecutor.getInstance().execute(
new StartOrRestartProcessSequence_7_0( getStartOrRestartProcessSequence(
getExecutor(), containerDmc, attributes, true, getExecutor(), containerDmc, attributes, true,
new DataRequestMonitor<IContainerDMContext>(ImmediateExecutor.getInstance(), rm))); new DataRequestMonitor<IContainerDMContext>(ImmediateExecutor.getInstance(), rm)));
} }
/**
* Return the sequence that is to be used to start or restart the specified process.
* Allows others to extend more easily.
* @since 4.0
*/
protected Sequence getStartOrRestartProcessSequence(DsfExecutor executor, IContainerDMContext containerDmc,
Map<String, Object> attributes, boolean restart,
DataRequestMonitor<IContainerDMContext> rm) {
return new StartOrRestartProcessSequence_7_0(executor, containerDmc, attributes, restart, rm);
}
@DsfServiceEventHandler @DsfServiceEventHandler
public void eventDispatched(final MIThreadGroupCreatedEvent e) { public void eventDispatched(final MIThreadGroupCreatedEvent e) {
IProcessDMContext procDmc = e.getDMContext(); IProcessDMContext procDmc = e.getDMContext();

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.dsf.gdb.service;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.DsfExecutor;
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.concurrent.Sequence; import org.eclipse.cdt.dsf.concurrent.Sequence;
@ -48,13 +49,6 @@ public class GDBProcesses_7_2 extends GDBProcesses_7_1 {
private IGDBControl fCommandControl; private IGDBControl fCommandControl;
private IGDBBackend fBackend; private IGDBBackend fBackend;
/**
* Keeps track if we are dealing with the very first
* process of GDB. In such a case, we should not create a new
* inferior, since GDB has already created one by default.
*/
private boolean fInitialProcess = true;
public GDBProcesses_7_2(DsfSession session) { public GDBProcesses_7_2(DsfSession session) {
super(session); super(session);
} }
@ -123,8 +117,10 @@ public class GDBProcesses_7_2 extends GDBProcesses_7_1 {
new Step() { new Step() {
@Override @Override
public void execute(final RequestMonitor rm) { public void execute(final RequestMonitor rm) {
if (fInitialProcess) { if (isInitialProcess()) {
fInitialProcess = false; // If it is the first inferior, GDB has already created it for us
// We really should get the id from GDB instead of hard-coding it
setIsInitialProcess(false);
fContainerDmc = createContainerContext(procCtx, "i1"); //$NON-NLS-1$ fContainerDmc = createContainerContext(procCtx, "i1"); //$NON-NLS-1$
rm.done(); rm.done();
return; return;
@ -286,22 +282,9 @@ public class GDBProcesses_7_2 extends GDBProcesses_7_1 {
} }
@Override @Override
public void debugNewProcess(IDMContext dmc, String file, protected Sequence getDebugNewProcessSequence(DsfExecutor executor, boolean isInitial, IDMContext dmc, String file,
Map<String, Object> attributes, DataRequestMonitor<IDMContext> rm) { Map<String, Object> attributes, DataRequestMonitor<IDMContext> rm) {
boolean isInitial = fInitialProcess; return new DebugNewProcessSequence_7_2(executor, isInitial, dmc, file, attributes, rm);
if (fInitialProcess) {
fInitialProcess = false;
} else {
// If we are trying to create another process than the initial one, see if we are allowed
if (!doIsDebugNewProcessSupported()) {
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INVALID_STATE, "Not allowed to create a new process", null)); //$NON-NLS-1$
rm.done();
return;
}
}
ImmediateExecutor.getInstance().execute(
new DebugNewProcessSequence_7_2(getExecutor(), isInitial, dmc, file, attributes, rm));
} }
} }

View file

@ -149,7 +149,7 @@ public class StartOrRestartProcessSequence_7_0 extends ReflectionSequence {
} }
/** /**
* Initialize the members of the {@link StartOrRestartProcessSequence_7_0} class. * Initialize the members of the StartOrRestartProcessSequence_7_0 class.
* This step is mandatory for the rest of the sequence to complete. * This step is mandatory for the rest of the sequence to complete.
*/ */
@Execute @Execute