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
.signal
.TmfTraceUpdatedSignal
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfEventParser
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTrace
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.location
.ITmfLocation
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.location
.TmfLongLocation
;
45 * GDB Tracepoint extension of TmfTrace. This class implements the necessary
46 * methods and functionalities so that a GDB tracepoint file can be used by the
47 * TMF framework as a "tracer".
51 * @author Francois Chouinard
52 * @author Matthew Khouzam
54 @SuppressWarnings("restriction")
55 public class GdbTrace
extends TmfTrace
implements ITmfEventParser
{
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
61 private static final int CACHE_SIZE
= 20;
63 /** The qualified name for the 'executable' persistent property */
64 public static final QualifiedName EXEC_KEY
= new QualifiedName(GdbTraceCorePlugin
.PLUGIN_ID
, "executable"); //$NON-NLS-1$
66 // ------------------------------------------------------------------------
68 // ------------------------------------------------------------------------
70 // Interface to access GDB Tracepoints
71 private DsfGdbAdaptor fGdbTpRef
;
72 private long fNbFrames
= 0;
77 // ------------------------------------------------------------------------
79 // ------------------------------------------------------------------------
85 setCacheSize(CACHE_SIZE
);
89 public IStatus
validate(IProject project
, String path
) {
90 if (fileExists(path
)) {
91 if ((new File(path
)).isFile()) {
92 return Status
.OK_STATUS
;
94 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
,
95 Messages
.GdbTrace_GdbTracesMustBeAFile
+ ": " + //$NON-NLS-1$
96 path
+ " " + Messages
.GdbTrace_IsNotAFile
); //$NON-NLS-1$
98 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.GdbTrace_FileNotFound
+ ": " + path
); //$NON-NLS-1$
102 public void initTrace(IResource resource
, String path
, Class
<?
extends ITmfEvent
> type
) throws TmfTraceException
{
104 String tracedExecutable
= resource
.getPersistentProperty(EXEC_KEY
);
105 if (tracedExecutable
== null) {
106 throw new TmfTraceException(Messages
.GdbTrace_ExecutableNotSet
);
109 String defaultGdbCommand
= Platform
.getPreferencesService().getString(GdbPlugin
.PLUGIN_ID
,
110 IGdbDebugPreferenceConstants
.PREF_DEFAULT_GDB_COMMAND
,
111 IGDBLaunchConfigurationConstants
.DEBUGGER_DEBUG_NAME_DEFAULT
, null);
113 fGdbTpRef
= new DsfGdbAdaptor(this, defaultGdbCommand
, path
, tracedExecutable
);
114 fNbFrames
= getNbFrames();
115 } catch (CoreException e
) {
116 throw new TmfTraceException(Messages
.GdbTrace_FailedToInitializeTrace
, e
);
119 super.initTrace(resource
, path
, type
);
123 public synchronized void dispose() {
124 if (fGdbTpRef
!= null) {
131 * @return GDB-DSF session id
133 public String
getDsfSessionId() {
134 return fGdbTpRef
.getSessionId();
138 * @return the number of frames in current tp session
140 public synchronized long getNbFrames() {
141 fNbFrames
= fGdbTpRef
.getNumberOfFrames();
145 // ------------------------------------------------------------------------
147 // ------------------------------------------------------------------------
150 public synchronized TmfContext
seekEvent(ITmfLocation location
) {
151 fLocation
= (location
!= null) ?
((Long
) location
.getLocationInfo()) : 0;
152 return new TmfContext(new TmfLongLocation(fLocation
), fLocation
);
156 public synchronized ITmfContext
seekEvent(double ratio
) {
157 TmfContext context
= seekEvent((long) ratio
* getNbEvents());
162 public double getLocationRatio(ITmfLocation location
) {
163 if (getNbEvents() > 0 && location
instanceof TmfLongLocation
) {
164 return (double) ((TmfLongLocation
) location
).getLocationInfo() / getNbEvents();
170 public ITmfLocation
getCurrentLocation() {
171 return new TmfLongLocation(fLocation
);
175 public GdbTraceEvent
parseEvent(ITmfContext context
) {
176 if (context
.getRank() >= fNbFrames
) {
179 // work-around to ensure that the select and parse of trace frame will
181 GdbTraceEvent event
= fGdbTpRef
.selectAndReadFrame(context
.getRank());
187 public synchronized TmfContext
seekEvent(ITmfTimestamp timestamp
) {
188 long rank
= timestamp
.getValue();
189 return seekEvent(rank
);
193 public synchronized TmfContext
seekEvent(long rank
) {
195 TmfContext context
= new TmfContext(new TmfLongLocation(fLocation
), rank
);
200 * Select a frame and update the visualization
205 public synchronized void selectFrame(long rank
) {
206 fGdbTpRef
.selectDataFrame(rank
, true);