/*******************************************************************************
- * Copyright (c) 2011, 2013 Ericsson
+ * Copyright (c) 2011, 2014 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
package org.eclipse.linuxtools.internal.gdbtrace.core.trace;
+import java.io.BufferedInputStream;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants;
+import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants;
+import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
import org.eclipse.linuxtools.internal.gdbtrace.core.Activator;
import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TraceValidationStatus;
import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
import org.eclipse.linuxtools.tmf.core.trace.location.TmfLongLocation;
+import org.eclipse.osgi.util.NLS;
/**
* GDB Tracepoint extension of TmfTrace. This class implements the necessary
* @author Francois Chouinard
* @author Matthew Khouzam
*/
+@SuppressWarnings("restriction")
public class GdbTrace extends TmfTrace implements ITmfEventParser {
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
private static final int CACHE_SIZE = 20;
- private static final String GDB_EXECUTABLE = "gdb"; //$NON-NLS-1$
+
+ private static final byte[] HEADER = new byte[] {0x7f, 'T', 'R', 'A', 'C', 'E'};
/** The qualified name for the 'executable' persistent property */
public static final QualifiedName EXEC_KEY = new QualifiedName(GdbTraceCorePlugin.PLUGIN_ID, "executable"); //$NON-NLS-1$
@Override
public IStatus validate(IProject project, String path) {
- if (fileExists(path)) {
- if ((new File(path)).isFile()) {
- return Status.OK_STATUS;
+ File file = new File(path);
+ if (!file.exists()) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ NLS.bind(Messages.GdbTrace_FileNotFound, path));
+ }
+ if (!file.isFile()) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ NLS.bind(Messages.GdbTrace_GdbTracesMustBeAFile, path));
+ }
+ try (BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file))) {
+ byte[] buffer = new byte[HEADER.length];
+ int read = stream.read(buffer);
+ if (read != HEADER.length || !Arrays.equals(buffer, HEADER)) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ NLS.bind(Messages.GdbTrace_NotGdbTraceFile, path));
}
+ } catch (IOException e) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
- Messages.GdbTrace_GdbTracesMustBeAFile + ": " + //$NON-NLS-1$
- path + " " + Messages.GdbTrace_IsNotAFile); //$NON-NLS-1$
+ NLS.bind(Messages.GdbTrace_IOException, path), e);
}
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.GdbTrace_FileNotFound + ": " + path); //$NON-NLS-1$
+ return new TraceValidationStatus(100, GdbTraceCorePlugin.PLUGIN_ID);
}
@Override
if (tracedExecutable == null) {
throw new TmfTraceException(Messages.GdbTrace_ExecutableNotSet);
}
- fGdbTpRef = new DsfGdbAdaptor(this, GDB_EXECUTABLE, path, tracedExecutable);
- fNbFrames = fGdbTpRef.getNumberOfFrames();
+
+ String defaultGdbCommand = Platform.getPreferencesService().getString(GdbPlugin.PLUGIN_ID,
+ IGdbDebugPreferenceConstants.PREF_DEFAULT_GDB_COMMAND,
+ IGDBLaunchConfigurationConstants.DEBUGGER_DEBUG_NAME_DEFAULT, null);
+
+ fGdbTpRef = new DsfGdbAdaptor(this, defaultGdbCommand, path, tracedExecutable);
+ fNbFrames = getNbFrames();
} catch (CoreException e) {
throw new TmfTraceException(Messages.GdbTrace_FailedToInitializeTrace, e);
}
/**
* @return the number of frames in current tp session
*/
- public long getNbFrames() {
+ public synchronized long getNbFrames() {
fNbFrames = fGdbTpRef.getNumberOfFrames();
return fNbFrames;
}
* @param rank
* the rank
*/
- public void selectFrame(long rank) {
+ public synchronized void selectFrame(long rank) {
fGdbTpRef.selectDataFrame(rank, true);
}
}
\ No newline at end of file