tmf: Move FunctionNameMapper (for the Callstack View) to the core plugin
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 11 Feb 2015 21:01:40 +0000 (16:01 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 12 Feb 2015 19:24:48 +0000 (14:24 -0500)
This also moves the dependency on cdt.core from tmf.ui to tmf.core.

Change-Id: Iefb44b7af16e281ec290115e66482ed3fbe84cc2
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/41686
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-by: Hudson CI
org.eclipse.tracecompass.tmf.core/META-INF/MANIFEST.MF
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/callstack/FunctionNameMapper.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.ui/META-INF/MANIFEST.MF
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/callstack/CallStackView.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/callstack/FunctionNameMapper.java [deleted file]

index d2f12b4f157b80bad9d7bd06a34dbe9423ace0f1..0b80e1e45dda8045d3913c929de60692820a3265 100644 (file)
@@ -11,9 +11,11 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.7
 Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.core.resources,
  org.eclipse.tracecompass.common.core,
- org.eclipse.tracecompass.statesystem.core;visibility:=reexport
+ org.eclipse.tracecompass.statesystem.core;visibility:=reexport,
+ org.eclipse.cdt.core
 Export-Package: org.eclipse.tracecompass.internal.tmf.core;x-friends:="org.eclipse.tracecompass.tmf.core.tests,org.eclipse.tracecompass.tmf.ui.swtbot.tests",
  org.eclipse.tracecompass.internal.tmf.core.analysis;x-friends:="org.eclipse.tracecompass.tmf.core.tests",
+ org.eclipse.tracecompass.internal.tmf.core.callstack;x-friends:="org.eclipse.tracecompass.tmf.ui",
  org.eclipse.tracecompass.internal.tmf.core.component;x-friends:="org.eclipse.tracecompass.tmf.core.tests",
  org.eclipse.tracecompass.internal.tmf.core.filter;x-friends:="org.eclipse.tracecompass.tmf.core.tests,org.eclipse.tracecompass.tmf.ui",
  org.eclipse.tracecompass.internal.tmf.core.parsers.custom;x-friends:="org.eclipse.tracecompass.tmf.ui",
diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/callstack/FunctionNameMapper.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/callstack/FunctionNameMapper.java
new file mode 100644 (file)
index 0000000..38ba9b8
--- /dev/null
@@ -0,0 +1,194 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 Ericsson
+ *
+ * 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:
+ *   Alexandre Montplaisir - Initial API and implementation
+ *   Marc-Andre Laperle - Map from binary file
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.core.callstack;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.IBinaryParser;
+import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
+import org.eclipse.cdt.core.IBinaryParser.ISymbol;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.tmf.core.Activator;
+
+/**
+ * Class containing the different methods to import an address->name mapping.
+ *
+ * @author Alexandre Montplaisir
+ */
+public class FunctionNameMapper {
+
+    /**
+     * Get the function name mapping from a text file obtained by doing
+     *
+     * <pre>
+     * nm[--demangle][binary] &gt; file.txt
+     * </pre>
+     *
+     * @param mappingFile
+     *            The file to import
+     * @return A map&lt;address, function name&gt; of the results
+     */
+    public static @Nullable Map<String, String> mapFromNmTextFile(File mappingFile) {
+        Map<String, String> map = new HashMap<>();
+
+        try (FileReader fr = new FileReader(mappingFile);
+                BufferedReader reader = new BufferedReader(fr);) {
+            for (String line = reader.readLine(); line != null; line = reader.readLine()) {
+                /* Only lines with 3 elements contain addresses */
+                String[] elems = line.split(" ", 3); //$NON-NLS-1$
+                if (elems.length == 3) {
+                    String address = stripLeadingZeros(elems[0]);
+                    String name = elems[elems.length - 1];
+                    map.put(address, name);
+                }
+            }
+        } catch (FileNotFoundException e) {
+            return null;
+        } catch (IOException e) {
+            /* Stop reading the file at this point */
+        }
+
+        if (map.isEmpty()) {
+            return null;
+        }
+        return Collections.unmodifiableMap(map);
+    }
+
+    /**
+     * Strip the leading zeroes from the address
+     * */
+    private static String stripLeadingZeros(String address) {
+        return address.replaceFirst("^0+(?!$)", "");  //$NON-NLS-1$ //$NON-NLS-2$;
+    }
+
+    /**
+     * Get the function name mapping from an executable binary.
+     *
+     * @param file
+     *            The file to import
+     * @return A map&lt;address, function name&gt; of the results
+     */
+    public static @Nullable Map<String, String> mapFromBinaryFile(File file) {
+        Map<String, String> map = new HashMap<>();
+        IBinaryParser.IBinaryObject binaryObject = getBinaryObject(file);
+        if (binaryObject != null) {
+            ISymbol[] symbols = binaryObject.getSymbols();
+            for (ISymbol symbol : symbols) {
+                String address = symbol.getAddress().toHexAddressString();
+                /* Remove "0x" */
+                address = address.substring(2);
+                /* Strip the leading zeroes from the address */
+                address = stripLeadingZeros(address);
+                map.put(address, symbol.getName());
+            }
+        }
+
+        return map;
+    }
+
+    private static @Nullable IBinaryParser.IBinaryObject getBinaryObject(File file) {
+        IPath filePath = new Path(file.toString());
+
+        /* Get all the available binary parsers */
+        final List<IBinaryParser> binaryParsers = new ArrayList<>();
+        IConfigurationElement[] elements = Platform.getExtensionRegistry()
+                .getConfigurationElementsFor(CCorePlugin.BINARY_PARSER_UNIQ_ID);
+        for (IConfigurationElement element : elements) {
+            IConfigurationElement[] children = element.getChildren("run"); //$NON-NLS-1$
+            for (final IConfigurationElement run : children) {
+                SafeRunner.run(new ISafeRunnable() {
+                    @Override
+                    public void run() throws Exception {
+                        IBinaryParser binaryParser = (IBinaryParser) run.createExecutableExtension("class"); //$NON-NLS-1$
+                        binaryParsers.add(binaryParser);
+                    }
+
+                    @Override
+                    public void handleException(Throwable exception) {
+                        Activator.logError("Error creating binary parser", exception); //$NON-NLS-1$
+                    }
+                });
+            }
+        }
+
+        /* Find the maximum "hint" buffer size we'll need from all the parsers */
+        int hintBufferSize = 0;
+        for (IBinaryParser parser : binaryParsers) {
+            if (parser.getHintBufferSize() > hintBufferSize) {
+                hintBufferSize = Math.max(hintBufferSize, parser.getHintBufferSize());
+            }
+        }
+
+        /* Read the initial "hint" bytes */
+        byte[] hintBuffer = new byte[hintBufferSize];
+        if (hintBufferSize > 0) {
+            try (InputStream is = new FileInputStream(file) ){
+
+                int count = 0;
+                // Make sure we read up to 'hints' bytes if we possibly can
+                while (count < hintBufferSize) {
+                    int bytesRead = is.read(hintBuffer, count, hintBufferSize - count);
+                    if (bytesRead < 0) {
+                        break;
+                    }
+                    count += bytesRead;
+                }
+                if (count > 0 && count < hintBuffer.length) {
+                    byte[] array = new byte[count];
+                    System.arraycopy(hintBuffer, 0, array, 0, count);
+                    hintBuffer = array;
+                }
+            } catch (IOException e) {
+                Activator.logError("Error reading initial bytes of binary file", e); //$NON-NLS-1$
+                return null;
+            }
+        }
+
+        /* For all binary parsers, try to get a binary object */
+        for (IBinaryParser parser : binaryParsers) {
+            if (parser.isBinary(hintBuffer, filePath)) {
+                IBinaryFile binFile;
+                try {
+                    binFile = parser.getBinary(hintBuffer, filePath);
+                    if (binFile != null && binFile instanceof IBinaryParser.IBinaryObject) {
+                        return (IBinaryParser.IBinaryObject)binFile;
+                    }
+                } catch (IOException e) {
+                    Activator.logError("Error parsing binary file", e); //$NON-NLS-1$
+                }
+            }
+        }
+
+        return null;
+    }
+
+}
index 3b5ce783f9bdb095c1a1c32651ee6dcd39107ae3..93b4faf4c3b2d85f83a60dcbdf5e476c6686d754 100644 (file)
@@ -19,7 +19,6 @@ Require-Bundle: org.eclipse.core.expressions,
  org.eclipse.ui.navigator,
  org.eclipse.ui.navigator.resources,
  org.swtchart,
- org.eclipse.cdt.core,
  com.ibm.icu
 Export-Package: org.eclipse.tracecompass.internal.tmf.ui;x-friends:="org.eclipse.tracecompass.tmf.ui.tests,org.eclipse.tracecompass.tmf.ctf.ui.tests",
  org.eclipse.tracecompass.internal.tmf.ui.commands;x-internal:=true,
index 8bc13e063c510216cb81599952a825a8e5fff755..17f81851afd33b3c3ebff3a9bd7079762002bfed 100644 (file)
@@ -59,6 +59,7 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.Tree;
+import org.eclipse.tracecompass.internal.tmf.core.callstack.FunctionNameMapper;
 import org.eclipse.tracecompass.internal.tmf.ui.Activator;
 import org.eclipse.tracecompass.internal.tmf.ui.ITmfImageConstants;
 import org.eclipse.tracecompass.internal.tmf.ui.Messages;
diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/callstack/FunctionNameMapper.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/callstack/FunctionNameMapper.java
deleted file mode 100644 (file)
index 62e908b..0000000
+++ /dev/null
@@ -1,177 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013, 2014 Ericsson
- *
- * 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:
- *   Alexandre Montplaisir - Initial API and implementation
- *   Marc-Andre Laperle - Map from binary file
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ui.views.callstack;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.IBinaryParser;
-import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
-import org.eclipse.cdt.core.IBinaryParser.ISymbol;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.ISafeRunnable;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.internal.tmf.ui.Activator;
-
-/**
- * Class containing the different methods to import an address->name mapping.
- *
- * @author Alexandre Montplaisir
- */
-class FunctionNameMapper {
-
-    public static @Nullable Map<String, String> mapFromNmTextFile(File mappingFile) {
-        Map<String, String> map = new HashMap<>();
-
-        try (FileReader fr = new FileReader(mappingFile);
-                BufferedReader reader = new BufferedReader(fr);) {
-            for (String line = reader.readLine(); line != null; line = reader.readLine()) {
-                /* Only lines with 3 elements contain addresses */
-                String[] elems = line.split(" ", 3); //$NON-NLS-1$
-                if (elems.length == 3) {
-                    /* Strip the leading zeroes from the address */
-                    String address = elems[0].replaceFirst("^0+(?!$)", ""); //$NON-NLS-1$ //$NON-NLS-2$;
-                    String name = elems[elems.length - 1];
-                    map.put(address, name);
-                }
-            }
-        } catch (FileNotFoundException e) {
-            return null;
-        } catch (IOException e) {
-            /* Stop reading the file at this point */
-        }
-
-        if (map.isEmpty()) {
-            return null;
-        }
-        return Collections.unmodifiableMap(map);
-    }
-
-    /**
-     * Strip the leading zeroes from the address
-     * */
-    private static String stripLeadingZeros(String address) {
-        return address.replaceFirst("^0+(?!$)", "");  //$NON-NLS-1$ //$NON-NLS-2$;
-    }
-
-    public static @Nullable Map<String, String> mapFromBinaryFile(File file) {
-        Map<String, String> map = new HashMap<>();
-        IBinaryParser.IBinaryObject binaryObject = getBinaryObject(file);
-        if (binaryObject != null) {
-            ISymbol[] symbols = binaryObject.getSymbols();
-            for (ISymbol symbol : symbols) {
-                String address = symbol.getAddress().toHexAddressString();
-                /* Remove "0x" */
-                address = address.substring(2);
-                /* Strip the leading zeroes from the address */
-                address = stripLeadingZeros(address);
-                map.put(address, symbol.getName());
-            }
-        }
-
-        return map;
-    }
-
-    private static @Nullable IBinaryParser.IBinaryObject getBinaryObject(File file) {
-        IPath filePath = new Path(file.toString());
-
-        /* Get all the available binary parsers */
-        final List<IBinaryParser> binaryParsers = new ArrayList<>();
-        IConfigurationElement[] elements = Platform.getExtensionRegistry()
-                .getConfigurationElementsFor(CCorePlugin.BINARY_PARSER_UNIQ_ID);
-        for (IConfigurationElement element : elements) {
-            IConfigurationElement[] children = element.getChildren("run"); //$NON-NLS-1$
-            for (final IConfigurationElement run : children) {
-                SafeRunner.run(new ISafeRunnable() {
-                    @Override
-                    public void run() throws Exception {
-                        IBinaryParser binaryParser = (IBinaryParser) run.createExecutableExtension("class"); //$NON-NLS-1$
-                        binaryParsers.add(binaryParser);
-                    }
-
-                    @Override
-                    public void handleException(Throwable exception) {
-                        Activator.getDefault().logError("Error creating binary parser", exception); //$NON-NLS-1$
-                    }
-                });
-            }
-        }
-
-        /* Find the maximum "hint" buffer size we'll need from all the parsers */
-        int hintBufferSize = 0;
-        for (IBinaryParser parser : binaryParsers) {
-            if (parser.getHintBufferSize() > hintBufferSize) {
-                hintBufferSize = Math.max(hintBufferSize, parser.getHintBufferSize());
-            }
-        }
-
-        /* Read the initial "hint" bytes */
-        byte[] hintBuffer = new byte[hintBufferSize];
-        if (hintBufferSize > 0) {
-            try (InputStream is = new FileInputStream(file) ){
-
-                int count = 0;
-                // Make sure we read up to 'hints' bytes if we possibly can
-                while (count < hintBufferSize) {
-                    int bytesRead = is.read(hintBuffer, count, hintBufferSize - count);
-                    if (bytesRead < 0) {
-                        break;
-                    }
-                    count += bytesRead;
-                }
-                if (count > 0 && count < hintBuffer.length) {
-                    byte[] array = new byte[count];
-                    System.arraycopy(hintBuffer, 0, array, 0, count);
-                    hintBuffer = array;
-                }
-            } catch (IOException e) {
-                Activator.getDefault().logError("Error reading initial bytes of binary file", e); //$NON-NLS-1$
-                return null;
-            }
-        }
-
-        /* For all binary parsers, try to get a binary object */
-        for (IBinaryParser parser : binaryParsers) {
-            if (parser.isBinary(hintBuffer, filePath)) {
-                IBinaryFile binFile;
-                try {
-                    binFile = parser.getBinary(hintBuffer, filePath);
-                    if (binFile != null && binFile instanceof IBinaryParser.IBinaryObject) {
-                        return (IBinaryParser.IBinaryObject)binFile;
-                    }
-                } catch (IOException e) {
-                    Activator.getDefault().logError("Error parsing binary file", e); //$NON-NLS-1$
-                }
-            }
-        }
-
-        return null;
-    }
-
-}
This page took 0.041358 seconds and 5 git commands to generate.