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;
* 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);
}
}));
* @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;
}
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(
}
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 */
--- /dev/null
+/*******************************************************************************
+ * 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$
+
+ }
+}
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
--- /dev/null
+/*******************************************************************************
+ * 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();
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * 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);
+ }
+
+}
* @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();
}
@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;
* @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());
* 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
}
String fullFileName = (pathPrefix + callsite.getFileName());
- return new TmfCallsite(fullFileName, callsite.getFunctionName(), callsite.getLineNumber());
+ return new SourceCallsite(fullFileName, callsite.getFunctionName(), callsite.getLineNumber());
}
}
# 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
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;
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();
}
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:
*
* @return the function name or null
*/
- String getFunctionName();
+ @Nullable String getFunctionName();
/**
* Returns the line number of the call site.