From 5226c0b13aa62a92d74459b6f5b4c3e91a281674 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Wed, 25 May 2011 19:07:11 +0000 Subject: [PATCH] Bug 347163: Canceling a remote attach causes a bad debug session --- .../ui/actions/GdbConnectCommand.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/actions/GdbConnectCommand.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/actions/GdbConnectCommand.java index c6282f4dbcb..60c921422dd 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/actions/GdbConnectCommand.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/actions/GdbConnectCommand.java @@ -167,16 +167,26 @@ public class GdbConnectCommand implements IConnect { binaryPath = fd.open(); } - final String finalBinaryPath = binaryPath; - fExecutor.execute(new DsfRunnable() { - public void run() { - IGDBProcesses procService = fTracker.getService(IGDBProcesses.class); - ICommandControlService commandControl = fTracker.getService(ICommandControlService.class); + if (binaryPath == null) { + // The user pressed the cancel button, so we cancel the attach gracefully + fRm.done(); + } else { + final String finalBinaryPath = binaryPath; + fExecutor.execute(new DsfRunnable() { + public void run() { + IGDBProcesses procService = fTracker.getService(IGDBProcesses.class); + ICommandControlService commandControl = fTracker.getService(ICommandControlService.class); - IProcessDMContext procDmc = procService.createProcessContext(commandControl.getContext(), fPid); - procService.attachDebuggerToProcess(procDmc, finalBinaryPath, new DataRequestMonitor(fExecutor, fRm)); - } - }); + if (procService != null && commandControl != null) { + IProcessDMContext procDmc = procService.createProcessContext(commandControl.getContext(), fPid); + procService.attachDebuggerToProcess(procDmc, finalBinaryPath, new DataRequestMonitor(fExecutor, fRm)); + } else { + fRm.setStatus(new Status(IStatus.ERROR, GdbUIPlugin.PLUGIN_ID, IDsfStatusConstants.INTERNAL_ERROR, "Cannot find services", null)); //$NON-NLS-1$ + fRm.done(); + } + } + }); + } return Status.OK_STATUS; }