From 508a4a90b34f91b5a881238ed1dcbfcf2accb480 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Mon, 24 Mar 2008 20:00:43 +0000 Subject: [PATCH] Splitting the LaunchSequence into ServicesLaunchSequence and FinalLaunchSequence, as discussed in Bug 221505 comment #7 --- ...Sequence.java => FinalLaunchSequence.java} | 159 +++++------------- .../launch/launching/GdbLaunchDelegate.java | 21 ++- .../launching/ServicesLaunchSequence.java | 157 +++++++++++++++++ 3 files changed, 211 insertions(+), 126 deletions(-) rename plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/{LaunchSequence.java => FinalLaunchSequence.java} (63%) create mode 100644 plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/ServicesLaunchSequence.java diff --git a/plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/LaunchSequence.java b/plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/FinalLaunchSequence.java similarity index 63% rename from plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/LaunchSequence.java rename to plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/FinalLaunchSequence.java index 8575b06d410..321305a15a2 100644 --- a/plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/LaunchSequence.java +++ b/plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/FinalLaunchSequence.java @@ -1,45 +1,33 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems and others. + * Copyright (c) 2008 Ericsson 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: - * Wind River Systems - initial API and implementation + * Ericsson - initial API and implementation *******************************************************************************/ package org.eclipse.dd.gdb.launch.launching; -import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector; import org.eclipse.cdt.debug.mi.core.IGDBServerMILaunchConfigurationConstants; -import org.eclipse.cdt.debug.mi.core.IMILaunchConfigurationConstants; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; +import org.eclipse.dd.dsf.concurrent.DsfExecutor; import org.eclipse.dd.dsf.concurrent.RequestMonitor; import org.eclipse.dd.dsf.concurrent.Sequence; -import org.eclipse.dd.dsf.debug.service.StepQueueManager; import org.eclipse.dd.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext; import org.eclipse.dd.dsf.debug.service.IRunControl.IContainerDMContext; -import org.eclipse.dd.dsf.service.DsfSession; +import org.eclipse.dd.dsf.service.DsfServicesTracker; import org.eclipse.dd.gdb.launch.internal.GdbLaunchPlugin; -import org.eclipse.dd.gdb.service.GDBRunControl; import org.eclipse.dd.gdb.service.command.GDBControl; import org.eclipse.dd.gdb.service.command.GDBControl.SessionType; import org.eclipse.dd.mi.service.CSourceLookup; -import org.eclipse.dd.mi.service.ExpressionService; -import org.eclipse.dd.mi.service.MIBreakpoints; import org.eclipse.dd.mi.service.MIBreakpointsManager; -import org.eclipse.dd.mi.service.MIDisassembly; -import org.eclipse.dd.mi.service.MIMemory; -import org.eclipse.dd.mi.service.MIModules; -import org.eclipse.dd.mi.service.MIRegisters; -import org.eclipse.dd.mi.service.MIStack; import org.eclipse.dd.mi.service.command.commands.MIBreakInsert; import org.eclipse.dd.mi.service.command.commands.MICommand; import org.eclipse.dd.mi.service.command.commands.MIExecContinue; @@ -49,98 +37,36 @@ import org.eclipse.dd.mi.service.command.output.MIBreakInsertInfo; import org.eclipse.dd.mi.service.command.output.MIInfo; import org.eclipse.debug.core.DebugException; -public class LaunchSequence extends Sequence { +public class FinalLaunchSequence extends Sequence { Step[] fSteps = new Step[] { - // Create and initialize the Connection service. - new Step() { - @Override - public void execute(RequestMonitor requestMonitor) { - String debugMode = ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN; - try { - debugMode = fLaunch.getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, - ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN ); - } catch (CoreException e) { - } + /* + * Fetch the control service for later use + */ + new Step() { @Override + public void execute(RequestMonitor requestMonitor) { + DsfServicesTracker tracker = new DsfServicesTracker(GdbLaunchPlugin.getBundleContext(), fLaunch.getSession().getId()); + fCommandControl = tracker.getService(GDBControl.class); + tracker.dispose(); - if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { - fSessionType = SessionType.RUN; - } else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH)) { - fSessionType = SessionType.ATTACH; - } else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_CORE)) { - fSessionType = SessionType.CORE; - } else if (debugMode.equals(IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE)) { - fSessionType = SessionType.REMOTE; - } else { - fSessionType = SessionType.RUN; - } + requestMonitor.done(); + }}, + /* + * Setup the source paths + */ + new Step() { @Override + public void execute(RequestMonitor requestMonitor) { + DsfServicesTracker tracker = new DsfServicesTracker(GdbLaunchPlugin.getBundleContext(), fLaunch.getSession().getId()); + CSourceLookup sourceLookup = tracker.getService(CSourceLookup.class); + tracker.dispose(); - // - // Create the connection. - // - fCommandControl = new GDBControl(fSession, getGDBPath(), fExecPath, fSessionType, 30); - fCommandControl.initialize(requestMonitor); - } - }, - new Step() { @Override - public void execute(RequestMonitor requestMonitor) { - new GDBRunControl(fSession).initialize(requestMonitor); + CSourceLookupDirector locator = (CSourceLookupDirector)fLaunch.getSourceLocator(); + sourceLookup.setSourceLookupPath(fCommandControl.getGDBDMContext(), + locator.getSourceContainers(), requestMonitor); }}, - new Step() { @Override - public void execute(RequestMonitor requestMonitor) { - new StepQueueManager(fSession).initialize(requestMonitor); - }}, - new Step() { @Override - public void execute(RequestMonitor requestMonitor) { - new MIMemory(fSession).initialize(requestMonitor); - }}, - new Step() { @Override - public void execute(RequestMonitor requestMonitor) { - new MIModules(fSession).initialize(requestMonitor); - }}, - new Step() { @Override - public void execute(RequestMonitor requestMonitor) { - new MIStack(fSession).initialize(requestMonitor); - }}, - new Step() { @Override - public void execute(RequestMonitor requestMonitor) { - new ExpressionService(fSession).initialize(requestMonitor); - }}, - new Step() { @Override - public void execute(RequestMonitor requestMonitor) { - fSourceLookup = new CSourceLookup(fSession); - fSourceLookup.initialize(requestMonitor); - }}, - new Step() { @Override - public void execute(RequestMonitor requestMonitor) { - CSourceLookupDirector locator = (CSourceLookupDirector)fLaunch.getSourceLocator(); - - fSourceLookup.setSourceLookupDirector(fCommandControl.getGDBDMContext(), locator); - fSourceLookup.setSourceLookupPath(fCommandControl.getGDBDMContext(), - locator.getSourceContainers(), requestMonitor); - }}, - new Step() { @Override - public void execute(final RequestMonitor requestMonitor) { - // Create the low-level breakpoint service - final MIBreakpoints bpService = new MIBreakpoints(fSession); - bpService.initialize(new RequestMonitor(getExecutor(), requestMonitor)); - }}, - new Step() { @Override - public void execute(final RequestMonitor requestMonitor) { - // Create high-level breakpoint service and install breakpoints - // for the GDB debug context. - fBpmService = new MIBreakpointsManager(fSession, CDebugCorePlugin.PLUGIN_ID); - fBpmService.initialize(new RequestMonitor(getExecutor(), requestMonitor)); - }}, - new Step() { @Override - public void execute(RequestMonitor requestMonitor) { - new MIRegisters(fSession).initialize(requestMonitor); - }}, - new Step() { @Override - public void execute(RequestMonitor requestMonitor) { - new MIDisassembly(fSession).initialize(requestMonitor); - }}, - /* If remote debugging, connect to target */ + /* + * If remote debugging, connect to target + */ new Step() { private boolean fTcpConnection; private String fRemoteTcpHost; @@ -228,7 +154,10 @@ public class LaunchSequence extends Sequence { */ new Step() { @Override public void execute(final RequestMonitor requestMonitor) { - fBpmService.startTrackingBreakpoints(fCommandControl.getGDBDMContext(), requestMonitor); + DsfServicesTracker tracker = new DsfServicesTracker(GdbLaunchPlugin.getBundleContext(), fLaunch.getSession().getId()); + MIBreakpointsManager bpmService = tracker.getService(MIBreakpointsManager.class); + tracker.dispose(); + bpmService.startTrackingBreakpoints(fCommandControl.getGDBDMContext(), requestMonitor); }}, /* * If needed, insert breakpoint at main and run to it. @@ -298,34 +227,22 @@ public class LaunchSequence extends Sequence { }, }; - DsfSession fSession; GdbLaunch fLaunch; - IPath fExecPath; SessionType fSessionType; GDBControl fCommandControl; - CSourceLookup fSourceLookup; - MIBreakpointsManager fBpmService; - public LaunchSequence(DsfSession session, GdbLaunch launch, IPath execPath) { - super(session.getExecutor()); - fSession = session; + public FinalLaunchSequence(DsfExecutor executor, GdbLaunch launch, SessionType type) { + super(executor); fLaunch = launch; - fExecPath = execPath; + fSessionType = type; } + @Override public Step[] getSteps() { return fSteps; } - - private IPath getGDBPath() { - IPath retVal = new Path("gdb.exe"); //$NON-NLS-1$ - try { - retVal = new Path( fLaunch.getLaunchConfiguration().getAttribute( IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, IMILaunchConfigurationConstants.DEBUGGER_DEBUG_NAME_DEFAULT ) ); - } catch (CoreException e) { - } - return retVal; - } } + diff --git a/plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/GdbLaunchDelegate.java b/plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/GdbLaunchDelegate.java index 96acd7f0581..0258f116093 100644 --- a/plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/GdbLaunchDelegate.java +++ b/plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/GdbLaunchDelegate.java @@ -124,15 +124,15 @@ public class GdbLaunchDelegate extends AbstractCLaunchDelegate // Create and invoke the launch sequence to create the debug control and services - final LaunchSequence launchSequence = - new LaunchSequence(launch.getSession(), launch, exePath); - launch.getSession().getExecutor().execute(launchSequence); + final ServicesLaunchSequence servicesLaunchSequence = + new ServicesLaunchSequence(launch.getSession(), launch, exePath); + launch.getSession().getExecutor().execute(servicesLaunchSequence); try { - launchSequence.get(); + servicesLaunchSequence.get(); } catch (InterruptedException e1) { throw new DebugException(new Status(IStatus.ERROR, GdbLaunchPlugin.PLUGIN_ID, DebugException.INTERNAL_ERROR, "Interrupted Exception in dispatch thread", e1)); //$NON-NLS-1$ } catch (ExecutionException e1) { - throw new DebugException(new Status(IStatus.ERROR, GdbLaunchPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Error in launch sequence", e1.getCause())); //$NON-NLS-1$ + throw new DebugException(new Status(IStatus.ERROR, GdbLaunchPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Error in services launch sequence", e1.getCause())); //$NON-NLS-1$ } launch.initializeControl(); @@ -163,6 +163,17 @@ public class GdbLaunchDelegate extends AbstractCLaunchDelegate throw new CoreException(new Status(IStatus.ERROR, GdbLaunchPlugin.PLUGIN_ID, 0, "Debugger shut down before launch was completed.", e)); //$NON-NLS-1$ } + // Create and invoke the final launch sequence to setup GDB + final FinalLaunchSequence finalLaunchSequence = + new FinalLaunchSequence(launch.getSession().getExecutor(), launch, fSessionType); + launch.getSession().getExecutor().execute(finalLaunchSequence); + try { + finalLaunchSequence.get(); + } catch (InterruptedException e1) { + throw new DebugException(new Status(IStatus.ERROR, GdbLaunchPlugin.PLUGIN_ID, DebugException.INTERNAL_ERROR, "Interrupted Exception in dispatch thread", e1)); //$NON-NLS-1$ + } catch (ExecutionException e1) { + throw new DebugException(new Status(IStatus.ERROR, GdbLaunchPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Error in final launch sequence", e1.getCause())); //$NON-NLS-1$ + } // Create a memory retrieval and register it with session try { launch.getDsfExecutor().submit( new Callable() { diff --git a/plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/ServicesLaunchSequence.java b/plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/ServicesLaunchSequence.java new file mode 100644 index 00000000000..281448bf5aa --- /dev/null +++ b/plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/ServicesLaunchSequence.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.dd.gdb.launch.launching; + +import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector; +import org.eclipse.cdt.debug.mi.core.IMILaunchConfigurationConstants; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.dd.dsf.concurrent.RequestMonitor; +import org.eclipse.dd.dsf.concurrent.Sequence; +import org.eclipse.dd.dsf.debug.service.StepQueueManager; +import org.eclipse.dd.dsf.service.DsfSession; +import org.eclipse.dd.gdb.service.GDBRunControl; +import org.eclipse.dd.gdb.service.command.GDBControl; +import org.eclipse.dd.gdb.service.command.GDBControl.SessionType; +import org.eclipse.dd.mi.service.CSourceLookup; +import org.eclipse.dd.mi.service.ExpressionService; +import org.eclipse.dd.mi.service.MIBreakpoints; +import org.eclipse.dd.mi.service.MIBreakpointsManager; +import org.eclipse.dd.mi.service.MIDisassembly; +import org.eclipse.dd.mi.service.MIMemory; +import org.eclipse.dd.mi.service.MIModules; +import org.eclipse.dd.mi.service.MIRegisters; +import org.eclipse.dd.mi.service.MIStack; + +public class ServicesLaunchSequence extends Sequence { + + Step[] fSteps = new Step[] { + // Create and initialize the Connection service. + new Step() { + @Override + public void execute(RequestMonitor requestMonitor) { + String debugMode = ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN; + try { + debugMode = fLaunch.getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, + ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN ); + } catch (CoreException e) { + } + + if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { + fSessionType = SessionType.RUN; + } else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH)) { + fSessionType = SessionType.ATTACH; + } else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_CORE)) { + fSessionType = SessionType.CORE; + } else if (debugMode.equals(IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE)) { + fSessionType = SessionType.REMOTE; + } else { + fSessionType = SessionType.RUN; + } + + // + // Create the connection. + // + fCommandControl = new GDBControl(fSession, getGDBPath(), fExecPath, fSessionType, 30); + fCommandControl.initialize(requestMonitor); + } + }, + new Step() { @Override + public void execute(RequestMonitor requestMonitor) { + new GDBRunControl(fSession).initialize(requestMonitor); + }}, + new Step() { @Override + public void execute(RequestMonitor requestMonitor) { + new StepQueueManager(fSession).initialize(requestMonitor); + }}, + new Step() { @Override + public void execute(RequestMonitor requestMonitor) { + new MIMemory(fSession).initialize(requestMonitor); + }}, + new Step() { @Override + public void execute(RequestMonitor requestMonitor) { + new MIModules(fSession).initialize(requestMonitor); + }}, + new Step() { @Override + public void execute(RequestMonitor requestMonitor) { + new MIStack(fSession).initialize(requestMonitor); + }}, + new Step() { @Override + public void execute(RequestMonitor requestMonitor) { + new ExpressionService(fSession).initialize(requestMonitor); + }}, + new Step() { @Override + public void execute(RequestMonitor requestMonitor) { + fSourceLookup = new CSourceLookup(fSession); + fSourceLookup.initialize(requestMonitor); + }}, + new Step() { @Override + public void execute(RequestMonitor requestMonitor) { + fSourceLookup.setSourceLookupDirector(fCommandControl.getGDBDMContext(), (CSourceLookupDirector)fLaunch.getSourceLocator()); + requestMonitor.done(); + }}, + new Step() { @Override + public void execute(final RequestMonitor requestMonitor) { + // Create the low-level breakpoint service + final MIBreakpoints bpService = new MIBreakpoints(fSession); + bpService.initialize(new RequestMonitor(getExecutor(), requestMonitor)); + }}, + new Step() { @Override + public void execute(final RequestMonitor requestMonitor) { + // Create high-level breakpoint service and install breakpoints + // for the GDB debug context. + fBpmService = new MIBreakpointsManager(fSession, CDebugCorePlugin.PLUGIN_ID); + fBpmService.initialize(new RequestMonitor(getExecutor(), requestMonitor)); + }}, + new Step() { @Override + public void execute(RequestMonitor requestMonitor) { + new MIRegisters(fSession).initialize(requestMonitor); + }}, + new Step() { @Override + public void execute(RequestMonitor requestMonitor) { + new MIDisassembly(fSession).initialize(requestMonitor); + }}, + }; + + DsfSession fSession; + GdbLaunch fLaunch; + IPath fExecPath; + SessionType fSessionType; + + GDBControl fCommandControl; + CSourceLookup fSourceLookup; + MIBreakpointsManager fBpmService; + + public ServicesLaunchSequence(DsfSession session, GdbLaunch launch, IPath execPath) { + super(session.getExecutor()); + fSession = session; + fLaunch = launch; + fExecPath = execPath; + } + + @Override + public Step[] getSteps() { + return fSteps; + } + + private IPath getGDBPath() { + IPath retVal = new Path("gdb.exe"); //$NON-NLS-1$ + try { + retVal = new Path( fLaunch.getLaunchConfiguration().getAttribute( IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, IMILaunchConfigurationConstants.DEBUGGER_DEBUG_NAME_DEFAULT ) ); + } catch (CoreException e) { + } + return retVal; + } + +}