|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2010, 2011 Elliott Baron |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* Elliott Baron <ebaron@fedoraproject.org> - initial API and implementation |
| 10 |
* Red Hat Inc. - rewrite to use RemoteConnection class |
| 11 |
* Corey Ashford <cjashfor@us.ibm.com> - converted to an abstract class for |
| 12 |
* the purposes of providing an ability |
| 13 |
* to create multiple launchers, one for |
| 14 |
* each Valgrind executable that is |
| 15 |
* available. |
| 16 |
*******************************************************************************/ |
| 17 |
package org.eclipse.linuxtools.valgrind.launch.remote; |
| 18 |
|
| 19 |
import java.io.IOException; |
| 20 |
|
| 21 |
import java.util.Map; |
| 22 |
|
| 23 |
import org.eclipse.cdt.debug.core.CDebugUtils; |
| 24 |
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; |
| 25 |
import org.eclipse.core.runtime.CoreException; |
| 26 |
import org.eclipse.core.runtime.IPath; |
| 27 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 28 |
import org.eclipse.core.runtime.NullProgressMonitor; |
| 29 |
import org.eclipse.core.runtime.Path; |
| 30 |
import org.eclipse.core.runtime.SubMonitor; |
| 31 |
import org.eclipse.core.runtime.SubProgressMonitor; |
| 32 |
import org.eclipse.debug.core.ILaunch; |
| 33 |
import org.eclipse.debug.core.ILaunchConfiguration; |
| 34 |
import org.eclipse.debug.core.ILaunchManager; |
| 35 |
import org.eclipse.linuxtools.internal.valgrind.launch.ValgrindLaunchConfigurationDelegate; |
| 36 |
import org.eclipse.linuxtools.internal.valgrind.launch.ValgrindLaunchPlugin; |
| 37 |
import org.eclipse.linuxtools.internal.valgrind.launch.remote.Messages; |
| 38 |
import org.eclipse.linuxtools.internal.valgrind.launch.remote.ValgrindRemoteLaunchConstants; |
| 39 |
import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindUIPlugin; |
| 40 |
import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart; |
| 41 |
import org.eclipse.linuxtools.profiling.launch.remote.RemoteConnection; |
| 42 |
import org.eclipse.linuxtools.profiling.launch.remote.RemoteConnectionException; |
| 43 |
import org.eclipse.linuxtools.valgrind.core.IValgrindMessage; |
| 44 |
import org.eclipse.linuxtools.valgrind.launch.IValgrindOutputDirectoryProvider; |
| 45 |
|
| 46 |
public abstract class AbstractValgrindRemoteLaunchDelegate extends |
| 47 |
ValgrindLaunchConfigurationDelegate { |
| 48 |
|
| 49 |
private SubMonitor monitor; |
| 50 |
private IPath localOutputDir; |
| 51 |
private IPath remoteBinFile; |
| 52 |
private RemoteConnection rc; |
| 53 |
private String valgrindLocAttr; |
| 54 |
private String defaultValgrindLoc; |
| 55 |
|
| 56 |
public AbstractValgrindRemoteLaunchDelegate(String valgrindLocAttr, String defaultValgrindLoc) { |
| 57 |
super(); |
| 58 |
this.valgrindLocAttr = valgrindLocAttr; |
| 59 |
this.defaultValgrindLoc = defaultValgrindLoc; |
| 60 |
} |
| 61 |
|
| 62 |
public void launch(final ILaunchConfiguration config, String mode, |
| 63 |
final ILaunch launch, IProgressMonitor m) throws CoreException { |
| 64 |
if (m == null) { |
| 65 |
m = new NullProgressMonitor(); |
| 66 |
} |
| 67 |
|
| 68 |
// Clear process as we wait on it to be instantiated |
| 69 |
process = null; |
| 70 |
|
| 71 |
monitor = SubMonitor |
| 72 |
.convert( |
| 73 |
m, |
| 74 |
Messages.ValgrindRemoteLaunchDelegate_task_name, 10); |
| 75 |
// check for cancellation |
| 76 |
if (monitor.isCanceled()) { |
| 77 |
return; |
| 78 |
} |
| 79 |
|
| 80 |
this.config = config; |
| 81 |
this.launch = launch; |
| 82 |
try { |
| 83 |
// remove any output from previous run |
| 84 |
ValgrindUIPlugin.getDefault().resetView(); |
| 85 |
// reset stored launch data |
| 86 |
getPlugin().setCurrentLaunchConfiguration(null); |
| 87 |
getPlugin().setCurrentLaunch(null); |
| 88 |
|
| 89 |
rc = new RemoteConnection(config); |
| 90 |
monitor.worked(1); |
| 91 |
|
| 92 |
// Copy binary using FileSystem service |
| 93 |
final IPath exePath = CDebugUtils.verifyProgramPath(config); |
| 94 |
final IPath remoteDir = Path.fromOSString(config.getAttribute(ValgrindRemoteLaunchConstants.ATTR_REMOTE_DESTDIR, ValgrindRemoteLaunchConstants.DEFAULT_REMOTE_DESTDIR)); |
| 95 |
|
| 96 |
remoteBinFile = remoteDir.append(exePath.lastSegment()); |
| 97 |
|
| 98 |
rc.upload(exePath, remoteDir, new SubProgressMonitor(monitor, 1)); |
| 99 |
|
| 100 |
IPath remoteLogDir = Path.fromOSString(config.getAttribute(ValgrindRemoteLaunchConstants.ATTR_REMOTE_OUTPUTDIR, ValgrindRemoteLaunchConstants.DEFAULT_REMOTE_OUTPUTDIR)); |
| 101 |
outputPath = remoteLogDir.append("eclipse-valgrind-" + System.currentTimeMillis()); //$NON-NLS-1$ |
| 102 |
|
| 103 |
rc.createFolder(outputPath, new SubProgressMonitor(monitor, 1)); |
| 104 |
|
| 105 |
// Retrieve user-defined Valgrind binary location |
| 106 |
final IPath valgrindLocation = Path.fromOSString(config.getAttribute(valgrindLocAttr, defaultValgrindLoc)); |
| 107 |
String[] arguments = getProgramArgumentsArray(config); |
| 108 |
// create/empty local output directory |
| 109 |
IValgrindOutputDirectoryProvider provider = getPlugin().getOutputDirectoryProvider(); |
| 110 |
try { |
| 111 |
localOutputDir = provider.getOutputPath(); |
| 112 |
createDirectory(localOutputDir); |
| 113 |
} catch (IOException e2) { |
| 114 |
// TODO Auto-generated catch block |
| 115 |
e2.printStackTrace(); |
| 116 |
} |
| 117 |
|
| 118 |
// tool that was launched |
| 119 |
toolID = getTool(config); |
| 120 |
// ask tool extension for arguments |
| 121 |
dynamicDelegate = getDynamicDelegate(toolID); |
| 122 |
String[] opts = getValgrindArgumentsArray(config); |
| 123 |
Map<String, String> env = (Map<String, String>) config.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map<String, String>) null); |
| 124 |
boolean usePty = config.getAttribute( |
| 125 |
ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, |
| 126 |
ICDTLaunchConfigurationConstants.USE_TERMINAL_DEFAULT); |
| 127 |
|
| 128 |
String command = valgrindLocation.toString(); |
| 129 |
// Add valgrind options |
| 130 |
for (String opt : opts) { |
| 131 |
command += " " + opt; //$NON-NLS-1$ |
| 132 |
} |
| 133 |
// Add executable to run |
| 134 |
command += " " + remoteBinFile.toString(); |
| 135 |
// Add arguments to pass to executable |
| 136 |
for (String argument : arguments) { |
| 137 |
command += " " + argument; //$NON-NLS-1$ |
| 138 |
} |
| 139 |
@SuppressWarnings("unused") |
| 140 |
String[] output = rc.runCommand(command, remoteDir, new SubProgressMonitor(monitor, 1)); |
| 141 |
|
| 142 |
// delete remote binary |
| 143 |
rc.delete(remoteBinFile, new SubProgressMonitor(monitor, 1)); |
| 144 |
|
| 145 |
// move remote log files to local directory |
| 146 |
rc.download(outputPath, localOutputDir, new SubProgressMonitor(monitor, 1)); |
| 147 |
|
| 148 |
// remove remote log dir and all files under it |
| 149 |
rc.delete(outputPath, new SubProgressMonitor(monitor, 1)); |
| 150 |
|
| 151 |
// store these for use by other classes |
| 152 |
getPlugin().setCurrentLaunchConfiguration(config); |
| 153 |
getPlugin().setCurrentLaunch(launch); |
| 154 |
|
| 155 |
// parse Valgrind logs |
| 156 |
IValgrindMessage[] messages = parseLogs(localOutputDir); |
| 157 |
|
| 158 |
// create launch summary string to distinguish this launch |
| 159 |
launchStr = createLaunchStr(); |
| 160 |
|
| 161 |
// create view |
| 162 |
ValgrindUIPlugin.getDefault().createView(launchStr, toolID); |
| 163 |
// set log messages |
| 164 |
ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView(); |
| 165 |
view.setMessages(messages); |
| 166 |
monitor.worked(1); |
| 167 |
|
| 168 |
// pass off control to extender |
| 169 |
dynamicDelegate.handleLaunch(config, launch, localOutputDir, monitor.newChild(2)); |
| 170 |
|
| 171 |
// initialize tool-specific part of view |
| 172 |
dynamicDelegate.initializeView(view.getDynamicView(), launchStr, monitor.newChild(1)); |
| 173 |
|
| 174 |
// refresh view |
| 175 |
ValgrindUIPlugin.getDefault().refreshView(); |
| 176 |
|
| 177 |
// show view |
| 178 |
ValgrindUIPlugin.getDefault().showView(); |
| 179 |
monitor.worked(1); |
| 180 |
|
| 181 |
} catch (IOException e) { |
| 182 |
// TODO Auto-generated catch block |
| 183 |
e.printStackTrace(); |
| 184 |
} catch (RemoteConnectionException e) { |
| 185 |
// TODO Auto-generated catch block |
| 186 |
abort(e.getLocalizedMessage(), null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); |
| 187 |
} finally { |
| 188 |
monitor.done(); |
| 189 |
m.done(); |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
protected String createLaunchStr() { |
| 195 |
return config.getName() |
| 196 |
+ " [" + getPlugin().getToolName(toolID) + " on " + rc.getId() + "] "; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 197 |
} |
| 198 |
|
| 199 |
@Override |
| 200 |
protected String getPluginID() { |
| 201 |
return ValgrindLaunchPlugin.PLUGIN_ID; |
| 202 |
} |
| 203 |
|
| 204 |
public void onError(Throwable t) { |
| 205 |
// for now do nothing |
| 206 |
} |
| 207 |
|
| 208 |
} |