tmf: Exclude GNU and deprecated CDT binary parser extensions

CDT GNU binary parsers now require a CProject configuration.
https://github.com/eclipse-cdt/cdt/issues/652

Exclude GNU and deprecated binary parser extensions.

Use CCorePlugin to get binary parsers.

Change-Id: I23387df519d89d5ab346270204bffd764f58e7dd
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/c/tracecompass/org.eclipse.tracecompass/+/206235
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/callstack/FunctionNameMapper.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/callstack/FunctionNameMapper.java
index bf8d039..cd0b602 100644
--- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/callstack/FunctionNameMapper.java
+++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/callstack/FunctionNameMapper.java
@@ -37,7 +37,7 @@
 import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
 import org.eclipse.cdt.core.IBinaryParser.ISymbol;
 import org.eclipse.cdt.utils.CPPFilt;
-import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.ISafeRunnable;
 import org.eclipse.core.runtime.Path;
@@ -49,6 +49,7 @@
 import org.eclipse.tracecompass.tmf.core.symbols.TmfResolvedSymbol;
 
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
 
 /**
  * Class containing the different methods to import an address->name mapping.
@@ -65,6 +66,8 @@
     private static final Pattern REMOVE_ZEROS_PATTERN = Pattern.compile("^0+(?!$)"); //$NON-NLS-1$
     private static final Pattern NM_PATTERN = Pattern.compile("([0-9a-f]+)([\\s][a-zA-Z][\\s])(.+)"); //$NON-NLS-1$
     private static final Pattern MAP_WITH_SIZE_PATTERN = Pattern.compile("([0-9a-f]+)[\\s]([a-f0-9]+)[\\s](.+)"); //$NON-NLS-1$
+    private static final String DEPRECATED = "(Deprecated)"; //$NON-NLS-1$
+    private static final String GNU = "GNU"; //$NON-NLS-1$
 
     /**
      * The type of mapping used in a file. Each type of mapping has its pattern
@@ -268,24 +271,30 @@
 
         /* 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(Objects.requireNonNull(binaryParser));
-                    }
+        IExtension[] extensions = Platform.getExtensionRegistry().
+                getExtensionPoint(CCorePlugin.BINARY_PARSER_UNIQ_ID).getExtensions();
 
-                    @Override
-                    public void handleException(@Nullable Throwable exception) {
-                        Activator.logError("Error creating binary parser", exception); //$NON-NLS-1$
-                    }
-                });
-            }
+        /*
+         * Remove GNU extensions that require CProject configuration and
+         * deprecated extensions
+         */
+        List<IExtension> filteredExtensions = Lists.newArrayList(extensions);
+        filteredExtensions.removeIf(ext -> ext.getLabel().startsWith(GNU));
+        filteredExtensions.removeIf(ext -> ext.getLabel().endsWith(DEPRECATED));
+
+        for (IExtension extension : filteredExtensions) {
+            SafeRunner.run(new ISafeRunnable() {
+                @Override
+                public void run() throws Exception {
+                    IBinaryParser binaryParser = CCorePlugin.getDefault().getBinaryParser(extension.getUniqueIdentifier());
+                    binaryParsers.add(Objects.requireNonNull(binaryParser));
+                }
+
+                @Override
+                public void handleException(@Nullable Throwable exception) {
+                    Activator.logError("Error creating binary parser", exception); //$NON-NLS-1$
+                }
+            });
         }
 
         /*