author | tzelaw |
Tue, 14 Apr 2009 15:03:19 -0500 | |
changeset 94 | d74b720418db |
parent 2 | d760517a8095 |
child 728 | a39d0ba41f81 |
child 857 | d66843399035 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: |
|
15 |
* |
|
16 |
*/ |
|
17 |
package com.nokia.cdt.internal.debug.launch; |
|
18 |
||
19 |
import java.io.File; |
|
20 |
||
21 |
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; |
|
22 |
import org.eclipse.cdt.core.model.ICProject; |
|
23 |
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; |
|
24 |
import org.eclipse.cdt.debug.core.ICDebugConfiguration; |
|
25 |
import org.eclipse.cdt.debug.core.cdi.ICDISession; |
|
26 |
import org.eclipse.cdt.ui.CUIPlugin; |
|
27 |
import org.eclipse.core.runtime.*; |
|
28 |
import org.eclipse.debug.core.*; |
|
29 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
30 |
import org.eclipse.swt.widgets.Display; |
|
31 |
||
32 |
import com.freescale.cdt.debug.cw.CWException; |
|
33 |
import com.freescale.cdt.debug.cw.core.RemoteConnectionsTRKHelper; |
|
34 |
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
|
35 |
import com.freescale.cdt.debug.cw.core.cdi.model.Target; |
2 | 36 |
import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin; |
37 |
import com.nokia.carbide.cdt.builder.builder.CarbideCPPBuilder; |
|
38 |
import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration; |
|
39 |
import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo; |
|
40 |
import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
|
41 |
import com.nokia.cdt.debug.cw.symbian.SettingsData; |
|
42 |
import com.nokia.cdt.debug.cw.symbian.SymbianPlugin; |
|
43 |
import com.nokia.cdt.internal.debug.launch.ui.PartialUpgradeAlertDialog; |
|
44 |
||
45 |
import cwdbg.PreferenceConstants; |
|
46 |
||
47 |
public class TRKLaunchDelegate extends NokiaAbstractLaunchDelegate { |
|
48 |
||
49 |
private static final String DONT_ASK_ABOUT_PARTIAL_UPGRADE_OPTION = "DONT_ASK_ABOUT_PARTIAL_UPGRADE_OPTION"; //$NON-NLS-1$ |
|
50 |
private static final int LARGE_SIS_THRESHOLD = 250 * 1024; // 250K |
|
51 |
||
52 |
protected Session cwDebugSession; |
|
53 |
||
54 |
||
55 |
public void launch( |
|
56 |
ILaunchConfiguration config, |
|
57 |
String mode, |
|
58 |
ILaunch launch, |
|
59 |
IProgressMonitor monitor) throws CoreException |
|
60 |
{ |
|
61 |
// See comment at definition of the "mutex" for why this "synchronized". |
|
62 |
synchronized(Session.sessionStartStopMutex()) { |
|
63 |
||
64 |
cwDebugSession = null; |
|
65 |
||
66 |
if (monitor == null) { |
|
67 |
monitor = new NullProgressMonitor(); |
|
68 |
} |
|
69 |
||
70 |
monitor.beginTask(LaunchMessages.getString("LocalRunLaunchDelegate.Launching_Local_C_Application"), 10); //$NON-NLS-1$ |
|
71 |
// check for cancellation |
|
72 |
if (monitor.isCanceled()) { |
|
73 |
return; |
|
74 |
} |
|
75 |
||
76 |
if (!RemoteConnectionsTRKHelper.configUsesConnectionAttribute(config)) { |
|
77 |
config = RemoteConnectionsTRKHelper.attemptUpdateLaunchConfiguration(config.getWorkingCopy()); |
|
78 |
} |
|
79 |
||
80 |
final IConnection connection = RemoteConnectionsTRKHelper.getConnectionFromConfig(config); |
|
81 |
if (connection == null) { |
|
82 |
IStatus status = new Status(Status.ERROR, LaunchPlugin.PLUGIN_ID, |
|
83 |
LaunchMessages.getString("TRKLaunchDelegate.NoConnectionErrorMsg")); //$NON-NLS-1$ |
|
84 |
throw new DebugException(status); |
|
85 |
} |
|
86 |
connection.useConnection(true); |
|
87 |
||
88 |
try { |
|
89 |
addBeingLaunched(config); // indicating the LC is being launched |
|
90 |
||
91 |
monitor.worked(1); |
|
92 |
IPath exePath = verifyProgramPath(config); |
|
93 |
ICProject project = verifyCProject(config); |
|
94 |
IBinaryObject exeFile = verifyBinary(project, exePath); |
|
95 |
String arguments[] = getProgramArgumentsArray(config); |
|
96 |
||
97 |
// See comment for this method for more. |
|
98 |
SettingsData.setInternalPreferences(config, SettingsData.LaunchConfig_AppTRK); |
|
99 |
||
100 |
// set the partial upgrade pref value |
|
101 |
ILaunchConfigurationWorkingCopy workingCopy = config.getWorkingCopy(); |
|
102 |
workingCopy.setAttribute(PreferenceConstants.J_PN_PUSisFileHostPath, ""); //$NON-NLS-1$ |
|
103 |
||
104 |
String sisHostPath = config.getAttribute(PreferenceConstants.J_PN_SisFileHostPath, ""); //$NON-NLS-1$ |
|
105 |
if (sisHostPath.length() > 0) { |
|
106 |
// app trk launch - see if there's a partial upgrade sis file |
|
107 |
IPath sisPath = new Path(sisHostPath); |
|
108 |
String buildConfigName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, ""); //$NON-NLS-1$ |
|
109 |
if (buildConfigName.length() > 0) { |
|
110 |
ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project.getProject()); |
|
111 |
if (cpi != null) { |
|
112 |
for (ICarbideBuildConfiguration buildConfig : cpi.getBuildConfigurations()) { |
|
113 |
if (buildConfig.getDisplayString().equals(buildConfigName)) { |
|
114 |
IPath puSisPath = CarbideCPPBuilder.getPartialUpgradeSisPath(buildConfig, sisPath); |
|
115 |
if (puSisPath != null && puSisPath.toFile().exists()) { |
|
116 |
workingCopy.setAttribute(PreferenceConstants.J_PN_PUSisFileHostPath, puSisPath.toOSString()); |
|
117 |
} |
|
118 |
break; |
|
119 |
} |
|
120 |
} |
|
121 |
} |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
// save the changes |
|
126 |
workingCopy.doSave(); |
|
127 |
||
128 |
// set the default source locator if required |
|
129 |
setDefaultSourceLocator(launch, config); |
|
130 |
||
131 |
if (mode.equals(ILaunchManager.DEBUG_MODE)) { |
|
132 |
// debug mode |
|
133 |
ICDebugConfiguration debugConfig = getDebugConfig(config); |
|
134 |
ICDISession dsession = null; |
|
135 |
String debugMode = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, |
|
136 |
ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN); |
|
137 |
if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { |
|
138 |
dsession = debugConfig.createDebugger().createDebuggerSession(launch, exeFile, |
|
139 |
new SubProgressMonitor(monitor, 8)); |
|
140 |
||
141 |
assert(dsession instanceof Session); |
|
142 |
cwDebugSession = (Session)dsession; |
|
143 |
||
144 |
doAdditionalSessionSetup(cwDebugSession); |
|
145 |
||
146 |
IPath[] otherExecutables = getOtherExecutables(project, exePath, config, monitor); |
|
147 |
{ |
|
148 |
try { |
|
149 |
monitor.worked(1); |
|
150 |
||
151 |
// if enabled in the prefs, show the console view(s) |
|
152 |
if (config.getAttribute(PreferenceConstants.J_PN_ViewUnframedData, false)) { |
|
153 |
SymbianPlugin.getDefault().openUnframedDataConsole(true); |
|
154 |
} |
|
155 |
||
156 |
if (config.getAttribute(PreferenceConstants.J_PN_ViewCommMessages, false)) { |
|
157 |
SymbianPlugin.getDefault().openTRKCommLogConsole(true); |
|
158 |
} |
|
159 |
||
160 |
config = synchronizeWithProjectAccessPaths(project, config); |
|
161 |
||
162 |
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
|
163 |
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
|
164 |
ATFLaunchSupport.saveDebugTargetFromLaunchDelegate(target.getCoreModelTarget()); |
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
|
165 |
|
2 | 166 |
} catch (CoreException e) { |
167 |
Session session = (Session)dsession; |
|
168 |
session.cleanupAfterLaunchFailure(); |
|
169 |
throw e; |
|
170 |
} catch (Exception e) { |
|
171 |
Session session = (Session)dsession; |
|
172 |
session.debuggingStopped(null); |
|
173 |
this.abort(e.getLocalizedMessage(), null, 0); |
|
174 |
} |
|
175 |
} |
|
176 |
} |
|
177 |
} |
|
178 |
else if (mode.equals(ILaunchManager.RUN_MODE)) { |
|
179 |
// Run the program. |
|
180 |
// Connect to DE, download and launch the program, close debug session. |
|
181 |
ICDebugConfiguration debugConfig = getDebugConfig(config); |
|
182 |
ICDISession dsession = null; |
|
183 |
||
184 |
// Set up communication with DE. |
|
185 |
dsession = debugConfig.createDebugger().createDebuggerSession(launch, exeFile, |
|
186 |
new SubProgressMonitor(monitor, 8)); |
|
187 |
||
188 |
// Launch the program through the DE. |
|
189 |
cwDebugSession = (Session)dsession; |
|
190 |
cwDebugSession.launchExecutable( |
|
191 |
launch, |
|
192 |
config, |
|
193 |
exeFile, |
|
194 |
new IPath[0], |
|
195 |
arguments, |
|
196 |
null, |
|
197 |
getEnvironmentAsProperty(config), |
|
198 |
monitor, |
|
199 |
project, |
|
200 |
"", //$NON-NLS-1$ |
|
201 |
false /* run instead of debug */); |
|
202 |
||
203 |
// The above call would throw exception on error. So it must have succeeded |
|
204 |
// if control gets here. Show success message in a dialog. |
|
205 |
// |
|
206 |
// get the name of the executable that's launched instead of, say, the DLL name if |
|
207 |
// exeFile is a DLL. |
|
208 |
final String exeLaunched = config.getAttribute(PreferenceConstants.J_PN_RemoteProcessToLaunch, exeFile.toString()); |
|
209 |
Display display = Display.getCurrent(); |
|
210 |
if (display == null) { |
|
211 |
display = Display.getDefault(); |
|
212 |
} |
|
213 |
||
214 |
display.syncExec(new Runnable() { |
|
215 |
public void run() { |
|
216 |
connection.useConnection(false); |
|
217 |
MessageDialog.openInformation( |
|
218 |
CUIPlugin.getActiveWorkbenchShell(), |
|
219 |
LaunchMessages.getString("CarbideCPPLaunchDelegate.DebuggerName"), //$NON-NLS-1$ |
|
220 |
LaunchMessages.getString("TRKLaunchDelegate.runSucceed") + //$NON-NLS-1$ |
|
221 |
"\n\t\"" + exeLaunched + "\""); //$NON-NLS-1$ //$NON-NLS-2$ |
|
222 |
} |
|
223 |
}); |
|
224 |
} |
|
225 |
} catch (CWException e) { |
|
226 |
connection.useConnection(false); |
|
227 |
if (! monitor.isCanceled()) // don't throw on user cancellation |
|
228 |
e.printStackTrace(); |
|
229 |
} catch (CoreException e) { |
|
230 |
connection.useConnection(false); |
|
231 |
if (! monitor.isCanceled()) // don't throw on user cancellation |
|
232 |
throw e; |
|
233 |
} finally { |
|
234 |
monitor.done(); |
|
235 |
removeBeingLaunched(config); |
|
236 |
} |
|
237 |
} // end of synchronized. |
|
238 |
} |
|
239 |
||
240 |
@Override |
|
241 |
public boolean buildForLaunch(final ILaunchConfiguration configuration, |
|
242 |
String mode, IProgressMonitor monitor) throws CoreException { |
|
243 |
// for app trk, check to see if we need to ask the user if they want to enable |
|
244 |
// partial upgrade builds |
|
245 |
String sisHostPath = configuration.getAttribute(PreferenceConstants.J_PN_SisFileHostPath, ""); //$NON-NLS-1$ |
|
246 |
if (sisHostPath.length() > 0) { |
|
247 |
// app trk launch - see if the partial upgrade option is enabled |
|
248 |
IPath sisPath = new Path(sisHostPath); |
|
249 |
String buildConfigName = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, ""); //$NON-NLS-1$ |
|
250 |
if (buildConfigName.length() > 0) { |
|
251 |
final ICProject project = verifyCProject(configuration); |
|
252 |
ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project.getProject()); |
|
253 |
if (cpi != null) { |
|
254 |
for (ICarbideBuildConfiguration buildConfig : cpi.getBuildConfigurations()) { |
|
255 |
if (buildConfig.getDisplayString().equals(buildConfigName)) { |
|
256 |
if (null == CarbideCPPBuilder.getPartialUpgradeSisPath(buildConfig, sisPath)) { |
|
257 |
if (!configuration.getAttribute(DONT_ASK_ABOUT_PARTIAL_UPGRADE_OPTION, false)) { |
|
258 |
// get the size of the sis file if it exists |
|
259 |
File sisFile = sisPath.toFile(); |
|
260 |
if (sisFile.exists() && sisFile.length() > LARGE_SIS_THRESHOLD) { |
|
261 |
// it's larger than the threshold so present dialog. |
|
262 |
||
263 |
Display.getDefault().syncExec(new Runnable() { |
|
264 |
||
265 |
public void run() { |
|
266 |
PartialUpgradeAlertDialog dlg = new PartialUpgradeAlertDialog(CUIPlugin.getActiveWorkbenchShell(), project.getProject()); |
|
267 |
dlg.open(); |
|
268 |
||
269 |
// if they check the option then remember it |
|
270 |
if (dlg.dontAskAgain()) { |
|
271 |
try { |
|
272 |
ILaunchConfigurationWorkingCopy workingCopy = configuration.getWorkingCopy(); |
|
273 |
workingCopy.setAttribute(DONT_ASK_ABOUT_PARTIAL_UPGRADE_OPTION, true); |
|
274 |
||
275 |
// save the changes |
|
276 |
workingCopy.doSave(); |
|
277 |
} catch (CoreException e) { |
|
278 |
e.printStackTrace(); |
|
279 |
LaunchPlugin.log(e); |
|
280 |
} |
|
281 |
} |
|
282 |
} |
|
283 |
}); |
|
284 |
} |
|
285 |
} |
|
286 |
} |
|
287 |
break; |
|
288 |
} |
|
289 |
} |
|
290 |
} |
|
291 |
} |
|
292 |
} |
|
293 |
||
294 |
||
295 |
return super.buildForLaunch(configuration, mode, monitor); |
|
296 |
} |
|
297 |
} |