1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Bug 528145 - Attach debugger to a gdbserver remote session

Change-Id: I18bfe412a46b727c74597ceb871391dcb48b302d
This commit is contained in:
Jonathan Tousignant 2021-12-14 13:06:38 -05:00 committed by Torbjörn Svensson
parent 66f3c6b08d
commit 7bddb5f4cb
2 changed files with 93 additions and 40 deletions

View file

@ -19,6 +19,7 @@
* Anton Gorenkov - A preference to use RTTI for variable types determination (Bug 377536) * Anton Gorenkov - A preference to use RTTI for variable types determination (Bug 377536)
* Xavier Raynaud (Kalray) - Avoid duplicating fields in sub-classes (add protected accessors) * Xavier Raynaud (Kalray) - Avoid duplicating fields in sub-classes (add protected accessors)
* Marc Khouzam (Ericsson) - Output the version of GDB at startup (Bug 455408) * Marc Khouzam (Ericsson) - Output the version of GDB at startup (Bug 455408)
* Jonathan Tousignant (NordiaSoft) - Remote session breakpoint (Bug 528145)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.dsf.gdb.launching; package org.eclipse.cdt.dsf.gdb.launching;
@ -38,6 +39,7 @@ import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
import org.eclipse.cdt.dsf.concurrent.RequestMonitorWithProgress; import org.eclipse.cdt.dsf.concurrent.RequestMonitorWithProgress;
import org.eclipse.cdt.dsf.datamodel.DataModelInitializedEvent; import org.eclipse.cdt.dsf.datamodel.DataModelInitializedEvent;
import org.eclipse.cdt.dsf.datamodel.IDMContext; import org.eclipse.cdt.dsf.datamodel.IDMContext;
import org.eclipse.cdt.dsf.debug.service.IProcesses.IProcessDMContext;
import org.eclipse.cdt.dsf.debug.service.ISourceLookup.ISourceLookupDMContext; import org.eclipse.cdt.dsf.debug.service.ISourceLookup.ISourceLookupDMContext;
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants;
@ -50,6 +52,7 @@ import org.eclipse.cdt.dsf.gdb.service.SessionType;
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl; import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl;
import org.eclipse.cdt.dsf.mi.service.CSourceLookup; import org.eclipse.cdt.dsf.mi.service.CSourceLookup;
import org.eclipse.cdt.dsf.mi.service.IMIProcesses; import org.eclipse.cdt.dsf.mi.service.IMIProcesses;
import org.eclipse.cdt.dsf.mi.service.MIProcesses;
import org.eclipse.cdt.dsf.mi.service.command.CommandFactory; import org.eclipse.cdt.dsf.mi.service.command.CommandFactory;
import org.eclipse.cdt.dsf.mi.service.command.output.MIGDBVersionInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIGDBVersionInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo;
@ -139,6 +142,8 @@ public class FinalLaunchSequence extends ReflectionSequence {
"stepNewProcess", //$NON-NLS-1$ "stepNewProcess", //$NON-NLS-1$
// For local attach launch only // For local attach launch only
"stepAttachToProcess", //$NON-NLS-1$ "stepAttachToProcess", //$NON-NLS-1$
// For remote attach launch only
"stepAttachRemoteToDebugger", //$NON-NLS-1$
// Global // Global
"stepDataModelInitializationComplete", //$NON-NLS-1$ "stepDataModelInitializationComplete", //$NON-NLS-1$
"stepCleanup", //$NON-NLS-1$ "stepCleanup", //$NON-NLS-1$
@ -647,6 +652,23 @@ public class FinalLaunchSequence extends ReflectionSequence {
} }
} }
/**
* If we are dealing with an remote attach session, perform the attach to debugger.
* Bug 528145
* @since 6.5
*/
@Execute
public void stepAttachRemoteToDebugger(final RequestMonitor requestMonitor) {
if (fGDBBackend.getIsAttachSession() && fGDBBackend.getSessionType() == SessionType.REMOTE) {
IProcessDMContext processContext = fProcService.createProcessContext(fCommandControl.getContext(),
MIProcesses.UNKNOWN_PROCESS_ID);
fProcService.attachDebuggerToProcess(processContext,
new DataRequestMonitor<IDMContext>(getExecutor(), requestMonitor));
} else {
requestMonitor.done();
}
}
/** /**
* Indicate that the Data Model has been filled. This will trigger the Debug view to expand. * Indicate that the Data Model has been filled. This will trigger the Debug view to expand.
* @since 4.0 * @since 4.0

View file

@ -13,6 +13,7 @@
* Marc Khouzam (Ericsson) - Workaround for Bug 352998 * Marc Khouzam (Ericsson) - Workaround for Bug 352998
* Marc Khouzam (Ericsson) - Update breakpoint handling for GDB >= 7.4 (Bug 389945) * Marc Khouzam (Ericsson) - Update breakpoint handling for GDB >= 7.4 (Bug 389945)
* Alvaro Sanchez-Leon (Ericsson) - Breakpoint Enable does not work after restarting the application (Bug 456959) * Alvaro Sanchez-Leon (Ericsson) - Breakpoint Enable does not work after restarting the application (Bug 456959)
* Jonathan Tousignant (NordiaSoft) - Remote session breakpoint (Bug 528145)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.dsf.gdb.service; package org.eclipse.cdt.dsf.gdb.service;
@ -265,13 +266,15 @@ public class GDBProcesses_7_2 extends GDBProcesses_7_1 implements IMultiTerminat
@Override @Override
protected boolean doIsDebuggerAttachSupported() { protected boolean doIsDebuggerAttachSupported() {
SessionType sessionType = fBackend.getSessionType();
// Multi-process is not applicable to post-mortem sessions (core) // Multi-process is not applicable to post-mortem sessions (core)
// or to non-attach remote sessions. // or to non-attach remote sessions.
if (fBackend.getSessionType() == SessionType.CORE) { if (sessionType == SessionType.CORE) {
return false; return false;
} }
if (fBackend.getSessionType() == SessionType.REMOTE && !fBackend.getIsAttachSession()) { if (sessionType == SessionType.REMOTE && !fBackend.getIsAttachSession()) {
return false; return false;
} }
@ -279,9 +282,22 @@ public class GDBProcesses_7_2 extends GDBProcesses_7_1 implements IMultiTerminat
IMIRunControl runControl = getServicesTracker().getService(IMIRunControl.class); IMIRunControl runControl = getServicesTracker().getService(IMIRunControl.class);
if (runControl != null && runControl.getRunMode() == MIRunMode.ALL_STOP) { if (runControl != null && runControl.getRunMode() == MIRunMode.ALL_STOP) {
// Only one process is allowed in all-stop (for now) // Only one process is allowed in all-stop (for now)
return getNumConnected() == 0;
// NOTE: when we support multi-process in all-stop mode, // NOTE: when we support multi-process in all-stop mode,
// we will need to interrupt the target to when doing the attach. // we will need to interrupt the target to when doing the attach.
int numConnected = getNumConnected();
switch (sessionType) {
case REMOTE:
// In remote session already one process is connected
// Bug 528145
return numConnected == 1;
case LOCAL:
return numConnected == 0;
default:
break;
}
return false;
} }
return true; return true;
@ -315,32 +331,40 @@ public class GDBProcesses_7_2 extends GDBProcesses_7_1 implements IMultiTerminat
new Step() { new Step() {
@Override @Override
public void execute(final RequestMonitor rm) { public void execute(final RequestMonitor rm) {
getProcessesBeingDebugged(procCtx, new ImmediateDataRequestMonitor<IDMContext[]>(rm) { // The remote session is already connected to the process
@Override // Bug 528145
protected void handleSuccess() { if (fBackend.getSessionType() == SessionType.REMOTE) {
assert getData() != null; rm.done();
} else {
getProcessesBeingDebugged(procCtx,
new ImmediateDataRequestMonitor<IDMContext[]>(rm) {
@Override
protected void handleSuccess() {
assert getData() != null;
boolean found = false; boolean found = false;
for (IDMContext dmc : getData()) { for (IDMContext dmc : getData()) {
IProcessDMContext procDmc = DMContexts.getAncestorOfType(dmc, IProcessDMContext procDmc = DMContexts.getAncestorOfType(dmc,
IProcessDMContext.class); IProcessDMContext.class);
if (procCtx.equals(procDmc)) { if (procCtx.equals(procDmc)) {
found = true; found = true;
} }
} }
if (found) { if (found) {
// abort the sequence // abort the sequence
Status failedStatus = new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, Status failedStatus = new Status(IStatus.ERROR,
REQUEST_FAILED, GdbPlugin.PLUGIN_ID, REQUEST_FAILED,
MessageFormat.format(Messages.Already_connected_process_err, MessageFormat.format(
((IMIProcessDMContext) procCtx).getProcId()), Messages.Already_connected_process_err,
null); ((IMIProcessDMContext) procCtx).getProcId()),
rm.done(failedStatus); null);
return; rm.done(failedStatus);
} return;
super.handleSuccess(); }
} super.handleSuccess();
}); }
});
}
} }
}, },
@ -451,19 +475,26 @@ public class GDBProcesses_7_2 extends GDBProcesses_7_1 implements IMultiTerminat
new Step() { new Step() {
@Override @Override
public void execute(RequestMonitor rm) { public void execute(RequestMonitor rm) {
// For non-stop mode, we do a non-interrupting attach // This call end the current attach to the gdbserver in remote session
// Bug 333284 // Bug 528145
boolean shouldInterrupt = true; if (fBackend.getSessionType() == SessionType.REMOTE) {
IMIRunControl runControl = getServicesTracker().getService(IMIRunControl.class); rm.done();
if (runControl != null && runControl.getRunMode() == MIRunMode.NON_STOP) { } else {
shouldInterrupt = false; // For non-stop mode, we do a non-interrupting attach
} // Bug 333284
boolean shouldInterrupt = true;
IMIRunControl runControl = getServicesTracker().getService(IMIRunControl.class);
if (runControl != null && runControl.getRunMode() == MIRunMode.NON_STOP) {
shouldInterrupt = false;
}
boolean extraNewline = targetAttachRequiresTrailingNewline(); boolean extraNewline = targetAttachRequiresTrailingNewline();
ICommand<MIInfo> miTargetAttach = fCommandFactory.createMITargetAttach(fContainerDmc, ICommand<MIInfo> miTargetAttach = fCommandFactory.createMITargetAttach(
((IMIProcessDMContext) procCtx).getProcId(), shouldInterrupt, extraNewline); fContainerDmc, ((IMIProcessDMContext) procCtx).getProcId(), shouldInterrupt,
fCommandControl.queueCommand(miTargetAttach, extraNewline);
new ImmediateDataRequestMonitor<MIInfo>(rm)); fCommandControl.queueCommand(miTargetAttach,
new ImmediateDataRequestMonitor<MIInfo>(rm));
}
} }
}, },