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 ac20bb396cc..6b7ec3b6129 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2015 TUBITAK BILGEM-ITI and others. + * Copyright (c) 2010, 2016 TUBITAK BILGEM-ITI and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -60,6 +60,8 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.ILaunch; +import com.ibm.icu.text.MessageFormat; + /** * Adding support for multi-process with GDB 7.2 * @@ -253,18 +255,52 @@ public class GDBProcesses_7_2 extends GDBProcesses_7_1 implements IMultiTerminat @Override public void attachDebuggerToProcess(final IProcessDMContext procCtx, final String binaryPath, final DataRequestMonitor dataRm) { if (procCtx instanceof IMIProcessDMContext) { - if (!doIsDebuggerAttachSupported()) { - dataRm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Attach not supported.", null)); //$NON-NLS-1$ - dataRm.done(); - return; - } - + if (!doIsDebuggerAttachSupported()) { + dataRm.setStatus( + new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Attach not supported.", null)); //$NON-NLS-1$ + dataRm.done(); + return; + } + // Use a sequence for better control of each step ImmediateExecutor.getInstance().execute(new Sequence(getExecutor(), dataRm) { private IMIContainerDMContext fContainerDmc; private Step[] steps = new Step[] { - // If this is not the very first inferior, we first need create the new inferior + // first check if requested process is already targetted + new Step() { + @Override + public void execute(final RequestMonitor rm) { + 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(); + } + }); + } + }, + + // If this is not the very first inferior, we first need create the new inferior new Step() { @Override public void execute(final RequestMonitor rm) { diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/Messages.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/Messages.java index 35d0b5f88bd..da5bc459d7a 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/Messages.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/Messages.java @@ -18,6 +18,7 @@ import org.eclipse.osgi.util.NLS; * @since 4.1 */ class Messages extends NLS { + public static String Already_connected_process_err; public static String Tracing_not_supported_error; public static String Invalid_post_mortem_type_error; public static String Cannot_get_post_mortem_file_path_error; diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/Messages.properties b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/Messages.properties index 01d2a5156bc..dd6e0eff46e 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/Messages.properties +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/Messages.properties @@ -10,6 +10,7 @@ # Alvaro Sanchez-Leon (Ericsson) - Support Register Groups (Bug 235747) ############################################################################### +Already_connected_process_err=Already connected to process {0} Tracing_not_supported_error=Tracing not supported Invalid_post_mortem_type_error=Invalid post-mortem type Cannot_get_post_mortem_file_path_error=Cannot get post mortem file path