debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/TRKLaunchDelegate.java
changeset 1260 f3b387a17eb7
parent 772 c3301e21f173
equal deleted inserted replaced
1259:2a211a55b277 1260:f3b387a17eb7
    15 *
    15 *
    16 */
    16 */
    17 package com.nokia.cdt.internal.debug.launch;
    17 package com.nokia.cdt.internal.debug.launch;
    18 
    18 
    19 import java.io.File;
    19 import java.io.File;
       
    20 import java.util.ArrayList;
       
    21 import java.util.List;
    20 
    22 
    21 import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
    23 import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
    22 import org.eclipse.cdt.core.model.ICProject;
    24 import org.eclipse.cdt.core.model.ICProject;
    23 import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
    25 import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
    24 import org.eclipse.cdt.debug.core.ICDebugConfiguration;
    26 import org.eclipse.cdt.debug.core.ICDebugConfiguration;
    25 import org.eclipse.cdt.debug.core.cdi.CDIException;
       
    26 import org.eclipse.cdt.debug.core.cdi.ICDISession;
    27 import org.eclipse.cdt.debug.core.cdi.ICDISession;
    27 import org.eclipse.cdt.ui.CUIPlugin;
    28 import org.eclipse.cdt.ui.CUIPlugin;
    28 import org.eclipse.core.runtime.CoreException;
    29 import org.eclipse.core.runtime.CoreException;
       
    30 import org.eclipse.core.runtime.IConfigurationElement;
    29 import org.eclipse.core.runtime.IPath;
    31 import org.eclipse.core.runtime.IPath;
    30 import org.eclipse.core.runtime.IProgressMonitor;
    32 import org.eclipse.core.runtime.IProgressMonitor;
    31 import org.eclipse.core.runtime.IStatus;
    33 import org.eclipse.core.runtime.IStatus;
    32 import org.eclipse.core.runtime.NullProgressMonitor;
    34 import org.eclipse.core.runtime.NullProgressMonitor;
    33 import org.eclipse.core.runtime.Path;
    35 import org.eclipse.core.runtime.Path;
       
    36 import org.eclipse.core.runtime.Platform;
    34 import org.eclipse.core.runtime.Status;
    37 import org.eclipse.core.runtime.Status;
    35 import org.eclipse.core.runtime.SubProgressMonitor;
    38 import org.eclipse.core.runtime.SubProgressMonitor;
    36 import org.eclipse.debug.core.DebugException;
    39 import org.eclipse.debug.core.DebugException;
    37 import org.eclipse.debug.core.ILaunch;
    40 import org.eclipse.debug.core.ILaunch;
    38 import org.eclipse.debug.core.ILaunchConfiguration;
    41 import org.eclipse.debug.core.ILaunchConfiguration;
    53 import com.nokia.carbide.remoteconnections.interfaces.IConnection;
    56 import com.nokia.carbide.remoteconnections.interfaces.IConnection;
    54 import com.nokia.carbide.remoteconnections.internal.api.IConnection2;
    57 import com.nokia.carbide.remoteconnections.internal.api.IConnection2;
    55 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus;
    58 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus;
    56 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatusChangedListener;
    59 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatusChangedListener;
    57 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus.EConnectionStatus;
    60 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus.EConnectionStatus;
       
    61 import com.nokia.cdt.debug.common.internal.api.ILaunchDelegateConnectionExtension;
    58 import com.nokia.cdt.debug.cw.symbian.SettingsData;
    62 import com.nokia.cdt.debug.cw.symbian.SettingsData;
    59 import com.nokia.cdt.debug.cw.symbian.SymbianPlugin;
    63 import com.nokia.cdt.debug.cw.symbian.SymbianPlugin;
    60 import com.nokia.cdt.internal.debug.launch.ui.PartialUpgradeAlertDialog;
    64 import com.nokia.cdt.internal.debug.launch.ui.PartialUpgradeAlertDialog;
    61 
    65 
    62 import cwdbg.PreferenceConstants;
    66 import cwdbg.PreferenceConstants;
    65 
    69 
    66 	private static final String DONT_ASK_ABOUT_PARTIAL_UPGRADE_OPTION = "DONT_ASK_ABOUT_PARTIAL_UPGRADE_OPTION"; //$NON-NLS-1$
    70 	private static final String DONT_ASK_ABOUT_PARTIAL_UPGRADE_OPTION = "DONT_ASK_ABOUT_PARTIAL_UPGRADE_OPTION"; //$NON-NLS-1$
    67 	private static final int LARGE_SIS_THRESHOLD = 250 * 1024; // 250K
    71 	private static final int LARGE_SIS_THRESHOLD = 250 * 1024; // 250K
    68 	
    72 	
    69 	protected Session cwDebugSession;
    73 	protected Session cwDebugSession;
    70 	private IConnection connection;
    74 	protected IConnection connection;
    71 	private IConnectionStatusChangedListener connectionStatusChangedListener;
    75 	private IConnectionStatusChangedListener connectionStatusChangedListener;
       
    76 	private List<ILaunchDelegateConnectionExtension> connectionExtensions;
    72 	
    77 	
    73 	public void launch(
    78 	public void launch(
    74 			ILaunchConfiguration 	config, 
    79 			ILaunchConfiguration 	config, 
    75 			String 					mode, 
    80 			final String 					mode, 
    76 			ILaunch 				launch, 
    81 			final ILaunch 				launch, 
    77 			IProgressMonitor monitor) throws CoreException 
    82 			IProgressMonitor monitor) throws CoreException 
    78 	{
    83 	{
    79 	// See comment at definition of the "mutex" for why this "synchronized".		
    84 	// See comment at definition of the "mutex" for why this "synchronized".		
    80 	synchronized(Session.sessionStartStopMutex()) {
    85 	synchronized(Session.sessionStartStopMutex()) {
    81 
    86 
    83 
    88 
    84 		if (monitor == null) {
    89 		if (monitor == null) {
    85             monitor = new NullProgressMonitor();
    90             monitor = new NullProgressMonitor();
    86         }
    91         }
    87 
    92 
    88         monitor.beginTask(LaunchMessages.getString("LocalRunLaunchDelegate.Launching_Local_C_Application"), 10); //$NON-NLS-1$
    93         monitor.beginTask(LaunchMessages.getString("LocalRunLaunchDelegate.Launching_Local_C_Application"), 30); //$NON-NLS-1$
    89         // check for cancellation
    94         // check for cancellation
    90         if (monitor.isCanceled()) {
    95         if (monitor.isCanceled()) {
    91             return;
    96             return;
    92         }
    97         }
    93 		
    98 		
    99 		if (connection == null) {
   104 		if (connection == null) {
   100 			IStatus status = new Status(Status.ERROR, LaunchPlugin.PLUGIN_ID, 
   105 			IStatus status = new Status(Status.ERROR, LaunchPlugin.PLUGIN_ID, 
   101 				LaunchMessages.getString("TRKLaunchDelegate.NoConnectionErrorMsg")); //$NON-NLS-1$
   106 				LaunchMessages.getString("TRKLaunchDelegate.NoConnectionErrorMsg")); //$NON-NLS-1$
   102 			throw new DebugException(status);
   107 			throw new DebugException(status);
   103 		}
   108 		}
       
   109 		
       
   110 		invokeConnectionSpecificSetup(launch, new SubProgressMonitor(monitor, 5));
       
   111 		
   104 		connection.useConnection(true);
   112 		connection.useConnection(true);
   105 		
       
   106         try {
   113         try {
   107         	addBeingLaunched(config); // indicating the LC is being launched
   114         	addBeingLaunched(config); // indicating the LC is being launched
   108         	
   115         	
   109             monitor.worked(1);
   116             monitor.worked(1);
   110             IPath exePath = verifyProgramPath(config);
   117             IPath exePath = verifyProgramPath(config);
   160 					assert(dsession instanceof Session);
   167 					assert(dsession instanceof Session);
   161 					cwDebugSession = (Session)dsession;
   168 					cwDebugSession = (Session)dsession;
   162 
   169 
   163 					doAdditionalSessionSetup(cwDebugSession);
   170 					doAdditionalSessionSetup(cwDebugSession);
   164 					
   171 					
   165 					IPath[] otherExecutables = getOtherExecutables(project, exePath, config, monitor);					
   172 					IPath[] otherExecutables = getOtherExecutables(project, exePath, config, new SubProgressMonitor(monitor, 1));					
   166 					{
   173 					{
   167 						try {
   174 						try {
   168 							monitor.worked(1);
   175 							monitor.worked(1);
   169 							
   176 							
   170 							// if enabled in the prefs, show the console view(s)
   177 							// if enabled in the prefs, show the console view(s)
   191 							session.debuggingStopped(null);
   198 							session.debuggingStopped(null);
   192 							this.abort(e.getLocalizedMessage(), null, 0);
   199 							this.abort(e.getLocalizedMessage(), null, 0);
   193 						}
   200 						}
   194 					}
   201 					}
   195                 }
   202                 }
   196                 hookSessionEnded();
   203                 hookSessionEnded(launch);
   197             }
   204             }
   198             else if (mode.equals(ILaunchManager.RUN_MODE)) {
   205             else if (mode.equals(ILaunchManager.RUN_MODE)) {
   199                 // Run the program.
   206                 // Run the program.
   200             	// Connect to DE, download and launch the program, close debug session.
   207             	// Connect to DE, download and launch the program, close debug session.
   201                 ICDebugConfiguration debugConfig = getDebugConfig(config);
   208                 ICDebugConfiguration debugConfig = getDebugConfig(config);
   213 										exeFile, 
   220 										exeFile, 
   214 										new IPath[0], 
   221 										new IPath[0], 
   215 										arguments, 
   222 										arguments, 
   216 										null, 
   223 										null, 
   217 										getEnvironmentAsProperty(config), 
   224 										getEnvironmentAsProperty(config), 
   218 										monitor, 
   225 										new SubProgressMonitor(monitor, 8), 
   219 										project, 
   226 										project, 
   220 										"",  //$NON-NLS-1$
   227 										"",  //$NON-NLS-1$
   221 										false  /* run instead of debug */);
   228 										false  /* run instead of debug */);
   222 				
   229 				
   223 				// The above call would throw exception on error. So it must have succeeded 
   230 				// The above call would throw exception on error. So it must have succeeded 
   231 					display = Display.getDefault();
   238 					display = Display.getDefault();
   232 				}
   239 				}
   233 				
   240 				
   234 				display.syncExec(new Runnable() {
   241 				display.syncExec(new Runnable() {
   235 					public void run() {
   242 					public void run() {
   236 						connection.useConnection(false);
   243 						shutdownConnection(launch);
   237 						MessageDialog.openInformation(
   244 						MessageDialog.openInformation(
   238 							CUIPlugin.getActiveWorkbenchShell(),
   245 							CUIPlugin.getActiveWorkbenchShell(),
   239 							LaunchMessages.getString("CarbideCPPLaunchDelegate.DebuggerName"),  //$NON-NLS-1$
   246 							LaunchMessages.getString("CarbideCPPLaunchDelegate.DebuggerName"),  //$NON-NLS-1$
   240 							LaunchMessages.getString("TRKLaunchDelegate.runSucceed") + //$NON-NLS-1$
   247 							LaunchMessages.getString("TRKLaunchDelegate.runSucceed") + //$NON-NLS-1$
   241 						           "\n\t\"" + exeLaunched + "\""); //$NON-NLS-1$ //$NON-NLS-2$
   248 						           "\n\t\"" + exeLaunched + "\""); //$NON-NLS-1$ //$NON-NLS-2$
   242 					}
   249 					}
   243 				});
   250 				});
   244             }
   251             }
       
   252             
       
   253             invokeConnectionSpecificPostLaunch(launch, new SubProgressMonitor(monitor, 5));
   245         } catch (CWException e) {
   254         } catch (CWException e) {
   246        		connection.useConnection(false);
   255         	shutdownConnection(launch);
   247        		unhookConnectionStatus();
   256        		unhookConnectionStatus();
   248         	if (! monitor.isCanceled()) // don't throw on user cancellation
   257         	if (! monitor.isCanceled()) // don't throw on user cancellation
   249         		e.printStackTrace();
   258         		e.printStackTrace();
   250 		} catch (CoreException e) {
   259 		} catch (CoreException e) {
   251 			connection.useConnection(false);
   260 			shutdownConnection(launch);
   252 			unhookConnectionStatus();
   261 			unhookConnectionStatus();
   253         	if (! monitor.isCanceled()) // don't throw on user cancellation
   262         	if (! monitor.isCanceled()) // don't throw on user cancellation
   254         		throw e;
   263         		throw e;
   255 		} finally {
   264 		} finally {
   256             monitor.done();
   265             monitor.done();
   257             removeBeingLaunched(config);
   266             removeBeingLaunched(config);
   258         }
   267         }
   259 	} // end of synchronized.
   268 	} // end of synchronized.
   260 	}
   269 	}
   261 
   270 
   262 	protected void hookSessionEnded() {
   271 	protected void shutdownConnection(ILaunch launch) {
       
   272 		try {
       
   273 			invokeConnectionSpecificShutdown(launch, new NullProgressMonitor());
       
   274 		} catch (CoreException e) {
       
   275 			LaunchPlugin.log(e);
       
   276 		} finally {
       
   277 			connection.useConnection(false);
       
   278 		}
       
   279 	}
       
   280 
       
   281 	/** Create the extensions every session, in case they hold state. */
       
   282 	protected List<ILaunchDelegateConnectionExtension> getLaunchDelegateConnectionExtensions() {
       
   283 		if (connectionExtensions == null) {
       
   284 			connectionExtensions = new ArrayList<ILaunchDelegateConnectionExtension>();
       
   285 			IConfigurationElement[] elements =
       
   286 				Platform.getExtensionRegistry().getConfigurationElementsFor(ILaunchDelegateConnectionExtension.ID);
       
   287 			for (IConfigurationElement element : elements) {
       
   288 				try {
       
   289 					connectionExtensions.add((ILaunchDelegateConnectionExtension) element.createExecutableExtension("class"));
       
   290 				} catch (CoreException e) {
       
   291 					LaunchPlugin.log(e);
       
   292 				}
       
   293 			}
       
   294 		}
       
   295 		return connectionExtensions;
       
   296 	}
       
   297 	
       
   298 	protected void invokeConnectionSpecificSetup(ILaunch launch,
       
   299 			IProgressMonitor monitor) throws CoreException {
       
   300 		List<ILaunchDelegateConnectionExtension> extensions = getLaunchDelegateConnectionExtensions();
       
   301 		monitor.beginTask("", extensions.size());
       
   302 		for (ILaunchDelegateConnectionExtension extension : extensions) {
       
   303 			extension.initializeConnection(launch, connection, new SubProgressMonitor(monitor, 1));
       
   304 		}
       
   305 		monitor.done();
       
   306 	}
       
   307 	
       
   308 	protected void invokeConnectionSpecificPostLaunch(ILaunch launch,
       
   309 			IProgressMonitor monitor) throws CoreException {
       
   310 		List<ILaunchDelegateConnectionExtension> extensions = getLaunchDelegateConnectionExtensions();
       
   311 		monitor.beginTask("", extensions.size());
       
   312 		for (ILaunchDelegateConnectionExtension extension : extensions) {
       
   313 			extension.launchStarted(launch, connection, new SubProgressMonitor(monitor, 1));
       
   314 		}
       
   315 		monitor.done();
       
   316 	}
       
   317 	
       
   318 
       
   319 	protected void invokeConnectionSpecificShutdown(
       
   320 			ILaunch launch, IProgressMonitor monitor) throws CoreException {
       
   321 		List<ILaunchDelegateConnectionExtension> extensions = getLaunchDelegateConnectionExtensions();
       
   322 		monitor.beginTask("", extensions.size());
       
   323 		for (ILaunchDelegateConnectionExtension extension : extensions) {
       
   324 			extension.terminateConnection(launch, connection, new SubProgressMonitor(monitor, 1));
       
   325 		}
       
   326 		monitor.done();
       
   327 	}
       
   328 
       
   329 	protected void hookSessionEnded(final ILaunch launch) {
   263 		if (cwDebugSession != null) {
   330 		if (cwDebugSession != null) {
   264 			cwDebugSession.addListener(new ISessionListener() {
   331 			cwDebugSession.addListener(new ISessionListener() {
   265 				public void sessionEnded() {
   332 				public void sessionEnded() {
   266 					connection.useConnection(false);
   333 					try {
   267 					unhookConnectionStatus();
   334 						invokeConnectionSpecificShutdown(launch, new NullProgressMonitor());
       
   335 					} catch (CoreException e) {
       
   336 						LaunchPlugin.log(e);
       
   337 					} finally {
       
   338 						connection.useConnection(false);
       
   339 						unhookConnectionStatus();
       
   340 					}
   268 				}
   341 				}
   269 			});
   342 			});
   270 		}
   343 		}
   271 	}
   344 	}
   272 
   345