debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/Trace32LaunchDelegate.java
author Ed Swartz <ed.swartz@nokia.com>
Wed, 21 Apr 2010 15:10:34 -0500
changeset 1260 f3b387a17eb7
parent 94 d74b720418db
permissions -rw-r--r--
Merge PlatSim changes from 2.x, but move ILaunchDelegateConnectionExtension into com.nokia.cdt.debug.common so EDC can use it
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 Trace32LaunchDelegate 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
	        	addBeingLaunched(config); // indicating the LC is being launched
cawthron
parents:
diff changeset
    69
	        	
cawthron
parents:
diff changeset
    70
	            monitor.worked(1);
cawthron
parents:
diff changeset
    71
	            IPath exePath = verifyProgramPath(config);
cawthron
parents:
diff changeset
    72
	            ICProject project = verifyCProject(config);
cawthron
parents:
diff changeset
    73
	            IBinaryObject exeFile = verifyBinary(project, exePath);
cawthron
parents:
diff changeset
    74
	            String arguments[] = getProgramArgumentsArray(config);
cawthron
parents:
diff changeset
    75
cawthron
parents:
diff changeset
    76
				// See comment for this method for more.
cawthron
parents:
diff changeset
    77
	            SettingsData.setInternalPreferences(config, SettingsData.LaunchConfig_Trace32);
cawthron
parents:
diff changeset
    78
	            			
cawthron
parents:
diff changeset
    79
	            // set the default source locator if required
cawthron
parents:
diff changeset
    80
	            setDefaultSourceLocator(launch, config);
cawthron
parents:
diff changeset
    81
cawthron
parents:
diff changeset
    82
	            if (mode.equals(ILaunchManager.DEBUG_MODE)) {
cawthron
parents:
diff changeset
    83
	                // debug mode
cawthron
parents:
diff changeset
    84
	                ICDebugConfiguration debugConfig = getDebugConfig(config);
cawthron
parents:
diff changeset
    85
	                ICDISession dsession = null;
cawthron
parents:
diff changeset
    86
	                String debugMode = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
cawthron
parents:
diff changeset
    87
	                        ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
cawthron
parents:
diff changeset
    88
	                if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) {
cawthron
parents:
diff changeset
    89
	                    dsession = debugConfig.createDebugger().createDebuggerSession(launch, exeFile,
cawthron
parents:
diff changeset
    90
	                            new SubProgressMonitor(monitor, 8));
cawthron
parents:
diff changeset
    91
cawthron
parents:
diff changeset
    92
						assert(dsession instanceof Session);
cawthron
parents:
diff changeset
    93
						Session cwDebugSession = (Session)dsession;
cawthron
parents:
diff changeset
    94
cawthron
parents:
diff changeset
    95
						doAdditionalSessionSetup(cwDebugSession);
cawthron
parents:
diff changeset
    96
						
cawthron
parents:
diff changeset
    97
						IPath[] otherExecutables = getOtherExecutables(project, exePath, config, monitor);
cawthron
parents:
diff changeset
    98
cawthron
parents:
diff changeset
    99
						{
cawthron
parents:
diff changeset
   100
							try {
cawthron
parents:
diff changeset
   101
								monitor.worked(1);
cawthron
parents:
diff changeset
   102
								
cawthron
parents:
diff changeset
   103
								// if enabled in the prefs, show the console view(s)
cawthron
parents:
diff changeset
   104
								if (config.getAttribute(SettingsData.spn_Trace32Conn_LogOption, false)) {
cawthron
parents:
diff changeset
   105
									SymbianPlugin.getDefault().openT32CommLogConsole(true);
cawthron
parents:
diff changeset
   106
								}
cawthron
parents:
diff changeset
   107
								if (config.getAttribute(PreferenceConstants.J_PN_LogUnresolved, false)) {
cawthron
parents:
diff changeset
   108
									SymbianPlugin.getDefault().openSymbianRomLogConsole(true);
cawthron
parents:
diff changeset
   109
								}
cawthron
parents:
diff changeset
   110
								
cawthron
parents:
diff changeset
   111
								config = synchronizeWithProjectAccessPaths(project, config);
cawthron
parents:
diff changeset
   112
								
cawthron
parents:
diff changeset
   113
								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
   114
								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
   115
								ATFLaunchSupport.saveDebugTargetFromLaunchDelegate(target.getCoreModelTarget());
2
cawthron
parents:
diff changeset
   116
cawthron
parents:
diff changeset
   117
							} catch (CoreException e) {
cawthron
parents:
diff changeset
   118
								Session session = (Session)dsession;
cawthron
parents:
diff changeset
   119
								session.cleanupAfterLaunchFailure();
cawthron
parents:
diff changeset
   120
								throw e;
cawthron
parents:
diff changeset
   121
							} catch (Exception e) {
cawthron
parents:
diff changeset
   122
								Session session = (Session)dsession;
cawthron
parents:
diff changeset
   123
								session.debuggingStopped(null);
cawthron
parents:
diff changeset
   124
								String msg = e.getLocalizedMessage();
cawthron
parents:
diff changeset
   125
								if (msg == null)
cawthron
parents:
diff changeset
   126
									msg = "Trace32 Debug session launch error due to exception.";
cawthron
parents:
diff changeset
   127
								this.abort(msg, null, 0);
cawthron
parents:
diff changeset
   128
							}
cawthron
parents:
diff changeset
   129
						}
cawthron
parents:
diff changeset
   130
	                }
