lttng.core: add Address handling to BinaryAspect
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.core / src / org / eclipse / tracecompass / lttng2 / ust / core / analysis / debuginfo / UstDebugInfoBinaryAspect.java
CommitLineData
df993132
AM
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
10package org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo;
11
12import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString;
13
14import org.eclipse.jdt.annotation.Nullable;
df993132
AM
15import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
16import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout;
17import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
18import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
19import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
20import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
21
22/**
23 * Event aspect of UST traces that indicate the binary callsite (binary, symbol
24 * and offset) from an IP (instruction pointer) context.
25 *
26 * Unlike the {@link UstDebugInfoSourceAspect}, this information should be
27 * available even without debug information.
28 *
29 * @author Alexandre Montplaisir
30 * @since 2.0
31 */
efcee324 32public class UstDebugInfoBinaryAspect implements ITmfEventAspect<BinaryCallsite> {
df993132
AM
33
34 /** Singleton instance */
35 public static final UstDebugInfoBinaryAspect INSTANCE = new UstDebugInfoBinaryAspect();
36
1323e984
MK
37 private UstDebugInfoBinaryAspect() {
38 }
df993132
AM
39
40 @Override
41 public String getName() {
42 return nullToEmptyString(Messages.UstDebugInfoAnalysis_BinaryAspectName);
43 }
44
45 @Override
46 public String getHelpText() {
47 return nullToEmptyString(Messages.UstDebugInfoAnalysis_BinaryAspectHelpText);
48 }
49
50 @Override
51 public @Nullable BinaryCallsite resolve(ITmfEvent event) {
52 /* This aspect only supports UST traces */
53 if (!(event.getTrace() instanceof LttngUstTrace)) {
54 return null;
55 }
cb2b5e56 56 LttngUstTrace trace = (LttngUstTrace) event.getTrace();
df993132 57
cb2b5e56 58 ILttngUstEventLayout layout = trace.getEventLayout();
df993132
AM
59
60 /* We need both the vpid and ip contexts */
61 ITmfEventField vpidField = event.getContent().getField(layout.contextVpid());
62 ITmfEventField ipField = event.getContent().getField(layout.contextIp());
1323e984
MK
63 if (ipField == null) {
64 ipField = event.getContent().getField(layout.fieldAddr());
65 }
df993132
AM
66 if (vpidField == null || ipField == null) {
67 return null;
68 }
69 Long vpid = (Long) vpidField.getValue();
70 Long ip = (Long) ipField.getValue();
cb2b5e56 71 long ts = event.getTimestamp().toNanos();
df993132 72
cb2b5e56
AM
73 return getBinaryCallsite(trace, vpid.intValue(), ts, ip.longValue());
74 }
75
76 /**
77 * Get the binary callsite (which means binary file and offset in this file)
78 * corresponding to the given instruction pointer, for the given PID and
79 * timetamp.
80 *
81 * @param trace
82 * The trace, from which we will get the debug info analysis
83 * @param pid
84 * The PID for which we want the symbol
85 * @param ts
86 * The timestamp of the query
87 * @param ip
88 * The instruction pointer address
89 * @return The {@link BinaryCallsite} object with the relevant information
90 */
91 public static @Nullable BinaryCallsite getBinaryCallsite(LttngUstTrace trace, int pid, long ts, long ip) {
df993132
AM
92 /*
93 * First match the IP to the correct binary or library, by using the
94 * UstDebugInfoAnalysis.
95 */
1323e984
MK
96 UstDebugInfoAnalysisModule module = TmfTraceUtils.getAnalysisModuleOfClass(trace,
97 UstDebugInfoAnalysisModule.class, UstDebugInfoAnalysisModule.ID);
df993132
AM
98 if (module == null) {
99 /*
1323e984
MK
100 * The analysis is not available for this trace, we won't be able to
101 * find the information.
df993132
AM
102 */
103 return null;
104 }
cb2b5e56 105 UstDebugInfoLoadedBinaryFile file = module.getMatchingFile(ts, pid, ip);
df993132
AM
106 if (file == null) {
107 return null;
108 }
109
cb2b5e56
AM
110 /* Apply the path prefix defined by the trace, if any */
111 String fullPath = (trace.getSymbolProviderConfig().getActualRootDirPath() + file.getFilePath());
112
df993132 113 long offset;
d89151ba 114 if (file.isPic()) {
1633ee0d 115 offset = ip - file.getBaseAddress();
df993132
AM
116 } else {
117 /*
1323e984
MK
118 * In the case of the object being non-position-independent, we must
119 * pass the actual 'ip' address directly to addr2line.
df993132 120 */
cb2b5e56 121 offset = ip;
df993132
AM
122 }
123
d89151ba 124 return new BinaryCallsite(fullPath, file.getBuildId(), offset, file.isPic());
df993132 125 }
df993132 126}
This page took 0.045682 seconds and 5 git commands to generate.