cdt/cdt_6_0_x/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunchDelegate.java
author timkelly
Tue, 15 Sep 2009 10:25:52 -0500
changeset 96 defec9d2b40a
parent 37 c2bce6dd59e7
permissions -rw-r--r--
refactor to use AbstractCLaunchDelegate (bug 9762)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     1
/*******************************************************************************
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     2
 * Copyright (c) 2008  QNX Software Systems and others.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     3
 * All rights reserved. This program and the accompanying materials
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     4
 * are made available under the terms of the Eclipse Public License v1.0
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     5
 * which accompanies this distribution, and is available at
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     6
 * http://www.eclipse.org/legal/epl-v10.html
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     7
 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     8
 * Contributors:
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     9
 * QNX Software Systems   - Initial API and implementation
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    10
 * Windriver and Ericsson - Updated for DSF
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    11
 *******************************************************************************/
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    12
package org.eclipse.cdt.dsf.gdb.launching; 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    13
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    14
import java.util.ArrayList;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    15
import java.util.HashSet;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    16
import java.util.concurrent.ExecutionException;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    17
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    18
import org.eclipse.cdt.core.model.ICModelMarker;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    19
import org.eclipse.cdt.core.model.ICProject;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    20
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    21
import org.eclipse.cdt.dsf.concurrent.DsfExecutor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    22
import org.eclipse.cdt.dsf.concurrent.Query;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    23
import org.eclipse.cdt.dsf.concurrent.Sequence;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    24
import org.eclipse.cdt.dsf.concurrent.ThreadSafe;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    25
import org.eclipse.cdt.dsf.debug.service.IDsfDebugServicesFactory;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    26
import org.eclipse.cdt.dsf.debug.sourcelookup.DsfSourceLookupDirector;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    27
import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    28
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    29
import org.eclipse.cdt.dsf.gdb.service.GdbDebugServicesFactory;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    30
import org.eclipse.cdt.dsf.gdb.service.GdbDebugServicesFactoryNS;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    31
import org.eclipse.cdt.dsf.gdb.service.SessionType;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    32
import org.eclipse.cdt.dsf.service.DsfSession;
96
defec9d2b40a refactor to use AbstractCLaunchDelegate (bug 9762)
timkelly
parents: 37
diff changeset
    33
import org.eclipse.cdt.launch.AbstractCLaunchDelegate;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    34
import org.eclipse.core.resources.IMarker;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    35
import org.eclipse.core.resources.IProject;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    36
import org.eclipse.core.resources.IResource;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    37
import org.eclipse.core.resources.ResourcesPlugin;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    38
import org.eclipse.core.runtime.CoreException;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    39
import org.eclipse.core.runtime.IPath;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    40
import org.eclipse.core.runtime.IProgressMonitor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    41
import org.eclipse.core.runtime.IStatus;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    42
import org.eclipse.core.runtime.NullProgressMonitor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    43
import org.eclipse.core.runtime.Path;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    44
import org.eclipse.core.runtime.Status;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    45
import org.eclipse.core.runtime.SubProgressMonitor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    46
import org.eclipse.debug.core.DebugException;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    47
import org.eclipse.debug.core.ILaunch;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    48
import org.eclipse.debug.core.ILaunchConfiguration;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    49
import org.eclipse.debug.core.ILaunchManager;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    50
import org.eclipse.debug.core.model.ISourceLocator;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    51
 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    52
/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    53
 * The shared launch configuration delegate for the DSF/GDB debugger.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    54
 * This delegate supports all configuration types (local, remote, attach, etc)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    55
 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    56
@ThreadSafe
96
defec9d2b40a refactor to use AbstractCLaunchDelegate (bug 9762)
timkelly
parents: 37
diff changeset
    57
