From b9d2bc1e131c0965df321ea4c7b0e757b255b987 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Wed, 16 Feb 2011 11:39:41 +0000 Subject: [PATCH] Bug 335528: Add method to allow overriding which StartOrRestart and DebugNewProcess sequences to use. --- .../gdb/service/DebugNewProcessSequence.java | 17 ++++- .../service/DebugNewProcessSequence_7_2.java | 10 +-- .../cdt/dsf/gdb/service/GDBProcesses.java | 14 +++- .../cdt/dsf/gdb/service/GDBProcesses_7_0.java | 65 ++++++++++++++++--- .../cdt/dsf/gdb/service/GDBProcesses_7_2.java | 33 +++------- .../StartOrRestartProcessSequence_7_0.java | 2 +- 6 files changed, 97 insertions(+), 44 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence.java index 501baf0485c..a0e171930e3 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence.java @@ -20,6 +20,7 @@ import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants; import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor; import org.eclipse.cdt.dsf.concurrent.ReflectionSequence; 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.IDMContext; import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext; @@ -68,7 +69,7 @@ public class DebugNewProcessSequence extends ReflectionSequence { fContainerCtx = ctx; } - public DebugNewProcessSequence(DsfExecutor executor, IDMContext dmc, String file, Map attributes, DataRequestMonitor rm) { + public DebugNewProcessSequence(DsfExecutor executor, boolean isInitial, IDMContext dmc, String file, Map attributes, DataRequestMonitor rm) { super(executor, rm); fContext = dmc; 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. */ @Execute @@ -267,7 +268,7 @@ public class DebugNewProcessSequence extends ReflectionSequence { public void stepStartExecution(final RequestMonitor rm) { if (fBackend.getSessionType() != SessionType.CORE) { ImmediateExecutor.getInstance().execute( - new StartOrRestartProcessSequence_7_0( + getStartOrRestartProcessSequence( getExecutor(), getContainerContext(), fAttributes, false, new DataRequestMonitor(ImmediateExecutor.getInstance(), rm) { @Override @@ -299,4 +300,14 @@ public class DebugNewProcessSequence extends ReflectionSequence { fTracker = null; 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 attributes, boolean restart, + DataRequestMonitor rm) { + return new StartOrRestartProcessSequence_7_0(executor, containerDmc, attributes, restart, rm); + } } \ No newline at end of file diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence_7_2.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence_7_2.java index 8ab4c69ca51..a1790cbbb38 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence_7_2.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence_7_2.java @@ -41,13 +41,13 @@ public class DebugNewProcessSequence_7_2 extends DebugNewProcessSequence { private IGDBControl fGdbControl; private IGDBProcesses fProcService; 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 attributes, DataRequestMonitor rm) { - super(executor, dmc, file, attributes, rm); + super(executor, isInitial, dmc, file, attributes, rm); fSessionId = dmc.getSessionId(); - fInitialProcess = initialProcess; + fInitialProcess = isInitial; } @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. */ @Execute diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses.java index da90ecd1f5c..108ac65deb6 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses.java @@ -20,8 +20,10 @@ import org.eclipse.cdt.core.IProcessList; import org.eclipse.cdt.debug.core.CDebugUtils; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; 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.RequestMonitor; +import org.eclipse.cdt.dsf.concurrent.Sequence; import org.eclipse.cdt.dsf.datamodel.DMContexts; import org.eclipse.cdt.dsf.datamodel.IDMContext; 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, Map attributes, DataRequestMonitor rm) { 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 attributes, DataRequestMonitor rm) { + return new DebugNewProcessSequence(executor, isInitial, dmc, file, attributes, rm); } @Override diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_0.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_0.java index 45b5288b9f0..dd9d696fd5d 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_0.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_0.java @@ -24,6 +24,7 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.IProcessInfo; import org.eclipse.cdt.core.IProcessList; 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.Immutable; 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$ + /** + * Keeps track if we are dealing with the very first process of GDB. + */ private boolean fInitialProcess = true; public GDBProcesses_7_0(DsfSession session) { @@ -538,6 +542,16 @@ public class GDBProcesses_7_0 extends AbstractDsfService 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 * @since 4.0 @@ -736,6 +750,13 @@ public class GDBProcesses_7_0 extends AbstractDsfService new Step() { @Override 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 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, Map attributes, DataRequestMonitor 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()) { - rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Cannot start a new process", null)); //$NON-NLS-1$ - rm.done(); - return; + 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; } } - - fInitialProcess = false; + 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 attributes, DataRequestMonitor rm) { + return new DebugNewProcessSequence(executor, isInitial, dmc, file, attributes, rm); + } + public void getProcessesBeingDebugged(final IDMContext dmc, final DataRequestMonitor rm) { final ICommandControlDMContext controlDmc = DMContexts.getAncestorOfType(dmc, ICommandControlDMContext.class); final IMIContainerDMContext containerDmc = DMContexts.getAncestorOfType(dmc, IMIContainerDMContext.class); @@ -1088,11 +1124,22 @@ public class GDBProcesses_7_0 extends AbstractDsfService /** @since 4.0 */ public void restart(IContainerDMContext containerDmc, Map attributes, RequestMonitor rm) { ImmediateExecutor.getInstance().execute( - new StartOrRestartProcessSequence_7_0( + getStartOrRestartProcessSequence( getExecutor(), containerDmc, attributes, true, new DataRequestMonitor(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 attributes, boolean restart, + DataRequestMonitor rm) { + return new StartOrRestartProcessSequence_7_0(executor, containerDmc, attributes, restart, rm); + } + @DsfServiceEventHandler public void eventDispatched(final MIThreadGroupCreatedEvent e) { IProcessDMContext procDmc = e.getDMContext(); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_2.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_2.java index 5341a670113..d42949861b4 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_2.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_2.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.dsf.gdb.service; import java.util.Map; 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.RequestMonitor; import org.eclipse.cdt.dsf.concurrent.Sequence; @@ -48,13 +49,6 @@ public class GDBProcesses_7_2 extends GDBProcesses_7_1 { private IGDBControl fCommandControl; 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) { super(session); } @@ -123,8 +117,10 @@ public class GDBProcesses_7_2 extends GDBProcesses_7_1 { new Step() { @Override public void execute(final RequestMonitor rm) { - if (fInitialProcess) { - fInitialProcess = false; + if (isInitialProcess()) { + // 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$ rm.done(); return; @@ -286,22 +282,9 @@ public class GDBProcesses_7_2 extends GDBProcesses_7_1 { } @Override - public void debugNewProcess(IDMContext dmc, String file, - Map attributes, DataRequestMonitor rm) { - boolean isInitial = fInitialProcess; - 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)); + protected Sequence getDebugNewProcessSequence(DsfExecutor executor, boolean isInitial, IDMContext dmc, String file, + Map attributes, DataRequestMonitor rm) { + return new DebugNewProcessSequence_7_2(executor, isInitial, dmc, file, attributes, rm); } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/StartOrRestartProcessSequence_7_0.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/StartOrRestartProcessSequence_7_0.java index bdd8c161e43..5f074486949 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/StartOrRestartProcessSequence_7_0.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/StartOrRestartProcessSequence_7_0.java @@ -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. */ @Execute