lttng.ust: Introduce a cache of the calls to addr2line
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.core / src / org / eclipse / tracecompass / lttng2 / ust / core / analysis / debuginfo / UstDebugInfoSourceAspect.java
CommitLineData
ef7f180d
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
522dff53
AM
14import java.io.File;
15
ef7f180d 16import org.eclipse.jdt.annotation.Nullable;
522dff53 17import org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.debuginfo.FileOffsetMapper;
ef7f180d 18import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
ef7f180d 19import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
ef7f180d
AM
20import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
21import org.eclipse.tracecompass.tmf.core.event.lookup.TmfCallsite;
ef7f180d 22
522dff53
AM
23import com.google.common.collect.Iterables;
24
ef7f180d
AM
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 */
ec48d248 32public class UstDebugInfoSourceAspect implements ITmfEventAspect<TmfCallsite> {
ef7f180d
AM
33
34 /** Singleton instance */
a103fe67 35 public static final UstDebugInfoSourceAspect INSTANCE = new UstDebugInfoSourceAspect();
ef7f180d 36
a103fe67 37 private UstDebugInfoSourceAspect() {}
ef7f180d
AM
38
39 @Override
40 public String getName() {
df993132 41 return nullToEmptyString(Messages.UstDebugInfoAnalysis_SourceAspectName);
ef7f180d
AM
42 }
43
44 @Override
45 public String getHelpText() {
df993132 46 return nullToEmptyString(Messages.UstDebugInfoAnalysis_SourceAspectHelpText);
ef7f180d
AM
47 }
48
ef7f180d 49 @Override
522dff53 50 public @Nullable TmfCallsite resolve(ITmfEvent event) {
ef7f180d
AM
51 /* This aspect only supports UST traces */
52 if (!(event.getTrace() instanceof LttngUstTrace)) {
53 return null;
54 }
55
ef7f180d 56 /*
df993132
AM
57 * Resolve the binary callsite first, from there we can use the file's
58 * debug information if it is present.
ef7f180d 59 */
df993132
AM
60 BinaryCallsite bc = UstDebugInfoBinaryAspect.INSTANCE.resolve(event);
61 if (bc == null) {
522dff53
AM
62 return null;
63 }
64
df993132 65 Iterable<TmfCallsite> callsites = FileOffsetMapper.getCallsiteFromOffset(new File(bc.getBinaryFilePath()), bc.getOffset());
522dff53
AM
66
67 if (callsites == null || Iterables.isEmpty(callsites)) {
68 return null;
69 }
70 /*
71 * TMF only supports the notion of one callsite per event at the moment.
72 * We will take the "deepest" one in the stack, which should refer to
73 * the initial, non-inlined location.
74 */
75 return Iterables.getLast(callsites);
76 }
ef7f180d 77}
This page took 0.061583 seconds and 5 git commands to generate.