|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2010 Ericsson 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 |
* Ericsson - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.cdt.dsf.gdb.service; |
| 12 |
|
| 13 |
import java.util.Map; |
| 14 |
import java.util.Properties; |
| 15 |
|
| 16 |
import org.eclipse.cdt.debug.core.CDebugUtils; |
| 17 |
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; |
| 18 |
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; |
| 19 |
import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor; |
| 20 |
import org.eclipse.cdt.dsf.concurrent.ReflectionSequence; |
| 21 |
import org.eclipse.cdt.dsf.concurrent.RequestMonitor; |
| 22 |
import org.eclipse.cdt.dsf.concurrent.Sequence; |
| 23 |
import org.eclipse.cdt.dsf.datamodel.DMContexts; |
| 24 |
import org.eclipse.cdt.dsf.datamodel.IDMContext; |
| 25 |
import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext; |
| 26 |
import org.eclipse.cdt.dsf.debug.service.command.ICommand; |
| 27 |
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; |
| 28 |
import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; |
| 29 |
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; |
| 30 |
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl; |
| 31 |
import org.eclipse.cdt.dsf.mi.service.IMICommandControl; |
| 32 |
import org.eclipse.cdt.dsf.mi.service.IMIContainerDMContext; |
| 33 |
import org.eclipse.cdt.dsf.mi.service.IMIProcessDMContext; |
| 34 |
import org.eclipse.cdt.dsf.mi.service.command.CommandFactory; |
| 35 |
import org.eclipse.cdt.dsf.mi.service.command.output.MIAddInferiorInfo; |
| 36 |
import org.eclipse.cdt.dsf.mi.service.command.output.MIBreakInsertInfo; |
| 37 |
import org.eclipse.cdt.dsf.mi.service.command.output.MIBreakpoint; |
| 38 |
import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; |
| 39 |
import org.eclipse.cdt.dsf.service.DsfSession; |
| 40 |
import org.eclipse.core.runtime.CoreException; |
| 41 |
import org.eclipse.core.runtime.IStatus; |
| 42 |
import org.eclipse.core.runtime.Status; |
| 43 |
|
| 44 |
/** |
| 45 |
* @since 4.0 |
| 46 |
*/ |
| 47 |
public class GDBProcesses_7_2 extends GDBProcesses_7_1 { |
| 48 |
|
| 49 |
private CommandFactory fCommandFactory; |
| 50 |
private IGDBControl fCommandControl; |
| 51 |
private IGDBBackend fBackend; |
| 52 |
|
| 53 |
public GDBProcesses_7_2(DsfSession session) { |
| 54 |
super(session); |
| 55 |
} |
| 56 |
|
| 57 |
@Override |
| 58 |
public void initialize(final RequestMonitor requestMonitor) { |
| 59 |
super.initialize(new RequestMonitor(getExecutor(), requestMonitor) { |
| 60 |
@Override |
| 61 |
protected void handleSuccess() { |
| 62 |
doInitialize(requestMonitor); |
| 63 |
} |
| 64 |
}); |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* This method initializes this service after our superclass's initialize() |
| 69 |
* method succeeds. |
| 70 |
* |
| 71 |
* @param requestMonitor |
| 72 |
* The call-back object to notify when this service's |
| 73 |
* initialization is done. |
| 74 |
*/ |
| 75 |
private void doInitialize(RequestMonitor requestMonitor) { |
| 76 |
fCommandControl = getServicesTracker().getService(IGDBControl.class); |
| 77 |
fCommandFactory = getServicesTracker().getService(IMICommandControl.class).getCommandFactory(); |
| 78 |
fBackend = getServicesTracker().getService(IGDBBackend.class); |
| 79 |
|
| 80 |
requestMonitor.done(); |
| 81 |
} |
| 82 |
|
| 83 |
@Override |
| 84 |
public void shutdown(RequestMonitor requestMonitor) { |
| 85 |
super.shutdown(requestMonitor); |
| 86 |
} |
| 87 |
|
| 88 |
@Override |
| 89 |
protected boolean doIsDebuggerAttachSupported() { |
| 90 |
return true; |
| 91 |
} |
| 92 |
|
| 93 |
@Override |
| 94 |
protected boolean doCanDetachDebuggerFromProcess() { |
| 95 |
return true; |
| 96 |
} |
| 97 |
|
| 98 |
protected class DebugNewProcessSequence extends ReflectionSequence { |
| 99 |
|
| 100 |
private String fBinaryName; |
| 101 |
private Map<String, Object> fAttributes; |
| 102 |
private IMIContainerDMContext fContainerCtx; |
| 103 |
// Store the dataRM so that we can fill it with the container context that we will be creating |
| 104 |
private DataRequestMonitor<IDMContext> fDataRequestMonitor; |
| 105 |
|
| 106 |
public DebugNewProcessSequence(IDMContext dmc, String file, Map<String, Object> attributes, final DataRequestMonitor<IDMContext> rm) { |
| 107 |
super(GDBProcesses_7_2.this.getExecutor(), rm); |
| 108 |
fBinaryName = file; |
| 109 |
fAttributes = attributes; |
| 110 |
fDataRequestMonitor = rm; |
| 111 |
} |
| 112 |
|
| 113 |
@Override |
| 114 |
protected String[] getExecutionOrder(String group) { |
| 115 |
if (GROUP_TOP_LEVEL.equals(group)) { |
| 116 |
return new String[] { |
| 117 |
"stepAddInferior", //$NON-NLS-1$ |
| 118 |
"stepSetEnvironmentVariables", //$NON-NLS-1$ |
| 119 |
"stepSetExecutable", //$NON-NLS-1$ |
| 120 |
"stepSetArguments", //$NON-NLS-1$ |
| 121 |
"stepStartExecution", //$NON-NLS-1$ |
| 122 |
}; |
| 123 |
} |
| 124 |
return null; |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Start executing the program. |
| 129 |
*/ |
| 130 |
@Execute |
| 131 |
public void stepAddInferior(final RequestMonitor rm) { |
| 132 |
fCommandControl.queueCommand( |
| 133 |
fCommandFactory.createMIAddInferior(fCommandControl.getContext()), |
| 134 |
new DataRequestMonitor<MIAddInferiorInfo>(ImmediateExecutor.getInstance(), rm) { |
| 135 |
@Override |
| 136 |
protected void handleSuccess() { |
| 137 |
final String groupId = getData().getGroupId(); |
| 138 |
if (groupId == null || groupId.trim().length() == 0) { |
| 139 |
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Invalid gdb group id.", null)); //$NON-NLS-1$ |
| 140 |
rm.done(); |
| 141 |
return; |
| 142 |
} |
| 143 |
|
| 144 |
IProcessDMContext procCtx = createProcessContext(fCommandControl.getContext(), null); |
| 145 |
fContainerCtx = createContainerContext(procCtx, groupId); |
| 146 |
rm.done(); |
| 147 |
} |
| 148 |
}); |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Specify environment variables if needed |
| 153 |
*/ |
| 154 |
@Execute |
| 155 |
public void stepSetEnvironmentVariables(RequestMonitor rm) { |
| 156 |
boolean clear = false; |
| 157 |
Properties properties = new Properties(); |
| 158 |
try { |
| 159 |
// here we need to pass the proper container context |
| 160 |
clear = fBackend.getClearEnvironment(); |
| 161 |
properties = fBackend.getEnvironmentVariables(); |
| 162 |
} catch (CoreException e) { |
| 163 |
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, "Cannot get environment information", e)); //$NON-NLS-1$ |
| 164 |
rm.done(); |
| 165 |
return; |
| 166 |
} |
| 167 |
|
| 168 |
if (clear == true || properties.size() > 0) { |
| 169 |
// here we need to pass the proper container context |
| 170 |
fCommandControl.setEnvironment(properties, clear, rm); |
| 171 |
} else { |
| 172 |
rm.done(); |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
/** |
| 177 |
* Specify the executable file to be debugged and read the symbol table. |
| 178 |
*/ |
| 179 |
@Execute |
| 180 |
public void stepSetExecutable(RequestMonitor rm) { |
| 181 |
boolean noFileCommand = CDebugUtils.getAttribute(fAttributes, IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_USE_SOLIB_SYMBOLS_FOR_APP, |
| 182 |
IGDBLaunchConfigurationConstants.DEBUGGER_USE_SOLIB_SYMBOLS_FOR_APP_DEFAULT); |
| 183 |
|
| 184 |
if (!noFileCommand && fBinaryName != null && fBinaryName.length() > 0) { |
| 185 |
fCommandControl.queueCommand( |
| 186 |
fCommandFactory.createMIFileExecAndSymbols(fContainerCtx, fBinaryName), |
| 187 |
new DataRequestMonitor<MIInfo>(getExecutor(), rm)); |
| 188 |
} else { |
| 189 |
rm.done(); |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
/** |
| 194 |
* Specify the arguments to the executable file. |
| 195 |
*/ |
| 196 |
@Execute |
| 197 |
public void stepSetArguments(RequestMonitor rm) { |
| 198 |
try { |
| 199 |
String args = fBackend.getProgramArguments(); |
| 200 |
|
| 201 |
if (args != null) { |
| 202 |
fCommandControl.queueCommand( |
| 203 |
// here we need to pass the proper container context |
| 204 |
fCommandFactory.createMIGDBSetArgs(fCommandControl.getContext(), args), |
| 205 |
new DataRequestMonitor<MIInfo>(getExecutor(), rm)); |
| 206 |
} else { |
| 207 |
rm.done(); |
| 208 |
} |
| 209 |
} catch (CoreException e) { |
| 210 |
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, "Cannot get inferior arguments", e)); //$NON-NLS-1$ |
| 211 |
rm.done(); |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
/** |
| 216 |
* Start executing the program. |
| 217 |
*/ |
| 218 |
@Execute |
| 219 |
public void stepStartExecution(final RequestMonitor rm) { |
| 220 |
startOrRestart(fContainerCtx, fAttributes, false, new DataRequestMonitor<IMIContainerDMContext>(ImmediateExecutor.getInstance(), rm) { |
| 221 |
@Override |
| 222 |
protected void handleSuccess() { |
| 223 |
// Set the container that we created |
| 224 |
fDataRequestMonitor.setData(getData()); |
| 225 |
|
| 226 |
// Don't call fDataRequestMonitor.done(), the sequence will |
| 227 |
// automatically do that when we call rm.done(); |
| 228 |
rm.done(); |
| 229 |
} |
| 230 |
}); |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
@Override |
| 235 |
public void debugNewProcess(IDMContext dmc, String file, |
| 236 |
Map<String, Object> attributes, DataRequestMonitor<IDMContext> rm) { |
| 237 |
Sequence debugNewProcess = new DebugNewProcessSequence(dmc, file, attributes, rm); |
| 238 |
ImmediateExecutor.getInstance().execute(debugNewProcess); |
| 239 |
} |
| 240 |
|
| 241 |
@Override |
| 242 |
public void attachDebuggerToProcess(final IProcessDMContext procCtx, final DataRequestMonitor<IDMContext> rm) { |
| 243 |
if (procCtx instanceof IMIProcessDMContext) { |
| 244 |
if (!doIsDebuggerAttachSupported()) { |
| 245 |
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Attach not supported.", null)); //$NON-NLS-1$ |
| 246 |
rm.done(); |
| 247 |
return; |
| 248 |
} |
| 249 |
|
| 250 |
ICommandControlDMContext controlDmc = DMContexts.getAncestorOfType(procCtx, ICommandControlDMContext.class); |
| 251 |
fCommandControl.queueCommand( |
| 252 |
fCommandFactory.createMIAddInferior(controlDmc), |
| 253 |
new DataRequestMonitor<MIAddInferiorInfo>(getExecutor(), rm) { |
| 254 |
@Override |
| 255 |
protected void handleSuccess() { |
| 256 |
final String groupId = getData().getGroupId(); |
| 257 |
if (groupId == null || groupId.trim().length() == 0) { |
| 258 |
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Invalid gdb group id.", null)); //$NON-NLS-1$ |
| 259 |
rm.done(); |
| 260 |
return; |
| 261 |
} |
| 262 |
|
| 263 |
final IMIContainerDMContext containerDmc = createContainerContext(procCtx, groupId); |
| 264 |
fCommandControl.queueCommand( |
| 265 |
fCommandFactory.createMITargetAttach(containerDmc, ((IMIProcessDMContext)procCtx).getProcId()), |
| 266 |
new DataRequestMonitor<MIInfo>(getExecutor(), rm) { |
| 267 |
@Override |
| 268 |
protected void handleSuccess() { |
| 269 |
rm.setData(containerDmc); |
| 270 |
rm.done(); |
| 271 |
} |
| 272 |
}); |
| 273 |
} |
| 274 |
}); |
| 275 |
} else { |
| 276 |
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Invalid process context.", null)); //$NON-NLS-1$ |
| 277 |
rm.done(); |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
@Override |
| 282 |
public void detachDebuggerFromProcess(IDMContext dmc, final RequestMonitor rm) { |
| 283 |
|
| 284 |
final IMIContainerDMContext containerDmc = DMContexts.getAncestorOfType(dmc, IMIContainerDMContext.class); |
| 285 |
|
| 286 |
if (containerDmc != null) { |
| 287 |
if (!doCanDetachDebuggerFromProcess()) { |
| 288 |
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Detach not supported.", null)); //$NON-NLS-1$ |
| 289 |
rm.done(); |
| 290 |
return; |
| 291 |
} |
| 292 |
|
| 293 |
fCommandControl.queueCommand( |
| 294 |
fCommandFactory.createMITargetDetach(containerDmc), |
| 295 |
new DataRequestMonitor<MIInfo>(getExecutor(), rm) { |
| 296 |
@Override |
| 297 |
protected void handleSuccess() { |
| 298 |
fCommandControl.queueCommand( |
| 299 |
fCommandFactory.createMIRemoveInferior(fCommandControl.getContext(), containerDmc.getGroupId()), |
| 300 |
new DataRequestMonitor<MIInfo>(getExecutor(), rm)); |
| 301 |
} |
| 302 |
}); |
| 303 |
} else { |
| 304 |
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Invalid context.", null)); //$NON-NLS-1$ |
| 305 |
rm.done(); |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
protected class StartOrRestartProcessSequence extends ReflectionSequence { |
| 310 |
|
| 311 |
// This variable will be used to store the original container context, |
| 312 |
// but once the new process is start (restarted), it will contain the new |
| 313 |
// container context. This new container context has for parent the process |
| 314 |
// context, which holds the new pid. |
| 315 |
private IMIContainerDMContext fContainerDmc; |
| 316 |
|
| 317 |
private MIBreakpoint fUserBreakpoint = null; |
| 318 |
private boolean fUserBreakpointIsOnMain = false; |
| 319 |
private boolean fReverseEnabled; |
| 320 |
private boolean fRestart; |
| 321 |
private Map<String, Object> fAttributes; |
| 322 |
// Store the dataRM so that we can fill it with the container context that we will be creating |
| 323 |
private DataRequestMonitor<IMIContainerDMContext> fDataRequestMonitor; |
| 324 |
|
| 325 |
public StartOrRestartProcessSequence(IMIContainerDMContext containerDmc, Map<String, Object> attributes, |
| 326 |
boolean restart, DataRequestMonitor<IMIContainerDMContext> rm) { |
| 327 |
super(GDBProcesses_7_2.this.getExecutor(), rm); |
| 328 |
fContainerDmc = containerDmc; |
| 329 |
fAttributes = attributes; |
| 330 |
fRestart = restart; |
| 331 |
fDataRequestMonitor = rm; |
| 332 |
fReverseEnabled = CDebugUtils.getAttribute(attributes, IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_REVERSE, |
| 333 |
IGDBLaunchConfigurationConstants.DEBUGGER_REVERSE_DEFAULT); |
| 334 |
} |
| 335 |
|
| 336 |
@Override |
| 337 |
protected String[] getExecutionOrder(String group) { |
| 338 |
if (GROUP_TOP_LEVEL.equals(group)) { |
| 339 |
return new String[] { |
| 340 |
"stepInsertStopOnMainBreakpoint", //$NON-NLS-1$ |
| 341 |
"stepSetBreakpointForReverse", //$NON-NLS-1$ |
| 342 |
"stepRunProgram", //$NON-NLS-1$ |
| 343 |
"stepSetReverseOff", //$NON-NLS-1$ |
| 344 |
"stepEnableReverse", //$NON-NLS-1$ |
| 345 |
"stepContinue", //$NON-NLS-1$ |
| 346 |
}; |
| 347 |
} |
| 348 |
return null; |
| 349 |
} |
| 350 |
|
| 351 |
/** |
| 352 |
* If the user requested a 'stopOnMain', let's set the temporary breakpoint |
| 353 |
* where the user specified. |
| 354 |
*/ |
| 355 |
@Execute |
| 356 |
public void stepInsertStopOnMainBreakpoint(final RequestMonitor rm) { |
| 357 |
boolean userRequestedStop = CDebugUtils.getAttribute(fAttributes, |
| 358 |
ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, |
| 359 |
false); |
| 360 |
|
| 361 |
if (userRequestedStop) { |
| 362 |
String userStopSymbol = CDebugUtils.getAttribute(fAttributes, |
| 363 |
ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, |
| 364 |
ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT); |
| 365 |
|
| 366 |
fCommandControl.queueCommand( |
| 367 |
fCommandFactory.createMIBreakInsert((IBreakpointsTargetDMContext)fCommandControl.getContext(), |
| 368 |
true, false, null, 0, userStopSymbol, 0), |
| 369 |
new DataRequestMonitor<MIBreakInsertInfo>(getExecutor(), rm) { |
| 370 |
@Override |
| 371 |
public void handleSuccess() { |
| 372 |
if (getData() != null) { |
| 373 |
MIBreakpoint[] breakpoints = getData().getMIBreakpoints(); |
| 374 |
if (breakpoints.length > 0) { |
| 375 |
fUserBreakpoint = breakpoints[0]; |
| 376 |
} |
| 377 |
} |
| 378 |
rm.done(); |
| 379 |
} |
| 380 |
}); |
| 381 |
} else { |
| 382 |
rm.done(); |
| 383 |
} |
| 384 |
} |
| 385 |
|
| 386 |
/* |
| 387 |
* If reverse debugging, set a breakpoint on main to be able to enable reverse |
| 388 |
* as early as possible. |
| 389 |
* If the user has requested a stop at the same point, we could skip this breakpoint |
| 390 |
* however, we have to first set it to find out! So, we just leave it. |
| 391 |
*/ |
| 392 |
@Execute |
| 393 |
public void stepSetBreakpointForReverse(final RequestMonitor rm) { |
| 394 |
if (fReverseEnabled) { |
| 395 |
fCommandControl.queueCommand( |
| 396 |
fCommandFactory.createMIBreakInsert((IBreakpointsTargetDMContext)fCommandControl.getContext(), |
| 397 |
true, false, null, 0, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT, 0), |
| 398 |
new DataRequestMonitor<MIBreakInsertInfo>(getExecutor(), rm) { |
| 399 |
@Override |
| 400 |
public void handleSuccess() { |
| 401 |
if (getData() != null) { |
| 402 |
MIBreakpoint[] breakpoints = getData().getMIBreakpoints(); |
| 403 |
if (breakpoints.length > 0 && fUserBreakpoint != null) { |
| 404 |
fUserBreakpointIsOnMain = breakpoints[0].getAddress().equals(fUserBreakpoint.getAddress()); |
| 405 |
} |
| 406 |
} |
| 407 |
rm.done(); |
| 408 |
} |
| 409 |
}); |
| 410 |
} else { |
| 411 |
rm.done(); |
| 412 |
} |
| 413 |
} |
| 414 |
/* |
| 415 |
* Now, run the program. Use either -exec-run or -exec-continue depending |
| 416 |
* on whether we have remote session or not. |
| 417 |
*/ |
| 418 |
@Execute |
| 419 |
public void stepRunProgram(final RequestMonitor rm) { |
| 420 |
ICommand<MIInfo> command; |
| 421 |
if (useContinueCommand(fAttributes, fRestart)) { |
| 422 |
command = fCommandFactory.createMIExecContinue(fContainerDmc); |
| 423 |
} else { |
| 424 |
command = fCommandFactory.createMIExecRun(fContainerDmc); |
| 425 |
} |
| 426 |
fCommandControl.queueCommand(command, new DataRequestMonitor<MIInfo>(ImmediateExecutor.getInstance(), rm) { |
| 427 |
@Override |
| 428 |
protected void handleSuccess() { |
| 429 |
// Now that the process is started, the pid has been allocated |
| 430 |
// so we need to fetch the proper container context |
| 431 |
// We replace our current context which does not have the pid, with one that has the pid. |
| 432 |
fContainerDmc = createContainerContextFromGroupId(fCommandControl.getContext(), fContainerDmc.getGroupId()); |
| 433 |
fDataRequestMonitor.setData(fContainerDmc); |
| 434 |
rm.done(); |
| 435 |
} |
| 436 |
}); |
| 437 |
|
| 438 |
} |
| 439 |
/* |
| 440 |
* In case of a restart, reverse debugging should be marked as off here because |
| 441 |
* GDB will have turned it off. We may turn it back on after. |
| 442 |
*/ |
| 443 |
@Execute |
| 444 |
public void stepSetReverseOff(RequestMonitor rm) { |
| 445 |
// Although it only makes sense for a restart, it doesn't hurt |
| 446 |
// do to it all the time. |
| 447 |
GDBRunControl_7_0 reverseService = getServicesTracker().getService(GDBRunControl_7_0.class); |
| 448 |
if (reverseService != null) { |
| 449 |
reverseService.setReverseModeEnabled(false); |
| 450 |
} |
| 451 |
rm.done(); |
| 452 |
} |
| 453 |
/* |
| 454 |
* Since we have started the program, we can turn on reverse debugging if needed |
| 455 |
*/ |
| 456 |
@Execute |
| 457 |
public void stepEnableReverse(RequestMonitor rm) { |
| 458 |
if (fReverseEnabled) { |
| 459 |
IReverseRunControl reverseService = getServicesTracker().getService(IReverseRunControl.class); |
| 460 |
if (reverseService != null) { |
| 461 |
reverseService.enableReverseMode(fCommandControl.getContext(), true, rm); |
| 462 |
return; |
| 463 |
} |
| 464 |
} |
| 465 |
rm.done(); |
| 466 |
} |
| 467 |
/* |
| 468 |
* Finally, if we are enabling reverse, and the userSymbolStop is not on main, |
| 469 |
* we should do a continue because we are currently stopped on main but that |
| 470 |
* is not what the user requested |
| 471 |
*/ |
| 472 |
@Execute |
| 473 |
public void stepContinue(RequestMonitor rm) { |
| 474 |
if (fReverseEnabled && !fUserBreakpointIsOnMain) { |
| 475 |
fCommandControl.queueCommand(fCommandFactory.createMIExecContinue(fContainerDmc), |
| 476 |
new DataRequestMonitor<MIInfo>(getExecutor(), rm)); |
| 477 |
} else { |
| 478 |
rm.done(); |
| 479 |
} |
| 480 |
} |
| 481 |
}; |
| 482 |
|
| 483 |
/** |
| 484 |
* Insert breakpoint at entry if set, and start or restart the program. |
| 485 |
* Note that restart does not apply to remote or attach sessions. |
| 486 |
* |
| 487 |
* If we want to enable Reverse debugging from the start of the program we do the following: |
| 488 |
* attachSession => enable reverse |
| 489 |
* else => set temp bp on main, run, enable reverse, continue if bp on main was not requested by user |
| 490 |
*/ |
| 491 |
protected void startOrRestart(IMIContainerDMContext containerDmc, Map<String, Object> attributes, boolean restart, DataRequestMonitor<IMIContainerDMContext> rm) { |
| 492 |
final boolean reverseEnabled = CDebugUtils.getAttribute(attributes, IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_REVERSE, |
| 493 |
IGDBLaunchConfigurationConstants.DEBUGGER_REVERSE_DEFAULT); |
| 494 |
|
| 495 |
if (fBackend.getIsAttachSession()) { |
| 496 |
// Restart does not apply to attach sessions. |
| 497 |
// |
| 498 |
// When attaching to a running process, we do not need to set a breakpoint or |
| 499 |
// start the program; it is left up to the user. |
| 500 |
// We only need to turn on Reverse Debugging if requested. |
| 501 |
if (reverseEnabled) { |
| 502 |
IReverseRunControl reverseService = getServicesTracker().getService(IReverseRunControl.class); |
| 503 |
if (reverseService != null) { |
| 504 |
reverseService.enableReverseMode(fCommandControl.getContext(), true, rm); |
| 505 |
return; |
| 506 |
} |
| 507 |
} |
| 508 |
//TODO khouzam must set rm.setdata() |
| 509 |
rm.done(); |
| 510 |
return; |
| 511 |
} |
| 512 |
|
| 513 |
// When it is not an attach session, it gets a little more complicated |
| 514 |
// so let's use a sequence. |
| 515 |
ImmediateExecutor.getInstance().execute(new StartOrRestartProcessSequence(containerDmc, attributes, restart, rm)); |
| 516 |
} |
| 517 |
|
| 518 |
/** |
| 519 |
* This method indicates if we should use the -exec-continue method |
| 520 |
* instead of the -exec-run method. |
| 521 |
* This can be overridden to allow for customization. |
| 522 |
*/ |
| 523 |
protected boolean useContinueCommand(Map<String, Object> attributes, boolean restart) { |
| 524 |
// When doing remote debugging, we use -exec-continue instead of -exec-run |
| 525 |
// Restart does not apply to remote sessions |
| 526 |
return fBackend.getSessionType() == SessionType.REMOTE; |
| 527 |
} |
| 528 |
} |
| 529 |
|