ust.core: making some classes final
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.core / src / org / eclipse / tracecompass / lttng2 / ust / core / analysis / debuginfo / UstDebugInfoSourceAspect.java
1 /*******************************************************************************
2 * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
3 *
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 *******************************************************************************/
9
10 package org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo;
11
12 import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString;
13
14 import java.io.File;
15
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;
22
23 import com.google.common.collect.Iterables;
24
25 /**
26 * Event aspect of UST traces to generate a {@link TmfCallsite} using the debug
27 * info analysis and the IP (instruction pointer) context.
28 *
29 * @author Alexandre Montplaisir
30 * @since 2.0
31 */
32 public final class UstDebugInfoSourceAspect implements ITmfEventAspect<SourceCallsite> {
33
34 /** Singleton instance */
35 public static final UstDebugInfoSourceAspect INSTANCE = new UstDebugInfoSourceAspect();
36
37 private UstDebugInfoSourceAspect() {}
38
39 @Override
40 public String getName() {
41 return nullToEmptyString(Messages.UstDebugInfoAnalysis_SourceAspectName);
42 }
43
44 @Override
45 public String getHelpText() {
46 return nullToEmptyString(Messages.UstDebugInfoAnalysis_SourceAspectHelpText);
47 }
48
49 @Override
50 public @Nullable SourceCallsite resolve(ITmfEvent event) {
51 /* This aspect only supports UST traces */
52 if (!(event.getTrace() instanceof LttngUstTrace)) {
53 return null;
54 }
55 LttngUstTrace trace = (LttngUstTrace) event.getTrace();
56
57 /*
58 * Resolve the binary callsite first, from there we can use the file's
59 * debug information if it is present.
60 */
61 BinaryCallsite bc = UstDebugInfoBinaryAspect.INSTANCE.resolve(event);
62 if (bc == null) {
63 return null;
64 }
65
66 return getSourceCallsite(trace, bc);
67 }
68
69 /**
70 * Get the source callsite (the full {@link TmfCallsite} information) from a
71 * binary callsite.
72 *
73 * @param trace
74 * The trace, which may contain trace-specific configuration
75 * @param bc
76 * The binary callsite
77 * @return The source callsite, which sould include file name, function name
78 * and line number
79 */
80 public static @Nullable SourceCallsite getSourceCallsite(LttngUstTrace trace, BinaryCallsite bc) {
81 Iterable<SourceCallsite> callsites = FileOffsetMapper.getCallsiteFromOffset(
82 new File(bc.getBinaryFilePath()),
83 bc.getBuildId(),
84 bc.getOffset());
85
86 if (callsites == null || Iterables.isEmpty(callsites)) {
87 return null;
88 }
89 /*
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.
93 */
94 SourceCallsite callsite = Iterables.getLast(callsites);
95
96 /*
97 * Apply the path prefix again, this time on the path given from
98 * addr2line. If applicable.
99 */
100 String pathPrefix = trace.getSymbolProviderConfig().getActualRootDirPath();
101 if (pathPrefix.isEmpty()) {
102 return callsite;
103 }
104
105 String fullFileName = (pathPrefix + callsite.getFileName());
106 return new SourceCallsite(fullFileName, callsite.getFunctionName(), callsite.getLineNumber());
107 }
108 }
This page took 0.033037 seconds and 5 git commands to generate.