diff options
author | Mikhail Khodjaiants | 2012-02-29 19:49:47 +0000 |
---|---|---|
committer | Mikhail Khodjaiants | 2012-02-29 19:51:28 +0000 |
commit | 84e82daec51fb96a75ac2c891af4f9fef6dcf2e1 (patch) | |
tree | 0e718cbfdcad1fa7250045bb219c471302b55851 /dsf-gdb | |
parent | 35530262d898a53db5a519216a5886e23172e8be (diff) | |
download | org.eclipse.cdt-84e82daec51fb96a75ac2c891af4f9fef6dcf2e1.tar.gz org.eclipse.cdt-84e82daec51fb96a75ac2c891af4f9fef6dcf2e1.tar.xz org.eclipse.cdt-84e82daec51fb96a75ac2c891af4f9fef6dcf2e1.zip |
Bug 372795 - Refactor common code in GDBControl* classes
Diffstat (limited to 'dsf-gdb')
7 files changed, 213 insertions, 426 deletions
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl.java index af159fe4632..1898564a836 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl.java @@ -11,6 +11,7 @@ * Nokia - create and use backend service. * Vladimir Prus (CodeSourcery) - Support for -data-read-memory-bytes (bug 322658) * Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121) + * Mikhail Khodjaiants (Mentor Graphics) - Refactor common code in GDBControl* classes (bug 372795) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.service.command; @@ -52,6 +53,7 @@ import org.eclipse.cdt.dsf.mi.service.command.AbstractCLIProcess; import org.eclipse.cdt.dsf.mi.service.command.AbstractMIControl; import org.eclipse.cdt.dsf.mi.service.command.CLIEventProcessor; import org.eclipse.cdt.dsf.mi.service.command.CommandFactory; +import org.eclipse.cdt.dsf.mi.service.command.IEventProcessor; import org.eclipse.cdt.dsf.mi.service.command.MIControlDMContext; import org.eclipse.cdt.dsf.mi.service.command.MIRunControlEventProcessor; import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; @@ -100,17 +102,31 @@ public class GDBControl extends AbstractMIControl implements IGDBControl { private IGDBBackend fMIBackend; - private MIRunControlEventProcessor fMIEventProcessor; - private CLIEventProcessor fCLICommandProcessor; + private IEventProcessor fMIEventProcessor; + private IEventProcessor fCLICommandProcessor; private AbstractCLIProcess fCLIProcess; + /** + * GDBControl is only used for GDB earlier that 7.0. Although -list-features + * is available in 6.8, it does not report anything we care about, so + * return empty list. + */ + private final List<String> fFeatures = new ArrayList<String>(); + private boolean fTerminated; /** * @since 3.0 */ public GDBControl(DsfSession session, ILaunchConfiguration config, CommandFactory factory) { - super(session, false, factory); + this(session, false, config, factory); + } + + /** + * @since 4.1 + */ + protected GDBControl(DsfSession session, boolean useThreadAndFrameOptions, ILaunchConfiguration config, CommandFactory factory) { + super(session, useThreadAndFrameOptions, factory); } @Override @@ -136,37 +152,18 @@ public class GDBControl extends AbstractMIControl implements IGDBControl { // have it, before we can create this context. fControlDmc = new GDBControlDMContext(getSession().getId(), getId()); - final Sequence.Step[] initializeSteps = new Sequence.Step[] { - new CommandMonitoringStep(InitializationShutdownStep.Direction.INITIALIZING), - new CommandProcessorsStep(InitializationShutdownStep.Direction.INITIALIZING), - new RegisterStep(InitializationShutdownStep.Direction.INITIALIZING), - }; - - Sequence startupSequence = new Sequence(getExecutor(), requestMonitor) { - @Override public Step[] getSteps() { return initializeSteps; } - }; - getExecutor().execute(startupSequence); + getExecutor().execute(getStartupSequence(requestMonitor)); } @Override public void shutdown(final RequestMonitor requestMonitor) { - final Sequence.Step[] shutdownSteps = new Sequence.Step[] { - new RegisterStep(InitializationShutdownStep.Direction.SHUTTING_DOWN), - new CommandProcessorsStep(InitializationShutdownStep.Direction.SHUTTING_DOWN), - new CommandMonitoringStep(InitializationShutdownStep.Direction.SHUTTING_DOWN), - }; - Sequence shutdownSequence = - new Sequence(getExecutor(), - new RequestMonitor(getExecutor(), requestMonitor) { - @Override - protected void handleCompleted() { - GDBControl.super.shutdown(requestMonitor); - } - }) { - @Override public Step[] getSteps() { return shutdownSteps; } - }; - getExecutor().execute(shutdownSequence); - + getExecutor().execute(getShutdownSequence(new RequestMonitor(getExecutor(), requestMonitor) { + + @Override + protected void handleCompleted() { + GDBControl.super.shutdown(requestMonitor); + } + })); } @Override @@ -403,8 +400,8 @@ public class GDBControl extends AbstractMIControl implements IGDBControl { return; } - fCLICommandProcessor = new CLIEventProcessor(GDBControl.this, fControlDmc); - fMIEventProcessor = new MIRunControlEventProcessor(GDBControl.this, fControlDmc); + fCLICommandProcessor = createCLIEventProcessor(GDBControl.this, fControlDmc); + fMIEventProcessor = createMIRunControlEventProcessor(GDBControl.this, fControlDmc); requestMonitor.done(); } @@ -443,13 +440,6 @@ public class GDBControl extends AbstractMIControl implements IGDBControl { } } - /** - * GDBControl is only used for GDB earlier that 7.0. Although -list-features - * is available in 6.8, it does not report anything we care about, so - * return empty list. - */ - private final List<String> fFeatures = new ArrayList<String>(); - /** @since 4.0 */ @Override public List<String> getFeatures() { @@ -471,4 +461,55 @@ public class GDBControl extends AbstractMIControl implements IGDBControl { public void setPrintPythonErrors(boolean enabled, RequestMonitor rm) { rm.done(); } + + /** + * @since 4.1 + */ + protected Sequence getStartupSequence(final RequestMonitor requestMonitor) { + final Sequence.Step[] initializeSteps = new Sequence.Step[] { + new CommandMonitoringStep(InitializationShutdownStep.Direction.INITIALIZING), + new CommandProcessorsStep(InitializationShutdownStep.Direction.INITIALIZING), + new RegisterStep(InitializationShutdownStep.Direction.INITIALIZING), + }; + + return new Sequence(getExecutor(), requestMonitor) { + @Override public Step[] getSteps() { return initializeSteps; } + }; + } + + /** + * @since 4.1 + */ + protected Sequence getShutdownSequence(RequestMonitor requestMonitor) { + final Sequence.Step[] shutdownSteps = new Sequence.Step[] { + new RegisterStep(InitializationShutdownStep.Direction.SHUTTING_DOWN), + new CommandProcessorsStep(InitializationShutdownStep.Direction.SHUTTING_DOWN), + new CommandMonitoringStep(InitializationShutdownStep.Direction.SHUTTING_DOWN), + }; + return new Sequence(getExecutor(), requestMonitor) { + @Override public Step[] getSteps() { return shutdownSteps; } + }; + } + + /** + * @since 4.1 + */ + protected IEventProcessor createCLIEventProcessor(ICommandControlService connection, ICommandControlDMContext controlDmc) { + return new CLIEventProcessor(connection, controlDmc); + } + + /** + * @since 4.1 + */ + protected IEventProcessor createMIRunControlEventProcessor(AbstractMIControl connection, ICommandControlDMContext controlDmc) { + return new MIRunControlEventProcessor(connection, controlDmc); + } + + /** + * @since 4.1 + */ + protected void setFeatures(List<String> features) { + fFeatures.clear(); + fFeatures.addAll(features); + } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl_7_0.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl_7_0.java index ebbcf745d65..ddfa69282d2 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl_7_0.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl_7_0.java @@ -12,57 +12,29 @@ * Vladimir Prus (CodeSourcery) - Support for -data-read-memory-bytes (bug 322658) * Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121) * Marc Khouzam (Ericsson) - Call new FinalLaunchSequence_7_0 (Bug 365471) + * Mikhail Khodjaiants (Mentor Graphics) - Refactor common code in GDBControl* classes (bug 372795) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.service.command; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.List; import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import org.eclipse.cdt.dsf.concurrent.CountingRequestMonitor; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; -import org.eclipse.cdt.dsf.concurrent.DsfRunnable; -import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants; -import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor; -import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor; import org.eclipse.cdt.dsf.concurrent.RequestMonitor; import org.eclipse.cdt.dsf.concurrent.RequestMonitorWithProgress; import org.eclipse.cdt.dsf.concurrent.Sequence; -import org.eclipse.cdt.dsf.datamodel.AbstractDMEvent; -import org.eclipse.cdt.dsf.debug.service.command.ICommandControl; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService; -import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; import org.eclipse.cdt.dsf.gdb.launching.FinalLaunchSequence_7_0; -import org.eclipse.cdt.dsf.gdb.service.IGDBBackend; import org.eclipse.cdt.dsf.gdb.service.IGDBTraceControl.ITraceRecordSelectedChangedDMEvent; -import org.eclipse.cdt.dsf.mi.service.IMIBackend; -import org.eclipse.cdt.dsf.mi.service.IMIBackend.BackendStateChangedEvent; -import org.eclipse.cdt.dsf.mi.service.IMICommandControl; -import org.eclipse.cdt.dsf.mi.service.IMIRunControl; -import org.eclipse.cdt.dsf.mi.service.command.AbstractCLIProcess; import org.eclipse.cdt.dsf.mi.service.command.AbstractMIControl; import org.eclipse.cdt.dsf.mi.service.command.CLIEventProcessor_7_0; import org.eclipse.cdt.dsf.mi.service.command.CommandFactory; -import org.eclipse.cdt.dsf.mi.service.command.MIControlDMContext; +import org.eclipse.cdt.dsf.mi.service.command.IEventProcessor; import org.eclipse.cdt.dsf.mi.service.command.MIRunControlEventProcessor_7_0; import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIListFeaturesInfo; import org.eclipse.cdt.dsf.service.DsfServiceEventHandler; import org.eclipse.cdt.dsf.service.DsfSession; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; -import org.osgi.framework.BundleContext; /** * GDB Debugger control implementation. This implementation extends the @@ -71,374 +43,144 @@ import org.osgi.framework.BundleContext; * - CLI console support,<br> * - inferior process status tracking.<br> */ -public class GDBControl_7_0 extends AbstractMIControl implements IGDBControl { +public class GDBControl_7_0 extends GDBControl { - /** - * Event indicating that the back end process has started. - */ - private static class GDBControlInitializedDMEvent extends AbstractDMEvent<ICommandControlDMContext> - implements ICommandControlInitializedDMEvent - { - public GDBControlInitializedDMEvent(ICommandControlDMContext context) { - super(context); - } + /** + * @deprecated use {@link GDBControl.InitializationShutdownStep}. + */ + @Deprecated + public static class InitializationShutdownStep extends GDBControl.InitializationShutdownStep { + + /** + * @deprecated use {@link GDBControl.InitializationShutdownStep.Direction}. + */ + @Deprecated + public enum Direction { INITIALIZING, SHUTTING_DOWN } + + public InitializationShutdownStep(Direction direction) { + super((direction == Direction.INITIALIZING) ? + GDBControl.InitializationShutdownStep.Direction.INITIALIZING : + GDBControl.InitializationShutdownStep.Direction.SHUTTING_DOWN); + } } - - /** - * Event indicating that the CommandControl (back end process) has terminated. - */ - private static class GDBControlShutdownDMEvent extends AbstractDMEvent<ICommandControlDMContext> - implements ICommandControlShutdownDMEvent - { - public GDBControlShutdownDMEvent(ICommandControlDMContext context) { - super(context); - } + + /** + * @deprecated use {@link GDBControl.CommandMonitoringStep}. + */ + @Deprecated + protected class CommandMonitoringStep extends GDBControl.CommandMonitoringStep { + + CommandMonitoringStep(GDBControl_7_0.InitializationShutdownStep.Direction direction) { + super((direction == GDBControl_7_0.InitializationShutdownStep.Direction.INITIALIZING) ? + GDBControl.InitializationShutdownStep.Direction.INITIALIZING : + GDBControl.InitializationShutdownStep.Direction.SHUTTING_DOWN); + } } - private GDBControlDMContext fControlDmc; + /** + * @deprecated use {@link GDBControl.CommandProcessorsStep}. + */ + @Deprecated + protected class CommandProcessorsStep extends GDBControl.CommandProcessorsStep { - private IGDBBackend fMIBackend; - - private MIRunControlEventProcessor_7_0 fMIEventProcessor; - private CLIEventProcessor_7_0 fCLICommandProcessor; - private AbstractCLIProcess fCLIProcess; - - private List<String> fFeatures = new ArrayList<String>(); + CommandProcessorsStep(GDBControl_7_0.InitializationShutdownStep.Direction direction) { + super((direction == GDBControl_7_0.InitializationShutdownStep.Direction.INITIALIZING) ? + GDBControl.InitializationShutdownStep.Direction.INITIALIZING : + GDBControl.InitializationShutdownStep.Direction.SHUTTING_DOWN); + } + } + + /** + * @deprecated use {@link GDBControl.RegisterStep}. + */ + @Deprecated + protected class RegisterStep extends GDBControl.RegisterStep { + + RegisterStep(GDBControl_7_0.InitializationShutdownStep.Direction direction) { + super((direction == GDBControl_7_0.InitializationShutdownStep.Direction.INITIALIZING) ? + GDBControl.InitializationShutdownStep.Direction.INITIALIZING : + GDBControl.InitializationShutdownStep.Direction.SHUTTING_DOWN); + } + } - private boolean fTerminated; - /** * @since 3.0 */ public GDBControl_7_0(DsfSession session, ILaunchConfiguration config, CommandFactory factory) { - super(session, true, factory); + super(session, true, config, factory); } - @Override - protected BundleContext getBundleContext() { - return GdbPlugin.getBundleContext(); - } - - @Override - public void initialize(final RequestMonitor requestMonitor) { - super.initialize(new ImmediateRequestMonitor(requestMonitor) { - @Override - protected void handleSuccess() { - doInitialize(requestMonitor); - } - }); - } - - private void doInitialize(final RequestMonitor requestMonitor) { - fMIBackend = getServicesTracker().getService(IGDBBackend.class); - - // getId uses the MIBackend service, which is why we must wait until we - // have it, before we can create this context. - fControlDmc = new GDBControlDMContext(getSession().getId(), getId()); - + @Override + protected Sequence getStartupSequence(RequestMonitor requestMonitor) { final Sequence.Step[] initializeSteps = new Sequence.Step[] { - new CommandMonitoringStep(InitializationShutdownStep.Direction.INITIALIZING), - new CommandProcessorsStep(InitializationShutdownStep.Direction.INITIALIZING), - new ListFeaturesStep(InitializationShutdownStep.Direction.INITIALIZING), - new RegisterStep(InitializationShutdownStep.Direction.INITIALIZING), + new GDBControl.CommandMonitoringStep(GDBControl.InitializationShutdownStep.Direction.INITIALIZING), + new GDBControl.CommandProcessorsStep(GDBControl.InitializationShutdownStep.Direction.INITIALIZING), + new ListFeaturesStep(GDBControl.InitializationShutdownStep.Direction.INITIALIZING), + new GDBControl.RegisterStep(GDBControl.InitializationShutdownStep.Direction.INITIALIZING), }; - Sequence startupSequence = new Sequence(getExecutor(), requestMonitor) { + return new Sequence(getExecutor(), requestMonitor) { @Override public Step[] getSteps() { return initializeSteps; } }; - getExecutor().execute(startupSequence); - } + } - @Override - public void shutdown(final RequestMonitor requestMonitor) { + @Override + protected Sequence getShutdownSequence(RequestMonitor requestMonitor) { final Sequence.Step[] shutdownSteps = new Sequence.Step[] { - new RegisterStep(InitializationShutdownStep.Direction.SHUTTING_DOWN), - new ListFeaturesStep(InitializationShutdownStep.Direction.SHUTTING_DOWN), - new CommandProcessorsStep(InitializationShutdownStep.Direction.SHUTTING_DOWN), - new CommandMonitoringStep(InitializationShutdownStep.Direction.SHUTTING_DOWN), + new GDBControl.RegisterStep(GDBControl.InitializationShutdownStep.Direction.SHUTTING_DOWN), + new ListFeaturesStep(GDBControl.InitializationShutdownStep.Direction.SHUTTING_DOWN), + new GDBControl.CommandProcessorsStep(GDBControl.InitializationShutdownStep.Direction.SHUTTING_DOWN), + new GDBControl.CommandMonitoringStep(GDBControl.InitializationShutdownStep.Direction.SHUTTING_DOWN), }; - Sequence shutdownSequence = - new Sequence(getExecutor(), - new RequestMonitor(getExecutor(), requestMonitor) { - @Override - protected void handleCompleted() { - GDBControl_7_0.super.shutdown(requestMonitor); - } - }) { + return new Sequence(getExecutor(), requestMonitor) { @Override public Step[] getSteps() { return shutdownSteps; } }; - getExecutor().execute(shutdownSequence); - - } - - @Override - public String getId() { - return fMIBackend.getId(); - } + } - @Override - public MIControlDMContext getControlDMContext() { - return fControlDmc; - } - @Override - public ICommandControlDMContext getContext() { - return fControlDmc; - } - - @Override - public void terminate(final RequestMonitor rm) { - if (fTerminated) { - rm.done(); - return; - } - fTerminated = true; - - // To fix bug 234467: - // Interrupt GDB in case the inferior is running. - // That way, the inferior will also be killed when we exit GDB. - // - IMIRunControl runControl = getServicesTracker().getService(IMIRunControl.class); - if (runControl != null && !runControl.isTargetAcceptingCommands()) { - fMIBackend.interrupt(); - } + protected IEventProcessor createCLIEventProcessor(ICommandControlService connection, ICommandControlDMContext controlDmc) { + return new CLIEventProcessor_7_0(connection, controlDmc); + } - // Schedule a runnable to be executed 2 seconds from now. - // If we don't get a response to the quit command, this - // runnable will kill the task. - final Future<?> forceQuitTask = getExecutor().schedule( - new DsfRunnable() { - @Override - public void run() { - fMIBackend.destroy(); - rm.done(); - } - - @Override - protected boolean isExecutionRequired() { - return false; - } - }, - 2, TimeUnit.SECONDS); - - queueCommand( - getCommandFactory().createMIGDBExit(fControlDmc), - new DataRequestMonitor<MIInfo>(getExecutor(), rm) { - @Override - public void handleCompleted() { - if (isSuccess()) { - // Cancel the time out runnable (if it hasn't run yet). - forceQuitTask.cancel(false); - rm.done(); - } - // else: the forceQuitTask has or will handle it. - // It is good to wait for the forceQuitTask to trigger - // to leave enough time for the interrupt() to complete. - } - } - ); - } + @Override + protected IEventProcessor createMIRunControlEventProcessor(AbstractMIControl connection, ICommandControlDMContext controlDmc) { + return new MIRunControlEventProcessor_7_0(connection, controlDmc); + } private void listFeatures(final RequestMonitor requestMonitor) { queueCommand( - getCommandFactory().createMIListFeatures(fControlDmc), + getCommandFactory().createMIListFeatures(getControlDMContext()), new DataRequestMonitor<MIListFeaturesInfo>(getExecutor(), requestMonitor) { @Override public void handleSuccess() { - fFeatures = getData().getFeatures(); + setFeatures(getData().getFeatures()); super.handleSuccess(); } }); } @Override - public AbstractCLIProcess getCLIProcess() { - return fCLIProcess; - } - - /** - * @since 2.0 - */ - @Override - public void setTracingStream(OutputStream tracingStream) { - setMITracingStream(tracingStream); - } - - /** @since 3.0 */ - @Override - public void setEnvironment(Properties props, boolean clear, RequestMonitor rm) { - int count = 0; - CountingRequestMonitor countingRm = new CountingRequestMonitor(getExecutor(), rm); - - // First clear the environment if requested. - if (clear) { - count++; - queueCommand( - getCommandFactory().createCLIUnsetEnv(getContext()), - new DataRequestMonitor<MIInfo>(getExecutor(), countingRm)); - } - - // Now set the new variables - for (Entry<Object,Object> property : props.entrySet()) { - count++; - String name = (String)property.getKey(); - String value = (String)property.getValue(); - queueCommand( - getCommandFactory().createMIGDBSetEnv(getContext(), name, value), - new DataRequestMonitor<MIInfo>(getExecutor(), countingRm)); - } - countingRm.setDoneCount(count); - } - - /** - * @since 4.0 - */ - @Override - @SuppressWarnings("unchecked") - public void completeInitialization(final RequestMonitor rm) { - // We take the attributes from the launchConfiguration - ILaunch launch = (ILaunch)getSession().getModelAdapter(ILaunch.class); - Map<String, Object> attributes = null; - try { - attributes = launch.getLaunchConfiguration().getAttributes(); - } catch (CoreException e) {} - - // We need a RequestMonitorWithProgress, if we don't have one, we create one. - RequestMonitorWithProgress progressRm; - if (rm instanceof RequestMonitorWithProgress) { - progressRm = (RequestMonitorWithProgress)rm; - } else { - progressRm = new RequestMonitorWithProgress(getExecutor(), new NullProgressMonitor()) { - @Override - protected void handleCompleted() { - rm.setStatus(getStatus()); - rm.done(); - } - }; - } - - ImmediateExecutor.getInstance().execute(getCompleteInitializationSequence(attributes, progressRm)); - } - - /** - * Return the sequence that is to be used to complete the initialization of GDB. - * - * @param rm A RequestMonitorWithProgress that will indicate when the sequence is completed, but that - * also contains an IProgressMonitor to be able to cancel the launch. A NullProgressMonitor - * can be used if cancellation is not required. - * - * @since 4.0 - */ protected Sequence getCompleteInitializationSequence(Map<String, Object> attributes, RequestMonitorWithProgress rm) { return new FinalLaunchSequence_7_0(getSession(), attributes, rm); } - /**@since 4.0 */ - @Override - public List<String> getFeatures() { - return fFeatures; - } - - @DsfServiceEventHandler + @Override + @DsfServiceEventHandler public void eventDispatched(ICommandControlShutdownDMEvent e) { // Handle our "GDB Exited" event and stop processing commands. stopCommandProcessing(); } - - @DsfServiceEventHandler - public void eventDispatched(BackendStateChangedEvent e) { - if (e.getState() == IMIBackend.State.TERMINATED && e.getBackendId().equals(fMIBackend.getId())) { - // Handle "GDB Exited" event, just relay to following event. - getSession().dispatchEvent(new GDBControlShutdownDMEvent(fControlDmc), getProperties()); - } - } /** @since 3.0 */ @DsfServiceEventHandler public void eventDispatched(ITraceRecordSelectedChangedDMEvent e) { } - public static class InitializationShutdownStep extends Sequence.Step { - public enum Direction { INITIALIZING, SHUTTING_DOWN } - - private Direction fDirection; - public InitializationShutdownStep(Direction direction) { fDirection = direction; } - - @Override - final public void execute(RequestMonitor requestMonitor) { - if (fDirection == Direction.INITIALIZING) { - initialize(requestMonitor); - } else { - shutdown(requestMonitor); - } - } - - @Override - final public void rollBack(RequestMonitor requestMonitor) { - if (fDirection == Direction.INITIALIZING) { - shutdown(requestMonitor); - } else { - super.rollBack(requestMonitor); - } - } - - protected void initialize(RequestMonitor requestMonitor) { - requestMonitor.done(); - } - protected void shutdown(RequestMonitor requestMonitor) { - requestMonitor.done(); - } - } - - protected class CommandMonitoringStep extends InitializationShutdownStep { - CommandMonitoringStep(Direction direction) { super(direction); } - - @Override - protected void initialize(final RequestMonitor requestMonitor) { - startCommandProcessing(fMIBackend.getMIInputStream(), fMIBackend.getMIOutputStream()); - requestMonitor.done(); - } - - @Override - protected void shutdown(RequestMonitor requestMonitor) { - stopCommandProcessing(); - requestMonitor.done(); - } - } - - protected class CommandProcessorsStep extends InitializationShutdownStep { - CommandProcessorsStep(Direction direction) { super(direction); } - - @Override - public void initialize(final RequestMonitor requestMonitor) { - try { - fCLIProcess = new GDBBackendCLIProcess(GDBControl_7_0.this, fMIBackend); - } - catch(IOException e) { - requestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, IDsfStatusConstants.REQUEST_FAILED, "Failed to create CLI Process", e)); //$NON-NLS-1$ - requestMonitor.done(); - return; - } - - fCLICommandProcessor = new CLIEventProcessor_7_0(GDBControl_7_0.this, fControlDmc); - fMIEventProcessor = new MIRunControlEventProcessor_7_0(GDBControl_7_0.this, fControlDmc); - - requestMonitor.done(); - } - - @Override - protected void shutdown(RequestMonitor requestMonitor) { - fCLICommandProcessor.dispose(); - fMIEventProcessor.dispose(); - fCLIProcess.dispose(); - - requestMonitor.done(); - } - } /** @since 4.0 */ - protected class ListFeaturesStep extends InitializationShutdownStep { - ListFeaturesStep(Direction direction) { super(direction); } + protected class ListFeaturesStep extends GDBControl.InitializationShutdownStep { + + ListFeaturesStep(GDBControl.InitializationShutdownStep.Direction direction) { super(direction); } @Override protected void initialize(final RequestMonitor requestMonitor) { @@ -451,37 +193,13 @@ public class GDBControl_7_0 extends AbstractMIControl implements IGDBControl { } } - protected class RegisterStep extends InitializationShutdownStep { - RegisterStep(Direction direction) { super(direction); } - @Override - public void initialize(final RequestMonitor requestMonitor) { - getSession().addServiceEventListener(GDBControl_7_0.this, null); - register( - new String[]{ ICommandControl.class.getName(), - ICommandControlService.class.getName(), - IMICommandControl.class.getName(), - AbstractMIControl.class.getName(), - IGDBControl.class.getName() }, - new Hashtable<String,String>()); - getSession().dispatchEvent(new GDBControlInitializedDMEvent(fControlDmc), getProperties()); - requestMonitor.done(); - } - - @Override - protected void shutdown(RequestMonitor requestMonitor) { - unregister(); - getSession().removeServiceEventListener(GDBControl_7_0.this); - requestMonitor.done(); - } - } - - /** + /** * @since 4.0 */ @Override public void enablePrettyPrintingForMIVariableObjects(RequestMonitor rm) { queueCommand( - getCommandFactory().createMIEnablePrettyPrinting(fControlDmc), + getCommandFactory().createMIEnablePrettyPrinting(getControlDMContext()), new DataRequestMonitor<MIInfo>(getExecutor(), rm)); } @@ -494,7 +212,7 @@ public class GDBControl_7_0 extends AbstractMIControl implements IGDBControl { String subCommand = "set python print-stack " + (enabled ? "on" : "off"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ queueCommand( - getCommandFactory().createCLIMaintenance(fControlDmc, subCommand), + getCommandFactory().createCLIMaintenance(getControlDMContext(), subCommand), new DataRequestMonitor<MIInfo>(getExecutor(), rm)); } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CLIEventProcessor.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CLIEventProcessor.java index 2d245d25eb1..454272a7de8 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CLIEventProcessor.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CLIEventProcessor.java @@ -9,6 +9,7 @@ * QNX Software Systems - Initial API and implementation * Wind River Systems - Modified for new DSF Reference Implementation * Ericsson AB - Additional handling of events + * Mikhail Khodjaiants (Mentor Graphics) - Refactor common code in GDBControl* classes (bug 372795) *******************************************************************************/ package org.eclipse.cdt.dsf.mi.service.command; @@ -25,10 +26,8 @@ import org.eclipse.cdt.dsf.debug.service.IRunControl.IStartedDMEvent; import org.eclipse.cdt.dsf.debug.service.ISignals.ISignalsDMContext; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; -import org.eclipse.cdt.dsf.debug.service.command.ICommandListener; import org.eclipse.cdt.dsf.debug.service.command.ICommandResult; import org.eclipse.cdt.dsf.debug.service.command.ICommandToken; -import org.eclipse.cdt.dsf.debug.service.command.IEventListener; import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; import org.eclipse.cdt.dsf.mi.service.IMIProcesses; import org.eclipse.cdt.dsf.mi.service.MIProcesses; @@ -51,7 +50,7 @@ import org.eclipse.cdt.dsf.service.DsfServicesTracker; */ @ConfinedToDsfExecutor("fConnection#getExecutor") public class CLIEventProcessor - implements ICommandListener, IEventListener + implements IEventProcessor { private final ICommandControlService fCommandControl; private final ICommandControlDMContext fControlDmc; @@ -74,7 +73,8 @@ public class CLIEventProcessor fCommandControl.getSession().addServiceEventListener(this, null); } - public void dispose() { + @Override + public void dispose() { fCommandControl.getSession().removeServiceEventListener(this); fCommandControl.removeCommandListener(this); fCommandControl.removeEventListener(this); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CLIEventProcessor_7_0.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CLIEventProcessor_7_0.java index bcafe71276b..681d26ba0ee 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CLIEventProcessor_7_0.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CLIEventProcessor_7_0.java @@ -10,6 +10,7 @@ * Wind River Systems - Modified for new DSF Reference Implementation * Ericsson AB - Additional handling of events * Ericsson - Version 7.0 + * Mikhail Khodjaiants (Mentor Graphics) - Refactor common code in GDBControl* classes (bug 372795) *******************************************************************************/ package org.eclipse.cdt.dsf.mi.service.command; @@ -20,11 +21,9 @@ import org.eclipse.cdt.dsf.datamodel.IDMContext; import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext; import org.eclipse.cdt.dsf.debug.service.ISignals.ISignalsDMContext; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService; -import org.eclipse.cdt.dsf.debug.service.command.ICommandListener; +import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; import org.eclipse.cdt.dsf.debug.service.command.ICommandResult; import org.eclipse.cdt.dsf.debug.service.command.ICommandToken; -import org.eclipse.cdt.dsf.debug.service.command.IEventListener; -import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; import org.eclipse.cdt.dsf.mi.service.command.commands.CLICommand; import org.eclipse.cdt.dsf.mi.service.command.commands.MIInterpreterExecConsole; @@ -41,7 +40,7 @@ import org.eclipse.cdt.dsf.service.DsfServicesTracker; */ @ConfinedToDsfExecutor("fConnection#getExecutor") public class CLIEventProcessor_7_0 - implements ICommandListener, IEventListener + implements IEventProcessor { private final ICommandControlService fCommandControl; @@ -54,7 +53,8 @@ public class CLIEventProcessor_7_0 fCommandControl.addEventListener(this); } - public void dispose() { + @Override + public void dispose() { fCommandControl.removeCommandListener(this); fCommandControl.removeEventListener(this); fServicesTracker.dispose(); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/IEventProcessor.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/IEventProcessor.java new file mode 100644 index 00000000000..9ff2c4070e9 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/IEventProcessor.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2012 Mentor Graphics 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mentor Graphics - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.dsf.mi.service.command; + +import org.eclipse.cdt.dsf.debug.service.command.ICommandListener; +import org.eclipse.cdt.dsf.debug.service.command.IEventListener; + +/** + * Common interface that represents all MI and CLI event/command processors. + * + * @since 4.1 + */ +public interface IEventProcessor extends IEventListener, ICommandListener { + + /** + * Disposes of this processor's resources. + */ + public void dispose(); +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/MIRunControlEventProcessor.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/MIRunControlEventProcessor.java index 2fd7e8ea20d..f618ab46f2b 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/MIRunControlEventProcessor.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/MIRunControlEventProcessor.java @@ -8,6 +8,7 @@ * Contributors: * Wind River Systems - initial API and implementation * Ericsson - Additional handling of events + * Mikhail Khodjaiants (Mentor Graphics) - Refactor common code in GDBControl* classes (bug 372795) *******************************************************************************/ package org.eclipse.cdt.dsf.mi.service.command; @@ -23,10 +24,8 @@ import org.eclipse.cdt.dsf.debug.service.IRunControl.IContainerDMContext; import org.eclipse.cdt.dsf.debug.service.IRunControl.IExecutionDMContext; import org.eclipse.cdt.dsf.debug.service.command.ICommand; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; -import org.eclipse.cdt.dsf.debug.service.command.ICommandListener; import org.eclipse.cdt.dsf.debug.service.command.ICommandResult; import org.eclipse.cdt.dsf.debug.service.command.ICommandToken; -import org.eclipse.cdt.dsf.debug.service.command.IEventListener; import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; import org.eclipse.cdt.dsf.gdb.service.IGDBBackend; import org.eclipse.cdt.dsf.mi.service.IMIProcesses; @@ -72,7 +71,7 @@ import org.eclipse.cdt.dsf.service.DsfServicesTracker; * received by other services and clients. */ public class MIRunControlEventProcessor - implements IEventListener, ICommandListener + implements IEventProcessor { private static final String STOPPED_REASON = "stopped"; //$NON-NLS-1$ @@ -107,6 +106,7 @@ public class MIRunControlEventProcessor /** * This processor must be disposed before the control service is un-registered. */ + @Override public void dispose() { fCommandControl.removeEventListener(this); fCommandControl.removeCommandListener(this); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/MIRunControlEventProcessor_7_0.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/MIRunControlEventProcessor_7_0.java index 03a04a35eeb..beac6f22d4e 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/MIRunControlEventProcessor_7_0.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/MIRunControlEventProcessor_7_0.java @@ -8,6 +8,7 @@ * Contributors: * Wind River Systems - initial API and implementation * Ericsson - Version 7.0 + * Mikhail Khodjaiants (Mentor Graphics) - Refactor common code in GDBControl* classes (bug 372795) *******************************************************************************/ package org.eclipse.cdt.dsf.mi.service.command; @@ -22,10 +23,8 @@ import org.eclipse.cdt.dsf.debug.service.IRunControl.IContainerDMContext; import org.eclipse.cdt.dsf.debug.service.IRunControl.IExecutionDMContext; import org.eclipse.cdt.dsf.debug.service.command.ICommand; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; -import org.eclipse.cdt.dsf.debug.service.command.ICommandListener; import org.eclipse.cdt.dsf.debug.service.command.ICommandResult; import org.eclipse.cdt.dsf.debug.service.command.ICommandToken; -import org.eclipse.cdt.dsf.debug.service.command.IEventListener; import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; import org.eclipse.cdt.dsf.mi.service.IMIProcesses; import org.eclipse.cdt.dsf.mi.service.MIProcesses; @@ -71,7 +70,7 @@ import org.eclipse.cdt.dsf.service.DsfServicesTracker; * @since 1.1 */ public class MIRunControlEventProcessor_7_0 - implements IEventListener, ICommandListener + implements IEventProcessor { private static final String STOPPED_REASON = "stopped"; //$NON-NLS-1$ private static final String RUNNING_REASON = "running"; //$NON-NLS-1$ @@ -107,6 +106,7 @@ public class MIRunControlEventProcessor_7_0 /** * This processor must be disposed before the control service is un-registered. */ + @Override public void dispose() { fCommandControl.removeEventListener(this); fCommandControl.removeCommandListener(this); |