cawthron
parents:
diff changeset
   131
	            }
cawthron
parents:
diff changeset
   132
	            else if (mode.equals(ILaunchManager.RUN_MODE)) {
cawthron
parents:
diff changeset
   133
	                // Run the program.
cawthron
parents:
diff changeset
   134
	            	// Connect to DE, download and launch the program, close debug session.
cawthron
parents:
diff changeset
   135
	                ICDebugConfiguration debugConfig = getDebugConfig(config);
cawthron
parents:
diff changeset
   136
	                ICDISession dsession = null;
cawthron
parents:
diff changeset
   137
	                
cawthron
parents:
diff changeset
   138
	                // Set up communication with DE.
cawthron
parents:
diff changeset
   139
	                dsession = debugConfig.createDebugger().createDebuggerSession(launch, exeFile,
cawthron
parents:
diff changeset
   140
	                            new SubProgressMonitor(monitor, 8));
cawthron
parents:
diff changeset
   141
cawthron
parents:
diff changeset
   142
	                // Launch the program through the DE.
cawthron
parents:
diff changeset
   143
	                Session cwDebugSession = (Session)dsession;
cawthron
parents:
diff changeset
   144
					cwDebugSession.launchExecutable(
cawthron
parents:
diff changeset
   145
											launch, 
cawthron
parents:
diff changeset
   146
											config, 
cawthron
parents:
diff changeset
   147
											exeFile, 
cawthron
parents:
diff changeset
   148
											new IPath[0], 
cawthron
parents:
diff changeset
   149
											arguments, 
cawthron
parents:
diff changeset
   150
											null, 
cawthron
parents:
diff changeset
   151
											getEnvironmentAsProperty(config), 
cawthron
parents:
diff changeset
   152
											monitor, 
cawthron
parents:
diff changeset
   153
											project, 
cawthron
parents:
diff changeset
   154
											"",  //$NON-NLS-1$
cawthron
parents:
diff changeset
   155
											false  /* run instead of debug */);
cawthron
parents:
diff changeset
   156
					
cawthron
parents:
diff changeset
   157
					// The above call would throw exception on error. So it must have succeeded 
cawthron
parents:
diff changeset
   158
					// if control gets here. Show success message in a dialog.
cawthron
parents:
diff changeset
   159
		    		//
cawthron
parents:
diff changeset
   160
		    		// get the name of the executable that's launched instead of, say, the DLL name if
cawthron
parents:
diff changeset
   161
		    		// exeFile is a DLL.
cawthron
parents:
diff changeset
   162
		    		final String exeLaunched = config.getAttribute(PreferenceConstants.J_PN_RemoteProcessToLaunch, exeFile.toString());
cawthron
parents:
diff changeset
   163
					Display display = Display.getCurrent();
cawthron
parents:
diff changeset
   164
					if (display == null) {
cawthron
parents:
diff changeset
   165
						display = Display.getDefault();
cawthron
parents:
diff changeset
   166
					}
cawthron
parents:
diff changeset
   167
					
cawthron
parents:
diff changeset
   168
					display.syncExec(new Runnable() {
cawthron
parents:
diff changeset
   169
						public void run() {
cawthron
parents:
diff changeset
   170
							MessageDialog.openInformation(
cawthron
parents:
diff changeset
   171
								CUIPlugin.getActiveWorkbenchShell(),
cawthron
parents:
diff changeset
   172
								LaunchMessages.getString("CarbideCPPLaunchDelegate.DebuggerName"),  //$NON-NLS-1$
cawthron
parents:
diff changeset
   173
								LaunchMessages.getString("TRKLaunchDelegate.runSucceed") + //$NON-NLS-1$
cawthron
parents:
diff changeset
   174
							           "\n\t\"" + exeLaunched + "\""); //$NON-NLS-1$ //$NON-NLS-2$
cawthron
parents:
diff changeset
   175
						}
cawthron
parents:
diff changeset
   176
					});
cawthron
parents:
diff changeset
   177
	            }
cawthron
parents:
diff changeset
   178
	        } catch (CWException e) {
cawthron
parents:
diff changeset
   179
	        	if (! monitor.isCanceled()) // don't throw on user cancellation
cawthron
parents:
diff changeset
   180
	        		e.printStackTrace();
cawthron
parents:
diff changeset
   181
			} catch (CoreException e) {
cawthron
parents:
diff changeset
   182
	        	if (! monitor.isCanceled()) // don't throw on user cancellation
cawthron
parents:
diff changeset
   183
	        		throw e;
cawthron
parents:
diff changeset
   184
			} finally {
cawthron
parents:
diff changeset
   185
	            monitor.done();
cawthron
parents:
diff changeset
   186
	            removeBeingLaunched(config);
cawthron
parents:
diff changeset
   187
	        }
cawthron
parents:
diff changeset
   188
		} // end of synchronized.
cawthron
parents:
diff changeset
   189
	}
cawthron
parents:
diff changeset
   190
}