diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java index 4b2de740547..7e893792d34 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java @@ -270,11 +270,20 @@ public class GdbConnectCommand extends RefreshableDebugCommand implements IConne } @Override - protected void doExecute(Object[] targets, IProgressMonitor monitor, IRequest request) throws CoreException { + protected void doExecute(Object[] targets, IProgressMonitor monitor, final IRequest request) throws CoreException { Query connectQuery = new Query() { @Override - public void execute(DataRequestMonitor rm) { - connect(rm); + public void execute(final DataRequestMonitor rm) { + connect(new RequestMonitor(fExecutor, rm) { + @Override + protected void handleCompleted() { + // pass any error to the caller + if (!isSuccess()) { + request.setStatus(getStatus()); + } + rm.done(); + } + }); } }; try { @@ -539,6 +548,7 @@ public class GdbConnectCommand extends RefreshableDebugCommand implements IConne // so we don't need to prompt for it. final IGDBProcesses procService = fTracker.getService(IGDBProcesses.class); final IGDBBackend backend = fTracker.getService(IGDBBackend.class); + final StringBuilder errors = new StringBuilder(); if (procService != null && backend != null) { // Attach to each process in a sequential fashion. We must do this @@ -548,6 +558,9 @@ public class GdbConnectCommand extends RefreshableDebugCommand implements IConne // Create a list of all our processes so we can attach to one at a time. // We need to create a new list so that we can remove elements from it. final List procList = new ArrayList(Arrays.asList(processes)); + // Create a one element array to remember what process we are trying to attach to, so that we can + // use it in case of error. + final IProcessExtendedInfo[] previousProcAttempt = new IProcessExtendedInfo[1]; class AttachToProcessRequestMonitor extends ImmediateDataRequestMonitor { public AttachToProcessRequestMonitor() { @@ -556,8 +569,9 @@ public class GdbConnectCommand extends RefreshableDebugCommand implements IConne @Override protected void handleCompleted() { + // Failed to attach to a process. Remember the error message. if (!isSuccess()) { - // Failed to attach to a process. Just ignore it and move on. + formatErrorMessage(errors, previousProcAttempt[0], getStatus().getMessage()); } // Check that we have a process to attach to @@ -574,6 +588,8 @@ public class GdbConnectCommand extends RefreshableDebugCommand implements IConne // Remove process from list and attach to it. IProcessExtendedInfo process = procList.remove(0); + // Store process in case of error + previousProcAttempt[0] = process; String pidStr = Integer.toString(process.getPid()); if (backend.getSessionType() == SessionType.REMOTE) { @@ -614,6 +630,10 @@ public class GdbConnectCommand extends RefreshableDebugCommand implements IConne } }); } else { + // If there were errors, pass them-on to the caller + if (errors.length() != 0) { + rm.setStatus(new Status(IStatus.ERROR, GdbUIPlugin.PLUGIN_ID, errors.toString())); + } // No other process to attach to rm.done(); } @@ -642,6 +662,29 @@ public class GdbConnectCommand extends RefreshableDebugCommand implements IConne protected boolean isRemainEnabled(IDebugCommandRequest request) { return false; } + + private void formatErrorMessage(StringBuilder errors, IProcessExtendedInfo process, String errorMsg) { + // Extract process name from full path. + // On windows host, paths of style "sendmail:", "udisk-daemon:" + // is treated as device id with no path segments + String name; + IPath path = new Path(process.getName()); + if (path.lastSegment() == null) { + name = process.getName(); + } else { + name = path.lastSegment(); + } + + if (errors.length() != 0) { + errors.append(System.lineSeparator()).append(System.lineSeparator()); + } + + errors.append(Messages.GdbConnectCommand_FailureMessage).append(" ") //$NON-NLS-1$ + .append(name).append(" [").append(process.getPid()).append("]") //$NON-NLS-1$ //$NON-NLS-2$ + .append(System.lineSeparator()) + .append(Messages.GdbConnectCommand_Error) + .append(System.lineSeparator()) + .append(errorMsg); + } } - diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.java index c7ea5a69b95..c42aeb84794 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.java @@ -51,6 +51,10 @@ public class Messages extends NLS { public static String GdbReverseDebugging_HardwareTracingNotAvailable; + public static String GdbConnectCommand_Error; + + public static String GdbConnectCommand_FailureMessage; + static { // initialize resource bundle NLS.initializeMessages( Messages.class.getName(), Messages.class ); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.properties b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.properties index a2b6225455b..8e5863a32da 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.properties +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.properties @@ -28,3 +28,6 @@ GdbDebugNewExecutableCommand_Select_Binary=Select Binary GdbDebugNewExecutableCommand_Select_binary_and_specify_arguments=Select a binary and specify the arguments GdbReverseDebugging_HardwareTracingNotAvailable=Hardware Tracing Method not available, Reverse debugging is switched Off, please select another method + +GdbConnectCommand_FailureMessage=Failure to attach to process: +GdbConnectCommand_Error=Error: \ No newline at end of file