1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Fix for 212632: Failure to debug-attach on Windows using GDB

and 224187: NPE launching debug configuration without app name
This commit is contained in:
Anton Leherbauer 2008-04-03 08:46:05 +00:00
parent 402016a6f0
commit f2bcb6cb77
2 changed files with 46 additions and 9 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 QNX Software Systems and others.
* Copyright (c) 2005, 2008 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
@ -9,6 +9,7 @@
* QNX Software Systems - initial API and implementation
* Andrew Ferguson (andrew.ferguson@arm.com) - bug 123997
* Ken Ryall (Nokia) - bug 178731
* Anton Leherbauer (Wind River Systems) - bug 224187
*******************************************************************************/
package org.eclipse.cdt.launch;
@ -153,9 +154,14 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat
* error code
*/
protected void abort(String message, Throwable exception, int code) throws CoreException {
MultiStatus status = new MultiStatus(getPluginID(), code, message, exception);
status.add(new Status(IStatus.ERROR, getPluginID(), code, exception == null ? "" : exception.getLocalizedMessage(), //$NON-NLS-1$
exception));
IStatus status;
if (exception != null) {
MultiStatus multiStatus = new MultiStatus(getPluginID(), code, message, exception);
multiStatus.add(new Status(IStatus.ERROR, getPluginID(), code, exception.getLocalizedMessage(), exception));
status= multiStatus;
} else {
status= new Status(IStatus.ERROR, getPluginID(), code, message, null);
}
throw new CoreException(status);
}
@ -190,7 +196,7 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat
public static IPath getProgramPath(ILaunchConfiguration configuration) throws CoreException {
String path = getProgramName(configuration);
if (path == null) {
if (path == null || path.trim().length() == 0) {
return null;
}
return new Path(path);
@ -364,7 +370,8 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat
ICProject cproject = verifyCProject(config);
IPath programPath = getProgramPath(config);
if (programPath == null || programPath.isEmpty()) {
return null;
abort(LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_not_specified"), null, //$NON-NLS-1$
ICDTLaunchConfigurationConstants.ERR_UNSPECIFIED_PROGRAM);
}
if (!programPath.isAbsolute()) {
IFile wsProgramPath = cproject.getProject().getFile(programPath);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 QNX Software Systems and others.
* Copyright (c) 2004, 2008 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
@ -7,7 +7,7 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Anton Leherbauer (Wind River Systems) - bug 205108
* Anton Leherbauer (Wind River Systems) - bugs 205108, 212632, 224187
*******************************************************************************/
package org.eclipse.cdt.launch.internal;
@ -16,6 +16,9 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IProcessInfo;
import org.eclipse.cdt.core.IProcessList;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.debug.core.CDIDebugModel;
@ -38,6 +41,7 @@ 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.DebugPlugin;
@ -196,7 +200,10 @@ public class LocalCDILaunchDelegate extends AbstractCLaunchDelegate {
}
cancel( "", -1 ); //$NON-NLS-1$
}
IPath exePath = verifyProgramPath( config );
IPath exePath = getProgramPath( config );
if (exePath == null) {
exePath= getProgramPathForPid(pid);
}
ICProject project = verifyCProject( config );
IBinaryObject exeFile = null;
if ( exePath != null ) {
@ -232,6 +239,29 @@ public class LocalCDILaunchDelegate extends AbstractCLaunchDelegate {
}
}
private IPath getProgramPathForPid(int pid) {
IProcessList processList= null;
try {
processList= CCorePlugin.getDefault().getProcessList();
} catch (CoreException exc) {
// ignored on purpose
}
if (processList != null) {
IProcessInfo[] pInfos= processList.getProcessList();
for (int i = 0; i < pInfos.length; i++) {
IProcessInfo processInfo = pInfos[i];
if (processInfo.getPid() == pid) {
final String name= processInfo.getName();
if (name != null) {
return new Path(name);
}
break;
}
}
}
return null;
}
private void launchCoreDebugSession( ILaunchConfiguration config, ILaunch launch, IProgressMonitor monitor ) throws CoreException {
if ( monitor.isCanceled() ) {
return;