0bc78f0237ea08fb08a3be84f21212e5b3195421
[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 /**
24 * Event aspect of UST traces to generate a {@link TmfCallsite} using the debug
25 * info analysis and the IP (instruction pointer) context.
26 *
27 * @author Alexandre Montplaisir
28 * @since 2.0
29 */
30 public class UstDebugInfoSourceAspect implements ITmfEventAspect<TmfCallsite> {
31
32 /** Singleton instance */
33 public static final UstDebugInfoSourceAspect INSTANCE = new UstDebugInfoSourceAspect();
34
35 private UstDebugInfoSourceAspect() {}
36
37 @Override
38 public String getName() {
39 return nullToEmptyString(Messages.UstDebugInfoAnalysis_SourceAspectName);
40 }
41
42 @Override
43 public String getHelpText() {
44 return nullToEmptyString(Messages.UstDebugInfoAnalysis_SourceAspectHelpText);
45 }
46
47 /**
48 * @since 2.1
49 */
50 @Override
51 public @Nullable TmfCallsite resolve(ITmfEvent event) {
52 /* This aspect only supports UST traces */
53 if (!(event.getTrace() instanceof LttngUstTrace)) {
54 return null;
55 }
56 LttngUstTrace trace = (LttngUstTrace) event.getTrace();
57
58 /*
59 * Resolve the binary callsite first, from there we can use the file's
60 * debug information if it is present.
61 */
62 BinaryCallsite bc = UstDebugInfoBinaryAspect.INSTANCE.resolve(event);
63 if (bc == null) {
64 return null;
65 }
66
67 TmfCallsite callsite = FileOffsetMapper.getCallsiteFromOffset(
68 new File(bc.getBinaryFilePath()),
69 bc.getBuildId(),
70 bc.getOffset());
71 if (callsite == null) {
72 return null;
73 }
74
75 /*
76 * Apply the path prefix again, this time on the path given from
77 * addr2line. If applicable.
78 */
79 String pathPrefix = trace.getSymbolProviderConfig().getActualRootDirPath();
80 if (pathPrefix.isEmpty()) {
81 return callsite;
82 }
83
84 String fullFileName = (pathPrefix + callsite.getFileName());
85 return new TmfCallsite(fullFileName, callsite.getLineNo());
86 }
87
88 /**
89 * Get the source callsite (the full {@link TmfCallsite} information) from a
90 * binary callsite.
91 *
92 * @param trace
93 * The trace, which may contain trace-specific configuration
94 * @param bc
95 * The binary callsite
96 * @return The source callsite, which sould include file name, function name
97 * and line number
98 * @since 2.0
99 * @deprecated Should not be needed anymore, call aspects's resolve() method
100 * directly. The SourceAspect does not include the function name
101 * anymore.
102 */
103 @Deprecated
104 public static @Nullable SourceCallsite getSourceCallsite(LttngUstTrace trace, BinaryCallsite bc) {
105 TmfCallsite callsite = FileOffsetMapper.getCallsiteFromOffset(
106 new File(bc.getBinaryFilePath()),
107 bc.getBuildId(),
108 bc.getOffset());
109 if (callsite == null) {
110 return null;
111 }
112
113 Long callsiteLineNo = callsite.getLineNo();
114 long lineNo = (callsiteLineNo == null ? -1 : callsiteLineNo.longValue());
115
116 /*
117 * Apply the path prefix again, this time on the path given from
118 * addr2line. If applicable.
119 */
120 String pathPrefix = trace.getSymbolProviderConfig().getActualRootDirPath();
121 if (pathPrefix.isEmpty()) {
122 return new SourceCallsite(callsite.getFileName(), null, lineNo);
123 }
124
125 String fullFileName = (pathPrefix + callsite.getFileName());
126 return new SourceCallsite(fullFileName, null, lineNo);
127 }
128 }
This page took 0.033853 seconds and 4 git commands to generate.