1 /*******************************************************************************
2 * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.lttng2
.ust
.core
.analysis
.debuginfo
;
12 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.nullToEmptyString
;
16 import org
.eclipse
.jdt
.annotation
.Nullable
;
17 import org
.eclipse
.tracecompass
.internal
.lttng2
.ust
.core
.analysis
.debuginfo
.FileOffsetMapper
;
18 import org
.eclipse
.tracecompass
.lttng2
.ust
.core
.trace
.LttngUstTrace
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.TmfCallsite
;
23 import com
.google
.common
.collect
.Iterables
;
26 * Event aspect of UST traces to generate a {@link TmfCallsite} using the debug
27 * info analysis and the IP (instruction pointer) context.
29 * @author Alexandre Montplaisir
32 public class UstDebugInfoSourceAspect
implements ITmfEventAspect
<TmfCallsite
> {
34 /** Singleton instance */
35 public static final UstDebugInfoSourceAspect INSTANCE
= new UstDebugInfoSourceAspect();
37 private UstDebugInfoSourceAspect() {}
40 public String
getName() {
41 return nullToEmptyString(Messages
.UstDebugInfoAnalysis_SourceAspectName
);
45 public String
getHelpText() {
46 return nullToEmptyString(Messages
.UstDebugInfoAnalysis_SourceAspectHelpText
);
50 public @Nullable TmfCallsite
resolve(ITmfEvent event
) {
51 /* This aspect only supports UST traces */
52 if (!(event
.getTrace() instanceof LttngUstTrace
)) {
55 LttngUstTrace trace
= (LttngUstTrace
) event
.getTrace();
58 * Resolve the binary callsite first, from there we can use the file's
59 * debug information if it is present.
61 BinaryCallsite bc
= UstDebugInfoBinaryAspect
.INSTANCE
.resolve(event
);
66 return getSourceCallsite(trace
, bc
);
70 * Get the source callsite (the full {@link TmfCallsite} information) from a
74 * The trace, which may contain trace-specific configuration
77 * @return The source callsite, which sould include file name, function name
80 public static @Nullable TmfCallsite
getSourceCallsite(LttngUstTrace trace
, BinaryCallsite bc
) {
81 Iterable
<TmfCallsite
> callsites
= FileOffsetMapper
.getCallsiteFromOffset(
82 new File(bc
.getBinaryFilePath()),
86 if (callsites
== null || Iterables
.isEmpty(callsites
)) {
90 * TMF only supports the notion of one callsite per event at the moment.
91 * We will take the "deepest" one in the stack, which should refer to
92 * the initial, non-inlined location.
94 TmfCallsite callsite
= Iterables
.getLast(callsites
);
97 * Apply the path prefix again, this time on the path given from
98 * addr2line. If applicable.
100 String pathPrefix
= trace
.getSymbolProviderConfig().getActualRootDirPath();
101 if (pathPrefix
.isEmpty()) {
105 String fullFileName
= (pathPrefix
+ callsite
.getFileName());
106 return new TmfCallsite(fullFileName
, callsite
.getFunctionName(), callsite
.getLineNumber());