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 | ||
522dff53 AM |
14 | import java.io.File; |
15 | ||
ef7f180d | 16 | import org.eclipse.jdt.annotation.Nullable; |
522dff53 | 17 | import org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.debuginfo.FileOffsetMapper; |
ef7f180d | 18 | import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace; |
ef7f180d | 19 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
ef7f180d AM |
20 | import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; |
21 | import org.eclipse.tracecompass.tmf.core.event.lookup.TmfCallsite; | |
ef7f180d AM |
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 | |
f0c26e1d | 28 | * @since 3.0 |
ef7f180d | 29 | */ |
0c65e461 | 30 | public class UstDebugInfoSourceAspect implements ITmfEventAspect<TmfCallsite> { |
ef7f180d AM |
31 | |
32 | /** Singleton instance */ | |
a103fe67 | 33 | public static final UstDebugInfoSourceAspect INSTANCE = new UstDebugInfoSourceAspect(); |
ef7f180d | 34 | |
a103fe67 | 35 | private UstDebugInfoSourceAspect() {} |
ef7f180d AM |
36 | |
37 | @Override | |
38 | public String getName() { | |
df993132 | 39 | return nullToEmptyString(Messages.UstDebugInfoAnalysis_SourceAspectName); |
ef7f180d AM |
40 | } |
41 | ||
42 | @Override | |
43 | public String getHelpText() { | |
df993132 | 44 | return nullToEmptyString(Messages.UstDebugInfoAnalysis_SourceAspectHelpText); |
ef7f180d AM |
45 | } |
46 | ||
0c65e461 AM |
47 | /** |
48 | * @since 2.1 | |
49 | */ | |
ef7f180d | 50 | @Override |
0c65e461 | 51 | public @Nullable TmfCallsite resolve(ITmfEvent event) { |
ef7f180d AM |
52 | /* This aspect only supports UST traces */ |
53 | if (!(event.getTrace() instanceof LttngUstTrace)) { | |
54 | return null; | |
55 | } | |
cb2b5e56 | 56 | LttngUstTrace trace = (LttngUstTrace) event.getTrace(); |
ef7f180d | 57 | |
ef7f180d | 58 | /* |
df993132 AM |
59 | * Resolve the binary callsite first, from there we can use the file's |
60 | * debug information if it is present. | |
ef7f180d | 61 | */ |
df993132 AM |
62 | BinaryCallsite bc = UstDebugInfoBinaryAspect.INSTANCE.resolve(event); |
63 | if (bc == null) { | |
522dff53 AM |
64 | return null; |
65 | } | |
66 | ||
0c65e461 AM |
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()); | |
cb2b5e56 | 86 | } |
ef7f180d | 87 | } |