diff options
author | Andrew Ferrazzutti | 2014-03-05 18:35:40 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2014-04-05 05:57:44 +0000 |
commit | 95fe2d52b52a516ec7bf422cba92a2ab5bc03df8 (patch) | |
tree | eeda5dcc2f2eec68a7fdd61b2076d051f99ff28f /systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal | |
parent | d42f1aa8fc3ef77ee436f65da8b38c1023f234ac (diff) | |
download | org.eclipse.linuxtools-95fe2d52b52a516ec7bf422cba92a2ab5bc03df8.tar.gz org.eclipse.linuxtools-95fe2d52b52a516ec7bf422cba92a2ab5bc03df8.tar.xz org.eclipse.linuxtools-95fe2d52b52a516ec7bf422cba92a2ab5bc03df8.zip |
Systemtap: Make some fixes to Probe & Function views.
-The icons next to Function view entries now correctly
represent the return type of functions and the variable
type of their parameters.
-Fix a bug that prevented some tapset functions, as well
as probe aliases, from being available in their appropriate
views (EBZ #429800).
-Remove an error from the stap-calling command in TapsetParser
that caused a crash when booting Eclipse with imported tapsets
(EBZ #429597). Also allow the parser to capture a script's error
output, in case the output of a verbose run is ever needed.
-Modify OpenFileAction to allow the Probe & Function views
to open a file without user interaction, and without forcing
the file's editor to use a PathEditorInput (which may open a
duplicate editor).
Change-Id: I0820534a2bc6c1d79ed75570d29d4992b05d920d
Signed-off-by: Andrew Ferrazzutti <aferrazz@redhat.com>
Reviewed-on: https://git.eclipse.org/r/23075
Reviewed-by: Alexander Kurtakov <akurtako@redhat.com>
IP-Clean: Alexander Kurtakov <akurtako@redhat.com>
Tested-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal')
9 files changed, 230 insertions, 155 deletions
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/CommentRemover.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/CommentRemover.java new file mode 100644 index 0000000000..06e039ea7a --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/CommentRemover.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2013 Red Hat. + * All rights reserved. This program and the accompanying materials + * 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 - Andrew Ferrazzutti + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.systemtap.ui.ide; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +/** + * A helper class for removing comments from a SystemTap script. + */ +public class CommentRemover { + + /** + * Remove comments from a .stp file in the filesystem. + * @param filename The filename of the script to remove comments from. + * @return The copy of the script with comments removed. + */ + public static String execWithFile(String filename) { + try (BufferedReader br = new BufferedReader(new FileReader(filename))) { + StringBuffer buffer = new StringBuffer(); + String line; + while ((line = br.readLine()) != null) { + buffer.append(line.concat("\n")); //$NON-NLS-1$ + } + return exec(buffer.toString()); + } catch (IOException e) { + return ""; //$NON-NLS-1$ + } + } + /** + * Remove comments from a .stp script. + * @param contents A complete .stp script. + * @return A copy of the script with comments removed. + */ + public static String exec(String contents) { + if (contents == null || contents.isEmpty()) { + return ""; //$NON-NLS-1$ + } + + char curchar, nxtchar; + boolean inQuotes = false; + boolean inComment = false; + + int c = 0; + StringBuffer buffer = new StringBuffer(); + + do { + curchar = contents.charAt(c++); + nxtchar = c < contents.length() ? contents.charAt(c) : '\0'; + + // Comment tags don't count if they are in a string. + if (!inQuotes) { + if (!inComment) { + if (curchar == '#' || (curchar == '/' && nxtchar == '/')) { + inQuotes = false; + c = contents.indexOf('\n', c + 1); + continue; + } + if (curchar == '/' && nxtchar == '*') { + inComment = true; + c++; //Skip the * on the next character scan. + continue; + } + } + else if (curchar == '*' && nxtchar == '/') { + inComment = false; + c++; //Skip the / on the next character scan. + continue; + } + } + + // Quotes only count if they aren't commented out. + if (!inComment) { + if (curchar == '\"') { + inQuotes = !inQuotes; + } + else if (curchar == '\n') { + inQuotes = false; + } + + buffer.append(curchar); + } + + } while (c != -1 && c < contents.length()); + + return buffer.toString(); + } +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/DefinitionAction.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/DefinitionAction.java index 7db1b13164..16ccf23a08 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/DefinitionAction.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/DefinitionAction.java @@ -11,21 +11,21 @@ package org.eclipse.linuxtools.internal.systemtap.ui.ide.actions; -import org.eclipse.core.runtime.Path; +import java.io.File; + import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.STPEditor; -import org.eclipse.linuxtools.systemtap.graphing.ui.widgets.ExceptionErrorDialog; +import org.eclipse.linuxtools.systemtap.structures.FunctionNodeData; import org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode; -import org.eclipse.linuxtools.systemtap.ui.editor.PathEditorInput; +import org.eclipse.linuxtools.systemtap.ui.editor.actions.file.OpenFileAction; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; -import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; @@ -59,23 +59,20 @@ public class DefinitionAction extends Action implements IObjectActionDelegate, I return; TreeDefinitionNode t = (TreeDefinitionNode)o; String filename = t.getDefinition(); - Path p = new Path(filename); - - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - PathEditorInput input = new PathEditorInput(p); - try { - IEditorPart editorPart = window.getActivePage().openEditor(input, STPEditor.ID); + File file = new File(filename); + OpenFileAction open = new OpenFileAction(); + open.run(file); + if (open.isSuccessful()) { + IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); STPEditor editor = (STPEditor)editorPart; int line; - if(t.getData().toString().startsWith("probe")) //$NON-NLS-1$ + if (!(t.getData() instanceof FunctionNodeData)) line = probeFind(t, editor); else line = functionFind(t, editor); editor.jumpToLocation(++line, 0); - } catch (PartInitException e) { - ExceptionErrorDialog.openError(Messages.ScriptRunAction_errorDialogTitle, e); } } @@ -87,10 +84,13 @@ public class DefinitionAction extends Action implements IObjectActionDelegate, I * @return int representing the line where the node is defined */ private int functionFind(TreeDefinitionNode t, STPEditor editor) { - String func = t.toString(); - int line = editor.findRegex("^function " + func + ".*\\(.*\\)"); //$NON-NLS-1$ //$NON-NLS-2$ - if(line < 0) - line = editor.find(func); + int line = editor.find(t.getData().toString()); + if(line < 0) { + line = editor.findRegex("(?<!\\w)function " + t.toString()); //$NON-NLS-1$ + if(line < 0) { + line = editor.find(t.toString()); + } + } return Math.max(line, 0); } diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/ProbeAliasAction.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/ProbeAliasAction.java index d250a2285c..4a97882598 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/ProbeAliasAction.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/ProbeAliasAction.java @@ -233,10 +233,10 @@ public class ProbeAliasAction extends Action implements ISelectionListener, IDou private IEditorPart openNewFile() { NewFileAction action = new NewFileAction(); action.run(); - if (action.wasCancelled()) { - return null; + if (action.isSuccessful()) { + return window.getActivePage().getActiveEditor(); } - return window.getActivePage().getActiveEditor(); + return null; } @Override diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/CommentRemover.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/CommentRemover.java deleted file mode 100644 index 39c8de6aaa..0000000000 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/CommentRemover.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.eclipse.linuxtools.internal.systemtap.ui.ide.launcher; - -class CommentRemover { - - public static String exec(String contents) { - if (contents.isEmpty()) { - return ""; //$NON-NLS-1$ - } - - char curchar, nxtchar; - boolean inQuotes = false; - boolean inComment = false; - - int c = 0; - StringBuffer buffer = new StringBuffer(); - - do { - curchar = contents.charAt(c++); - nxtchar = c < contents.length() ? contents.charAt(c) : '\0'; - - // Comment tags don't count if they are in a string. - if (!inQuotes) { - if (!inComment) { - if (curchar == '#' || (curchar == '/' && nxtchar == '/')) { - inQuotes = false; - c = contents.indexOf('\n', c + 1); - continue; - } - if (curchar == '/' && nxtchar == '*') { - inComment = true; - c++; //Skip the * on the next character scan. - continue; - } - } - else if (curchar == '*' && nxtchar == '/') { - inComment = false; - c++; //Skip the / on the next character scan. - continue; - } - } - - // Quotes only count if they aren't commented out. - if (!inComment) { - if (curchar == '\"') { - inQuotes = !inQuotes; - } - else if (curchar == '\n') { - inQuotes = false; - } - - buffer.append(curchar); - } - - } while (c != -1 && c < contents.length()); - - return buffer.toString(); - } -}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptGraphOptionsTab.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptGraphOptionsTab.java index 53cbe67640..52c58608e9 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptGraphOptionsTab.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptGraphOptionsTab.java @@ -36,6 +36,7 @@ import org.eclipse.debug.ui.ILaunchConfigurationTab; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.linuxtools.internal.systemtap.ui.ide.CommentRemover; import org.eclipse.linuxtools.internal.systemtap.ui.ide.IDEPlugin; import org.eclipse.linuxtools.systemtap.graphing.core.datasets.IDataSet; import org.eclipse.linuxtools.systemtap.graphing.core.datasets.IDataSetParser; diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/FunctionParser.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/FunctionParser.java index 059fb39416..d2d4f87bd1 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/FunctionParser.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/FunctionParser.java @@ -11,7 +11,7 @@ package org.eclipse.linuxtools.internal.systemtap.ui.ide.structures; -import java.io.File; +import java.text.MessageFormat; import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -19,8 +19,9 @@ import java.util.regex.Pattern; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.linuxtools.internal.systemtap.ui.ide.CommentRemover; import org.eclipse.linuxtools.internal.systemtap.ui.ide.IDEPlugin; -import org.eclipse.linuxtools.internal.systemtap.ui.ide.preferences.IDEPreferenceConstants; +import org.eclipse.linuxtools.systemtap.structures.FunctionNodeData; import org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode; import org.eclipse.linuxtools.systemtap.structures.TreeNode; @@ -45,16 +46,12 @@ public class FunctionParser extends TapsetParser { if (parser != null) { return parser; } - - String[] tapsets = IDEPlugin.getDefault().getPreferenceStore() - .getString(IDEPreferenceConstants.P_TAPSETS).split(File.pathSeparator); - parser = new FunctionParser(tapsets); - + parser = new FunctionParser(); return parser; } - private FunctionParser(String[] tapsets) { - super(tapsets, "Function Parser"); //$NON-NLS-1$ + private FunctionParser() { + super("Function Parser"); //$NON-NLS-1$ functions = new TreeNode("", false); //$NON-NLS-1$ } @@ -81,59 +78,86 @@ public class FunctionParser extends TapsetParser { * 'probe begin{}' and parsing the output. */ private void runPass2Functions() { - int i = 0; - TreeNode parent; String script = "probe begin{}"; //$NON-NLS-1$ - String result = runStap(new String[] {"-v", "-p1", "-e"}, script); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + String result = runStap(new String[] {"-v", "-p1", "-e"}, script, false); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ if (result == null) { return; } StringTokenizer st = new StringTokenizer(result, "\n", false); //$NON-NLS-1$ st.nextToken(); //skip that stap command String tok = ""; //$NON-NLS-1$ - String regex = "^function .*\\)\n$"; //match ^function and ending the line with ')' //$NON-NLS-1$ - String pathname = null; - Pattern p = Pattern.compile(regex, Pattern.MULTILINE | Pattern.UNIX_LINES | Pattern.COMMENTS); - Pattern secondp = Pattern.compile("[\\W]"); //take our function line and split it up //$NON-NLS-1$ - Pattern underscorep = Pattern.compile("^function _.*"); //remove any lines that "^function _" //$NON-NLS-1$ - Pattern allCaps = Pattern.compile("[A-Z_1-9]*"); //$NON-NLS-1$ - Pattern pathnamep = Pattern.compile("^# file (/.*\\.stp)"); //$NON-NLS-1$ + String filename = null; + String scriptText = null; + + String functionRegex = "(?s)(?<!\\w)function\\s+({0})(?:\\s*:\\s*(\\w+))?\\s*\\(([^)]+?)?\\)"; //$NON-NLS-1$ + // Get functions (with proper typing) directly from the .stp files being used by stap. + Pattern pFilename = Pattern.compile("# file (/.*\\.stp)"); //$NON-NLS-1$ + Pattern pFunction = Pattern.compile("function (?!_)(\\w+) \\(.*?\\)"); //Ignore functions starting with _. //$NON-NLS-1$ + Pattern pParams = Pattern.compile("(\\w+)(?:\\s*:\\s*(\\w+))?"); //$NON-NLS-1$ + Pattern pAllCaps = Pattern.compile("[A-Z_1-9]*"); //$NON-NLS-1$ + Pattern pReturn = Pattern.compile("\\sreturn\\W"); //$NON-NLS-1$ + while(st.hasMoreTokens()) { tok = st.nextToken(); - Matcher m = p.matcher(tok); - while(m.find()) { - // this gives us function foo (bar, bar) - // we need to strip the ^function and functions with a leading _ - String functionLine = m.group(); - String[] us = underscorep.split(functionLine); - - for(String s : us) { - String[] test = secondp.split(s); - i = 0; - for(String t : test) { - // If i== 1 this is a function name. - // Ignore ALL_CAPS functions; they are not meant for end - // user use. - if(i == 1 && !allCaps.matcher(t).matches()) { - // A function node's data is the entire function line. - functions.add(new TreeDefinitionNode(functionLine, t, pathname, true)); + Matcher mFilename = pFilename.matcher(tok); + if(mFilename.matches()) { + filename = mFilename.group(1).toString(); + scriptText = null; + } else if (filename != null) { + Matcher mFunction = pFunction.matcher(tok); + if(mFunction.matches()) { + // Ignore ALL_CAPS functions, since they are not meant for end-user use. + String functionName = mFunction.group(1); + if (pAllCaps.matcher(functionName).matches()) { + continue; + } + if (scriptText == null) { + scriptText = CommentRemover.execWithFile(filename); + } + Matcher mScript = Pattern.compile(MessageFormat.format(functionRegex, functionName)).matcher(scriptText); + while (mScript.find()) { + String functionLine = mScript.group(); + String functionType = mScript.group(2); + // If the function has no return type, look for a "return" statement to check + // if it's really a void function, or if its return type is just unspecified + if (functionType == null && searchForPattern(scriptText, mScript.end(), pReturn)) { + functionType = FunctionNodeData.UNKNOWN_TYPE; } - else if(i > 1 && t.length() >= 1) { - parent = functions.getChildAt(functions.getChildCount()-1); - parent.add(new TreeNode(t, t, false)); + TreeDefinitionNode function = new TreeDefinitionNode( + new FunctionNodeData(functionLine, functionType), + functionName, filename, true); + functions.add(function); + // Add all function parameters that exist + String params = mScript.group(3); + if (params != null) { + Matcher mParams = pParams.matcher(params); + while (mParams.find()) { + function.add(new TreeNode( + new FunctionNodeData(null, mParams.group(2)), + mParams.group(1), false)); + } } - i++; } } } - Matcher f = pathnamep.matcher(tok); - if(f.find()) { - pathname = f.group(1).toString(); - } } functions.sortTree(); } + private boolean searchForPattern(String scriptText, int start, Pattern p) { + int end, bcount = 1; + start = scriptText.indexOf('{', start) + 1; + for (end = start; end < scriptText.length(); end++) { + char c = scriptText.charAt(end); + if (c == '{') { + bcount++; + } else if (c == '}' && --bcount == 0) { + break; + } + } + return p.matcher(scriptText.substring(start, end)).find(); + } + /** * This method will clean up everything from the run. */ diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/ProbeParser.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/ProbeParser.java index bd9cf9f4bd..4589a2882a 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/ProbeParser.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/ProbeParser.java @@ -24,7 +24,6 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.linuxtools.internal.systemtap.ui.ide.IDEPlugin; -import org.eclipse.linuxtools.internal.systemtap.ui.ide.preferences.IDEPreferenceConstants; import org.eclipse.linuxtools.systemtap.graphing.ui.widgets.ExceptionErrorDialog; import org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode; import org.eclipse.linuxtools.systemtap.structures.TreeNode; @@ -50,16 +49,12 @@ public class ProbeParser extends TapsetParser { if (parser != null) { return parser; } - - String[] tapsets = IDEPlugin.getDefault().getPreferenceStore() - .getString(IDEPreferenceConstants.P_TAPSETS).split(File.pathSeparator); - parser = new ProbeParser(tapsets); - + parser = new ProbeParser(); return parser; } - private ProbeParser(String[] tapsets) { - super(tapsets, "Probe Parser"); //$NON-NLS-1$ + private ProbeParser() { + super("Probe Parser"); //$NON-NLS-1$ probes = new TreeNode("", false); //$NON-NLS-1$ } @@ -102,7 +97,7 @@ public class ProbeParser extends TapsetParser { options = null; } - String s = runStap(options, script); + String s = runStap(options, script, false); if (s == null) { return ""; //$NON-NLS-1$ } diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/TapsetParser.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/TapsetParser.java index 67bb2f666e..ccf4245f55 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/TapsetParser.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/TapsetParser.java @@ -11,9 +11,9 @@ package org.eclipse.linuxtools.internal.systemtap.ui.ide.structures; +import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.dialogs.MessageDialog; @@ -52,9 +52,10 @@ public abstract class TapsetParser extends Job { private String[] tapsets; protected boolean cancelRequested; - protected TapsetParser(String[] tapsets, String jobTitle) { + protected TapsetParser(String jobTitle) { super(jobTitle); - this.tapsets = Arrays.copyOf(tapsets, tapsets.length); + this.tapsets = IDEPlugin.getDefault().getPreferenceStore() + .getString(IDEPreferenceConstants.P_TAPSETS).split(File.pathSeparator); listeners = new ArrayList<>(); cancelRequested = false; } @@ -98,38 +99,37 @@ public abstract class TapsetParser extends Job { * Runs the stap with the given options and returns the output generated * @param options String[] of any optional parameters to pass to stap * @param probe String containing the script to run stap on - * @since 1.2 + * @param getErrors Set this to <code>true</code> if the script's error + * stream contents should be returned instead of its standard output */ - protected String runStap(String[] options, String probe) { + protected String runStap(String[] options, String probe, boolean getErrors) { String[] args = null; int size = 2; //start at 2 for stap, script, options will be added in later - if (null != tapsets && tapsets.length > 0 && tapsets[0].trim().length() > 0) { + if (tapsets.length > 0 && tapsets[0].trim().length() > 0) { size += tapsets.length<<1; } - if (null != options && options.length > 0 && options[0].trim().length() > 0) { + if (options.length > 0 && options[0].trim().length() > 0) { size += options.length; } args = new String[size]; args[0] = "stap"; //$NON-NLS-1$ args[size-1] = probe; - args[size-2] = ""; //$NON-NLS-1$ //Add extra tapset directories - if(null != tapsets && tapsets.length > 0 && tapsets[0].trim().length() > 0) { + if(tapsets.length > 0 && tapsets[0].trim().length() > 0) { for(int i=0; i<tapsets.length; i++) { - args[2+(i<<1)] = "-I"; //$NON-NLS-1$ - args[3+(i<<1)] = tapsets[i]; + args[1+(i<<1)] = "-I"; //$NON-NLS-1$ + args[2+(i<<1)] = tapsets[i]; } } if(null != options && options.length > 0 && options[0].trim().length() > 0) { for(int i=0; i<options.length; i++) { - args[args.length-options.length-1+i] = options[i]; + args[size-1-options.length+i] = options[i]; } } - String output = null; try { if (IDEPlugin.getDefault().getPreferenceStore().getBoolean(IDEPreferenceConstants.P_REMOTE_PROBES)) { StringOutputStream str = new StringOutputStream(); @@ -145,18 +145,29 @@ public abstract class TapsetParser extends Job { displayError(Messages.TapsetParser_CannotRunStapTitle, Messages.TapsetParser_CannotRunStapMessage); } - output = str.toString(); + return (!getErrors ? str : strErr).toString(); } else { Process process = SystemtapProcessFactory.exec(args, null); if(process == null){ displayError(Messages.TapsetParser_CannotRunStapTitle, Messages.TapsetParser_CannotRunStapMessage); - return output; + return null; } StringStreamGobbler gobbler = new StringStreamGobbler(process.getInputStream()); + StringStreamGobbler egobbler = null; gobbler.start(); + if (getErrors) { + egobbler = new StringStreamGobbler(process.getErrorStream()); + egobbler.start(); + } process.waitFor(); - output = gobbler.getOutput().toString(); + gobbler.stop(); + if (egobbler == null) { + return gobbler.getOutput().toString(); + } else { + egobbler.stop(); + return egobbler.getOutput().toString(); + } } } catch (JSchException e) { @@ -168,7 +179,7 @@ public abstract class TapsetParser extends Job { e.printStackTrace(); } - return output; + return null; } private void displayError(final String title, final String error){ diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/views/FunctionBrowserView.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/views/FunctionBrowserView.java index 7dae1a0ccd..4beb5ce4e1 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/views/FunctionBrowserView.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/views/FunctionBrowserView.java @@ -16,6 +16,7 @@ import org.eclipse.jface.action.Separator; import org.eclipse.linuxtools.internal.systemtap.ui.ide.IDEPlugin; import org.eclipse.linuxtools.internal.systemtap.ui.ide.actions.FunctionBrowserAction; import org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.TapsetLibrary; +import org.eclipse.linuxtools.systemtap.structures.FunctionNodeData; import org.eclipse.linuxtools.systemtap.structures.TreeNode; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; @@ -51,17 +52,20 @@ public class FunctionBrowserView extends BrowserView { @Override protected Image getEntryImage(TreeNode treeObj) { - String item = treeObj.getData().toString(); - if (item.startsWith("function")) { //$NON-NLS-1$ - item = item.substring(0, item.indexOf('(')).trim(); + if (!(treeObj.getData() instanceof FunctionNodeData)) { + return null; } - if(item.endsWith(":long")) {//$NON-NLS-1$ + FunctionNodeData d = (FunctionNodeData) treeObj.getData(); + String type = d.getType(); + if (type == null) { + return IDEPlugin.getImageDescriptor("icons/vars/var_void.gif").createImage(); //$NON-NLS-1$ + } else if(type.equals("long")) {//$NON-NLS-1$ return IDEPlugin.getImageDescriptor("icons/vars/var_long.gif").createImage(); //$NON-NLS-1$ - } - if(item.endsWith(":string")) {//$NON-NLS-1$ + } else if(type.equals("string")) {//$NON-NLS-1$ return IDEPlugin.getImageDescriptor("icons/vars/var_str.gif").createImage(); //$NON-NLS-1$ + } else { + return IDEPlugin.getImageDescriptor("icons/vars/var_unk.gif").createImage(); //$NON-NLS-1$ } - return IDEPlugin.getImageDescriptor("icons/vars/var_void.gif").createImage(); //$NON-NLS-1$ } /** |