callgraph: make callgraph runnable with the current systemtap

- Move escaping of characters to the final stage of writing the launch script.
- Use --runtime=dyninst to work around missing return probes.
- Remove the use of probefunc() as it is not supported in dyninst mode.
- Replace the use of -o with redirecting the output as dyninst does not support -o.
- Update tests to expect the new command output format.
- Save actions:
  Organize imports.
  Add braces.
  Remove trailing white space.

This is a combination of two patches commited to master.
Reviewed here: https://git.eclipse.org/r/13654
and here: https://git.eclipse.org/r/13711

Change-Id: Id6ecafc94b745ad4a84d7484b47bb4270a9fa6ae
Reviewed-on: https://git.eclipse.org/r/13741
Tested-by: Hudson CI
Reviewed-by: Roland Grunberg <rgrunber@redhat.com>
IP-Clean: Roland Grunberg <rgrunber@redhat.com>
Tested-by: Roland Grunberg <rgrunber@redhat.com>
diff --git a/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/PluginConstants.java b/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/PluginConstants.java
index 96a25f9..cb33dda 100644
--- a/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/PluginConstants.java
+++ b/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/PluginConstants.java
@@ -4,14 +4,14 @@
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * 
+ *
  * Contributors:
  *     Red Hat - initial API and implementation
  *******************************************************************************/
 package org.eclipse.linuxtools.internal.callgraph.core;
 
 public final class PluginConstants {
-	
+
 	private static String PLUGIN_LOCATION = ""; //$NON-NLS-1$
 	public static final String CONFIGURATION_TYPE_ID = "org.eclipse.linuxtools.callgraph.launch.systemtapLaunch";	 //$NON-NLS-1$
 	public static final String PARSER_CLASS = "org.eclipse.linuxtools.callgraph.core.parser"; //$NON-NLS-1$
@@ -23,21 +23,21 @@
 	public static final String ATTR_CLASS = "class"; //$NON-NLS-1$
 	public static final String ATTR_REALTIME = "realtime"; //$NON-NLS-1$
 	public static final String VAL_TRUE = "true"; //$NON-NLS-1$
-	
+
 	public static final String NEW_LINE = "\n"; //$NON-NLS-1$
 	public static final int MAX_ERRORS = 500;	//Maximum number of errors to tolerate
 	public static int SYSTEMTAP_OPTIONS_TAB_HORIZONTAL_SPACING = 30;
 	public static String STAP_PATH = "stap"; //$NON-NLS-1$
-	
+
 	public static final String DEFAULT_VIEW_ID = "org.eclipse.linuxtools.callgraph.core.staptextview"; //$NON-NLS-1$
 	public static final String DEFAULT_PARSER_ID = "org.eclipse.linuxtools.callgraph.core.systemtaptextparser"; //$NON-NLS-1$
 	private static String DEFAULT_OUTPUT = ""; //$NON-NLS-1$
 	private static String STAP_GRAPH_DEFAULT_IO_PATH = ""; //$NON-NLS-1$
-	
+
 	/**
 	 * Sets the absolute path of the Plugin folder and updates
 	 * the PLUGIN_LOCATION.
-	 * 
+	 *
 	 * @param loc
 	 */
 	public static void setPluginLocation(String loc) {
@@ -45,23 +45,28 @@
 	}
 
 	public static String getPluginLocation() {
-		if (PLUGIN_LOCATION.length() < 1)
+		if (PLUGIN_LOCATION.length() < 1) {
 			PluginConstants.setPluginLocation(CallgraphCorePlugin.getPluginLocation());
-		
+		}
+
 		return PLUGIN_LOCATION;
 	}
 
 	public static String getDefaultOutput() {
-		if (DEFAULT_OUTPUT.length() < 1)
+		if (DEFAULT_OUTPUT.length() < 1){
 			DEFAULT_OUTPUT = CallgraphCorePlugin.getDefault().getStateLocation().toString()+"/"; //$NON-NLS-1$
+		}
+
 		return DEFAULT_OUTPUT;
 	}
-	
+
 	public static String getDefaultIOPath() {
 		if (STAP_GRAPH_DEFAULT_IO_PATH.length() < 1)
+		 {
 			STAP_GRAPH_DEFAULT_IO_PATH = CallgraphCorePlugin.getDefault().getStateLocation().toString()+"/callgraph.out"; //$NON-NLS-1$
+		}
 		return STAP_GRAPH_DEFAULT_IO_PATH;
 	}
-	
-	
+
+
 }
