Skip to content

Commit

Permalink
tmf: Exclude GNU and deprecated CDT binary parser extensions
Browse files Browse the repository at this point in the history
CDT GNU binary parsers now require a CProject configuration.
eclipse-cdt/cdt#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>
  • Loading branch information
PatrickTasse committed Jan 31, 2024
1 parent d6f31e1 commit 0118ab4
Showing 1 changed file with 27 additions and 18 deletions.
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -65,6 +66,8 @@ public final class FunctionNameMapper {
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
Expand Down Expand Up @@ -268,24 +271,30 @@ private static String stripLeadingZeros(String address) {

/* 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$
}
});
}

/*
Expand Down

0 comments on commit 0118ab4

Please sign in to comment.