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
;
24 * Event aspect of UST traces to generate a {@link TmfCallsite} using the debug
25 * info analysis and the IP (instruction pointer) context.
27 * @author Alexandre Montplaisir
30 public class UstDebugInfoSourceAspect
implements ITmfEventAspect
<TmfCallsite
> {
32 /** Singleton instance */
33 public static final UstDebugInfoSourceAspect INSTANCE
= new UstDebugInfoSourceAspect();
35 private UstDebugInfoSourceAspect() {}
38 public String
getName() {
39 return nullToEmptyString(Messages
.UstDebugInfoAnalysis_SourceAspectName
);
43 public String
getHelpText() {
44 return nullToEmptyString(Messages
.UstDebugInfoAnalysis_SourceAspectHelpText
);
51 public @Nullable TmfCallsite
resolve(ITmfEvent event
) {
52 /* This aspect only supports UST traces */
53 if (!(event
.getTrace() instanceof LttngUstTrace
)) {
56 LttngUstTrace trace
= (LttngUstTrace
) event
.getTrace();
59 * Resolve the binary callsite first, from there we can use the file's
60 * debug information if it is present.
62 BinaryCallsite bc
= UstDebugInfoBinaryAspect
.INSTANCE
.resolve(event
);
67 TmfCallsite callsite
= FileOffsetMapper
.getCallsiteFromOffset(
68 new File(bc
.getBinaryFilePath()),
71 if (callsite
== null) {
76 * Apply the path prefix again, this time on the path given from
77 * addr2line. If applicable.
79 String pathPrefix
= trace
.getSymbolProviderConfig().getActualRootDirPath();
80 if (pathPrefix
.isEmpty()) {
84 String fullFileName
= (pathPrefix
+ callsite
.getFileName());
85 return new TmfCallsite(fullFileName
, callsite
.getLineNo());
89 * Get the source callsite (the full {@link TmfCallsite} information) from a
93 * The trace, which may contain trace-specific configuration
96 * @return The source callsite, which sould include file name, function name
99 * @deprecated Should not be needed anymore, call aspects's resolve() method
100 * directly. The SourceAspect does not include the function name
104 public static @Nullable SourceCallsite
getSourceCallsite(LttngUstTrace trace
, BinaryCallsite bc
) {
105 TmfCallsite callsite
= FileOffsetMapper
.getCallsiteFromOffset(
106 new File(bc
.getBinaryFilePath()),
109 if (callsite
== null) {
113 Long callsiteLineNo
= callsite
.getLineNo();
114 long lineNo
= (callsiteLineNo
== null ?
-1 : callsiteLineNo
.longValue());
117 * Apply the path prefix again, this time on the path given from
118 * addr2line. If applicable.
120 String pathPrefix
= trace
.getSymbolProviderConfig().getActualRootDirPath();
121 if (pathPrefix
.isEmpty()) {
122 return new SourceCallsite(callsite
.getFileName(), null, lineNo
);
125 String fullFileName
= (pathPrefix
+ callsite
.getFileName());
126 return new SourceCallsite(fullFileName
, null, lineNo
);