|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2010 TUBITAK BILGEM-ITI 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 |
* Onur Akdemir (TUBITAK BILGEM-ITI) - Multi-process debugging (Bug 237306) |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.cdt.dsf.gdb.service; |
| 12 |
|
| 13 |
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; |
| 14 |
import org.eclipse.cdt.dsf.concurrent.RequestMonitor; |
| 15 |
import org.eclipse.cdt.dsf.datamodel.DMContexts; |
| 16 |
import org.eclipse.cdt.dsf.datamodel.IDMContext; |
| 17 |
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; |
| 18 |
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; |
| 19 |
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl; |
| 20 |
import org.eclipse.cdt.dsf.mi.service.IMICommandControl; |
| 21 |
import org.eclipse.cdt.dsf.mi.service.IMIContainerDMContext; |
| 22 |
import org.eclipse.cdt.dsf.mi.service.IMIProcessDMContext; |
| 23 |
import org.eclipse.cdt.dsf.mi.service.command.CommandFactory; |
| 24 |
import org.eclipse.cdt.dsf.mi.service.command.output.MIAddInferiorInfo; |
| 25 |
import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; |
| 26 |
import org.eclipse.cdt.dsf.service.DsfSession; |
| 27 |
import org.eclipse.core.runtime.IStatus; |
| 28 |
import org.eclipse.core.runtime.Status; |
| 29 |
|
| 30 |
/** |
| 31 |
* Adding support for multi-process with GDB 7.2 |
| 32 |
* |
| 33 |
* @since 4.0 |
| 34 |
*/ |
| 35 |
public class GDBProcesses_7_2 extends GDBProcesses_7_1 { |
| 36 |
|
| 37 |
private CommandFactory fCommandFactory; |
| 38 |
private IGDBControl fCommandControl; |
| 39 |
|
| 40 |
public GDBProcesses_7_2(DsfSession session) { |
| 41 |
super(session); |
| 42 |
} |
| 43 |
|
| 44 |
@Override |
| 45 |
public void initialize(final RequestMonitor requestMonitor) { |
| 46 |
super.initialize(new RequestMonitor(getExecutor(), requestMonitor) { |
| 47 |
@Override |
| 48 |
protected void handleSuccess() { |
| 49 |
doInitialize(requestMonitor); |
| 50 |
} |
| 51 |
}); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* This method initializes this service after our superclass's initialize() |
| 56 |
* method succeeds. |
| 57 |
* |
| 58 |
* @param requestMonitor |
| 59 |
* The call-back object to notify when this service's |
| 60 |
* initialization is done. |
| 61 |
*/ |
| 62 |
private void doInitialize(RequestMonitor requestMonitor) { |
| 63 |
fCommandControl = getServicesTracker().getService(IGDBControl.class); |
| 64 |
fCommandFactory = getServicesTracker().getService(IMICommandControl.class).getCommandFactory(); |
| 65 |
requestMonitor.done(); |
| 66 |
} |
| 67 |
|
| 68 |
@Override |
| 69 |
public void shutdown(RequestMonitor requestMonitor) { |
| 70 |
super.shutdown(requestMonitor); |
| 71 |
} |
| 72 |
|
| 73 |
@Override |
| 74 |
public void attachDebuggerToProcess(final IProcessDMContext procCtx, final DataRequestMonitor<IDMContext> rm) { |
| 75 |
if (procCtx instanceof IMIProcessDMContext) { |
| 76 |
if (!doIsDebuggerAttachSupported()) { |
| 77 |
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Attach not supported.", null)); //$NON-NLS-1$ |
| 78 |
rm.done(); |
| 79 |
return; |
| 80 |
} |
| 81 |
|
| 82 |
ICommandControlDMContext controlDmc = DMContexts.getAncestorOfType(procCtx, ICommandControlDMContext.class); |
| 83 |
fCommandControl.queueCommand( |
| 84 |
fCommandFactory.createMIAddInferior(controlDmc), |
| 85 |
new DataRequestMonitor<MIAddInferiorInfo>(getExecutor(), rm) { |
| 86 |
@Override |
| 87 |
protected void handleSuccess() { |
| 88 |
final String groupId = getData().getGroupId(); |
| 89 |
if (groupId == null || groupId.trim().length() == 0) { |
| 90 |
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Invalid gdb group id.", null)); //$NON-NLS-1$ |
| 91 |
rm.done(); |
| 92 |
return; |
| 93 |
} |
| 94 |
|
| 95 |
final IMIContainerDMContext containerDmc = createContainerContext(procCtx, groupId); |
| 96 |
fCommandControl.queueCommand( |
| 97 |
fCommandFactory.createMITargetAttach(containerDmc, ((IMIProcessDMContext)procCtx).getProcId()), |
| 98 |
new DataRequestMonitor<MIInfo>(getExecutor(), rm) { |
| 99 |
@Override |
| 100 |
protected void handleSuccess() { |
| 101 |
rm.setData(containerDmc); |
| 102 |
rm.done(); |
| 103 |
} |
| 104 |
}); |
| 105 |
} |
| 106 |
}); |
| 107 |
} else { |
| 108 |
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Invalid process context.", null)); //$NON-NLS-1$ |
| 109 |
rm.done(); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
@Override |
| 114 |
public void detachDebuggerFromProcess(IDMContext dmc, final RequestMonitor rm) { |
| 115 |
|
| 116 |
ICommandControlDMContext controlDmc = DMContexts.getAncestorOfType(dmc, ICommandControlDMContext.class); |
| 117 |
final IMIContainerDMContext containerDmc = DMContexts.getAncestorOfType(dmc, IMIContainerDMContext.class); |
| 118 |
|
| 119 |
if (controlDmc != null && containerDmc != null) { |
| 120 |
if (!doCanDetachDebuggerFromProcess()) { |
| 121 |
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Detach not supported.", null)); //$NON-NLS-1$ |
| 122 |
rm.done(); |
| 123 |
return; |
| 124 |
} |
| 125 |
|
| 126 |
fCommandControl.queueCommand( |
| 127 |
fCommandFactory.createMITargetDetach(controlDmc, containerDmc.getGroupId()), |
| 128 |
new DataRequestMonitor<MIInfo>(getExecutor(), rm) { |
| 129 |
@Override |
| 130 |
protected void handleCompleted() { |
| 131 |
if (isSuccess()) { |
| 132 |
// Bug in GDB 7.2 where removing an inferior will lead to a crash when running other processes. |
| 133 |
// I'm hoping it will be fixed in 7.2.1 |
| 134 |
// fCommandControl.queueCommand( |
| 135 |
// fCommandFactory.createMIRemoveInferior(fCommandControl.getContext(), containerDmc.getGroupId()), |
| 136 |
// new DataRequestMonitor<MIInfo>(getExecutor(), rm)); |
| 137 |
} else { |
| 138 |
// This command fails with GDB 7.2 because of a GDB bug, which was fixed with GDB 7.2.1 |
| 139 |
// In case we get here, we assume we are using GDB 7.2 (although we should not) and we work |
| 140 |
// around it. |
| 141 |
// Also, with GDB 7.2, removing the inferior does not work because of another bug, so we just don't do it. |
| 142 |
fCommandControl.queueCommand( |
| 143 |
fCommandFactory.createMITargetDetach(containerDmc), |
| 144 |
new DataRequestMonitor<MIInfo>(getExecutor(), rm)); |
| 145 |
} |
| 146 |
} |
| 147 |
}); |
| 148 |
} else { |
| 149 |
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Invalid context.", null)); //$NON-NLS-1$ |
| 150 |
rm.done(); |
| 151 |
} |
| 152 |
} |
| 153 |
} |
| 154 |
|