diff --git a/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/SystemTapCommandGenerator.java b/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/SystemTapCommandGenerator.java
index 235f5c7..b816618 100644
--- a/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/SystemTapCommandGenerator.java
+++ b/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/SystemTapCommandGenerator.java
@@ -38,7 +38,7 @@
 		binaryPath = binPath;
 		scriptPath = scrPath;
 		isGuru = false;
-		arguments = arg;
+		arguments = "--runtime=dyninst " + arg; //$NON-NLS-1$
 		flags = opts;
 		binaryArguments = binArguments;
 		command = cmdTarget;
diff --git a/systemtap/org.eclipse.linuxtools.callgraph.launch.tests/src/org/eclipse/linuxtools/callgraph/launch/tests/ConfigurationTest.java b/systemtap/org.eclipse.linuxtools.callgraph.launch.tests/src/org/eclipse/linuxtools/callgraph/launch/tests/ConfigurationTest.java
index a72b6ab..64edeac 100644
--- a/systemtap/org.eclipse.linuxtools.callgraph.launch.tests/src/org/eclipse/linuxtools/callgraph/launch/tests/ConfigurationTest.java
+++ b/systemtap/org.eclipse.linuxtools.callgraph.launch.tests/src/org/eclipse/linuxtools/callgraph/launch/tests/ConfigurationTest.java
@@ -33,9 +33,9 @@
 
 		String testCDirectives = "-DRandomjunk -DMoreJunk";
 		String testOutputPath = "/tmp/ThisFileDoesNothingDeleteIt";
-		String testBinaryPath = "More random junk";
+		String testBinaryPath = "/path/to/binary";
 		String testScriptPath = "/tmp/NotAScriptFile.stp";
-		String testArguments = "Nonexistent Arguments";
+		String testArguments = "/path/to/binary";
 		int testPid = 413;
 		int testBuffer = 100;
 		int testPass = 10;
@@ -86,9 +86,9 @@
 
 		assertEquals("stap -v -p" + testPass + " -k -g -P -u -w -b -t -s"
 				+ testBuffer + " -x" + testPid + " " + testCDirectives
-				+ " -F --skip-badvars --ignore-dwarf -q " + "-o "
-				+ testOutputPath + " -c '" + testBinaryPath + "' "
-				+ testScriptPath + " " + testArguments,
+				+ " -F --skip-badvars --ignore-dwarf -q " + " -c '" + testBinaryPath
+				+ "' " + testScriptPath + " --runtime=dyninst " + testArguments + " >& "
+				+ testOutputPath,
 				del.generateCommand(config));
 
 		killStap();
diff --git a/systemtap/org.eclipse.linuxtools.callgraph.launch.tests/src/org/eclipse/linuxtools/callgraph/launch/tests/SystemTapCommandGeneratorTest.java b/systemtap/org.eclipse.linuxtools.callgraph.launch.tests/src/org/eclipse/linuxtools/callgraph/launch/tests/SystemTapCommandGeneratorTest.java
index f2113af..e9c671a 100644
--- a/systemtap/org.eclipse.linuxtools.callgraph.launch.tests/src/org/eclipse/linuxtools/callgraph/launch/tests/SystemTapCommandGeneratorTest.java
+++ b/systemtap/org.eclipse.linuxtools.callgraph.launch.tests/src/org/eclipse/linuxtools/callgraph/launch/tests/SystemTapCommandGeneratorTest.java
@@ -4,7 +4,7 @@
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * 
+ *
  * Contributors:
  *     Red Hat - initial API and implementation
  *******************************************************************************/
@@ -15,13 +15,13 @@
 import org.eclipse.linuxtools.internal.callgraph.core.PluginConstants;
 import org.eclipse.linuxtools.internal.callgraph.core.SystemTapCommandGenerator;
 
