1
/*******************************************************************************
2
* Copyright (c) 2004, 2008, 2009, 2012 Red Hat, Inc. and others
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
9
* Kent Sebastian <ksebasti@redhat.com> - initial API and implementation
10
* Keith Seitz <keiths@redhat.com> - setup code in launch the method, initially
11
* written in the now-defunct OprofileSession class
12
* QNX Software Systems and others - the section of code marked in the launch
13
* method, and the exec method
14
* Red Hat Inc. - modification of OProfileLaunchConfigurationDelegate to here
15
*******************************************************************************/
16
package org.eclipse.linuxtools.internal.gcov.launch;
19
import java.util.List;
21
import org.eclipse.cdt.debug.core.CDebugUtils;
22
import org.eclipse.core.resources.IProject;
23
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.IPath;
25
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.Path;
27
import org.eclipse.debug.core.DebugPlugin;
28
import org.eclipse.debug.core.ILaunch;
29
import org.eclipse.debug.core.ILaunchConfiguration;
30
import org.eclipse.debug.core.ILaunchManager;
31
import org.eclipse.debug.core.ILaunchesListener2;
32
import org.eclipse.jface.dialogs.MessageDialog;
33
import org.eclipse.linuxtools.gcov.launch.GcovLaunchPlugin;
34
import org.eclipse.linuxtools.internal.gcov.parser.CovManager;
35
import org.eclipse.linuxtools.internal.gcov.view.CovView;
36
import org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher;
37
import org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationDelegate;
38
import org.eclipse.linuxtools.profiling.launch.RemoteProxyManager;
39
import org.eclipse.swt.widgets.Display;
40
import org.eclipse.swt.widgets.Shell;
41
import org.eclipse.ui.PlatformUI;
43
public class GcovLaunchConfigurationDelegate extends ProfileLaunchConfigurationDelegate {
44
protected ILaunchConfiguration config;
47
public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
49
IPath exePath = getExePath(config);
52
* this code written by QNX Software Systems and others and was
53
* originally in the CDT under LocalCDILaunchDelegate::RunLocalApplication
55
//set up and launch the local c/c++ program
56
IRemoteCommandLauncher launcher = RemoteProxyManager.getInstance().getLauncher(getProject());
58
URI workingDirURI = getProject().getLocationURI();
59
IPath workingDirPath = new Path(workingDirURI.getPath());
60
String arguments[] = getProgramArgumentsArray( config );
62
//add a listener for termination of the launch
63
ILaunchManager lmgr = DebugPlugin.getDefault().getLaunchManager();
64
lmgr.addLaunchListener(new LaunchTerminationWatcher(launch, exePath));
66
Process process = launcher.execute(exePath, arguments, getEnvironment(config), workingDirPath, monitor);
68
DebugPlugin.newProcess( launch, process, renderProcessLabel( exePath.toOSString() ) );
72
//A class used to listen for the termination of the current launch, and
73
// run some functions when it is finished.
74
class LaunchTerminationWatcher implements ILaunchesListener2 {
75
private ILaunch launch;
76
private IPath exePath;
77
public LaunchTerminationWatcher(ILaunch il, IPath exePath) {
79
this.exePath = exePath;
81
public void launchesTerminated(ILaunch[] launches) {
83
for (ILaunch l : launches) {
85
* Dump samples from the daemon,
86
* shut down the daemon,
87
* activate the OProfile view (open it if it isn't already),
88
* refresh the view (which parses the data/ui model and displays it).
90
if (l.equals(launch)) {
91
//need to run this in the ui thread otherwise get SWT Exceptions
92
// based on concurrency issues
93
Display.getDefault().syncExec(new Runnable() {
95
String s = exePath.toOSString();
96
CovManager cvrgeMnger = new CovManager(s, getProject());
99
List<String> gcdaPaths = cvrgeMnger.getGCDALocations();
100
if (gcdaPaths.size() == 0) {
101
String title = GcovLaunchMessages.GcovCompilerOptions_msg;
102
String message = GcovLaunchMessages.GcovCompileAgain_msg;
103
Shell parent = PlatformUI.getWorkbench().getDisplay().getActiveShell();
104
MessageDialog.openWarning(parent, title, message);
106
CovView.displayCovResults(s, null);
107
} catch (InterruptedException e) {
116
public void launchesAdded(ILaunch[] launches) { /* dont care */}
117
public void launchesChanged(ILaunch[] launches) { /* dont care */ }
118
public void launchesRemoved(ILaunch[] launches) { /* dont care */ }
123
protected String getPluginID() {
124
return GcovLaunchPlugin.getUniqueIdentifier();
127
/* all these functions exist to be overridden by the test class in order to allow launch testing */
129
protected IProject getProject(){
131
IProject project = CDebugUtils.verifyCProject(config).getProject();
133
} catch (CoreException e) {
140
* Return the exe path of the binary to be profiled.
142
* @return the exe path of the binary stored in the configuration
143
* @throws CoreException
146
protected IPath getExePath(ILaunchConfiguration config) throws CoreException{
147
IPath exePath = CDebugUtils.verifyProgramPath( config );
153
public String generateCommand(ILaunchConfiguration config) {