From 3335f36e94716b95ca11df1840912732c152b1bb Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Thu, 7 Apr 2016 02:36:28 -0400 Subject: [PATCH] lttng.ust: Split the function name into its own aspect/column 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 Reviewed-on: https://git.eclipse.org/r/70308 Reviewed-by: Hudson CI Reviewed-by: Marc-Andre Laperle Tested-by: Marc-Andre Laperle --- .../analysis/debuginfo/FileOffsetMapper.java | 15 ++--- .../analysis/debuginfo/FunctionLocation.java | 52 +++++++++++++++++ .../ust/core/analysis/debuginfo/Messages.java | 6 +- .../analysis/debuginfo/SourceCallsite.java | 47 +++++++++++++++ .../debuginfo/UstDebugInfoFunctionAspect.java | 57 +++++++++++++++++++ .../debuginfo/UstDebugInfoSourceAspect.java | 12 ++-- .../analysis/debuginfo/messages.properties | 6 +- .../lttng2/ust/core/trace/LttngUstTrace.java | 2 + .../tmf/core/event/lookup/ITmfCallsite.java | 3 +- 9 files changed, 182 insertions(+), 18 deletions(-) create mode 100644 lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/FunctionLocation.java create mode 100644 lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/SourceCallsite.java create mode 100644 lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/UstDebugInfoFunctionAspect.java diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/debuginfo/FileOffsetMapper.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/debuginfo/FileOffsetMapper.java index 4a83cbb121..1d07f566fe 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/debuginfo/FileOffsetMapper.java +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/debuginfo/FileOffsetMapper.java @@ -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> CALLSITE_CACHE; + private static final LoadingCache> CALLSITE_CACHE; static { CALLSITE_CACHE = checkNotNull(CacheBuilder.newBuilder() .maximumSize(CACHE_SIZE) - .build(new CacheLoader>() { + .build(new CacheLoader>() { @Override - public @Nullable Iterable load(FileOffset fo) { + public @Nullable Iterable 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 getCallsiteFromOffset(File file, String buildId, long offset) { + public static @Nullable Iterable 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 getCallsiteFromOffsetWithAddr2line(FileOffset fo) { + private static @Nullable Iterable getCallsiteFromOffsetWithAddr2line(FileOffset fo) { String filePath = fo.fFilePath; long offset = fo.fOffset; - List callsites = new LinkedList<>(); + List callsites = new LinkedList<>(); // FIXME Could eventually use CDT's Addr2line class once it implements --inlines List 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 index 0000000000..ce13611afa --- /dev/null +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/FunctionLocation.java @@ -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$ + + } +} diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/Messages.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/Messages.java index c9f8f2c76f..8613351733 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/Messages.java +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/Messages.java @@ -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 index 0000000000..22a25bc2d6 --- /dev/null +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/SourceCallsite.java @@ -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 index 0000000000..6c73d0072a --- /dev/null +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/UstDebugInfoFunctionAspect.java @@ -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 { + + /** 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); + } + +} diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/UstDebugInfoSourceAspect.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/UstDebugInfoSourceAspect.java index 03d1352e3a..98c0fd4a48 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/UstDebugInfoSourceAspect.java +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/UstDebugInfoSourceAspect.java @@ -29,7 +29,7 @@ import com.google.common.collect.Iterables; * @author Alexandre Montplaisir * @since 2.0 */ -public class UstDebugInfoSourceAspect implements ITmfEventAspect { +public class UstDebugInfoSourceAspect implements ITmfEventAspect { /** Singleton instance */ public static final UstDebugInfoSourceAspect INSTANCE = new UstDebugInfoSourceAspect(); @@ -47,7 +47,7 @@ public class UstDebugInfoSourceAspect implements ITmfEventAspect { } @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 { * @return The source callsite, which sould include file name, function name * and line number */ - public static @Nullable TmfCallsite getSourceCallsite(LttngUstTrace trace, BinaryCallsite bc) { - Iterable callsites = FileOffsetMapper.getCallsiteFromOffset( + public static @Nullable SourceCallsite getSourceCallsite(LttngUstTrace trace, BinaryCallsite bc) { + Iterable callsites = FileOffsetMapper.getCallsiteFromOffset( new File(bc.getBinaryFilePath()), bc.getBuildId(), bc.getOffset()); @@ -91,7 +91,7 @@ public class UstDebugInfoSourceAspect implements ITmfEventAspect { * 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 { } String fullFileName = (pathPrefix + callsite.getFileName()); - return new TmfCallsite(fullFileName, callsite.getFunctionName(), callsite.getLineNumber()); + return new SourceCallsite(fullFileName, callsite.getFunctionName(), callsite.getLineNumber()); } } diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/messages.properties b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/messages.properties index a16603810b..010623fa95 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/messages.properties +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/debuginfo/messages.properties @@ -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 diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/LttngUstTrace.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/LttngUstTrace.java index de923a12ec..03fe86ed9f 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/LttngUstTrace.java +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/LttngUstTrace.java @@ -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> 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(); } diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/event/lookup/ITmfCallsite.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/event/lookup/ITmfCallsite.java index 4954388e31..9ebd74ec47 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/event/lookup/ITmfCallsite.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/event/lookup/ITmfCallsite.java @@ -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. -- 2.34.1