1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Marc Dumais - Initial implementation
11 * Francois Chouinard - Initial API and implementation
12 * Patrick Tasse - Updated for TMF 2.0
13 * Matthew Khouzam - update validate
14 *******************************************************************************/
16 package org
.eclipse
.linuxtools
.internal
.gdbtrace
.core
.trace
;
20 import org
.eclipse
.cdt
.dsf
.gdb
.IGDBLaunchConfigurationConstants
;
21 import org
.eclipse
.cdt
.dsf
.gdb
.IGdbDebugPreferenceConstants
;
22 import org
.eclipse
.cdt
.dsf
.gdb
.internal
.GdbPlugin
;
23 import org
.eclipse
.core
.resources
.IProject
;
24 import org
.eclipse
.core
.resources
.IResource
;
25 import org
.eclipse
.core
.runtime
.CoreException
;
26 import org
.eclipse
.core
.runtime
.IStatus
;
27 import org
.eclipse
.core
.runtime
.Platform
;
28 import org
.eclipse
.core
.runtime
.QualifiedName
;
29 import org
.eclipse
.core
.runtime
.Status
;
30 import org
.eclipse
.linuxtools
.internal
.gdbtrace
.core
.Activator
;
31 import org
.eclipse
.linuxtools
.internal
.gdbtrace
.core
.GdbTraceCorePlugin
;
32 import org
.eclipse
.linuxtools
.internal
.gdbtrace
.core
.event
.GdbTraceEvent
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfEventParser
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTrace
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.location
.ITmfLocation
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.location
.TmfLongLocation
;
44 * GDB Tracepoint extension of TmfTrace. This class implements the necessary
45 * methods and functionalities so that a GDB tracepoint file can be used by the
46 * TMF framework as a "tracer".
50 * @author Francois Chouinard
51 * @author Matthew Khouzam
53 @SuppressWarnings("restriction")
54 public class GdbTrace
extends TmfTrace
implements ITmfEventParser
{
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
60 private static final int CACHE_SIZE
= 20;
62 /** The qualified name for the 'executable' persistent property */
63 public static final QualifiedName EXEC_KEY
= new QualifiedName(GdbTraceCorePlugin
.PLUGIN_ID
, "executable"); //$NON-NLS-1$
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
69 // Interface to access GDB Tracepoints
70 private DsfGdbAdaptor fGdbTpRef
;
71 private long fNbFrames
= 0;
76 // ------------------------------------------------------------------------
78 // ------------------------------------------------------------------------
84 setCacheSize(CACHE_SIZE
);
88 public IStatus
validate(IProject project
, String path
) {
89 if (fileExists(path
)) {
90 if ((new File(path
)).isFile()) {
91 return Status
.OK_STATUS
;
93 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
,
94 Messages
.GdbTrace_GdbTracesMustBeAFile
+ ": " + //$NON-NLS-1$
95 path
+ " " + Messages
.GdbTrace_IsNotAFile
); //$NON-NLS-1$
97 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.GdbTrace_FileNotFound
+ ": " + path
); //$NON-NLS-1$
101 public void initTrace(IResource resource
, String path
, Class
<?
extends ITmfEvent
> type
) throws TmfTraceException
{
103 String tracedExecutable
= resource
.getPersistentProperty(EXEC_KEY
);
104 if (tracedExecutable
== null) {
105 throw new TmfTraceException(Messages
.GdbTrace_ExecutableNotSet
);
108 String defaultGdbCommand
= Platform
.getPreferencesService().getString(GdbPlugin
.PLUGIN_ID
,
109 IGdbDebugPreferenceConstants
.PREF_DEFAULT_GDB_COMMAND
,
110 IGDBLaunchConfigurationConstants
.DEBUGGER_DEBUG_NAME_DEFAULT
, null);
112 fGdbTpRef
= new DsfGdbAdaptor(this, defaultGdbCommand
, path
, tracedExecutable
);
113 fNbFrames
= getNbFrames();
114 } catch (CoreException e
) {
115 throw new TmfTraceException(Messages
.GdbTrace_FailedToInitializeTrace
, e
);
118 super.initTrace(resource
, path
, type
);
122 public synchronized void dispose() {
123 if (fGdbTpRef
!= null) {
130 * @return GDB-DSF session id
132 public String
getDsfSessionId() {
133 return fGdbTpRef
.getSessionId();
137 * @return the number of frames in current tp session
139 public synchronized long getNbFrames() {
140 fNbFrames
= fGdbTpRef
.getNumberOfFrames();
144 // ------------------------------------------------------------------------
146 // ------------------------------------------------------------------------
149 public synchronized TmfContext
seekEvent(ITmfLocation location
) {
150 fLocation
= (location
!= null) ?
((Long
) location
.getLocationInfo()) : 0;
151 return new TmfContext(new TmfLongLocation(fLocation
), fLocation
);
155 public synchronized ITmfContext
seekEvent(double ratio
) {
156 TmfContext context
= seekEvent((long) ratio
* getNbEvents());
161 public double getLocationRatio(ITmfLocation location
) {
162 if (getNbEvents() > 0 && location
instanceof TmfLongLocation
) {
163 return (double) ((TmfLongLocation
) location
).getLocationInfo() / getNbEvents();
169 public ITmfLocation
getCurrentLocation() {
170 return new TmfLongLocation(fLocation
);
174 public GdbTraceEvent
parseEvent(ITmfContext context
) {
175 if (context
.getRank() >= fNbFrames
) {
178 // work-around to ensure that the select and parse of trace frame will
180 GdbTraceEvent event
= fGdbTpRef
.selectAndReadFrame(context
.getRank());
186 public synchronized TmfContext
seekEvent(ITmfTimestamp timestamp
) {
187 long rank
= timestamp
.getValue();
188 return seekEvent(rank
);
192 public synchronized TmfContext
seekEvent(long rank
) {
194 TmfContext context
= new TmfContext(new TmfLongLocation(fLocation
), rank
);
199 * Select a frame and update the visualization
204 public synchronized void selectFrame(long rank
) {
205 fGdbTpRef
.selectDataFrame(rank
, true);