1 /*******************************************************************************
2 * Copyright (c) 2016 Movidius Inc. and others
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
9 *******************************************************************************/
11 package org
.eclipse
.tracecompass
.internal
.tmf
.ui
.symbols
;
14 import java
.util
.Collections
;
17 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
18 import org
.eclipse
.jdt
.annotation
.NonNull
;
19 import org
.eclipse
.jdt
.annotation
.Nullable
;
20 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.callstack
.FunctionNameMapper
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfCallsite
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.TmfCallsite
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
24 import org
.eclipse
.tracecompass
.tmf
.ui
.symbols
.ISymbolProvider
;
25 import org
.eclipse
.tracecompass
.tmf
.ui
.symbols
.ISymbolProviderPreferencePage
;
28 * The {@link BasicSymbolProvider} can use either an executable or a simple
29 * symbol mapping file to resolve symbols.
34 public class BasicSymbolProvider
implements ISymbolProvider
{
36 private final @NonNull ITmfTrace fTrace
;
38 private @NonNull Map
<String
, String
> fMapping
= Collections
.emptyMap();
40 private String fSource
;
42 private @NonNull SourceKind fKind
= SourceKind
.BINARY
;
44 private boolean fConfigured
;
47 * The kind of source this provider is configured with
50 public static enum SourceKind
{
52 * Literal for binary configuration
57 * Literal for mapping configuration
63 * Create a new {@link BasicSymbolProvider} for the given trace
68 public BasicSymbolProvider(@NonNull ITmfTrace trace
) {
74 * @return the configured source
76 public String
getConfiguredSource() {
81 * @return the configured source kind
83 public @NonNull SourceKind
getConfiguredSourceKind() {
88 * Set the configuration to the given source and kind.
91 * File path to either a binary file or a mapping file.
93 * the type of the referenced file
95 public void setConfiguredSource(String fileSource
, @NonNull SourceKind kind
) {
102 public @NonNull ITmfTrace
getTrace() {
107 public void loadConfiguration(IProgressMonitor monitor
) {
109 synchronized (this) {
112 fMapping
= Collections
.emptyMap();
113 if (fSource
!= null) {
114 File file
= new File(fSource
);
116 Map
<String
, String
> result
;
117 if (fKind
== SourceKind
.BINARY
) {
118 result
= FunctionNameMapper
.mapFromBinaryFile(file
);
120 result
= FunctionNameMapper
.mapFromNmTextFile(file
);
122 if (result
!= null) {
136 public @Nullable String
getSymbolText(long address
) {
137 loadConfiguration(null);
138 return fMapping
.get(Long
.toHexString(address
));
143 public @Nullable ITmfCallsite
getSymbolInfo(long address
) {
144 loadConfiguration(null);
145 String symbolText
= getSymbolText(address
);
146 if (symbolText
!= null) {
147 return new TmfCallsite(null, symbolText
, -1);
153 public ISymbolProviderPreferencePage
createPreferencePage() {
154 return new BasicSymbolProviderPreferencePage(this);