-public class SystemTapCommandGeneratorTest extends AbstractStapTest{ 
-	
+public class SystemTapCommandGeneratorTest extends AbstractStapTest{
+
 	//HACK TO GET THE PATH TO THE TESTING PROJECT
 	File file = new File("");
 	private String location = file.getAbsolutePath() + "/";
 	SystemTapCommandGenerator stapgen = new SystemTapCommandGenerator();
-	
+
 	public void testExecutionWithScriptAndBinaryAndArgument(){
 
 		String binaryFilePath = location + "factorial";
@@ -32,12 +32,12 @@
 				binaryFilePath, "", true, true, binaryFilePath, "",
 				PluginConstants.STAP_PATH);
 
-		assertEquals("stap -c '" + binaryFilePath + "' " + scriptPath + " "
+		assertEquals("stap -c '" + binaryFilePath + "' " + scriptPath + " --runtime=dyninst "
 				+ binaryFilePath, cmd);
 		killStap();
 		// END
 	}
-	
+
 	public void testScriptExecution(){
 
 		String scriptPath = location + "simple.stp";
@@ -61,7 +61,7 @@
 
 		assertEquals("stap -c '" + binaryFilePath + "' " + scriptPath, cmd);
 		// END
-		
+
 		killStap();
 	}
 
diff --git a/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/CallgraphLaunchPlugin.java b/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/CallgraphLaunchPlugin.java
index dc76ce9..4b05b8d 100644
--- a/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/CallgraphLaunchPlugin.java
+++ b/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/CallgraphLaunchPlugin.java
@@ -80,4 +80,5 @@
 	public static Shell getActiveWorkbenchShell() {
 		return getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
 	}
+
 }
diff --git a/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/LaunchStapGraph.java b/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/LaunchStapGraph.java
index 58c675e..d823ada 100644
--- a/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/LaunchStapGraph.java
+++ b/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/LaunchStapGraph.java
@@ -70,17 +70,19 @@
 		projectName = bin.getCProject().getElementName();
 
 		try {
-			if (wc == null)
+			if (wc == null) {
 				wc = createConfiguration(bin, name);
+			}
 			binaryPath = bin.getResource().getLocation().toString();
-			binaryPath = escapeSpecialCharacters(binaryPath);
 			arguments = binaryPath;
 			outputPath = PluginConstants.getDefaultIOPath();
 
-			if (writeFunctionListToScript(resourceToSearchFor) == null)
+			if (writeFunctionListToScript(resourceToSearchFor) == null) {
 				return;
-			if (funcs == null || funcs.length() < 0)
+			}
+			if (funcs == null || funcs.length() < 0) {
 				return;
+			}
 
 			needToGenerate = true;
 			finishLaunch(name, mode, wc);
@@ -110,7 +112,7 @@
 	 * @return
 	 */
 	private String generateProbe(String function) {
-		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$
+		String output = "probe process(@1).function(\"" + function + "\").call ? {	if ( ! isinstr(\"" + function + "\", \"___STAP_MARKER___\")) { callFunction(\"" + function + "\",tid()) } 	}	probe process(@1).function(\"" + function + "\").return ? {		if ( ! isinstr(\"" + function + "\", \"___STAP_MARKER___\")) returnFunction(\"" + function + "\",tid())	else { printf(\"?%d,,%s\\n\", tid(), user_string(strtol(tokenize($$return, \"return=\"),16)))}}\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
 		return output;
 	}
 
diff --git a/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/LaunchWizard.java b/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/LaunchWizard.java
index 01003a2..59660f7 100644
--- a/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/LaunchWizard.java
+++ b/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/LaunchWizard.java
@@ -249,7 +249,6 @@
 			public void widgetSelected(SelectionEvent e) {
 					scriptPath = scriptLocation.getText();
 					binaryPath = binaryLocation.getText();
-					binaryPath = escapeSpecialCharacters(binaryPath);
 					arguments = argumentsLocation.getText();
 					ILaunchConfigurationWorkingCopy wc = createConfiguration(null, name);
 					try {
diff --git a/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/SystemTapLaunchConfigurationDelegate.java b/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/SystemTapLaunchConfigurationDelegate.java
index 4c89ef9..e2b7fe1 100644
--- a/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/SystemTapLaunchConfigurationDelegate.java
+++ b/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/SystemTapLaunchConfigurationDelegate.java
@@ -4,7 +4,7 @@
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * 
+ *
  * Contributors:
  *     Red Hat - initial API and implementation
  *******************************************************************************/
@@ -43,11 +43,13 @@
 /**
  * Delegate for Stap scripts. The Delegate generates part of the command string
  * and schedules a job to finish generation of the command and execute.
- * 
+ *
  */
 public class SystemTapLaunchConfigurationDelegate extends
 		ProfileLaunchConfigurationDelegate {
 
+	private static final String [] escapableChars = new String []  {"(", ")", " "}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
 	private static final String TEMP_ERROR_OUTPUT =
 		PluginConstants.getDefaultOutput() + "stapTempError.error"; //$NON-NLS-1$
 	private String cmd;
@@ -68,7 +70,7 @@
 	protected String getPluginID() {
 		return null;
 	}
-	
+
 	/**
 	 * Sets strings to blank, booleans to false and everything else to null
 	 */
@@ -83,11 +85,11 @@
 		 useColour = false;
 		 binaryArguments = ""; //$NON-NLS-1$
 	}
-	
+
 	@Override
 	public void launch(ILaunchConfiguration config, String mode,
 			ILaunch launch, IProgressMonitor m) throws CoreException {
-		
+
 		if (m == null) {
 			m = new NullProgressMonitor();
 		}
@@ -99,13 +101,14 @@
 		if (monitor.isCanceled()) {
 			return;
 		}
-		
+
 		/*
 		 * Set variables
 		 */
 		if (config.getAttribute(LaunchConfigurationConstants.USE_COLOUR,
-				LaunchConfigurationConstants.DEFAULT_USE_COLOUR))
-			useColour = true; 
+				LaunchConfigurationConstants.DEFAULT_USE_COLOUR)) {
+			useColour = true;
+		}
 		if (!config.getAttribute(LaunchConfigurationConstants.ARGUMENTS,
 				LaunchConfigurationConstants.DEFAULT_ARGUMENTS).equals(
 				LaunchConfigurationConstants.DEFAULT_ARGUMENTS)) {
@@ -153,21 +156,20 @@
 				e1.printStackTrace();
 			}
 		}
-		
+
 		stap = config.getAttribute(LaunchConfigurationConstants.COMMAND,
 				PluginConstants.STAP_PATH);
 
 		/**
 		 * Generate partial command
 		 */
-		partialCommand = ConfigurationOptionsSetter.setOptions(config);  
+		partialCommand = ConfigurationOptionsSetter.setOptions(config);
 
 		outputPath = config.getAttribute(
 				LaunchConfigurationConstants.OUTPUT_PATH,
 				PluginConstants.getDefaultOutput());
-		partialCommand += "-o " + outputPath; //$NON-NLS-1$
 
-		boolean fileExists;
+		boolean fileExists = true;
 		try {
 			//Make sure the output file exists
 			File tempFile = new File(outputPath);
@@ -188,19 +190,21 @@
 
 		finishLaunch(launch, config, m, true);
 	}
-	
+
 	/**
 	 * Returns the current SystemTap command, or returns an error message.
 	 * @return
 	 */
 	public String getCommand() {
-		if (cmd.length() > 0)
+		if (cmd.length() > 0) {
 			return cmd;
-		else
+		}
+		else {
 			return Messages.getString("SystemTapLaunchConfigurationDelegate.NoCommand"); //$NON-NLS-1$
+		}
 	}
 
-	private void finishLaunch(ILaunch launch, ILaunchConfiguration config, 
+	private void finishLaunch(ILaunch launch, ILaunchConfiguration config,
 			IProgressMonitor monitor, boolean retry) {
 
 		try {
@@ -212,16 +216,16 @@
 
 			// set the default source locator if required
 			setDefaultSourceLocator(launch, config);
-			
+
 			/*
-			 * Fetch a parser 
+			 * Fetch a parser
 			 */
-			String parserClass = config.getAttribute(LaunchConfigurationConstants.PARSER_CLASS, 
+			String parserClass = config.getAttribute(LaunchConfigurationConstants.PARSER_CLASS,
 					LaunchConfigurationConstants.DEFAULT_PARSER_CLASS);
 			IExtensionRegistry reg = Platform.getExtensionRegistry();
 			IConfigurationElement[] extensions = reg
-					.getConfigurationElementsFor(PluginConstants.PARSER_RESOURCE, 
-							PluginConstants.PARSER_NAME, 
+					.getConfigurationElementsFor(PluginConstants.PARSER_RESOURCE,
+							PluginConstants.PARSER_NAME,
 							parserClass);
 			if (extensions == null || extensions.length < 1) {
 				SystemTapUIErrorMessages mess = new SystemTapUIErrorMessages(Messages.getString("SystemTapLaunchConfigurationDelegate.InvalidParser1"),  //$NON-NLS-1$
@@ -231,11 +235,11 @@
 				mess.schedule();
 				return;
 			}
-			
+
 			IConfigurationElement element = extensions[0];
-			SystemTapParser parser = 
+			SystemTapParser parser =
 				(SystemTapParser) element.createExecutableExtension(PluginConstants.ATTR_CLASS);
-			
+
 			//Set parser options
 			parser.setViewID(config.getAttribute(LaunchConfigurationConstants.VIEW_CLASS,
 					LaunchConfigurationConstants.VIEW_CLASS));
@@ -246,13 +250,13 @@
 					LaunchConfigurationConstants.DEFAULT_SECONDARY_VIEW_ID));
 
 			parser.setKillButtonEnabled(true);
-						
+
 			monitor.worked(1);
 
 			/*
 			 * Launch
 			 */
-			
+
 			File workDir = getWorkingDirectory(config);
 			if (workDir == null) {
 				workDir = new File(System.getProperty("user.home", ".")); //$NON-NLS-1$ //$NON-NLS-2$
@@ -260,7 +264,7 @@
 
 			//Put command into a shell script
 			String cmd = generateCommand(config);
-			File script = File.createTempFile("org.eclipse.linuxtools.profiling.launch" + System.currentTimeMillis(), ".sh");
+			File script = File.createTempFile("org.eclipse.linuxtools.profiling.launch" + System.currentTimeMillis(), ".sh"); //$NON-NLS-1$ //$NON-NLS-2$
 			String data = "#!/bin/sh\nexec " + cmd; //$NON-NLS-1$
 			FileOutputStream out = null;
 			try {
@@ -282,10 +286,10 @@
 			process.setAttribute(IProcess.ATTR_CMDLINE,cmd);
 
 			monitor.worked(1);
-			
+
 			StreamListener s = new StreamListener();
 			process.getStreamsProxy().getErrorStreamMonitor().addListener(s);
-			
+
 			while (!process.isTerminated()) {
 				Thread.sleep(100);
 				if ((monitor != null && monitor.isCanceled()) || parser.isDone()) {
@@ -306,45 +310,46 @@
 							Messages.getString("SystemTapLaunchConfigurationDelegate.CallGraphGenericError"), //$NON-NLS-1$
 							Messages.getString("SystemTapLaunchConfigurationDelegate.CallGraphGenericError"), //$NON-NLS-1$
 							Messages.getString("SystemTapLaunchConfigurationDelegate.stapNotFound")); //$NON-NLS-1$
-					
+
 					errorDialog.schedule();
 				}else{
 					SystemTapErrorHandler errorHandler = new SystemTapErrorHandler();
-					
+
 					//Prepare stap information
 					errorHandler.appendToLog(config.getName() + Messages.getString("SystemTapLaunchConfigurationDelegate.stap_command") + cmd+ PluginConstants.NEW_LINE + PluginConstants.NEW_LINE);//$NON-NLS-1$
-					
+
 					//Handle error from TEMP_ERROR_OUTPUT
 					errorHandler.handle(monitor, new FileReader(TEMP_ERROR_OUTPUT));
-					if ((monitor != null && monitor.isCanceled()))
+					if ((monitor != null && monitor.isCanceled())) {
 						return;
-					
+					}
+
 					errorHandler.finishHandling(monitor, scriptPath);
 					if (errorHandler.isErrorRecognized()) {
 						SystemTapUIErrorMessages errorDialog = new SystemTapUIErrorMessages(
 								Messages.getString("SystemTapLaunchConfigurationDelegate.CallGraphGenericError"),  //$NON-NLS-1$
 								Messages.getString("SystemTapLaunchConfigurationDelegate.CallGraphGenericError"),  //$NON-NLS-1$
 								errorHandler.getErrorMessage());
-						
+
 						errorDialog.schedule();
 					}
 				}
 				return;
 			}
-			
+
 			if (element.getAttribute(PluginConstants.ATTR_REALTIME).equals(PluginConstants.VAL_TRUE)) {
 				parser.setRealTime(true);
 			}
-			
+
 			parser.schedule();
 			monitor.worked(1);
-			
+
 			String message = generateErrorMessage(config.getName(), binaryArguments);
-			
+
 			DocWriter dw = new DocWriter(Messages.getString("SystemTapLaunchConfigurationDelegate.DocWriterName"),  //$NON-NLS-1$
 					(Helper.getConsoleByName(config.getName())), message);
 			dw.schedule();
-			
+
 		} catch (IOException e) {
 			e.printStackTrace();
 		} catch (InterruptedException e) {
@@ -353,17 +358,17 @@
 			e.printStackTrace();
 		} finally {
 			monitor.done();
-			
+
 		}
 	}
-	
+
 	private String generateErrorMessage(String configName, String binaryCommand) {
 		String output = ""; //$NON-NLS-1$
-		
+
 		if (binaryCommand == null || binaryCommand.length() < 0) {
 			output = PluginConstants.NEW_LINE +
 						PluginConstants.NEW_LINE + "-------------" + //$NON-NLS-1$
-						PluginConstants.NEW_LINE + 
+						PluginConstants.NEW_LINE +
 						Messages.getString("SystemTapLaunchConfigurationDelegate.Relaunch10") //$NON-NLS-1$
 						+ configName + PluginConstants.NEW_LINE +
 						Messages.getString("SystemTapLaunchConfigurationDelegate.Relaunch8") + //$NON-NLS-1$
@@ -371,9 +376,9 @@
 						"configuration in Profile As --> Profile Configurations." + //$NON-NLS-1$
 						PluginConstants.NEW_LINE + PluginConstants.NEW_LINE;
 		} else {
-			output = PluginConstants.NEW_LINE 
+			output = PluginConstants.NEW_LINE
 					+ PluginConstants.NEW_LINE +"-------------" //$NON-NLS-1$
-					+ PluginConstants.NEW_LINE 
+					+ PluginConstants.NEW_LINE
 					+ Messages.getString("SystemTapLaunchConfigurationDelegate.EndMessage1")  //$NON-NLS-1$
 					+ configName + PluginConstants.NEW_LINE +
 					Messages.getString("SystemTapLaunchConfigurationDelegate.EndMessage2") //$NON-NLS-1$
@@ -383,14 +388,14 @@
 					Messages.getString("SystemTapLaunchConfigurationDelegate.EndMessage5") +  //$NON-NLS-1$
 					PluginConstants.NEW_LINE + PluginConstants.NEW_LINE;
 		}
-			
+
 		return output;
 	}
 
 	private static class StreamListener implements IStreamListener{
 		private int counter;
 		private BufferedWriter bw;
-		
+
 		public StreamListener() throws IOException {
 			File file = new File(TEMP_ERROR_OUTPUT);
 			file.delete();
@@ -398,14 +403,17 @@
 			bw = Helper.setBufferedWriter(TEMP_ERROR_OUTPUT);
 			counter = 0;
 		}
-		
+
 		@Override
 		public void streamAppended(String text, IStreamMonitor monitor) {
 			try {
-				if (text.length() < 1) return;
+				if (text.length() < 1) {
+					return;
+				}
 				counter++;
-				if (counter < PluginConstants.MAX_ERRORS)
+				if (counter < PluginConstants.MAX_ERRORS) {
 					bw.append(text);
+				}
 			} catch (IOException e) {
 				e.printStackTrace();
 			}
@@ -418,8 +426,24 @@
 
 	public String generateCommand(ILaunchConfiguration config) {
 		// Generate the command
-		cmd = SystemTapCommandGenerator.generateCommand(scriptPath, binaryPath,
-				partialCommand, needsBinary, needsArguments, arguments, binaryArguments, stap);
+		cmd = SystemTapCommandGenerator.generateCommand(escapeSpecialCharacters(scriptPath), escapeSpecialCharacters(binaryPath),
+				partialCommand, needsBinary, needsArguments, escapeSpecialCharacters(arguments), binaryArguments, stap);
+		cmd += " >& " + escapeSpecialCharacters(outputPath); //$NON-NLS-1$
 		return cmd;
 	}
+
+	/**
+	 * Escapes special characters in the target string
+	 *
+	 * @param script the script to be executed by the shell.
+	 * @return the formatted string that will be executed.
+	 */
+	private String escapeSpecialCharacters(String str) {
+		// Modify script to catch escapable characters.
+		String res = str;
+		for (int i = 0; i < escapableChars.length; i++) {
+			res = res.replace(escapableChars[i], "\\" + escapableChars[i]); //$NON-NLS-1$
+		}
+		return res;
+	}
 }
diff --git a/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/SystemTapLaunchShortcut.java b/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/SystemTapLaunchShortcut.java
index 02974c2..9a890be 100644
--- a/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/SystemTapLaunchShortcut.java
+++ b/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/SystemTapLaunchShortcut.java
@@ -130,7 +130,6 @@
 	private Button OKButton;
 	private boolean testMode = false;
 	protected String secondaryID = ""; //$NON-NLS-1$
-	private final String [] escapableChars = new String []  {"(", ")", " "}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 
 	/**
 	 * Initialize variables. Highly recommend calling this function within the
@@ -233,7 +232,6 @@
 				wc.setAttribute(LaunchConfigurationConstants.BINARY_PATH,binaryPath);
 			}
 
-			outputPath = escapeSpecialCharacters(outputPath);
 			wc.setAttribute(LaunchConfigurationConstants.OUTPUT_PATH,outputPath);
 			wc.setAttribute(LaunchConfigurationConstants.ARGUMENTS, arguments);
 			wc.setAttribute(LaunchConfigurationConstants.GENERATED_SCRIPT,generatedScript);
@@ -637,7 +635,7 @@
 							if (!(validElement(c))) {
 								continue;
 							}
-							if (c.getElementName().contains("main") && !output.contains(c)) {
+							if (c.getElementName().contains("main") && !output.contains(c)) { //$NON-NLS-1$
 								output.add(c);
 							}
 						}
@@ -796,7 +794,7 @@
 	}
 
 	/**
-	 * Function for generating scripts. Should be overriden by interested
+	 * Function for generating scripts. Should be overridden by interested
 	 * classes
 	 *
 	 * @throws IOException
@@ -935,7 +933,6 @@
 
 			ILaunchConfigurationWorkingCopy wc = createConfiguration(bin, name);
 			binaryPath = bin.getResource().getLocation().toString();
-			binaryPath = escapeSpecialCharacters(binaryPath);
 			arguments = binaryPath;
 			outputPath = PluginConstants.getDefaultIOPath();
 			finishLaunch(name, mode, wc);
@@ -971,18 +968,4 @@
 		return ""; //$NON-NLS-1$
 	}
 
-	/**
-	 * Escapes special characters in the target string
-	 *
-	 * @param script the script to be executed by the shell.
-	 * @return the formatted string that will be executed.
-	 */
-	protected String escapeSpecialCharacters(String str) {
-		// Modify script to catch escapable characters.
-		String res = str;
-		for (int i = 0; i < escapableChars.length; i++) {
-			res = res.replace(escapableChars[i], "\\" + escapableChars[i]); //$NON-NLS-1$
-		}
-		return res;
-	}
 }