lttng.ust: Split the function name into its own aspect/column
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Thu, 7 Apr 2016 06:36:28 +0000 (02:36 -0400)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Wed, 4 May 2016 20:23:37 +0000 (16:23 -0400)
Introduce a new aspect for the Function Location. For now it will
be used to store the function name, but could eventually also
print the offset within the function once we can retrieve it.

Implement a new Callsite object for this analysis which will not
print the function name, since we will have it separately.

Change-Id: Ie7d1598a2bfebe690c3e82183e8ad16f62489b4e
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-on: https://git.eclipse.org/r/70308
Reviewed-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/debuginfo/FileOffsetMapper.java
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/FunctionLocation.java [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/Messages.java
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/SourceCallsite.java [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/UstDebugInfoFunctionAspect.java [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/UstDebugInfoSourceAspect.java
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/messages.properties
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/LttngUstTrace.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/event/lookup/ITmfCallsite.java

index 4a83cbb1217fd94e3cad47a7cffdcca5ff95729a..1d07f566fe7c7cd15e6ff26d7217f6a235ac1130 100644 (file)
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.stream.Collectors;
 
 import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo.SourceCallsite;
 import org.eclipse.tracecompass.tmf.core.event.lookup.TmfCallsite;
 
 import com.google.common.base.Objects;
@@ -89,13 +90,13 @@ public final class FileOffsetMapper {
      * It is static, meaning one cache for the whole application, since the
      * symbols in a file on disk are independent from the trace referring to it.
      */
-    private static final LoadingCache<FileOffset, @Nullable Iterable<TmfCallsite>> CALLSITE_CACHE;
+    private static final LoadingCache<FileOffset, @Nullable Iterable<SourceCallsite>> CALLSITE_CACHE;
     static {
         CALLSITE_CACHE = checkNotNull(CacheBuilder.newBuilder()
             .maximumSize(CACHE_SIZE)
-            .build(new CacheLoader<FileOffset, @Nullable Iterable<TmfCallsite>>() {
+            .build(new CacheLoader<FileOffset, @Nullable Iterable<SourceCallsite>>() {
                 @Override
-                public @Nullable Iterable<TmfCallsite> load(FileOffset fo) {
+                public @Nullable Iterable<SourceCallsite> load(FileOffset fo) {
                     return getCallsiteFromOffsetWithAddr2line(fo);
                 }
             }));
@@ -118,7 +119,7 @@ public final class FileOffsetMapper {
      * @return The list of callsites corresponding to the offset, reported from
      *         the "highest" inlining location, down to the initial definition.
      */
-    public static @Nullable Iterable<TmfCallsite> getCallsiteFromOffset(File file, String buildId, long offset) {
+    public static @Nullable Iterable<SourceCallsite> getCallsiteFromOffset(File file, String buildId, long offset) {
         if (!Files.exists((file.toPath()))) {
             return null;
         }
@@ -129,11 +130,11 @@ public final class FileOffsetMapper {
         return CALLSITE_CACHE.getUnchecked(fo);
     }
 
-    private static @Nullable Iterable<TmfCallsite> getCallsiteFromOffsetWithAddr2line(FileOffset fo) {
+    private static @Nullable Iterable<SourceCallsite> getCallsiteFromOffsetWithAddr2line(FileOffset fo) {
         String filePath = fo.fFilePath;
         long offset = fo.fOffset;
 
-        List<TmfCallsite> callsites = new LinkedList<>();
+        List<SourceCallsite> callsites = new LinkedList<>();
 
         // FIXME Could eventually use CDT's Addr2line class once it implements --inlines
         List<String> output = getOutputFromCommand(Arrays.asList(
@@ -166,7 +167,7 @@ public final class FileOffsetMapper {
                 }
                 long lineNumber = Long.parseLong(elems[1]);
 
-                callsites.add(new TmfCallsite(fileName, currentFunctionName, lineNumber));
+                callsites.add(new SourceCallsite(fileName, currentFunctionName, lineNumber));
             }
 
             /* Flip the boolean for the following line */
diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/FunctionLocation.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/FunctionLocation.java
new file mode 100644 (file)
index 0000000..ce13611
--- /dev/null
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo;
+
+import org.eclipse.jdt.annotation.Nullable;
+
+/**
+ * Compound object representing a binary location inside a function/symbol
+ * inside a binary.
+ *
+ * It consists of the function/symbol name, and offset within this function. The
+ * offset may or may not be available.
+ *
+ * @author Alexandre Montplaisir
+ * @since 2.0
+ */
+public class FunctionLocation {
+
+    private final String fFunctionName;
+    private final @Nullable Long fOffset;
+
+    /**
+     * Constructor
+     *
+     * @param functionName
+     *            Name of the function
+     * @param offsetInFunction
+     *            Offset *within this function*. May be null to mean unknown.
+     */
+    public FunctionLocation(String functionName, @Nullable Long offsetInFunction) {
+        fFunctionName = functionName;
+        fOffset = offsetInFunction;
+    }
+
+    @Override
+    public String toString() {
+        Long offset = fOffset;
+
+        if (offset == null) {
+            return fFunctionName;
+        }
+        return (fFunctionName + "+0x" + Long.toHexString(offset.longValue())); //$NON-NLS-1$
+
+    }
+}
index c9f8f2c76f400e3e326696aeaf3bbb96840baa38..8613351733458bd6ad7f2ebbd3c07e3d96b20f1b 100644 (file)
@@ -23,10 +23,12 @@ public class Messages extends NLS {
 
     private static final String BUNDLE_NAME = "org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo.messages"; //$NON-NLS-1$
 
-    public static @Nullable String UstDebugInfoAnalysis_SourceAspectName;
-    public static @Nullable String UstDebugInfoAnalysis_SourceAspectHelpText;
     public static @Nullable String UstDebugInfoAnalysis_BinaryAspectName;
     public static @Nullable String UstDebugInfoAnalysis_BinaryAspectHelpText;
+    public static @Nullable String UstDebugInfoAnalysis_FunctionAspectName;
+    public static @Nullable String UstDebugInfoAnalysis_FunctionAspectHelpText;
+    public static @Nullable String UstDebugInfoAnalysis_SourceAspectName;
+    public static @Nullable String UstDebugInfoAnalysis_SourceAspectHelpText;
 
     static {
         // initialize resource bundle
diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/SourceCallsite.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/SourceCallsite.java
new file mode 100644 (file)
index 0000000..22a25bc
--- /dev/null
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.tmf.core.event.lookup.TmfCallsite;
+
+/**
+ * Extension of {@link TmfCallsite} specifically for the debug-info analysis,
+ * which will not print the function name in the event table. This name will be
+ * available by a separate aspect.
+ *
+ * @author Alexandre Montplaisir
+ * @since 2.0
+ */
+public class SourceCallsite extends TmfCallsite {
+
+    /**
+     * Constructor
+     *
+     * @param fileName
+     *            File name
+     * @param functionName
+     *            Function name
+     * @param lineNumber
+     *            Line number
+     */
+    public SourceCallsite(String fileName, @Nullable String functionName, long lineNumber) {
+        super(fileName, functionName, lineNumber);
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append(getFileName()).append(':');
+        builder.append(Long.toString(getLineNumber()));
+        return builder.toString();
+    }
+
+}
diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/UstDebugInfoFunctionAspect.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/UstDebugInfoFunctionAspect.java
new file mode 100644 (file)
index 0000000..6c73d00
--- /dev/null
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo;
+
+import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
+
+/**
+ * Aspect for the function location obtained with the UST debug info.
+ *
+ * @author Alexandre Montplaisir
+ * @since 2.0
+ */
+public class UstDebugInfoFunctionAspect implements ITmfEventAspect<FunctionLocation> {
+
+    /** Singleton instance */
+    public static final UstDebugInfoFunctionAspect INSTANCE = new UstDebugInfoFunctionAspect();
+
+    private UstDebugInfoFunctionAspect() {}
+
+    @Override
+    public String getName() {
+        return nullToEmptyString(Messages.UstDebugInfoAnalysis_FunctionAspectName);
+    }
+
+    @Override
+    public String getHelpText() {
+        return nullToEmptyString(Messages.UstDebugInfoAnalysis_FunctionAspectHelpText);
+    }
+
+    @Override
+    public @Nullable FunctionLocation resolve(ITmfEvent event) {
+        SourceCallsite sc = UstDebugInfoSourceAspect.INSTANCE.resolve(event);
+        if (sc == null) {
+            return null;
+        }
+
+        String functionName = sc.getFunctionName();
+        if (functionName == null) {
+            return null;
+        }
+
+        /* We do not track the offset in the function at this time */
+        return new FunctionLocation(functionName, null);
+    }
+
+}
index 03d1352e3a8be29d9e06887c994a6b8461d0b294..98c0fd4a48046bf7a6d7756aa270cf17c9daefc4 100644 (file)
@@ -29,7 +29,7 @@ import com.google.common.collect.Iterables;
  * @author Alexandre Montplaisir
  * @since 2.0
  */
-public class UstDebugInfoSourceAspect implements ITmfEventAspect<TmfCallsite> {
+public class UstDebugInfoSourceAspect implements ITmfEventAspect<SourceCallsite> {
 
     /** Singleton instance */
     public static final UstDebugInfoSourceAspect INSTANCE = new UstDebugInfoSourceAspect();
@@ -47,7 +47,7 @@ public class UstDebugInfoSourceAspect implements ITmfEventAspect<TmfCallsite> {
     }
 
     @Override
-    public @Nullable TmfCallsite resolve(ITmfEvent event) {
+    public @Nullable SourceCallsite resolve(ITmfEvent event) {
         /* This aspect only supports UST traces */
         if (!(event.getTrace() instanceof LttngUstTrace)) {
             return null;
@@ -77,8 +77,8 @@ public class UstDebugInfoSourceAspect implements ITmfEventAspect<TmfCallsite> {
      * @return The source callsite, which sould include file name, function name
      *         and line number
      */
-    public static @Nullable TmfCallsite getSourceCallsite(LttngUstTrace trace, BinaryCallsite bc) {
-        Iterable<TmfCallsite> callsites = FileOffsetMapper.getCallsiteFromOffset(
+    public static @Nullable SourceCallsite getSourceCallsite(LttngUstTrace trace, BinaryCallsite bc) {
+        Iterable<SourceCallsite> callsites = FileOffsetMapper.getCallsiteFromOffset(
                 new File(bc.getBinaryFilePath()),
                 bc.getBuildId(),
                 bc.getOffset());
@@ -91,7 +91,7 @@ public class UstDebugInfoSourceAspect implements ITmfEventAspect<TmfCallsite> {
          * We will take the "deepest" one in the stack, which should refer to
          * the initial, non-inlined location.
          */
-        TmfCallsite callsite = Iterables.getLast(callsites);
+        SourceCallsite callsite = Iterables.getLast(callsites);
 
         /*
          * Apply the path prefix again, this time on the path given from
@@ -103,6 +103,6 @@ public class UstDebugInfoSourceAspect implements ITmfEventAspect<TmfCallsite> {
         }
 
         String fullFileName = (pathPrefix + callsite.getFileName());
-        return new TmfCallsite(fullFileName, callsite.getFunctionName(), callsite.getLineNumber());
+        return new SourceCallsite(fullFileName, callsite.getFunctionName(), callsite.getLineNumber());
     }
 }
index a16603810b819601ba2a1109701187600a853475..010623fa9551a6e4cae1788a368e242e7a5000c5 100644 (file)
@@ -7,7 +7,9 @@
 # http://www.eclipse.org/legal/epl-v10.html
 ###############################################################################
 
-UstDebugInfoAnalysis_SourceAspectName = Source callsite
-UstDebugInfoAnalysis_SourceAspectHelpText = The call site of this event in the source code
 UstDebugInfoAnalysis_BinaryAspectName = Binary Location
 UstDebugInfoAnalysis_BinaryAspectHelpText = The call site of this event in the binary file
+UstDebugInfoAnalysis_FunctionAspectName = Function Location
+UstDebugInfoAnalysis_FunctionAspectHelpText = The call site location relative to the function/symbol
+UstDebugInfoAnalysis_SourceAspectName = Source Location
+UstDebugInfoAnalysis_SourceAspectHelpText = The call site of this event in the source code
\ No newline at end of file
index de923a12ecb7c69044e9d0b84e04997c28bb6ea7..03fe86ed9f648fc2aa77e6f59a4f5c3ffc9fb68d 100644 (file)
@@ -28,6 +28,7 @@ import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst20
 import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst27EventLayout;
 import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst28EventLayout;
 import org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo.UstDebugInfoBinaryAspect;
+import org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo.UstDebugInfoFunctionAspect;
 import org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo.UstDebugInfoSourceAspect;
 import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
@@ -63,6 +64,7 @@ public class LttngUstTrace extends CtfTmfTrace {
         ImmutableSet.Builder<ITmfEventAspect<?>> builder = ImmutableSet.builder();
         builder.addAll(CtfTmfTrace.CTF_ASPECTS);
         builder.add(UstDebugInfoBinaryAspect.INSTANCE);
+        builder.add(UstDebugInfoFunctionAspect.INSTANCE);
         builder.add(UstDebugInfoSourceAspect.INSTANCE);
         LTTNG_UST_ASPECTS = builder.build();
     }
index 4954388e318a6e579f6076a5c9d140024e883550..9ebd74ec47977537892a51855f40e7987e0141ce 100644 (file)
@@ -13,6 +13,7 @@
 package org.eclipse.tracecompass.tmf.core.event.lookup;
 
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 
 /**
  * The generic call site structure in TMF. A call site has:
@@ -40,7 +41,7 @@ public interface ITmfCallsite {
      *
      * @return the function name or null
      */
-    String getFunctionName();
+    @Nullable String getFunctionName();
 
     /**
      * Returns the line number of the call site.
This page took 0.03149 seconds and 5 git commands to generate.