public class GdbLaunchDelegate extends AbstractCLaunchDelegate
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    58
{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    59
    public final static String GDB_DEBUG_MODEL_ID = "org.eclipse.cdt.dsf.gdb"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    60
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    61
    private final static String NON_STOP_FIRST_VERSION = "6.8.50"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    62
	private boolean isNonStopSession = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    63
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    64
	public void launch( ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor ) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    65
		if ( monitor == null ) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    66
			monitor = new NullProgressMonitor();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    67
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    68
		if ( mode.equals( ILaunchManager.DEBUG_MODE ) ) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    69
			launchDebugger( config, launch, monitor );
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    70
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    71
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    72
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    73
	private void launchDebugger( ILaunchConfiguration config, ILaunch launch, IProgressMonitor monitor ) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    74
		monitor.beginTask("Launching debugger session", 10); 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    75
		if ( monitor.isCanceled() ) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    76
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    77
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    78
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    79
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    80
    		launchDebugSession( config, launch, monitor );
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    81
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    82
		finally {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    83
			monitor.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    84
		}		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    85
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    86
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    87
	private void launchDebugSession( final ILaunchConfiguration config, ILaunch l, IProgressMonitor monitor ) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    88
		if ( monitor.isCanceled() ) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    89
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    90
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    91
		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    92
		SessionType sessionType = LaunchUtils.getSessionType(config);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    93
		boolean attach = LaunchUtils.getIsAttach(config);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    94
		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    95
        final GdbLaunch launch = (GdbLaunch)l;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    96
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    97
        if (sessionType == SessionType.REMOTE) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    98
            monitor.subTask( "Debugging remote C/C++ application" );     	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    99
        } else if (sessionType == SessionType.CORE) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   100
            monitor.subTask( "Post Mortem Debugging of C/C++ application" ); 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   101
        } else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   102
            monitor.subTask( "Debugging local C/C++ application" ); 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   103
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   104
        
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   105
        IPath exePath = new Path(""); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   106
        // An attach session does not need to necessarily have an
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   107
        // executable specified.  This is because:
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   108
        // - In remote multi-process attach, there will be more than one executable
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   109
        //   In this case executables need to be specified differently.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   110
        //   The current solution is to use the solib-search-path to specify
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   111
        //   the path of any executable we can attach to.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   112
        // - In local single process, GDB has the ability to find the executable
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   113
        //   automatically.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   114
        //
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   115
        // An attach session also does not need to necessarily have a project
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   116
        // specified.  This is because we can perform source lookup towards
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   117
        // code that is outside the workspace.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   118
        // See bug 244567
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   119
        if (!attach) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   120
        	// First verify we are dealing with a proper project.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   121
        	ICProject project = LaunchUtils.verifyCProject(config);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   122
        	// Now verify we know the program to debug.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   123
        	exePath = LaunchUtils.verifyProgramPath(config, project);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   124
        	// Finally, make sure the program is a proper binary.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   125
        	LaunchUtils.verifyBinary(config, exePath);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   126
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   127
    	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   128
        monitor.worked( 1 );
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   129
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   130
        String gdbVersion = getGDBVersion(config);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   131
        
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   132
        // First make sure non-stop is supported, if the user want to use this mode
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   133
        if (isNonStopSession && !isNonStopSupported(gdbVersion)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   134
            throw new DebugException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Non-stop mode is only supported starting with GDB " + NON_STOP_FIRST_VERSION, null)); //$NON-NLS-1$        	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   135
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   136
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   137
        launch.setServiceFactory(newServiceFactory(gdbVersion));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   138
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   139
        // Create and invoke the launch sequence to create the debug control and services
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   140
        IProgressMonitor subMon1 = new SubProgressMonitor(monitor, 4, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK); 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   141
        final ServicesLaunchSequence servicesLaunchSequence = 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   142
            new ServicesLaunchSequence(launch.getSession(), launch, subMon1);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   143
        
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   144
        launch.getSession().getExecutor().execute(servicesLaunchSequence);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   145
        try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   146
            servicesLaunchSequence.get();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   147
        } catch (InterruptedException e1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   148
            throw new DebugException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.INTERNAL_ERROR, "Interrupted Exception in dispatch thread", e1)); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   149
        } catch (ExecutionException e1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   150
            throw new DebugException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Error in services launch sequence", e1.getCause())); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   151
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   152
        
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   153
        if (monitor.isCanceled())
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   154
        	return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   155
        
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   156
        // The initializeControl method should be called after the ICommandControlService
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   157
        // be initialized in the ServicesLaunchSequence above.  This is because it is that
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   158
        // service that will trigger the launch cleanup (if we need it during this launch)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   159
        // through an ICommandControlShutdownDMEvent
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   160
        launch.initializeControl();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   161
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   162
        // Add the CLI and "inferior" process objects to the launch.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   163
        launch.addCLIProcess("gdb"); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   164
        if (!attach && sessionType != SessionType.CORE) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   165
        	launch.addInferiorProcess(exePath.lastSegment());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   166
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   167
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   168
        monitor.worked(1);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   169
        
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   170
        // Create and invoke the final launch sequence to setup GDB
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   171
        IProgressMonitor subMon2 = new SubProgressMonitor(monitor, 4, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK); 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   172
        final Sequence finalLaunchSequence = 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   173
        	getFinalLaunchSequence(launch.getSession().getExecutor(), launch, sessionType, attach, subMon2);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   174
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   175
        launch.getSession().getExecutor().execute(finalLaunchSequence);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   176
        boolean succeed = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   177
        try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   178
        	finalLaunchSequence.get();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   179
        	succeed = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   180
        } catch (InterruptedException e1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   181
            throw new DebugException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.INTERNAL_ERROR, "Interrupted Exception in dispatch thread", e1)); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   182
        } catch (ExecutionException e1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   183
            throw new DebugException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Error in final launch sequence", e1.getCause())); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   184
        } finally {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   185
            if (!succeed) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   186
                // finalLaunchSequence failed. Shutdown the session so that all started
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   187
                // services including any GDB process are shutdown. (bug 251486)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   188
                //
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   189
                Query<Object> launchShutdownQuery = new Query<Object>() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   190
                    @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   191
                    protected void execute(DataRequestMonitor<Object> rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   192
                        launch.shutdownSession(rm);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   193
                    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   194
                };
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   195
                    
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   196
                launch.getSession().getExecutor().execute(launchShutdownQuery);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   197
                
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   198
                // wait for the shutdown to finish.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   199
                // The Query.get() method is a synchronous call which blocks until the 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   200
                // query completes.  
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   201
                try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   202
                    launchShutdownQuery.get();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   203
                } catch (InterruptedException e) { 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   204
                    throw new DebugException( new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.INTERNAL_ERROR, "InterruptedException while shutting down debugger launch " + launch, e)); //$NON-NLS-1$ 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   205
                } catch (ExecutionException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   206
                    throw new DebugException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Error in shutting down debugger launch " + launch, e)); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   207
                }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   208
            }        
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   209
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   210
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   211
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   212
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   213
	 * Returns the GDB version. 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   214
	 * Subclass can override for special need.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   215
     *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   216
	 * @since 2.0
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   217
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   218
	protected String getGDBVersion(ILaunchConfiguration config) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   219
		return LaunchUtils.getGDBVersion(config);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   220
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   221
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   222
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   223
	 * This method can be overridden by subclasses to allow to change the final launch sequence without
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   224
	 * having to change the entire GdbLaunchDelegate
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   225
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   226
	protected Sequence getFinalLaunchSequence(DsfExecutor executor, GdbLaunch launch, SessionType type, boolean attach, IProgressMonitor pm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   227
		return new FinalLaunchSequence(executor, launch, type, attach, pm);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   228
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   229
	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   230
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   231
	private boolean isNonStopSession(ILaunchConfiguration config) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   232
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   233
			boolean nonStopMode = config.getAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_NON_STOP,
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   234
                    IGDBLaunchConfigurationConstants.DEBUGGER_NON_STOP_DEFAULT);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   235
    		return nonStopMode;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   236
    	} catch (CoreException e) {    		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   237
    	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   238
    	return false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   239
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   240
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   241
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   242
	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   243
    public boolean preLaunchCheck(ILaunchConfiguration config, String mode, IProgressMonitor monitor) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   244
		// no pre launch check for core file
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   245
		if (mode.equals(ILaunchManager.DEBUG_MODE) && LaunchUtils.getSessionType(config) == SessionType.CORE) return true; 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   246
		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   247
		return super.preLaunchCheck(config, mode, monitor);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   248
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   249
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   250
    @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   251
    public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   252
        // Need to configure the source locator before creating the launch
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   253
        // because once the launch is created and added to launch manager, 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   254
        // the adapters will be created for the whole session, including 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   255
        // the source lookup adapter.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   256
        
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   257
		isNonStopSession = isNonStopSession(configuration);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   258
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   259
        GdbLaunch launch = new GdbLaunch(configuration, mode, null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   260
        launch.initialize();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   261
        launch.setSourceLocator(getSourceLocator(configuration, launch.getSession()));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   262
        return launch;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   263
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   264
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   265
    private ISourceLocator getSourceLocator(ILaunchConfiguration configuration, DsfSession session) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   266
        DsfSourceLookupDirector locator = new DsfSourceLookupDirector(session);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   267
        String memento = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, (String)null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   268
        if (memento == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   269
            locator.initializeDefaults(configuration);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   270
        } else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   271
            locator.initializeFromMemento(memento, configuration);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   272
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   273
        return locator;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   274
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   275
    
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   276
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   277
	 * Recursively creates a set of projects referenced by the current project
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   278
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   279
	 * @param proj
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   280
	 *            The current project
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   281
	 * @param referencedProjSet
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   282
	 *            A set of referenced projects
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   283
	 * @throws CoreException
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   284
	 *             if an error occurs while getting referenced projects from the
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   285
	 *             current project
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   286
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   287
	private HashSet<IProject> getReferencedProjectSet(IProject proj, HashSet<IProject> referencedProjSet) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   288
		// The top project is a reference too and it must be added at the top to avoid cycles
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   289
		referencedProjSet.add(proj);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   290
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   291
		IProject[] projects = proj.getReferencedProjects();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   292
		for (IProject refProject : projects) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   293
			if (refProject.exists() && !referencedProjSet.contains(refProject)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   294
				getReferencedProjectSet(refProject, referencedProjSet);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   295
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   296
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   297
		return referencedProjSet;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   298
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   299
	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   300
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   301
	 * Returns the order list of projects to build before launching.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   302
	 *  Used in buildForLaunch() 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   303
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   304
	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   305
	protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   306
		IProject[] orderedProjects = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   307
		ArrayList<IProject> orderedProjList = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   308
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   309
		ICProject cProject = LaunchUtils.verifyCProject(configuration);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   310
		if (cProject != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   311
			HashSet<IProject> projectSet = getReferencedProjectSet(cProject.getProject(), new HashSet<IProject>());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   312
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   313
			String[] orderedNames = ResourcesPlugin.getWorkspace().getDescription().getBuildOrder();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   314
			if (orderedNames != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   315
				//Projects may not be in the build order but should still be built if selected
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   316
				ArrayList<IProject> unorderedProjects = new ArrayList<IProject>(projectSet.size());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   317
				unorderedProjects.addAll(projectSet);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   318
				orderedProjList = new ArrayList<IProject>(projectSet.size());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   319
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   320
				for (String projectName : orderedNames) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   321
					for (IProject proj : unorderedProjects) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   322
						if (proj.getName().equals(projectName)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   323
							orderedProjList.add(proj);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   324
							unorderedProjects.remove(proj);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   325
							break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   326
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   327
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   328
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   329
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   330
				// Add any remaining projects to the end of the list
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   331
				orderedProjList.addAll(unorderedProjects);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   332
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   333
				orderedProjects = orderedProjList.toArray(new IProject[orderedProjList.size()]);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   334
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   335
				// Try the project prerequisite order then
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   336
				IProject[] projects = projectSet.toArray(new IProject[projectSet.size()]);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   337
				orderedProjects = ResourcesPlugin.getWorkspace().computeProjectOrder(projects).projects;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   338
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   339
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   340
		return orderedProjects;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   341
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   342
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   343
	/* Used in finalLaunchCheck() */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   344
	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   345
	protected IProject[] getProjectsForProblemSearch(ILaunchConfiguration configuration, String mode) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   346
		return getBuildOrder(configuration, mode);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   347
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   348
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   349
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   350
	 * Searches for compile errors in the specified project
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   351
	 * Used in finalLaunchCheck() 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   352
	 * @param proj
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   353
	 *            The project to search
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   354
	 * @return true if compile errors exist, otherwise false
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   355
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   356
	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   357
	protected boolean existsProblems(IProject proj) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   358
		IMarker[] markers = proj.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   359
		if (markers.length > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   360
			for (IMarker marker : markers) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   361
				Integer severity = (Integer)marker.getAttribute(IMarker.SEVERITY);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   362
				if (severity != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   363
					return severity.intValue() >= IMarker.SEVERITY_ERROR;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   364
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   365
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   366
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   367
		return false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   368
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   369
	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   370
	private boolean isNonStopSupported(String version) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   371
		if (NON_STOP_FIRST_VERSION.compareTo(version) <= 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   372
			return true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   373
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   374
		return false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   375
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   376
	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   377
	// A subclass can override this method and provide its own ServiceFactory.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   378
	protected IDsfDebugServicesFactory newServiceFactory(String version) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   379
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   380
		if (isNonStopSession && isNonStopSupported(version)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   381
			return new GdbDebugServicesFactoryNS(version);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   382
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   383
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   384
		if (version.startsWith("6.6") ||  //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   385
			version.startsWith("6.7") ||  //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   386
			version.startsWith("6.8")) {  //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   387
			return new GdbDebugServicesFactory(version);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   388
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   389
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   390
		return new GdbDebugServicesFactory(version);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   391
	}
96
defec9d2b40a refactor to use AbstractCLaunchDelegate (bug 9762)
timkelly
parents: 37
diff changeset
   392
defec9d2b40a refactor to use AbstractCLaunchDelegate (bug 9762)
timkelly
parents: 37
diff changeset
   393
	@Override
defec9d2b40a refactor to use AbstractCLaunchDelegate (bug 9762)
timkelly
parents: 37
diff changeset
   394
	protected String getPluginID() {
defec9d2b40a refactor to use AbstractCLaunchDelegate (bug 9762)
timkelly
parents: 37
diff changeset
   395
		return GdbPlugin.getUniqueIdentifier();
defec9d2b40a refactor to use AbstractCLaunchDelegate (bug 9762)
timkelly
parents: 37
diff changeset
   396
	}
defec9d2b40a refactor to use AbstractCLaunchDelegate (bug 9762)
timkelly
parents: 37
diff changeset
   397
	
defec9d2b40a refactor to use AbstractCLaunchDelegate (bug 9762)
timkelly
parents: 37
diff changeset
   398
	
defec9d2b40a refactor to use AbstractCLaunchDelegate (bug 9762)
timkelly
parents: 37
diff changeset
   399
	
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   400
}