debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/SophiaSTILaunchDelegate.java
author tzelaw
Tue, 14 Apr 2009 15:03:19 -0500
changeset 94 d74b720418db
parent 2 d760517a8095
permissions -rw-r--r--
Test framework support: Ask debugger to remember DebugTarget so test framework can use it to setup test framework related utility. With this we can use the DebugUI way of launching while keeping test framework functionality
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
cawthron
parents:
diff changeset
     1
/*
cawthron
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
cawthron
parents:
diff changeset
     3
* All rights reserved.
cawthron
parents:
diff changeset
     4
* This component and the accompanying materials are made available
cawthron
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
cawthron
parents:
diff changeset
     6
* which accompanies this distribution, and is available
cawthron
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
cawthron
parents:
diff changeset
     8
*
cawthron
parents:
diff changeset
     9
* Initial Contributors:
cawthron
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
cawthron
parents:
diff changeset
    11
*
cawthron
parents:
diff changeset
    12
* Contributors:
cawthron
parents:
diff changeset
    13
*
cawthron
parents:
diff changeset
    14
* Description: 
cawthron
parents:
diff changeset
    15
*
cawthron
parents:
diff changeset
    16
*/
cawthron
parents:
diff changeset
    17
package com.nokia.cdt.internal.debug.launch;
cawthron
parents:
diff changeset
    18
cawthron
parents:
diff changeset
    19
import java.io.File;
cawthron
parents:
diff changeset
    20
cawthron
parents:
diff changeset
    21
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
cawthron
parents:
diff changeset
    22
import org.eclipse.cdt.core.model.ICProject;
cawthron
parents:
diff changeset
    23
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
cawthron
parents:
diff changeset
    24
import org.eclipse.cdt.debug.core.ICDebugConfiguration;
cawthron
parents:
diff changeset
    25
import org.eclipse.cdt.debug.core.cdi.ICDISession;
cawthron
parents:
diff changeset
    26
import org.eclipse.cdt.launch.internal.ui.LaunchMessages;
cawthron
parents:
diff changeset
    27
import org.eclipse.cdt.ui.CUIPlugin;
cawthron
parents:
diff changeset
    28
import org.eclipse.core.runtime.CoreException;
cawthron
parents:
diff changeset
    29
import org.eclipse.core.runtime.IPath;
cawthron
parents:
diff changeset
    30
import org.eclipse.core.runtime.IProgressMonitor;
cawthron
parents:
diff changeset
    31
import org.eclipse.core.runtime.NullProgressMonitor;
cawthron
parents:
diff changeset
    32
import org.eclipse.core.runtime.SubProgressMonitor;
cawthron
parents:
diff changeset
    33
import org.eclipse.debug.core.ILaunch;
cawthron
parents:
diff changeset
    34
import org.eclipse.debug.core.ILaunchConfiguration;
cawthron
parents:
diff changeset
    35
import org.eclipse.debug.core.ILaunchManager;
cawthron
parents:
diff changeset
    36
import org.eclipse.jface.dialogs.MessageDialog;
cawthron
parents:
diff changeset
    37
import org.eclipse.swt.widgets.Display;
cawthron
parents:
diff changeset
    38
cawthron
parents:
diff changeset
    39
import com.freescale.cdt.debug.cw.CWException;
cawthron
parents:
diff changeset
    40
import com.freescale.cdt.debug.cw.core.cdi.Session;
94
d74b720418db Test framework support: Ask debugger to remember DebugTarget so test framework can use it to setup test framework related utility. With this we can use the DebugUI way of launching while keeping test framework functionality
tzelaw
parents: 2
diff changeset
    41
import com.freescale.cdt.debug.cw.core.cdi.model.Target;
2
cawthron
parents:
diff changeset
    42
import com.nokia.cdt.debug.cw.symbian.SettingsData;
cawthron
parents:
diff changeset
    43
import com.nokia.cdt.debug.cw.symbian.SymbianPlugin;
cawthron
parents:
diff changeset
    44
