From 4239136a9514f154d94782c53d71980ffbe46acb Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Tue, 26 Apr 2011 19:29:56 +0000 Subject: [PATCH] Bug 343861: Project should not be required to perform debugging --- .../launching/RemoteGdbLaunchDelegate.java | 2 +- .../launch/remote/tabs/RemoteCDSFMainTab.java | 3 +- .../gdb/internal/ui/launching/CMainTab.java | 47 ++++++++++--------- .../dsf/gdb/launching/GdbLaunchDelegate.java | 13 ++--- .../cdt/dsf/gdb/launching/LaunchUtils.java | 21 +++++---- .../dsf/gdb/launching/TestLaunchDelegate.java | 10 ++-- 6 files changed, 49 insertions(+), 47 deletions(-) diff --git a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteGdbLaunchDelegate.java b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteGdbLaunchDelegate.java index 85e8afb71ee..029b478fc71 100644 --- a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteGdbLaunchDelegate.java +++ b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteGdbLaunchDelegate.java @@ -48,7 +48,7 @@ public class RemoteGdbLaunchDelegate extends GdbLaunchDelegate { } } - IPath exePath = CDebugUtils.verifyProgramPath(config); + IPath exePath = checkBinaryDetails(config); if (exePath != null) { // 1.Download binary if needed String remoteExePath = config.getAttribute( diff --git a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/tabs/RemoteCDSFMainTab.java b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/tabs/RemoteCDSFMainTab.java index 1d26b14eb6d..98ddacd1654 100644 --- a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/tabs/RemoteCDSFMainTab.java +++ b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/tabs/RemoteCDSFMainTab.java @@ -22,6 +22,7 @@ *******************************************************************************/ package org.eclipse.cdt.launch.remote.tabs; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.dsf.gdb.internal.ui.launching.CMainTab; import org.eclipse.cdt.internal.launch.remote.Messages; import org.eclipse.cdt.launch.remote.IRemoteConnectionConfigurationConstants; @@ -506,9 +507,9 @@ public class RemoteCDSFMainTab extends CMainTab { } if (programName.length() != 0 && bUpdateRemote) { - IProject project = getCProject().getProject(); IPath exePath = new Path(programName); if (!exePath.isAbsolute()) { + IProject project = getCProject().getProject(); exePath = project.getFile(programName).getLocation(); IPath wsRoot = project.getWorkspace().getRoot().getLocation(); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/CMainTab.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/CMainTab.java index f268e9c1942..cc979aa15f4 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/CMainTab.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/CMainTab.java @@ -432,39 +432,40 @@ public class CMainTab extends CAbstractMainTab { setMessage(null); if (!fDontCheckProgram) { - String name = fProjText.getText().trim(); - if (name.length() == 0) { - setErrorMessage(LaunchMessages.getString("CMainTab.Project_not_specified")); //$NON-NLS-1$ - return false; - } - if (!ResourcesPlugin.getWorkspace().getRoot().getProject(name).exists()) { - setErrorMessage(LaunchMessages.getString("Launch.common.Project_does_not_exist")); //$NON-NLS-1$ - return false; - } - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); - if (!project.isOpen()) { - setErrorMessage(LaunchMessages.getString("CMainTab.Project_must_be_opened")); //$NON-NLS-1$ - return false; - } - - name = fProgText.getText().trim(); - if (name.length() == 0) { + String programName = fProgText.getText().trim(); + if (programName.length() == 0) { setErrorMessage(LaunchMessages.getString("CMainTab.Program_not_specified")); //$NON-NLS-1$ return false; } - if (name.equals(".") || name.equals("..")) { //$NON-NLS-1$ //$NON-NLS-2$ + if (programName.equals(".") || programName.equals("..")) { //$NON-NLS-1$ //$NON-NLS-2$ setErrorMessage(LaunchMessages.getString("CMainTab.Program_does_not_exist")); //$NON-NLS-1$ return false; } - IPath exePath = new Path(name); - if (!exePath.isAbsolute()) { - if (!project.getFile(name).exists()) { + IPath exePath = new Path(programName); + if (exePath.isAbsolute()) { + // For absolute paths, we don't need a project, we can debug the binary directly + // as long as it exists + if (!exePath.toFile().exists()) { setErrorMessage(LaunchMessages.getString("CMainTab.Program_does_not_exist")); //$NON-NLS-1$ return false; } - exePath = project.getFile(name).getLocation(); } else { - if (!exePath.toFile().exists()) { + // For relative paths, we need a proper project + String projectName = fProjText.getText().trim(); + if (projectName.length() == 0) { + setErrorMessage(LaunchMessages.getString("CMainTab.Project_not_specified")); //$NON-NLS-1$ + return false; + } + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + if (!project.exists()) { + setErrorMessage(LaunchMessages.getString("Launch.common.Project_does_not_exist")); //$NON-NLS-1$ + return false; + } + if (!project.isOpen()) { + setErrorMessage(LaunchMessages.getString("CMainTab.Project_must_be_opened")); //$NON-NLS-1$ + return false; + } + if (!project.getFile(programName).exists()) { setErrorMessage(LaunchMessages.getString("CMainTab.Program_does_not_exist")); //$NON-NLS-1$ return false; } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunchDelegate.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunchDelegate.java index 9b36e8862ae..8ba3c9a68e3 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunchDelegate.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunchDelegate.java @@ -39,7 +39,6 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.debug.core.DebugException; @@ -64,7 +63,9 @@ public class GdbLaunchDelegate extends AbstractCLaunchDelegate2 private boolean fIsPostMortemTracingSession; public GdbLaunchDelegate() { - super(); + // We now fully support project-less debugging + // See bug 343861 + this(false); } /** @@ -118,7 +119,6 @@ public class GdbLaunchDelegate extends AbstractCLaunchDelegate2 monitor.subTask( LaunchMessages.getString("GdbLaunchDelegate.3") ); //$NON-NLS-1$ } - IPath exePath = new Path(""); //$NON-NLS-1$ // An attach session does not need to necessarily have an // executable specified. This is because: // - In remote multi-process attach, there will be more than one executable @@ -127,13 +127,8 @@ public class GdbLaunchDelegate extends AbstractCLaunchDelegate2 // the path of any executable we can attach to. // - In local single process, GDB has the ability to find the executable // automatically. - // - // An attach session also does not need to necessarily have a project - // specified. This is because we can perform source lookup towards - // code that is outside the workspace. - // See bug 244567 if (!attach) { - exePath = checkBinaryDetails(config); + checkBinaryDetails(config); } monitor.worked( 1 ); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/LaunchUtils.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/LaunchUtils.java index a422b589825..88c10f4cfb0 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/LaunchUtils.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/LaunchUtils.java @@ -138,16 +138,19 @@ public class LaunchUtils { * @return An object representing the binary file. */ public static IBinaryObject verifyBinary(ILaunchConfiguration configuration, IPath exePath) throws CoreException { - ICConfigExtensionReference[] parserRefs = CCorePlugin.getDefault().getDefaultBinaryParserExtensions(getCProject(configuration).getProject()); - for (ICConfigExtensionReference parserRef : parserRefs) { - try { - IBinaryParser parser = CoreModelUtil.getBinaryParser(parserRef); - IBinaryObject exe = (IBinaryObject)parser.getBinary(exePath); - if (exe != null) { - return exe; + ICProject cproject = getCProject(configuration); + if (cproject != null) { + ICConfigExtensionReference[] parserRefs = CCorePlugin.getDefault().getDefaultBinaryParserExtensions(cproject.getProject()); + for (ICConfigExtensionReference parserRef : parserRefs) { + try { + IBinaryParser parser = CoreModelUtil.getBinaryParser(parserRef); + IBinaryObject exe = (IBinaryObject)parser.getBinary(exePath); + if (exe != null) { + return exe; + } + } catch (ClassCastException e) { + } catch (IOException e) { } - } catch (ClassCastException e) { - } catch (IOException e) { } } diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/launching/TestLaunchDelegate.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/launching/TestLaunchDelegate.java index 7055bafc703..9e282f2f380 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/launching/TestLaunchDelegate.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/launching/TestLaunchDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 QNX Software Systems and others. + * Copyright (c) 2004, 2011 QNX Software Systems 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 @@ -10,14 +10,12 @@ *******************************************************************************/ package org.eclipse.cdt.tests.dsf.gdb.launching; -import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.dsf.concurrent.ThreadSafe; import org.eclipse.cdt.dsf.gdb.launching.GdbLaunchDelegate; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; import org.eclipse.debug.core.ILaunchConfiguration; /** @@ -55,7 +53,11 @@ public class TestLaunchDelegate extends GdbLaunchDelegate @Override protected IPath checkBinaryDetails(ILaunchConfiguration config) throws CoreException { - return new Path(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, "")); + // Now that GdbLaunchDelegate supports project-less debugging, we don't need to + // override this method. In fact, we should not override it so that we test + // that project-less debugging keeps on working. + // See bug 343861 + return super.checkBinaryDetails(config); } } \ No newline at end of file