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

Splitting the LaunchSequence into ServicesLaunchSequence and FinalLaunchSequence, as discussed in Bug 221505 comment #7

This commit is contained in:
Marc Khouzam 2008-03-24 20:00:43 +00:00
parent 7158eeed07
commit 508a4a90b3
3 changed files with 211 additions and 126 deletions

View file

@ -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;
}
}

View file

@ -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<Object>() {

View file

@ -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;
}
}