1
/*******************************************************************************
2
* Copyright (c) 2009 Red Hat, Inc.
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
* Red Hat - initial API and implementation
10
*******************************************************************************/
12
package org.eclipse.linuxtools.internal.callgraph.launch;
14
import java.io.BufferedReader;
16
import java.io.FileReader;
17
import java.io.IOException;
18
import java.util.ArrayList;
20
import org.eclipse.cdt.core.model.IBinary;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
23
import org.eclipse.linuxtools.internal.callgraph.core.PluginConstants;
24
import org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages;
25
import org.eclipse.ui.IEditorPart;
27
public class LaunchStapGraph extends SystemTapLaunchShortcut {
30
//TODO: Do not let this class persist, or otherwise change it so persistence doesn't matter.
31
private String partialScriptPath;
33
private ArrayList<String> exclusions;
34
private String projectName;
35
protected static final String ATTR_PARSER = "org.eclipse.linuxtools.callgraph.graphparser"; //$NON-NLS-1$
36
protected static final String ATTR_VIEWER = "org.eclipse.linuxtools.callgraph.callgraphview"; //$NON-NLS-1$
40
public LaunchStapGraph() {
42
exclusions = new ArrayList<String>();
48
public void launch(IEditorPart ed, String mode) {
49
resourceToSearchFor = ed.getTitle();
50
searchForResource = true;
52
//Note: This launch will eventually end up calling
53
//launch(IBinary bin, String mode) below
54
super.launch(ed, mode);
57
public void launch(IBinary bin, String mode) {
58
launch(bin, mode, null);
61
public void launch(IBinary bin, String mode, ILaunchConfigurationWorkingCopy wc) {
64
name = "SystemTapGraph"; //$NON-NLS-1$
65
binName = getName(bin);
66
partialScriptPath = PluginConstants.getPluginLocation()
67
+ "parse_function_partial.stp"; //$NON-NLS-1$
69
viewID = "org.eclipse.linuxtools.callgraph.callgraphview"; //$NON-NLS-1$
73
projectName = bin.getCProject().getElementName();
77
wc = createConfiguration(bin, name);
78
binaryPath = bin.getResource().getLocation().toString();
79
binaryPath = escapeSpecialCharacters(binaryPath);
80
arguments = binaryPath;
81
outputPath = PluginConstants.getDefaultIOPath();
83
if (writeFunctionListToScript(resourceToSearchFor) == null)
85
if (funcs == null || funcs.length() < 0)
88
needToGenerate = true;
89
finishLaunch(name, mode, wc);
91
} catch (IOException e) {
92
SystemTapUIErrorMessages mess = new SystemTapUIErrorMessages(
93
"LaunchShortcutScriptGen", //$NON-NLS-1$
94
Messages.getString("LaunchStapGraph.ScriptGenErr"), //$NON-NLS-1$
95
Messages.getString("LaunchStapGraph.ScriptGenErrMsg")); //$NON-NLS-1$
98
} catch (CoreException e1) {
100
} catch (Exception e) {
103
resourceToSearchFor = ""; //$NON-NLS-1$
104
searchForResource = false;
110
public void setFuncs(String val) {
115
* Generates the call and return function probes for the specified function
119
private String generateProbe(String function) {
120
String output = "probe process(@1).function(\"" + function + "\").call ? { if ( ! isinstr(probefunc(), \"___STAP_MARKER___\")) { callFunction(probefunc(),tid()) } } probe process(@1).function(\"" + function + "\").return ? { if ( ! isinstr(probefunc(), \"___STAP_MARKER___\")) returnFunction(probefunc(),tid()) else { printf(\"?%d,,%s\\n\", tid(), user_string(strtol(tokenize($$return, \"return=\"),16)))}}\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
125
* Prompts the user for a list of functions to probe
129
* @throws IOException
131
public String writeFunctionListToScript(String resourceToSearchFor) throws IOException {
132
String toWrite = getFunctionsFromBinary(bin, resourceToSearchFor);
134
if (toWrite == null || toWrite.length() < 1) {
138
StringBuffer output = new StringBuffer();
140
for (String func : toWrite.split(" ")) { //$NON-NLS-1$
141
if (func.length() > 0) {
142
if (exclusions == null || exclusions.size() < 1 || exclusions.contains(func) ) {
143
output.append(generateProbe(func));
148
funcs = output.toString();
153
* Copies the contents of the specified partial script. You should call writeStapMarkers first
154
* if you want StapMarkers to function properly.
158
* @throws IOException
160
private String writeFromPartialScript(String projectName) throws IOException {
161
String toWrite = ""; //$NON-NLS-1$
162
String temp = ""; //$NON-NLS-1$
163
toWrite += "\nprobe begin{\n" + //$NON-NLS-1$
164
"printf(\"\\nPROBE_BEGIN\\n\")\n" + //$NON-NLS-1$
165
"serial=1\n" + //$NON-NLS-1$
166
"startTime = 0;\n" + //$NON-NLS-1$
167
"printf(\"" + projectName + "\\n\")\n" + //$NON-NLS-1$ //$NON-NLS-2$
169
File partialScript = new File(partialScriptPath);
170
BufferedReader scriptReader = new BufferedReader(new FileReader(
172
while ((temp = scriptReader.readLine()) != null) {
173
toWrite += temp + "\n"; //$NON-NLS-1$
175
scriptReader.close();
181
public void setExclusions(ArrayList<String> e) {
186
public String generateScript() throws IOException {
188
String scriptContents = ""; //$NON-NLS-1$
191
// scriptContents += writeStapMarkers();
193
scriptContents += funcs;
195
scriptContents += writeFromPartialScript(projectName);
197
return scriptContents;
200
public void setPartialScriptPath(String val) {
201
partialScriptPath = val;
205
public String setScriptPath() {
206
scriptPath = PluginConstants.getDefaultOutput()
207
+ "callgraphGen.stp"; //$NON-NLS-1$
212
public String setParserID() {
213
parserID = ATTR_PARSER;
218
public String setViewID() {
223
// * Determines whether or not the user wants StapMarkers and inserts them. To
224
// * disable StapMarkers, simply stop calling this function. This should be called
225
// * before writeFromPartialScript.
229
// * @throws IOException
231
// private String writeStapMarkers() throws IOException {
232
// String toWrite = Messages.getString("LaunchStapGraph.26"); //$NON-NLS-1$
233
// if (MessageDialog.openQuestion(new Shell(),
234
// Messages.getString("LaunchStapGraph.27"), //$NON-NLS-1$
235
// Messages.getString("LaunchStapGraph.28") //$NON-NLS-1$
236
// + Messages.getString("LaunchStapGraph.29"))) { //$NON-NLS-1$
237
// toWrite = Messages.getString("LaunchStapGraph.30") //$NON-NLS-1$
238
// + Messages.getString("LaunchStapGraph.31") //$NON-NLS-1$
239
// + Messages.getString("LaunchStapGraph.32") //$NON-NLS-1$
240
// + Messages.getString("LaunchStapGraph.33") //$NON-NLS-1$
241
// + Messages.getString("LaunchStapGraph.34") //$NON-NLS-1$
242
// + Messages.getString("LaunchStapGraph.35") //$NON-NLS-1$
243
// + Messages.getString("LaunchStapGraph.36") //$NON-NLS-1$
244
// + Messages.getString("LaunchStapGraph.37") //$NON-NLS-1$
245
// + Messages.getString("LaunchStapGraph.38") //$NON-NLS-1$
246
// + Messages.getString("LaunchStapGraph.39") + Messages.getString("LaunchStapGraph.40"); //$NON-NLS-1$ //$NON-NLS-2$
247
// partialScriptPath = PluginConstants.getPluginLocation()
248
// + Messages.getString("LaunchStapGraph.41"); //$NON-NLS-1$