tmf: Remove function name from ITmfCallsite
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.core / src / org / eclipse / tracecompass / lttng2 / ust / core / analysis / debuginfo / UstDebugInfoFunctionAspect.java
1 /*******************************************************************************
2 * Copyright (c) 2016 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.tmf.core.event.ITmfEvent;
19 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
20
21 /**
22 * Aspect for the function location obtained with the UST debug info.
23 *
24 * @author Alexandre Montplaisir
25 * @since 2.0
26 */
27 public class UstDebugInfoFunctionAspect implements ITmfEventAspect<FunctionLocation> {
28
29 /** Singleton instance */
30 public static final UstDebugInfoFunctionAspect INSTANCE = new UstDebugInfoFunctionAspect();
31
32 private UstDebugInfoFunctionAspect() {}
33
34 @Override
35 public String getName() {
36 return nullToEmptyString(Messages.UstDebugInfoAnalysis_FunctionAspectName);
37 }
38
39 @Override
40 public String getHelpText() {
41 return nullToEmptyString(Messages.UstDebugInfoAnalysis_FunctionAspectHelpText);
42 }
43
44 @Override
45 public @Nullable FunctionLocation resolve(ITmfEvent event) {
46 /* Resolve the binary callsite first. */
47 BinaryCallsite bc = UstDebugInfoBinaryAspect.INSTANCE.resolve(event);
48 if (bc == null) {
49 return null;
50 }
51
52 return getFunctionFromBinaryLocation(bc);
53 }
54
55 /**
56 * Get a function location starting directly from a binary callsite, instead
57 * of from a trace event.
58 *
59 * @param bc
60 * The binary callsite, representing a binary and offset within
61 * this binary
62 * @return The corresponding function location
63 * @since 2.1
64 */
65 public static @Nullable FunctionLocation getFunctionFromBinaryLocation(BinaryCallsite bc) {
66 String functionName = FileOffsetMapper.getFunctionNameFromOffset(
67 new File(bc.getBinaryFilePath()),
68 bc.getBuildId(),
69 bc.getOffset());
70 if (functionName == null) {
71 return null;
72 }
73
74 /* We do not track the offset inside the function at this time */
75 return new FunctionLocation(functionName, null);
76 }
77
78 }
This page took 0.03284 seconds and 5 git commands to generate.