Commit | Line | Data |
---|---|---|
6de2f761 PT |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011, 2013 Ericsson | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Marc Dumais - Initial implementation | |
11 | * Francois Chouinard - Initial API and implementation | |
12 | * Patrick Tasse - Updated for TMF 2.0 | |
a94410d9 | 13 | * Matthew Khouzam - update validate |
6de2f761 PT |
14 | *******************************************************************************/ |
15 | ||
8343b1f5 | 16 | package org.eclipse.linuxtools.internal.gdbtrace.core.trace; |
6de2f761 | 17 | |
0eefbc92 MK |
18 | import java.io.File; |
19 | ||
6131f792 MAL |
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; | |
6de2f761 PT |
23 | import org.eclipse.core.resources.IProject; |
24 | import org.eclipse.core.resources.IResource; | |
25 | import org.eclipse.core.runtime.CoreException; | |
a94410d9 | 26 | import org.eclipse.core.runtime.IStatus; |
6131f792 | 27 | import org.eclipse.core.runtime.Platform; |
6de2f761 | 28 | import org.eclipse.core.runtime.QualifiedName; |
a94410d9 | 29 | import org.eclipse.core.runtime.Status; |
0eefbc92 | 30 | import org.eclipse.linuxtools.internal.gdbtrace.core.Activator; |
8343b1f5 PT |
31 | import org.eclipse.linuxtools.internal.gdbtrace.core.GdbTraceCorePlugin; |
32 | import org.eclipse.linuxtools.internal.gdbtrace.core.event.GdbTraceEvent; | |
6de2f761 PT |
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; | |
6de2f761 | 38 | import org.eclipse.linuxtools.tmf.core.trace.TmfContext; |
6de2f761 | 39 | import org.eclipse.linuxtools.tmf.core.trace.TmfTrace; |
a3db8436 AM |
40 | import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation; |
41 | import org.eclipse.linuxtools.tmf.core.trace.location.TmfLongLocation; | |
6de2f761 PT |
42 | |
43 | /** | |
a94410d9 MK |
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". | |
6de2f761 | 47 | * <p> |
a94410d9 | 48 | * |
6de2f761 PT |
49 | * @author Marc Dumais |
50 | * @author Francois Chouinard | |
a94410d9 | 51 | * @author Matthew Khouzam |
6de2f761 | 52 | */ |
6131f792 | 53 | @SuppressWarnings("restriction") |
6de2f761 PT |
54 | public class GdbTrace extends TmfTrace implements ITmfEventParser { |
55 | ||
56 | // ------------------------------------------------------------------------ | |
57 | // Constants | |
58 | // ------------------------------------------------------------------------ | |
59 | ||
60 | private static final int CACHE_SIZE = 20; | |
6de2f761 PT |
61 | |
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$ | |
64 | ||
65 | // ------------------------------------------------------------------------ | |
66 | // Attributes | |
67 | // ------------------------------------------------------------------------ | |
68 | ||
69 | // Interface to access GDB Tracepoints | |
70 | private DsfGdbAdaptor fGdbTpRef; | |
71 | private long fNbFrames = 0; | |
72 | ||
73 | // The trace location | |
74 | long fLocation; | |
75 | ||
76 | // ------------------------------------------------------------------------ | |
77 | // Constructor | |
78 | // ------------------------------------------------------------------------ | |
79 | ||
80 | /** | |
81 | * Default constructor | |
82 | */ | |
83 | public GdbTrace() { | |
84 | setCacheSize(CACHE_SIZE); | |
85 | } | |
86 | ||
87 | @Override | |
a94410d9 MK |
88 | public IStatus validate(IProject project, String path) { |
89 | if (fileExists(path)) { | |
0eefbc92 MK |
90 | if ((new File(path)).isFile()) { |
91 | return Status.OK_STATUS; | |
92 | } | |
93 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, | |
94 | Messages.GdbTrace_GdbTracesMustBeAFile + ": " + //$NON-NLS-1$ | |
95 | path + " " + Messages.GdbTrace_IsNotAFile); //$NON-NLS-1$ | |
a94410d9 MK |
96 | } |
97 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.GdbTrace_FileNotFound + ": " + path); //$NON-NLS-1$ | |
6de2f761 PT |
98 | } |
99 | ||
100 | @Override | |
101 | public void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type) throws TmfTraceException { | |
102 | try { | |
103 | String tracedExecutable = resource.getPersistentProperty(EXEC_KEY); | |
104 | if (tracedExecutable == null) { | |
0eefbc92 | 105 | throw new TmfTraceException(Messages.GdbTrace_ExecutableNotSet); |
6de2f761 | 106 | } |
6131f792 MAL |
107 | |
108 | String defaultGdbCommand = Platform.getPreferencesService().getString(GdbPlugin.PLUGIN_ID, | |
109 | IGdbDebugPreferenceConstants.PREF_DEFAULT_GDB_COMMAND, | |
110 | IGDBLaunchConfigurationConstants.DEBUGGER_DEBUG_NAME_DEFAULT, null); | |
111 | ||
112 | fGdbTpRef = new DsfGdbAdaptor(this, defaultGdbCommand, path, tracedExecutable); | |
6b6e81de | 113 | fNbFrames = getNbFrames(); |
6de2f761 | 114 | } catch (CoreException e) { |
0eefbc92 | 115 | throw new TmfTraceException(Messages.GdbTrace_FailedToInitializeTrace, e); |
6de2f761 PT |
116 | } |
117 | ||
118 | super.initTrace(resource, path, type); | |
119 | } | |
120 | ||
121 | @Override | |
122 | public synchronized void dispose() { | |
123 | if (fGdbTpRef != null) { | |
124 | fGdbTpRef.dispose(); | |
125 | } | |
126 | super.dispose(); | |
127 | } | |
128 | ||
129 | /** | |
130 | * @return GDB-DSF session id | |
131 | */ | |
a94410d9 | 132 | public String getDsfSessionId() { |
6de2f761 PT |
133 | return fGdbTpRef.getSessionId(); |
134 | } | |
135 | ||
136 | /** | |
137 | * @return the number of frames in current tp session | |
138 | */ | |
6b6e81de | 139 | public synchronized long getNbFrames() { |
a94410d9 | 140 | fNbFrames = fGdbTpRef.getNumberOfFrames(); |
6de2f761 PT |
141 | return fNbFrames; |
142 | } | |
143 | ||
144 | // ------------------------------------------------------------------------ | |
145 | // TmfTrace | |
146 | // ------------------------------------------------------------------------ | |
147 | ||
148 | @Override | |
149 | public synchronized TmfContext seekEvent(ITmfLocation location) { | |
150 | fLocation = (location != null) ? ((Long) location.getLocationInfo()) : 0; | |
151 | return new TmfContext(new TmfLongLocation(fLocation), fLocation); | |
152 | } | |
153 | ||
154 | @Override | |
155 | public synchronized ITmfContext seekEvent(double ratio) { | |
156 | TmfContext context = seekEvent((long) ratio * getNbEvents()); | |
157 | return context; | |
158 | } | |
159 | ||
160 | @Override | |
161 | public double getLocationRatio(ITmfLocation location) { | |
162 | if (getNbEvents() > 0 && location instanceof TmfLongLocation) { | |
163 | return (double) ((TmfLongLocation) location).getLocationInfo() / getNbEvents(); | |
164 | } | |
165 | return 0; | |
166 | } | |
167 | ||
168 | @Override | |
169 | public ITmfLocation getCurrentLocation() { | |
170 | return new TmfLongLocation(fLocation); | |
171 | } | |
172 | ||
173 | @Override | |
174 | public GdbTraceEvent parseEvent(ITmfContext context) { | |
175 | if (context.getRank() >= fNbFrames) { | |
176 | return null; | |
177 | } | |
a94410d9 MK |
178 | // work-around to ensure that the select and parse of trace frame will |
179 | // be atomic | |
6de2f761 PT |
180 | GdbTraceEvent event = fGdbTpRef.selectAndReadFrame(context.getRank()); |
181 | fLocation++; | |
182 | return event; | |
183 | } | |
184 | ||
185 | @Override | |
186 | public synchronized TmfContext seekEvent(ITmfTimestamp timestamp) { | |
187 | long rank = timestamp.getValue(); | |
188 | return seekEvent(rank); | |
189 | } | |
190 | ||
191 | @Override | |
192 | public synchronized TmfContext seekEvent(long rank) { | |
193 | fLocation = rank; | |
194 | TmfContext context = new TmfContext(new TmfLongLocation(fLocation), rank); | |
195 | return context; | |
196 | } | |
197 | ||
198 | /** | |
199 | * Select a frame and update the visualization | |
a94410d9 MK |
200 | * |
201 | * @param rank | |
202 | * the rank | |
6de2f761 | 203 | */ |
e9a6e38e | 204 | public synchronized void selectFrame(long rank) { |
6de2f761 PT |
205 | fGdbTpRef.selectDataFrame(rank, true); |
206 | } | |
207 | } |