From db2d46c7fc29147f840c7f5278cf8e74938504a2 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Sun, 3 Jul 2016 21:17:54 -0400 Subject: [PATCH] Bug 497206: Remote-attach fails attach if binary not specified in launch The core exception we used to throw when the program patch was not present is necessary for GDBBackend#getProgramPath() to set the path to an empty value instead of returning null. Although we could have made GdbLaunch#getProgramPath return and empty string to fix this problem, I thought we should play it safe and behave like we used to in case something else needed that exception thrown. Change-Id: I4684226c731aedef50bdeb37accdf2a2feb818b5 --- .../cdt/dsf/gdb/launching/GdbLaunch.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java index 71ba42f4eeb..113ce91ee30 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java @@ -15,6 +15,7 @@ package org.eclipse.cdt.dsf.gdb.launching; import java.io.BufferedReader; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -808,12 +809,14 @@ public class GdbLaunch extends DsfLaunch implements ITerminate, IDisconnect, ITr (String) null); } if (programName == null) { - return null; + throwException(LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_not_specified"), null, //$NON-NLS-1$ + ICDTLaunchConfigurationConstants.ERR_UNSPECIFIED_PROGRAM); } programName = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(programName); IPath programPath = new Path(programName); if (programPath.isEmpty()) { - return null; + throwException(LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_does_not_exist"), null, //$NON-NLS-1$ + ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST); } if (!programPath.isAbsolute()) { @@ -826,12 +829,36 @@ public class GdbLaunch extends DsfLaunch implements ITerminate, IDisconnect, ITr } } if (!programPath.toFile().exists()) { - return null; + throwException(LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_does_not_exist"), //$NON-NLS-1$ + new FileNotFoundException( + LaunchMessages.getFormattedString("AbstractCLaunchDelegate.PROGRAM_PATH_not_found", //$NON-NLS-1$ + programPath.toOSString())), + ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST); } return programPath.toOSString(); } + /** + * Throws a core exception with an error status object built from the given + * message, lower level exception, and error code. + * + * @param message + * the status message + * @param exception + * lower level exception associated with the error, or + * null if none + * @param code + * error code + */ + private static void throwException(String message, Throwable exception, int code) throws CoreException { + MultiStatus status = new MultiStatus(GdbPlugin.PLUGIN_ID, code, message, exception); + status.add(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, code, + exception == null ? "" : exception.getLocalizedMessage(), //$NON-NLS-1$ + exception)); + throw new CoreException(status); + } + /** * Sets the program path *