|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2006, 2010 Wind River Systems and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* Wind River Systems - initial API and implementation |
| 10 |
* Nokia - handled GDBBackend service. Sep. 2008 |
| 11 |
* IBM Corporation |
| 12 |
* Ericsson - Support for Tracing Control service |
| 13 |
* Ericsson - Converted to use ReflectionSequence to allow for overriding |
| 14 |
*******************************************************************************/ |
| 15 |
package org.eclipse.cdt.dsf.gdb.launching; |
| 16 |
|
| 17 |
import java.util.ArrayList; |
| 18 |
import java.util.Arrays; |
| 19 |
import java.util.Collections; |
| 20 |
import java.util.List; |
| 21 |
|
| 22 |
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector; |
| 23 |
import org.eclipse.cdt.dsf.concurrent.ReflectionSequence; |
| 24 |
import org.eclipse.cdt.dsf.concurrent.RequestMonitor; |
| 25 |
import org.eclipse.cdt.dsf.concurrent.RequestMonitorWithProgress; |
| 26 |
import org.eclipse.cdt.dsf.debug.service.IBreakpoints; |
| 27 |
import org.eclipse.cdt.dsf.debug.service.IDisassembly; |
| 28 |
import org.eclipse.cdt.dsf.debug.service.IExpressions; |
| 29 |
import org.eclipse.cdt.dsf.debug.service.IMemory; |
| 30 |
import org.eclipse.cdt.dsf.debug.service.IModules; |
| 31 |
import org.eclipse.cdt.dsf.debug.service.IProcesses; |
| 32 |
import org.eclipse.cdt.dsf.debug.service.IRegisters; |
| 33 |
import org.eclipse.cdt.dsf.debug.service.IRunControl; |
| 34 |
import org.eclipse.cdt.dsf.debug.service.ISourceLookup; |
| 35 |
import org.eclipse.cdt.dsf.debug.service.ISourceLookup.ISourceLookupDMContext; |
| 36 |
import org.eclipse.cdt.dsf.debug.service.IStack; |
| 37 |
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService; |
| 38 |
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; |
| 39 |
import org.eclipse.cdt.dsf.gdb.service.IGDBTraceControl; |
| 40 |
import org.eclipse.cdt.dsf.mi.service.CSourceLookup; |
| 41 |
import org.eclipse.cdt.dsf.mi.service.IMIBackend; |
| 42 |
import org.eclipse.cdt.dsf.mi.service.MIBreakpointsManager; |
| 43 |
import org.eclipse.cdt.dsf.service.DsfServicesTracker; |
| 44 |
import org.eclipse.cdt.dsf.service.DsfSession; |
| 45 |
import org.eclipse.cdt.dsf.service.IDsfService; |
| 46 |
|
| 47 |
/** |
| 48 |
* This class replaces both ServicesLaunchSequence and ShutdownSequence to |
| 49 |
* allow to easily override this functionality. The two classes have been merged into |
| 50 |
* a single class since they are so closely related. |
| 51 |
* |
| 52 |
* @since 4.0 |
| 53 |
*/ |
| 54 |
@SuppressWarnings( "restriction" ) |
| 55 |
public class GdbServicesSequence extends ReflectionSequence { |
| 56 |
|
| 57 |
public enum ServiceSequenceOperation { INITIALIZE, SHUTDOWN }; |
| 58 |
|
| 59 |
private final static String[] INITIALIZATION_STEPS = new String[] { |
| 60 |
"handleBackendService", //$NON-NLS-1$ |
| 61 |
"handleCommandControlService", //$NON-NLS-1$ |
| 62 |
"handleProcessesService", //$NON-NLS-1$ |
| 63 |
"handleRunControlService", //$NON-NLS-1$ |
| 64 |
"handleMemoryService", //$NON-NLS-1$ |
| 65 |
"handleModuleService", //$NON-NLS-1$ |
| 66 |
"handleStackService", //$NON-NLS-1$ |
| 67 |
"handleExpressionsService", //$NON-NLS-1$ |
| 68 |
"handleSourceLookupService", //$NON-NLS-1$ |
| 69 |
"handleBreakpointsService", //$NON-NLS-1$ |
| 70 |
"handleBreakpointsMediatorService", //$NON-NLS-1$ |
| 71 |
"handleRegistersService", //$NON-NLS-1$ |
| 72 |
"handleDisassemblyService", //$NON-NLS-1$ |
| 73 |
"handleTraceControlService", //$NON-NLS-1$ |
| 74 |
}; |
| 75 |
|
| 76 |
private final ServiceSequenceOperation fOperation; |
| 77 |
private final DsfSession fSession; |
| 78 |
private final GdbLaunch fLaunch; |
| 79 |
|
| 80 |
private ICommandControlService fCommandControl; |
| 81 |
|
| 82 |
public GdbServicesSequence(ServiceSequenceOperation operation, DsfSession session, GdbLaunch launch, RequestMonitorWithProgress rm) { |
| 83 |
super(session.getExecutor(), rm, |
| 84 |
operation == ServiceSequenceOperation.INITIALIZE ? LaunchMessages.getString("ServicesLaunchSequence_0") : "", //$NON-NLS-1$ //$NON-NLS-2$ |
| 85 |
operation == ServiceSequenceOperation.INITIALIZE ? LaunchMessages.getString("ServicesLaunchSequence_1") : ""); //$NON-NLS-1$ //$NON-NLS-2$ |
| 86 |
fSession = session; |
| 87 |
fLaunch = launch; |
| 88 |
fOperation = operation; |
| 89 |
} |
| 90 |
|
| 91 |
@Override |
| 92 |
protected String[] getExecutionOrder(String group) { |
| 93 |
if (GROUP_TOP_LEVEL.equals(group)) { |
| 94 |
if (fOperation == ServiceSequenceOperation.INITIALIZE) { |
| 95 |
return INITIALIZATION_STEPS; |
| 96 |
} else { |
| 97 |
// Use the reverse order of the initialization sequence |
| 98 |
// We need to create a brand new array list or else we'll actually reverse the init_steps array. |
| 99 |
List<String> orderedList = new ArrayList<String>(Arrays.asList(INITIALIZATION_STEPS)); |
| 100 |
Collections.reverse(orderedList); |
| 101 |
return orderedList.toArray(new String[orderedList.size()]); |
| 102 |
} |
| 103 |
} |
| 104 |
return null; |
| 105 |
} |
| 106 |
|
| 107 |
@Execute |
| 108 |
public void handleBackendService(RequestMonitor requestMonitor) { |
| 109 |
if (fOperation == ServiceSequenceOperation.INITIALIZE) { |
| 110 |
fLaunch.getServiceFactory().createService(IMIBackend.class, fSession, fLaunch.getLaunchConfiguration()).initialize(requestMonitor); |
| 111 |
} else { |
| 112 |
shutdownService(IMIBackend.class, requestMonitor); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
@Execute |
| 117 |
public void handleCommandControlService(RequestMonitor requestMonitor) { |
| 118 |
if (fOperation == ServiceSequenceOperation.INITIALIZE) { |
| 119 |
fCommandControl = fLaunch.getServiceFactory().createService(ICommandControlService.class, fSession, fLaunch.getLaunchConfiguration()); |
| 120 |
fCommandControl.initialize(requestMonitor); |
| 121 |
} else { |
| 122 |
shutdownService(ICommandControlService.class, requestMonitor); |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
@Execute |
| 127 |
public void handleProcessesService(RequestMonitor requestMonitor) { |
| 128 |
if (fOperation == ServiceSequenceOperation.INITIALIZE) { |
| 129 |
fLaunch.getServiceFactory().createService(IProcesses.class, fSession).initialize(requestMonitor); |
| 130 |
} else { |
| 131 |
shutdownService(IProcesses.class, requestMonitor); |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
@Execute |
| 136 |
public void handleRunControlService(RequestMonitor requestMonitor) { |
| 137 |
if (fOperation == ServiceSequenceOperation.INITIALIZE) { |
| 138 |
fLaunch.getServiceFactory().createService(IRunControl.class, fSession).initialize(requestMonitor); |
| 139 |
} else { |
| 140 |
shutdownService(IRunControl.class, requestMonitor); |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
@Execute |
| 145 |
public void handleMemoryService(RequestMonitor requestMonitor) { |
| 146 |
if (fOperation == ServiceSequenceOperation.INITIALIZE) { |
| 147 |
fLaunch.getServiceFactory().createService(IMemory.class, fSession).initialize(requestMonitor); |
| 148 |
} else { |
| 149 |
shutdownService(IMemory.class, requestMonitor); |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
@Execute |
| 154 |
public void handleModuleService(RequestMonitor requestMonitor) { |
| 155 |
if (fOperation == ServiceSequenceOperation.INITIALIZE) { |
| 156 |
fLaunch.getServiceFactory().createService(IModules.class, fSession).initialize(requestMonitor); |
| 157 |
} else { |
| 158 |
shutdownService(IModules.class, requestMonitor); |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
@Execute |
| 163 |
public void handleStackService(RequestMonitor requestMonitor) { |
| 164 |
if (fOperation == ServiceSequenceOperation.INITIALIZE) { |
| 165 |
fLaunch.getServiceFactory().createService(IStack.class, fSession).initialize(requestMonitor); |
| 166 |
} else { |
| 167 |
shutdownService(IStack.class, requestMonitor); |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
@Execute |
| 172 |
public void handleExpressionsService(RequestMonitor requestMonitor) { |
| 173 |
if (fOperation == ServiceSequenceOperation.INITIALIZE) { |
| 174 |
fLaunch.getServiceFactory().createService(IExpressions.class, fSession).initialize(requestMonitor); |
| 175 |
} else { |
| 176 |
shutdownService(IExpressions.class, requestMonitor); |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
@Execute |
| 181 |
public void handleSourceLookupService(final RequestMonitor requestMonitor) { |
| 182 |
if (fOperation == ServiceSequenceOperation.INITIALIZE) { |
| 183 |
final CSourceLookup sourceLookup = (CSourceLookup)fLaunch.getServiceFactory().createService(ISourceLookup.class, fSession); |
| 184 |
sourceLookup.initialize(new RequestMonitor(getExecutor(), requestMonitor) { |
| 185 |
@Override |
| 186 |
protected void handleSuccess() { |
| 187 |
ISourceLookupDMContext sourceLookupDmc = (ISourceLookupDMContext)fCommandControl.getContext(); |
| 188 |
sourceLookup.setSourceLookupDirector(sourceLookupDmc, (CSourceLookupDirector)fLaunch.getSourceLocator()); |
| 189 |
requestMonitor.done(); |
| 190 |
} |
| 191 |
}); |
| 192 |
} else { |
| 193 |
shutdownService(ISourceLookup.class, requestMonitor); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
@Execute |
| 198 |
public void handleBreakpointsService(final RequestMonitor requestMonitor) { |
| 199 |
if (fOperation == ServiceSequenceOperation.INITIALIZE) { |
| 200 |
fLaunch.getServiceFactory().createService(IBreakpoints.class, fSession).initialize(new RequestMonitor(getExecutor(), requestMonitor)); |
| 201 |
} else { |
| 202 |
shutdownService(IBreakpoints.class, requestMonitor); |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
@Execute |
| 207 |
public void handleBreakpointsMediatorService(final RequestMonitor requestMonitor) { |
| 208 |
if (fOperation == ServiceSequenceOperation.INITIALIZE) { |
| 209 |
fLaunch.getServiceFactory().createService(MIBreakpointsManager.class, fSession).initialize(new RequestMonitor(getExecutor(), requestMonitor)); |
| 210 |
} else { |
| 211 |
shutdownService(MIBreakpointsManager.class, requestMonitor); |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
@Execute |
| 216 |
public void handleRegistersService(RequestMonitor requestMonitor) { |
| 217 |
if (fOperation == ServiceSequenceOperation.INITIALIZE) { |
| 218 |
fLaunch.getServiceFactory().createService(IRegisters.class, fSession).initialize(requestMonitor); |
| 219 |
} else { |
| 220 |
shutdownService(IRegisters.class, requestMonitor); |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
@Execute |
| 225 |
public void handleDisassemblyService(RequestMonitor requestMonitor) { |
| 226 |
if (fOperation == ServiceSequenceOperation.INITIALIZE) { |
| 227 |
fLaunch.getServiceFactory().createService(IDisassembly.class, fSession).initialize(requestMonitor); |
| 228 |
} else { |
| 229 |
shutdownService(IDisassembly.class, requestMonitor); |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
@Execute |
| 234 |
public void handleTraceControlService(RequestMonitor requestMonitor) { |
| 235 |
if (fOperation == ServiceSequenceOperation.INITIALIZE) { |
| 236 |
IGDBTraceControl traceService = fLaunch.getServiceFactory().createService(IGDBTraceControl.class, fSession, fLaunch.getLaunchConfiguration()); |
| 237 |
// Note that for older versions of GDB, we don't support tracing, so there is no trace service. |
| 238 |
if (traceService != null) { |
| 239 |
traceService.initialize(requestMonitor); |
| 240 |
} else { |
| 241 |
requestMonitor.done(); |
| 242 |
} |
| 243 |
} else { |
| 244 |
shutdownService(IGDBTraceControl.class, requestMonitor); |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
public <V extends IDsfService> void shutdownService(Class<V> clazz, final RequestMonitor requestMonitor) { |
| 249 |
DsfServicesTracker tracker = new DsfServicesTracker(GdbPlugin.getBundleContext(), fSession.getId()); |
| 250 |
IDsfService service = tracker.getService(clazz); |
| 251 |
tracker.dispose(); |
| 252 |
if (service != null) { |
| 253 |
service.shutdown(new RequestMonitor(getExecutor(), requestMonitor) { |
| 254 |
@Override |
| 255 |
protected void handleCompleted() { |
| 256 |
if (!isSuccess()) { |
| 257 |
GdbPlugin.getDefault().getLog().log(getStatus()); |
| 258 |
} |
| 259 |
requestMonitor.done(); |
| 260 |
} |
| 261 |
}); |
| 262 |
} else { |
| 263 |
// It is possible that a particular service was not instantiated at all |
| 264 |
// depending on our backend |
| 265 |
requestMonitor.done(); |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
protected ServiceSequenceOperation getOperation() { |
| 270 |
return fOperation; |
| 271 |
} |
| 272 |
|
| 273 |
protected DsfSession getSession() { |
| 274 |
return fSession; |
| 275 |
} |
| 276 |
|
| 277 |
protected GdbLaunch getLaunch() { |
| 278 |
return fLaunch; |
| 279 |
} |
| 280 |
} |