lttng: Make use of "is_pic" event field in debug info analysis
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.core / src / org / eclipse / tracecompass / lttng2 / ust / core / analysis / debuginfo / UstDebugInfoAnalysisModule.java
index 09b3a6251aec23217ed19919ac113aa3b81471e8..8f9cf5115134ab59ff51f1fe057553697c383e09 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
+ * Copyright (c) 2015, 2016 EfficiOS Inc., Alexandre Montplaisir
  *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -15,8 +15,10 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.NavigableSet;
+import java.util.Optional;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.stream.Collectors;
 
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.debuginfo.UstDebugInfoBinaryFile;
@@ -29,19 +31,14 @@ import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundExc
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
 import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
-import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisRequirement;
+import org.eclipse.tracecompass.tmf.core.analysis.requirements.TmfAbstractAnalysisRequirement;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
 import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
 import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfUtils;
 
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Ordering;
 
 /**
  * Analysis to provide TMF Callsite information by mapping IP (instruction
@@ -76,10 +73,10 @@ public class UstDebugInfoAnalysisModule extends TmfStateSystemAnalysisModule {
     }
 
     @Override
-    public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() {
+    public Iterable<TmfAbstractAnalysisRequirement> getAnalysisRequirements() {
         // TODO specify actual requirements once the requirement-checking is
         // implemented. This analysis needs "ip" and "vpid" contexts.
-        return checkNotNull(Collections.EMPTY_SET);
+        return Collections.EMPTY_SET;
     }
 
     @Override
@@ -122,44 +119,53 @@ public class UstDebugInfoAnalysisModule extends TmfStateSystemAnalysisModule {
         ITmfStateSystem ss = checkNotNull(getStateSystem());
 
         Set<UstDebugInfoBinaryFile> files = new TreeSet<>();
-        try {
-            ImmutableList.Builder<Integer> builder = ImmutableList.builder();
-            List<Integer> vpidQuarks = ss.getSubAttributes(-1, false);
-            for (Integer vpidQuark : vpidQuarks) {
-                builder.addAll(ss.getSubAttributes(vpidQuark, false));
-            }
-            List<Integer> baddrQuarks = builder.build();
+        ImmutableList.Builder<Integer> builder = ImmutableList.builder();
+        List<Integer> vpidQuarks = ss.getSubAttributes(-1, false);
+        for (Integer vpidQuark : vpidQuarks) {
+            builder.addAll(ss.getSubAttributes(vpidQuark, false));
+        }
+        List<Integer> baddrQuarks = builder.build();
 
-            /*
-             * For each "baddr" attribute, get the "buildId" sub-attribute,
-             * whose value is the file path.
-             */
+        /*
+         * For each "baddr" attribute, get the "buildId" sub-attribute,
+         * whose value is the file path.
+         */
 