cawthron
parents:
diff changeset
    45
import cwdbg.PreferenceConstants;
cawthron
parents:
diff changeset
    46
cawthron
parents:
diff changeset
    47
public class SophiaSTILaunchDelegate extends NokiaAbstractLaunchDelegate {
cawthron
parents:
diff changeset
    48
cawthron
parents:
diff changeset
    49
	public void launch(ILaunchConfiguration config, 
cawthron
parents:
diff changeset
    50
					   String mode,
cawthron
parents:
diff changeset
    51
					   ILaunch launch, 
cawthron
parents:
diff changeset
    52
					   IProgressMonitor monitor) throws CoreException {
cawthron
parents:
diff changeset
    53
		
cawthron
parents:
diff changeset
    54
cawthron
parents:
diff changeset
    55
		// See comment at definition of the "mutex" for why this "synchronized".		
cawthron
parents:
diff changeset
    56
		synchronized(Session.sessionStartStopMutex()) {
cawthron
parents:
diff changeset
    57
cawthron
parents:
diff changeset
    58
	        if (monitor == null) {
cawthron
parents:
diff changeset
    59
	            monitor = new NullProgressMonitor();
cawthron
parents:
diff changeset
    60
	        }
cawthron
parents:
diff changeset
    61
cawthron
parents:
diff changeset
    62
	        monitor.beginTask(LaunchMessages.getString("LocalRunLaunchDelegate.Launching_Local_C_Application"), 10); //$NON-NLS-1$
cawthron
parents:
diff changeset
    63
	        // check for cancellation
cawthron
parents:
diff changeset
    64
	        if (monitor.isCanceled()) {
cawthron
parents:
diff changeset
    65
	            return;
cawthron
parents:
diff changeset
    66
	        }
cawthron
parents:
diff changeset
    67
	        try {
cawthron
parents:
diff changeset
    68
	            monitor.worked(1);
cawthron
parents:
diff changeset
    69
	            IPath exePath = verifyProgramPath(config);
cawthron
parents:
diff changeset
    70
	            ICProject project = verifyCProject(config);
cawthron
parents:
diff changeset
    71
	            IBinaryObject exeFile = verifyBinary(project, exePath);
cawthron
parents:
diff changeset
    72
	            String arguments[] = getProgramArgumentsArray(config);
cawthron
parents:
diff changeset
    73
cawthron
parents:
diff changeset
    74
				// See comment for this method for more.
cawthron
parents:
diff changeset
    75
	            SettingsData.setInternalPreferences(config, SettingsData.LaunchConfig_SophiaSTI);
cawthron
parents:
diff changeset
    76
	            			
cawthron
parents:
diff changeset
    77
	            // set the default source locator if required
cawthron
parents:
diff changeset
    78
	            setDefaultSourceLocator(launch, config);
cawthron
parents:
diff changeset
    79
cawthron
parents:
diff changeset
    80
	            if (mode.equals(ILaunchManager.DEBUG_MODE)) {
cawthron
parents:
diff changeset
    81
	                // debug mode
cawthron
parents:
diff changeset
    82
	                ICDebugConfiguration debugConfig = getDebugConfig(config);
cawthron
parents:
diff changeset
    83
	                ICDISession dsession = null;
cawthron
parents:
diff changeset
    84
	                String debugMode = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
cawthron
parents:
diff changeset
    85
	                        ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
cawthron
parents:
diff changeset
    86
	                if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) {
cawthron
parents:
diff changeset
    87
	                    dsession = debugConfig.createDebugger().createDebuggerSession(launch, exeFile,
cawthron
parents:
diff changeset
    88
	                            new SubProgressMonitor(monitor, 8));
cawthron
parents:
diff changeset
    89
cawthron
parents:
diff changeset
    90
						assert(dsession instanceof Session);
cawthron
parents:
diff changeset
    91
						Session cwDebugSession = (Session)dsession;
cawthron
parents:
diff changeset
    92
cawthron
parents:
diff changeset
    93
						doAdditionalSessionSetup(cwDebugSession);
cawthron
parents:
diff changeset
    94
						
cawthron
parents:
diff changeset
    95
						IPath[] otherExecutables = getOtherExecutables(project, exePath, config, monitor);
cawthron
parents:
diff changeset
    96
						{
cawthron
parents:
diff changeset
    97
							try {
cawthron
parents:
diff changeset
    98
								monitor.worked(1);
cawthron
parents:
diff changeset
    99
								
cawthron
parents:
diff changeset
   100
								// if enabled in the prefs, show the console view(s)
cawthron
parents:
diff changeset
   101
								if (config.getAttribute(SettingsData.spn_SophiaSTIConn_LogOption, false)) {
cawthron
parents:
diff changeset
   102
									SymbianPlugin.getDefault().openSTICommLogConsole(true);
cawthron
parents:
diff changeset
   103
								}
cawthron
parents:
diff changeset
   104
								if (config.getAttribute(PreferenceConstants.J_PN_LogUnresolved, false)) {
cawthron
parents:
diff changeset
   105
									SymbianPlugin.getDefault().openSymbianRomLogConsole(true);
cawthron
parents:
diff changeset
   106
								}
cawthron
parents:
diff changeset
   107
								
cawthron
parents:
diff changeset
   108
								config = synchronizeWithProjectAccessPaths(project, config);
cawthron
parents:
diff changeset
   109
								
cawthron
parents:
diff changeset
   110
								File wd = getWorkingDirectory(config);
94
d74b720418db Test framework support: Ask debugger to remember DebugTarget so test framework can use it to setup test framework related utility. With this we can use the DebugUI way of launching while keeping test framework functionality
tzelaw
parents: 2
diff changeset
   111
								Target target = cwDebugSession.launchExecutable(launch, config, exeFile, otherExecutables, arguments, wd, getEnvironmentAsProperty(config), monitor, project, getTargetLabel(exeFile.getName()), true);
d74b720418db Test framework support: Ask debugger to remember DebugTarget so test framework can use it to setup test framework related utility. With this we can use the DebugUI way of launching while keeping test framework functionality
tzelaw
parents: 2
diff changeset
   112
								ATFLaunchSupport.saveDebugTargetFromLaunchDelegate(target.getCoreModelTarget());
2
cawthron
parents:
diff changeset
   113
cawthron
parents:
diff changeset
   114
							} catch (CoreException e) {
cawthron
parents:
diff changeset
   115
								Session session = (Session)dsession;
cawthron
parents:
diff changeset
   116
								session.cleanupAfterLaunchFailure();
cawthron
parents:
diff changeset
   117
								throw e;
cawthron
parents:
diff changeset
   118
							} catch (Exception e) {
cawthron
parents:
diff changeset
   119
								Session session = (Session)dsession;
cawthron
parents:
diff changeset
   120
								session.debuggingStopped(null);
cawthron
parents:
diff changeset
   121
								this.abort(e.getLocalizedMessage(), null, 0);
cawthron
parents:
diff changeset
   122
							}
cawthron
parents:
diff changeset
   123
						}
cawthron
parents:
diff changeset
   124
	                }
cawthron
parents:
diff changeset
   125
	            }
cawthron
parents:
diff changeset
   126
	            else if (mode.equals(ILaunchManager.RUN_MODE)) {
cawthron
parents:
diff changeset
   127
	                // Run the program.
cawthron
parents:
diff changeset
   128
	            	// Connect to DE, download and launch the program, close debug session.
cawthron
parents:
diff changeset
   129
	                ICDebugConfiguration debugConfig = getDebugConfig(config);
cawthron
parents:
diff changeset
   130
	                ICDISession dsession = null;
cawthron
parents:
diff changeset
   131
	                
cawthron
parents:
diff changeset
   132
	                // Set up communication with DE.
cawthron
parents:
diff changeset
   133
	                dsession = debugConfig.createDebugger().createDebuggerSession(launch, exeFile,
cawthron
parents:
diff changeset
   134
	                            new SubProgressMonitor(monitor, 8));
cawthron
parents:
diff changeset
   135
cawthron
parents:
diff changeset
   136
	                // Launch the program through the DE.
cawthron
parents:
diff changeset
   137
	                Session cwDebugSession = (Session)dsession;
cawthron
parents:
diff changeset
   138
					cwDebugSession.launchExecutable(
cawthron
parents:
diff changeset
   139
											launch, 
cawthron
parents:
diff changeset
   140
											config, 
cawthron
parents:
diff changeset
   141
											exeFile, 
cawthron
parents:
diff changeset
   142
											new IPath[0], 
cawthron
parents:
diff changeset
   143
											arguments, 
cawthron
parents:
diff changeset
   144
											null, 
cawthron
parents:
diff changeset
   145
											getEnvironmentAsProperty(config), 
cawthron
parents:
diff changeset
   146
											monitor, 
cawthron
parents:
diff changeset
   147
											project, 
cawthron
parents:
diff changeset
   148
											"",  //$NON-NLS-1$
cawthron
parents:
diff changeset
   149
											false  /* run instead of debug */);
cawthron
parents:
diff changeset
   150
					
cawthron
parents:
diff changeset
   151
					// The above call would throw exception on error. So it must have succeeded 
cawthron
parents:
diff changeset
   152
					// if control gets here. Show success message in a dialog.
cawthron
parents:
diff changeset
   153
		    		//
cawthron
parents:
diff changeset
   154
		    		// get the name of the executable that's launched instead of, say, the DLL name if
cawthron
parents:
diff changeset
   155
		    		// exeFile is a DLL.
cawthron
parents:
diff changeset
   156
		    		final String exeLaunched = config.getAttribute(PreferenceConstants.J_PN_RemoteProcessToLaunch, exeFile.toString());
cawthron
parents:
diff changeset
   157
					Display display = Display.getCurrent();
cawthron
parents:
diff changeset
   158
					if (display == null) {
cawthron
parents:
diff changeset
   159
						display = Display.getDefault();
cawthron
parents:
diff changeset
   160
					}
cawthron
parents:
diff changeset
   161
					
cawthron
parents:
diff changeset
   162
					display.syncExec(new Runnable() {
cawthron
parents:
diff changeset
   163
						public void run() {
cawthron
parents:
diff changeset
   164
							MessageDialog.openInformation(
cawthron
parents:
diff changeset
   165
								CUIPlugin.getActiveWorkbenchShell(),
cawthron
parents:
diff changeset
   166
								LaunchMessages.getString("CarbideCPPLaunchDelegate.DebuggerName"),  //$NON-NLS-1$
cawthron
parents:
diff changeset
   167
								LaunchMessages.getString("TRKLaunchDelegate.runSucceed") + //$NON-NLS-1$
cawthron
parents:
diff changeset
   168
							           "\n\t\"" + exeLaunched + "\""); //$NON-NLS-1$ //$NON-NLS-2$
cawthron
parents:
diff changeset
   169
						}
cawthron
parents:
diff changeset
   170
					});
cawthron
parents:
diff changeset
   171
	            }
cawthron
parents:
diff changeset
   172
	        } catch (CWException e) {
cawthron
parents:
diff changeset
   173
	        	if (! monitor.isCanceled()) // don't throw on user cancellation
cawthron
parents:
diff changeset
   174
	        		e.printStackTrace();
cawthron
parents:
diff changeset
   175
			} catch (CoreException e) {
cawthron
parents:
diff changeset
   176
	        	if (! monitor.isCanceled()) // don't throw on user cancellation
cawthron
parents:
diff changeset
   177
	        		throw e;
cawthron
parents:
diff changeset
   178
			} finally {
cawthron
parents:
diff changeset
   179
	            monitor.done();
cawthron
parents:
diff changeset
   180
	        }
cawthron
parents:
diff changeset
   181
		} // end of synchronized.
cawthron
parents:
diff changeset
   182
	}
cawthron
parents:
diff changeset
   183
}