Lines 1-14
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2006, 2007 PalmSource, Inc. and others. |
2 |
* Copyright (c) 2006, 2008 PalmSource, Inc. and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
7 |
* |
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* Ewa Matejska (PalmSource) - Adapted from LocalRunLaunchDelegate |
9 |
* Ewa Matejska (PalmSource) - Adapted from LocalRunLaunchDelegate |
10 |
* Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API |
10 |
* Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API |
11 |
* Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry |
11 |
* Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry |
|
|
12 |
* Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error |
12 |
*******************************************************************************/ |
13 |
*******************************************************************************/ |
13 |
|
14 |
|
14 |
|
15 |
|
Lines 55-73
Link Here
|
55 |
import org.eclipse.swt.widgets.Display; |
56 |
import org.eclipse.swt.widgets.Display; |
56 |
|
57 |
|
57 |
public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate { |
58 |
public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate { |
58 |
|
59 |
|
59 |
private final static String SHELL_SERVICE = "shell.service"; //$NON-NLS-1$ |
60 |
private final static String SHELL_SERVICE = "shell.service"; //$NON-NLS-1$ |
60 |
private final static String FILE_SERVICE = "file.service"; //$NON-NLS-1$ |
61 |
private final static String FILE_SERVICE = "file.service"; //$NON-NLS-1$ |
61 |
private final static String EXIT_CMD = "exit"; //$NON-NLS-1$ |
62 |
private final static String EXIT_CMD = "exit"; //$NON-NLS-1$ |
62 |
private final static String CMD_DELIMITER = ";"; //$NON-NLS-1$ |
63 |
private final static String CMD_DELIMITER = ";"; //$NON-NLS-1$ |
63 |
|
64 |
|
64 |
/* |
65 |
/* |
65 |
* (non-Javadoc) |
66 |
* (non-Javadoc) |
66 |
* @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch |
67 |
* @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch |
67 |
*/ |
68 |
*/ |
68 |
public void launch(ILaunchConfiguration config, String mode, ILaunch launch, |
69 |
public void launch(ILaunchConfiguration config, String mode, ILaunch launch, |
69 |
IProgressMonitor monitor) throws CoreException { |
70 |
IProgressMonitor monitor) throws CoreException { |
70 |
|
71 |
|
71 |
IBinaryObject exeFile = null; |
72 |
IBinaryObject exeFile = null; |
72 |
IPath exePath = verifyProgramPath(config); |
73 |
IPath exePath = verifyProgramPath(config); |
73 |
ICProject project = verifyCProject(config); |
74 |
ICProject project = verifyCProject(config); |
Lines 77-85
Link Here
|
77 |
|
78 |
|
78 |
String arguments = getProgramArguments(config); |
79 |
String arguments = getProgramArguments(config); |
79 |
String remoteExePath = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_REMOTE_PATH, ""); //$NON-NLS-1$ |
80 |
String remoteExePath = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_REMOTE_PATH, ""); //$NON-NLS-1$ |
80 |
|
81 |
|
81 |
if(mode.equals(ILaunchManager.DEBUG_MODE)){ |
82 |
if(mode.equals(ILaunchManager.DEBUG_MODE)){ |
82 |
setDefaultSourceLocator(launch, config); |
83 |
setDefaultSourceLocator(launch, config); |
83 |
String debugMode = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, |
84 |
String debugMode = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, |
84 |
ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN); |
85 |
ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN); |
85 |
if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { |
86 |
if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { |
Lines 88-94
Link Here
|
88 |
try { |
89 |
try { |
89 |
// Download the binary to the remote before debugging. |
90 |
// Download the binary to the remote before debugging. |
90 |
remoteFileDownload(config, launch, exePath.toString(), remoteExePath); |
91 |
remoteFileDownload(config, launch, exePath.toString(), remoteExePath); |
91 |
|
92 |
|
92 |
// Automatically start up the gdbserver. In the future this should be expanded to launch |
93 |
// Automatically start up the gdbserver. In the future this should be expanded to launch |
93 |
// an arbitrary remote damon. |
94 |
// an arbitrary remote damon. |
94 |
String gdbserver_port_number = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_GDBSERVER_PORT, |
95 |
String gdbserver_port_number = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_GDBSERVER_PORT, |
Lines 102-129
Link Here
|
102 |
remoteShellProcess = remoteShellExec(config, gdbserver_command, |
103 |
remoteShellProcess = remoteShellExec(config, gdbserver_command, |
103 |
command_arguments); |
104 |
command_arguments); |
104 |
DebugPlugin.newProcess(launch, remoteShellProcess, Messages.RemoteRunLaunchDelegate_RemoteShell); |
105 |
DebugPlugin.newProcess(launch, remoteShellProcess, Messages.RemoteRunLaunchDelegate_RemoteShell); |
105 |
|
106 |
|
106 |
// Pre-set configuration constants for the GDBSERVERCDIDebugger to indicate how the gdbserver |
107 |
// Pre-set configuration constants for the GDBSERVERCDIDebugger to indicate how the gdbserver |
107 |
// was automatically started on the remote. GDBServerCDIDebugger uses these to figure out how |
108 |
// was automatically started on the remote. GDBServerCDIDebugger uses these to figure out how |
108 |
// to connect to the remote gdbserver. |
109 |
// to connect to the remote gdbserver. |
109 |
ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy(); |
110 |
ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy(); |
110 |
wc.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, true); |
111 |
wc.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, true); |
111 |
wc.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_HOST, getRemoteHostname(config)); |
112 |
wc.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_HOST, getRemoteHostname(config)); |
112 |
wc.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, |
113 |
wc.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, |
113 |
gdbserver_port_number); |
114 |
gdbserver_port_number); |
114 |
wc.doSave(); |
115 |
wc.doSave(); |
115 |
|
116 |
|
116 |
// Default to using the GDBServerCDIDebugger. |
117 |
// Default to using the GDBServerCDIDebugger. |
117 |
GDBServerCDIDebugger2 debugger = new GDBServerCDIDebugger2(); |
118 |
GDBServerCDIDebugger2 debugger = new GDBServerCDIDebugger2(); |
118 |
dsession = ((ICDIDebugger2)debugger).createSession(launch, exePath.toFile(), |
119 |
dsession = ((ICDIDebugger2)debugger).createSession(launch, exePath.toFile(), |
119 |
new SubProgressMonitor(monitor, 8)); |
120 |
new SubProgressMonitor(monitor, 8)); |
120 |
|
121 |
|
121 |
boolean stopInMain = config |
122 |
boolean stopInMain = config |
122 |
.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false); |
123 |
.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false); |
123 |
String stopSymbol = null; |
124 |
String stopSymbol = null; |
124 |
if ( stopInMain ) |
125 |
if ( stopInMain ) |
125 |
stopSymbol = launch.getLaunchConfiguration().getAttribute( |
126 |
stopSymbol = launch.getLaunchConfiguration().getAttribute( |
126 |
ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, |
127 |
ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, |
127 |
ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT ); |
128 |
ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT ); |
128 |
|
129 |
|
129 |
ICDITarget[] targets = dsession.getTargets(); |
130 |
ICDITarget[] targets = dsession.getTargets(); |
Lines 133-140
Link Here
|
133 |
if (process != null) { |
134 |
if (process != null) { |
134 |
iprocess = DebugPlugin.newProcess(launch, process, |
135 |
iprocess = DebugPlugin.newProcess(launch, process, |
135 |
renderProcessLabel(exePath.toOSString()), getDefaultProcessMap()); |
136 |
renderProcessLabel(exePath.toOSString()), getDefaultProcessMap()); |
136 |
} |
137 |
} |
137 |
CDIDebugModel.newDebugTarget(launch, project.getProject(), targets[i], |
138 |
CDIDebugModel.newDebugTarget(launch, project.getProject(), targets[i], |
138 |
renderProcessLabel("gdbserver debugger"), //$NON-NLS-1$ |
139 |
renderProcessLabel("gdbserver debugger"), //$NON-NLS-1$ |
139 |
iprocess, exeFile, true, false, stopSymbol, true); |
140 |
iprocess, exeFile, true, false, stopSymbol, true); |
140 |
} |
141 |
} |
Lines 164-184
Link Here
|
164 |
remoteProcess.destroy(); |
165 |
remoteProcess.destroy(); |
165 |
throw e; |
166 |
throw e; |
166 |
} |
167 |
} |
167 |
|
168 |
|
168 |
} else { |
169 |
} else { |
169 |
IStatus status = new Status(IStatus.ERROR, getPluginID(), |
170 |
IStatus status = new Status(IStatus.ERROR, getPluginID(), |
170 |
IStatus.OK, NLS.bind(Messages.RemoteRunLaunchDelegate_1, mode), null); |
171 |
IStatus.OK, NLS.bind(Messages.RemoteRunLaunchDelegate_1, mode), null); |
171 |
throw new CoreException(status); |
172 |
throw new CoreException(status); |
172 |
} |
173 |
} |
173 |
} |
174 |
} |
174 |
|
175 |
|
175 |
private String spaceEscapify(String inputString) { |
176 |
private String spaceEscapify(String inputString) { |
176 |
if(inputString == null) |
177 |
if(inputString == null) |
177 |
return null; |
178 |
return null; |
178 |
|
179 |
|
179 |
return inputString.replaceAll(" ", "\\\\ "); //$NON-NLS-1$ //$NON-NLS-2$ |
180 |
return inputString.replaceAll(" ", "\\\\ "); //$NON-NLS-1$ //$NON-NLS-2$ |
180 |
} |
181 |
} |
181 |
|
182 |
|
182 |
protected IHost getCurrentConnection(ILaunchConfiguration config) throws CoreException { |
183 |
protected IHost getCurrentConnection(ILaunchConfiguration config) throws CoreException { |
183 |
String remoteConnection = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_REMOTE_CONNECTION, ""); //$NON-NLS-1$ |
184 |
String remoteConnection = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_REMOTE_CONNECTION, ""); //$NON-NLS-1$ |
184 |
|
185 |
|
Lines 192-207
Link Here
|
192 |
} |
193 |
} |
193 |
return connections[i]; |
194 |
return connections[i]; |
194 |
} |
195 |
} |
195 |
|
196 |
|
196 |
protected IService getConnectedRemoteService(ILaunchConfiguration config, String kindOfService) |
197 |
protected IService getConnectedRemoteService(ILaunchConfiguration config, String kindOfService) |
197 |
throws CoreException { |
198 |
throws CoreException { |
198 |
|
199 |
|
199 |
// Check that the service requested is file or shell. |
200 |
// Check that the service requested is file or shell. |
200 |
if(!kindOfService.equals(SHELL_SERVICE) && !kindOfService.equals(FILE_SERVICE)) |
201 |
if(!kindOfService.equals(SHELL_SERVICE) && !kindOfService.equals(FILE_SERVICE)) |
201 |
abort(Messages.RemoteRunLaunchDelegate_3, null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); |
202 |
abort(Messages.RemoteRunLaunchDelegate_3, null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); |
202 |
|
203 |
|
203 |
IHost currentConnection = getCurrentConnection(config); |
204 |
IHost currentConnection = getCurrentConnection(config); |
204 |
|
205 |
|
205 |
ISubSystem[] subSystems = currentConnection.getSubSystems(); |
206 |
ISubSystem[] subSystems = currentConnection.getSubSystems(); |
206 |
int i = 0; |
207 |
int i = 0; |
207 |
for(i = 0; i < subSystems.length; i++) { |
208 |
for(i = 0; i < subSystems.length; i++) { |
Lines 226-246
Link Here
|
226 |
} |
227 |
} |
227 |
} |
228 |
} |
228 |
}); |
229 |
}); |
229 |
|
230 |
|
230 |
if(!subsystem.isConnected()) |
231 |
if(!subsystem.isConnected()) |
231 |
abort(Messages.RemoteRunLaunchDelegate_5, null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); |
232 |
abort(Messages.RemoteRunLaunchDelegate_5, null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); |
232 |
|
233 |
|
233 |
if(kindOfService.equals(SHELL_SERVICE)) |
234 |
if(kindOfService.equals(SHELL_SERVICE)) |
234 |
return ((IShellServiceSubSystem) subsystem).getShellService(); |
235 |
return ((IShellServiceSubSystem) subsystem).getShellService(); |
235 |
else |
236 |
else |
236 |
return ((IFileServiceSubSystem) subsystem).getFileService(); |
237 |
return ((IFileServiceSubSystem) subsystem).getFileService(); |
237 |
} |
238 |
} |
238 |
|
239 |
|
239 |
protected Process remoteFileDownload(ILaunchConfiguration config, ILaunch launch, |
240 |
protected Process remoteFileDownload(ILaunchConfiguration config, ILaunch launch, |
240 |
String localExePath, String remoteExePath) throws CoreException { |
241 |
String localExePath, String remoteExePath) throws CoreException { |
241 |
|
242 |
|
242 |
boolean skipDownload = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_SKIP_DOWNLOAD_TO_TARGET, false); |
243 |
boolean skipDownload = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_SKIP_DOWNLOAD_TO_TARGET, false); |
243 |
|
244 |
|
244 |
if(skipDownload) |
245 |
if(skipDownload) |
245 |
// Nothing to do. Download is skipped. |
246 |
// Nothing to do. Download is skipped. |
246 |
return null; |
247 |
return null; |
Lines 257-300
Link Here
|
257 |
p.destroy(); |
258 |
p.destroy(); |
258 |
} catch (Exception e) { |
259 |
} catch (Exception e) { |
259 |
abort(Messages.RemoteRunLaunchDelegate_6, e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR ); |
260 |
abort(Messages.RemoteRunLaunchDelegate_6, e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR ); |
260 |
} |
261 |
} |
261 |
return null; |
262 |
return null; |
262 |
} |
263 |
} |
263 |
|
264 |
|
264 |
protected String getRemoteHostname(ILaunchConfiguration config) throws CoreException { |
265 |
protected String getRemoteHostname(ILaunchConfiguration config) throws CoreException { |
265 |
IHost currentConnection = getCurrentConnection(config); |
266 |
IHost currentConnection = getCurrentConnection(config); |
266 |
return currentConnection.getHostName(); |
267 |
return currentConnection.getHostName(); |
267 |
} |
268 |
} |
268 |
|
269 |
|
269 |
protected Process remoteShellExec(ILaunchConfiguration config, String remoteCommandPath, |
270 |
protected Process remoteShellExec(ILaunchConfiguration config, String remoteCommandPath, |
270 |
String arguments) throws CoreException { |
271 |
String arguments) throws CoreException { |
271 |
// The exit command is called to force the remote shell to close after our command |
272 |
// The exit command is called to force the remote shell to close after our command |
272 |
// is executed. This is to prevent a running process at the end of the debug session. |
273 |
// is executed. This is to prevent a running process at the end of the debug session. |
273 |
// See Bug 158786. |
274 |
// See Bug 158786. |
274 |
String real_remote_command = arguments == null ? spaceEscapify(remoteCommandPath) : |
275 |
String real_remote_command = arguments == null ? spaceEscapify(remoteCommandPath) : |
275 |
spaceEscapify(remoteCommandPath) + " " + arguments; //$NON-NLS-1$ |
276 |
spaceEscapify(remoteCommandPath) + " " + arguments; //$NON-NLS-1$ |
276 |
String remote_command = real_remote_command + CMD_DELIMITER + EXIT_CMD; |
277 |
String remote_command = real_remote_command + CMD_DELIMITER + EXIT_CMD; |
277 |
|
278 |
|
278 |
IShellService shellService = (IShellService) getConnectedRemoteService(config, SHELL_SERVICE); |
279 |
IShellService shellService = (IShellService) getConnectedRemoteService(config, SHELL_SERVICE); |
279 |
|
280 |
|
280 |
// This is necessary because runCommand does not actually run the command right now. |
281 |
// This is necessary because runCommand does not actually run the command right now. |
281 |
String env[] = new String[0]; |
282 |
String env[] = new String[0]; |
282 |
IHostShell hostShell = shellService.launchShell("", env,new NullProgressMonitor()); //$NON-NLS-1$ |
|
|
283 |
hostShell.writeToShell(remote_command); |
284 |
|
285 |
Process p = null; |
283 |
Process p = null; |
286 |
try { |
284 |
try { |
|
|
285 |
IHostShell hostShell = shellService.launchShell("", env, new NullProgressMonitor()); //$NON-NLS-1$ |
286 |
hostShell.writeToShell(remote_command); |
287 |
p = new HostShellProcessAdapter(hostShell); |
287 |
p = new HostShellProcessAdapter(hostShell); |
288 |
} catch (Exception e) { |
288 |
} catch (Exception e) { |
289 |
if (p != null) { |
289 |
if (p != null) { |
290 |
p.destroy(); |
290 |
p.destroy(); |
291 |
} |
291 |
} |
292 |
abort(Messages.RemoteRunLaunchDelegate_7, null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); |
292 |
abort(Messages.RemoteRunLaunchDelegate_7, e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); |
293 |
} |
293 |
} |
294 |
return p; |
294 |
return p; |
295 |
|
295 |
|
296 |
} |
296 |
} |
297 |
|
297 |
|
298 |
protected String getPluginID() { |
298 |
protected String getPluginID() { |
299 |
return "org.eclipse.rse.internal.remotecdt"; //$NON-NLS-1$ |
299 |
return "org.eclipse.rse.internal.remotecdt"; //$NON-NLS-1$ |
300 |
} |
300 |
} |