From 96839a029d7de3016bd63787a55b1095d7806d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B6rn=20Svensson?= Date: Thu, 30 Jun 2022 10:30:12 +0200 Subject: [PATCH] Bug 580259: Not all remote session have a connected process MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Contributed by STMicroelectronics Change-Id: Idec88f4bf0cbc8326bf19b9f081af9f9f9d437e2 Signed-off-by: Torbjörn Svensson --- .../gdb/launching/FinalLaunchSequence.java | 17 ++- .../cdt/dsf/gdb/service/GDBProcesses_7_2.java | 107 +++++++++--------- 2 files changed, 62 insertions(+), 62 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java index c491ff4f6c3..cf07edf79bd 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java @@ -660,13 +660,18 @@ public class FinalLaunchSequence extends ReflectionSequence { @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(getExecutor(), requestMonitor)); - } else { - requestMonitor.done(); + DataRequestMonitor rm = new DataRequestMonitor<>(getExecutor(), null); + fProcService.canDetachDebuggerFromProcess(null, rm); + + if (rm.getData()) { + IProcessDMContext processContext = fProcService.createProcessContext(fCommandControl.getContext(), + MIProcesses.UNKNOWN_PROCESS_ID); + fProcService.attachDebuggerToProcess(processContext, + new DataRequestMonitor(getExecutor(), requestMonitor)); + return; + } } + requestMonitor.done(); } /** diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_2.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_2.java index b3c471c04c4..136116a6ed5 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_2.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_2.java @@ -285,19 +285,13 @@ public class GDBProcesses_7_2 extends GDBProcesses_7_1 implements IMultiTerminat // NOTE: when we support multi-process in all-stop mode, // 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; + if (numConnected == 1 && sessionType == SessionType.REMOTE) { + // Bug 528145: Special case for remote sessions with an existing connection. + return true; } - return false; + return numConnected == 0; } return true; @@ -333,38 +327,38 @@ public class GDBProcesses_7_2 extends GDBProcesses_7_1 implements IMultiTerminat public void execute(final RequestMonitor rm) { // The remote session is already connected to the process // Bug 528145 - if (fBackend.getSessionType() == SessionType.REMOTE) { + if (fBackend.getSessionType() == SessionType.REMOTE + && doCanDetachDebuggerFromProcess()) { rm.done(); - } else { - getProcessesBeingDebugged(procCtx, - new ImmediateDataRequestMonitor(rm) { - @Override - protected void handleSuccess() { - assert getData() != null; - - boolean found = false; - for (IDMContext dmc : getData()) { - IProcessDMContext procDmc = DMContexts.getAncestorOfType(dmc, - IProcessDMContext.class); - if (procCtx.equals(procDmc)) { - found = true; - } - } - if (found) { - // abort the sequence - Status failedStatus = new Status(IStatus.ERROR, - GdbPlugin.PLUGIN_ID, REQUEST_FAILED, - MessageFormat.format( - Messages.Already_connected_process_err, - ((IMIProcessDMContext) procCtx).getProcId()), - null); - rm.done(failedStatus); - return; - } - super.handleSuccess(); - } - }); + return; } + + getProcessesBeingDebugged(procCtx, new ImmediateDataRequestMonitor(rm) { + @Override + protected void handleSuccess() { + assert getData() != null; + + boolean found = false; + for (IDMContext dmc : getData()) { + IProcessDMContext procDmc = DMContexts.getAncestorOfType(dmc, + IProcessDMContext.class); + if (procCtx.equals(procDmc)) { + found = true; + } + } + if (found) { + // abort the sequence + Status failedStatus = new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, + REQUEST_FAILED, + MessageFormat.format(Messages.Already_connected_process_err, + ((IMIProcessDMContext) procCtx).getProcId()), + null); + rm.done(failedStatus); + return; + } + super.handleSuccess(); + } + }); } }, @@ -477,24 +471,25 @@ public class GDBProcesses_7_2 extends GDBProcesses_7_1 implements IMultiTerminat public void execute(RequestMonitor rm) { // This call end the current attach to the gdbserver in remote session // Bug 528145 - if (fBackend.getSessionType() == SessionType.REMOTE) { + if (fBackend.getSessionType() == SessionType.REMOTE + && doCanDetachDebuggerFromProcess()) { rm.done(); - } else { - // 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(); - ICommand miTargetAttach = fCommandFactory.createMITargetAttach( - fContainerDmc, ((IMIProcessDMContext) procCtx).getProcId(), shouldInterrupt, - extraNewline); - fCommandControl.queueCommand(miTargetAttach, - new ImmediateDataRequestMonitor(rm)); + return; } + + // 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(); + ICommand miTargetAttach = fCommandFactory.createMITargetAttach(fContainerDmc, + ((IMIProcessDMContext) procCtx).getProcId(), shouldInterrupt, extraNewline); + fCommandControl.queueCommand(miTargetAttach, + new ImmediateDataRequestMonitor(rm)); } },