-            for (Integer baddrQuark : baddrQuarks) {
+        for (Integer baddrQuark : baddrQuarks) {
 
-                List<Integer> buildIdQuarks = ss.getSubAttributes(baddrQuark, false);
-                for (Integer buildIdQuark : buildIdQuarks) {
-                    String buildId = ss.getAttributeName(buildIdQuark);
+            List<Integer> buildIdQuarks = ss.getSubAttributes(baddrQuark, false);
+            for (Integer buildIdQuark : buildIdQuarks) {
+                String buildId = ss.getAttributeName(buildIdQuark);
 
+                /*
+                 * Explore the history of this attribute "horizontally",
+                 * even though there should only be one valid interval.
+                 */
+                ITmfStateInterval interval = StateSystemUtils.queryUntilNonNullValue(ss, buildIdQuark, ss.getStartTime(), Long.MAX_VALUE);
+                if (interval == null) {
                     /*
-                     * Explore the history of this attribute "horizontally",
-                     * even though there should only be one valid interval.
+                     * If we created the attribute, we should have assigned
+                     * a value to it!
                      */
-                    ITmfStateInterval interval = StateSystemUtils.queryUntilNonNullValue(ss, buildIdQuark, ss.getStartTime(), Long.MAX_VALUE);
-                    if (interval == null) {
-                        /*
-                         * If we created the attribute, we should have assigned
-                         * a value to it!
-                         */
-                        throw new IllegalStateException();
-                    }
-                    String filePath = interval.getStateValue().unboxStr();
-
-                    files.add(new UstDebugInfoBinaryFile(filePath, buildId));
+                    throw new IllegalStateException();
+                }
+                String filePath = interval.getStateValue().unboxStr();
+
+                /* Retrieve the value of "is_pic" at that time */
+                try {
+                    int isPicQuark = ss.getQuarkRelative(buildIdQuark, UstDebugInfoStateProvider.IS_PIC_ATTRIB);
+                    int isPicVal = ss.querySingleState(interval.getStartTime(), isPicQuark).getStateValue().unboxInt();
+                    boolean isPic = (isPicVal != 0);
+
+                    files.add(new UstDebugInfoBinaryFile(filePath, buildId, isPic));
+
+                } catch (AttributeNotFoundException e) {
+                    /* We should have built "is_pic" sub-attributes */
+                    throw new IllegalStateException("Missing expected \"is_pic\" attribute"); //$NON-NLS-1$
+                } catch (StateSystemDisposedException e) {
+                    /* We're closing down, ignore */
                 }
             }
-        } catch (AttributeNotFoundException e) {
-            throw new IllegalStateException(e);
         }
         return files;
     }
@@ -185,15 +191,17 @@ public class UstDebugInfoAnalysisModule extends TmfStateSystemAnalysisModule {
         List<Integer> possibleBaddrQuarks = ss.getQuarks(String.valueOf(vpid), "*"); //$NON-NLS-1$
 
         /* Get the most probable base address from all the known ones */
-        NavigableSet<Long> possibleBaddrs = FluentIterable.from(possibleBaddrQuarks)
-                .transform(new Function<Integer, Long>(){
-                    @Override
-                    public Long apply(@Nullable Integer quark) {
-                        String baddrStr = ss.getAttributeName(checkNotNull(quark).intValue());
-                        return checkNotNull(Long.valueOf(baddrStr));
-                    }
-                }).toSortedSet(Ordering.natural());
+        NavigableSet<Long> possibleBaddrs = possibleBaddrQuarks.stream()
+            .map(quark -> {
+                String baddrStr = ss.getAttributeName(quark.intValue());
+                return checkNotNull(Long.valueOf(baddrStr));
+            })
+            .collect(Collectors.toCollection(TreeSet::new));
+
         final Long potentialBaddr = possibleBaddrs.floor(ip);
+        if (potentialBaddr == null) {
+            return null;
+        }
 
         /* Make sure the 'ip' fits in the expected memory range */
         try {
@@ -215,14 +223,13 @@ public class UstDebugInfoAnalysisModule extends TmfStateSystemAnalysisModule {
              * library was loaded there at that time.
              */
             List<Integer> buildIds = ss.getSubAttributes(baddrQuark, false);
-            Optional<Integer> potentialBuildIdQuark = FluentIterable.from(buildIds).firstMatch(new Predicate<Integer>() {
-                @Override
-                public boolean apply(@Nullable Integer input) {
-                    int quark = checkNotNull(input).intValue();
+            Optional<Integer> potentialBuildIdQuark = buildIds.stream()
+                .filter(id -> {
+                    int quark = id.intValue();
                     ITmfStateValue value = fullState.get(quark).getStateValue();
                     return (!value.isNull());
-                }
-            });
+                })
+                .findFirst();
 
             if (!potentialBuildIdQuark.isPresent()) {
                 /* We didn't have the information after all. */
@@ -235,7 +242,12 @@ public class UstDebugInfoAnalysisModule extends TmfStateSystemAnalysisModule {
             int buildIdQuark = potentialBuildIdQuark.get().intValue();
             String buildId = ss.getAttributeName(buildIdQuark);
             String filePath = fullState.get(buildIdQuark).getStateValue().unboxStr();
-            return new UstDebugInfoLoadedBinaryFile(baddr, filePath, buildId);
+
+            int isPicQuark = ss.getQuarkRelative(buildIdQuark, UstDebugInfoStateProvider.IS_PIC_ATTRIB);
+            int isPicVal = fullState.get(isPicQuark).getStateValue().unboxInt();
+            boolean isPic = (isPicVal != 0);
+
+            return new UstDebugInfoLoadedBinaryFile(baddr, filePath, buildId, isPic);
 
         } catch (AttributeNotFoundException e) {
             /* We're only using quarks we've checked for. */
This page took 0.027907 seconds and 5 git commands to generate.