Commit | Line | Data |
---|---|---|
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 | ||
10 | package org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo; | |
11 | ||
12 | import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString; | |
13 | ||
14 | import org.eclipse.jdt.annotation.Nullable; | |
15 | import org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.debuginfo.UstDebugInfoBinaryFile; | |
16 | import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace; | |
17 | import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout; | |
18 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; | |
19 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; | |
20 | import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; | |
21 | import org.eclipse.tracecompass.tmf.core.event.lookup.TmfCallsite; | |
22 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; | |
23 | ||
24 | /** | |
25 | * Event aspect of UST traces to generate a {@link TmfCallsite} using the debug | |
26 | * info analysis and the IP (instruction pointer) context. | |
27 | * | |
28 | * @author Alexandre Montplaisir | |
29 | * @since 2.0 | |
30 | */ | |
31 | public class UstDebugInfoAspect implements ITmfEventAspect { | |
32 | ||
33 | /** Singleton instance */ | |
34 | public static final UstDebugInfoAspect INSTANCE = new UstDebugInfoAspect(); | |
35 | ||
36 | private UstDebugInfoAspect() {} | |
37 | ||
38 | @Override | |
39 | public String getName() { | |
40 | return nullToEmptyString(Messages.UstDebugInfoAnalysis_AspectName); | |
41 | } | |
42 | ||
43 | @Override | |
44 | public String getHelpText() { | |
45 | return nullToEmptyString(Messages.UstDebugInfoAnalysis_AspectHelpText); | |
46 | } | |
47 | ||
48 | // TODO Will return a TmfCallsite eventually | |
49 | @Override | |
50 | public @Nullable String resolve(ITmfEvent event) { | |
51 | /* This aspect only supports UST traces */ | |
52 | if (!(event.getTrace() instanceof LttngUstTrace)) { | |
53 | return null; | |
54 | } | |
55 | ||
56 | ILttngUstEventLayout layout = ((LttngUstTrace) event.getTrace()).getEventLayout(); | |
57 | ||
58 | /* We need both the vpid and ip contexts */ | |
59 | ITmfEventField vpidField = event.getContent().getField(layout.contextVpid()); | |
60 | ITmfEventField ipField = event.getContent().getField(layout.contextIp()); | |
61 | if (vpidField == null || ipField == null) { | |
62 | return null; | |
63 | } | |
64 | Long vpid = (Long) vpidField.getValue(); | |
65 | Long ip = (Long) ipField.getValue(); | |
66 | ||
67 | /* | |
68 | * First match the IP to the correct binary or library, by using the | |
69 | * UstDebugInfoAnalysis. | |
70 | */ | |
71 | UstDebugInfoAnalysisModule module = | |
72 | TmfTraceUtils.getAnalysisModuleOfClass(event.getTrace(), | |
73 | UstDebugInfoAnalysisModule.class, UstDebugInfoAnalysisModule.ID); | |
74 | if (module == null) { | |
75 | /* | |
76 | * The analysis is not available for this trace, we won't be | |
77 | * able to find the information. | |
78 | */ | |
79 | return null; | |
80 | } | |
81 | long ts = event.getTimestamp().getValue(); | |
82 | UstDebugInfoBinaryFile file = module.getMatchingFile(ts, vpid, ip); | |
83 | ||
84 | return (file == null ? null : file.toString()); | |
85 | } | |
86 | ||
87 | } |