summaryrefslogtreecommitdiff
path: root/org.eclipse.linuxtools.gcov
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.linuxtools.gcov')
-rw-r--r--org.eclipse.linuxtools.gcov/.classpath7
-rw-r--r--org.eclipse.linuxtools.gcov/.project28
-rw-r--r--org.eclipse.linuxtools.gcov/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--org.eclipse.linuxtools.gcov/META-INF/MANIFEST.MF31
-rw-r--r--org.eclipse.linuxtools.gcov/NOTICE6
-rw-r--r--org.eclipse.linuxtools.gcov/about.html28
-rw-r--r--org.eclipse.linuxtools.gcov/build.properties8
-rw-r--r--org.eclipse.linuxtools.gcov/icons/c_file_obj.gifbin0 -> 1019 bytes
-rw-r--r--org.eclipse.linuxtools.gcov/icons/directory_obj.gifbin0 -> 162 bytes
-rw-r--r--org.eclipse.linuxtools.gcov/icons/function_obj.gifbin0 -> 617 bytes
-rw-r--r--org.eclipse.linuxtools.gcov/icons/src_file_obj.gifbin0 -> 617 bytes
-rw-r--r--org.eclipse.linuxtools.gcov/icons/toggle.gifbin0 -> 610 bytes
-rw-r--r--org.eclipse.linuxtools.gcov/plugin.properties16
-rw-r--r--org.eclipse.linuxtools.gcov/plugin.xml38
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/Activator.java71
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/action/OpenGCAction.java166
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/action/SwitchContentProviderAction.java44
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/dialog/OpenGCDialog.java303
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/AbstractTreeElement.java79
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovFileTreeElement.java25
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovFolderTreeElement.java24
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovFunctionTreeElement.java57
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovRootTreeElement.java26
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/TreeElement.java27
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Arc.java131
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Block.java177
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/CovManager.java372
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/CoverageInfo.java52
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Folder.java65
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/GcdaRecordsParser.java272
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/GcnoFunction.java255
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/GcnoRecordsParser.java241
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Line.java50
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/SourceFile.java110
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/BEDataInputStream.java191
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/GcovStringReader.java38
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/LEDataInputStream.java208
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/MasksGenerator.java15
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/STGcovProgramChecker.java85
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovFileContentProvider.java60
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovFolderContentProvider.java61
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovFunctionContentProvider.java52
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovView.java279
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovViewer.java119
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldCoveragePercentage.java99
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldExecutedLines.java68
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldInstrumentedLines.java77
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldName.java69
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldTotalLines.java82
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/CoverageAnnotationColumn.java79
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/OpenSourceFileAction.java136
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/STAnnotatedSourceEditorInput.java73
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/STAnnotatedSourceNotFoundEditor.java50
-rw-r--r--org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/STAnnotatedSourceNotFoundEditorInput.java69
54 files changed, 4626 insertions, 0 deletions
diff --git a/org.eclipse.linuxtools.gcov/.classpath b/org.eclipse.linuxtools.gcov/.classpath
new file mode 100644
index 0000000..a87b062
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry exported="true" kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry excluding="**/.svn/**" kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.linuxtools.gcov/.project b/org.eclipse.linuxtools.gcov/.project
new file mode 100644
index 0000000..7c48214
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.linuxtools.gcov</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.linuxtools.gcov/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.gcov/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3d3c172
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+#Thu Jan 15 16:04:09 CET 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/org.eclipse.linuxtools.gcov/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.gcov/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..3cb4508
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/META-INF/MANIFEST.MF
@@ -0,0 +1,31 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %bundleName
+Bundle-SymbolicName: org.eclipse.linuxtools.gcov;singleton:=true
+Bundle-Version: 4.1.1.qualifier
+Bundle-Activator: org.eclipse.linuxtools.gcov.Activator
+Bundle-Vendor: %bundleProvider
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.linuxtools.dataviewers,
+ org.eclipse.core.filesystem,
+ org.eclipse.core.variables,
+ org.eclipse.ui.ide,
+ org.eclipse.ui.editors,
+ org.eclipse.linuxtools.binutils,
+ org.eclipse.cdt.core,
+ org.eclipse.cdt.ui,
+ org.eclipse.jface.text,
+ org.eclipse.debug.ui,
+ org.eclipse.linuxtools.dataviewers.charts,
+ org.eclipse.linuxtools.dataviewers.annotatedsourceeditor
+Export-Package: org.eclipse.linuxtools.gcov,
+ org.eclipse.linuxtools.gcov.parser,
+ org.eclipse.linuxtools.gcov.utils,
+ org.eclipse.linuxtools.gcov.view
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-Localization: plugin
+Import-Package: org.tizen.common.core.application,
+ org.tizen.common.util,
+ org.tizen.nativecommon.build
diff --git a/org.eclipse.linuxtools.gcov/NOTICE b/org.eclipse.linuxtools.gcov/NOTICE
new file mode 100644
index 0000000..d4ca105
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/NOTICE
@@ -0,0 +1,6 @@
+
+org.eclipse.linuxtools.gcov.parser
+ - CovManager.java line 272
+ if windows then use strings binary in MinGW
+
+
diff --git a/org.eclipse.linuxtools.gcov/about.html b/org.eclipse.linuxtools.gcov/about.html
new file mode 100644
index 0000000..c258ef5
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2006</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/org.eclipse.linuxtools.gcov/build.properties b/org.eclipse.linuxtools.gcov/build.properties
new file mode 100644
index 0000000..a4d0a62
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/build.properties
@@ -0,0 +1,8 @@
+source.. = src/
+output.. = bin/
+bin.includes = .,\
+ META-INF/,\
+ icons/,\
+ plugin.xml,\
+ about.html,\
+ plugin.properties \ No newline at end of file
diff --git a/org.eclipse.linuxtools.gcov/icons/c_file_obj.gif b/org.eclipse.linuxtools.gcov/icons/c_file_obj.gif
new file mode 100644
index 0000000..915b7f4
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/icons/c_file_obj.gif
Binary files differ
diff --git a/org.eclipse.linuxtools.gcov/icons/directory_obj.gif b/org.eclipse.linuxtools.gcov/icons/directory_obj.gif
new file mode 100644
index 0000000..7937f33
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/icons/directory_obj.gif
Binary files differ
diff --git a/org.eclipse.linuxtools.gcov/icons/function_obj.gif b/org.eclipse.linuxtools.gcov/icons/function_obj.gif
new file mode 100644
index 0000000..08aef8f
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/icons/function_obj.gif
Binary files differ
diff --git a/org.eclipse.linuxtools.gcov/icons/src_file_obj.gif b/org.eclipse.linuxtools.gcov/icons/src_file_obj.gif
new file mode 100644
index 0000000..8fd6adb
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/icons/src_file_obj.gif
Binary files differ
diff --git a/org.eclipse.linuxtools.gcov/icons/toggle.gif b/org.eclipse.linuxtools.gcov/icons/toggle.gif
new file mode 100644
index 0000000..62a7d86
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/icons/toggle.gif
Binary files differ
diff --git a/org.eclipse.linuxtools.gcov/plugin.properties b/org.eclipse.linuxtools.gcov/plugin.properties
new file mode 100644
index 0000000..f29e54a
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/plugin.properties
@@ -0,0 +1,16 @@
+#******************************************************************************
+# Copyright (c) 2009 STMicroelectronics.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+#*******************************************************************************
+bundleProvider = Eclipse Linux Tools
+bundleName = Gcov Plug-in (Incubation)
+gcovEditor = Gcov Editor
+gcov = gcov
+gcovDescription = Gcov view displays the profiling information contained in gcda/gcno files
+gcovCategory = gcov \ No newline at end of file
diff --git a/org.eclipse.linuxtools.gcov/plugin.xml b/org.eclipse.linuxtools.gcov/plugin.xml
new file mode 100644
index 0000000..a546b66
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/plugin.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.views">
+ <category
+ id="org.eclipse.linuxtools.gcov"
+ name="%gcovCategory">
+ </category>
+ <view
+ allowMultiple="true"
+ category="org.tizen.nativeapp.viewCategory"
+ class="org.eclipse.linuxtools.gcov.view.CovView"
+ icon="icons/toggle.gif"
+ id="org.eclipse.linuxtools.gcov.view"
+ name="%gcov"
+ restorable="false">
+ </view>
+ </extension>
+ <extension
+ point="org.eclipse.ui.editors">
+ <editor
+ class="org.eclipse.linuxtools.gcov.view.annotatedsource.STAnnotatedSourceNotFoundEditor"
+ icon="icons/src_file_obj.gif"
+ id="org.eclipse.linuxtools.gcov.view.annotatedsource.STAnnotatedSourceNotFoundEditor"
+ name="Source Not Found">
+ </editor>
+ <editor
+ extensions="gcda, gcno"
+ icon="icons/toggle.gif"
+ id="org.eclipse.linuxtools.gcov.editor"
+ launcher="org.eclipse.linuxtools.gcov.action.OpenGCAction"
+ name="%gcovEditor">
+ </editor>
+ </extension>
+
+
+</plugin>
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/Activator.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/Activator.java
new file mode 100644
index 0000000..e595b1d
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/Activator.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.linuxtools.gcov";
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given
+ * plug-in relative path
+ *
+ * @param path the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/action/OpenGCAction.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/action/OpenGCAction.java
new file mode 100644
index 0000000..bfc86b4
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/action/OpenGCAction.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.action;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.IBinary;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.linuxtools.gcov.Activator;
+import org.eclipse.linuxtools.gcov.dialog.OpenGCDialog;
+import org.eclipse.linuxtools.gcov.view.CovView;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorLauncher;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * Action performed when user clicks on a gcda/gcno file
+ *
+ * @author Xavier Raynaud <xavier.raynaud@st.com>
+ */
+public class OpenGCAction implements IEditorLauncher {
+
+ public void open(IPath file) {
+ Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
+ String extension = file.getFileExtension();
+ File gcno;
+ File gcda;
+ if ("gcno".equals(extension)) {
+ IPath file2 = file.removeFileExtension().addFileExtension("gcda");
+ gcno = file.toFile();
+ gcda = file2.toFile();
+ } else if ("gcda".equals(extension)) {
+ IPath file2 = file.removeFileExtension().addFileExtension("gcno");
+ gcda = file.toFile();
+ gcno = file2.toFile();
+
+ } else {
+ // should never occurs
+ return;
+ }
+
+ if (gcda == null || !gcda.isFile()) {
+ String msg = "File " + gcda + " does not exist.";
+ msg += "\nPlease run your application at least once.";
+ MessageDialog.openError(shell, "gcov Error", msg);
+ return;
+ }
+ if (gcno == null || !gcno.isFile()) {
+ String msg = "File " + gcno + " does not exist.";
+ msg += "\nPlease recompile your application.";
+ MessageDialog.openError(shell, "gcov Error", msg);
+ return;
+ }
+
+
+ String s = getDefaultBinary(file);
+ OpenGCDialog d = new OpenGCDialog(shell, s, file);
+ if (d.open() != OpenGCDialog.OK) {
+ return;
+ }
+ String binaryPath = d.getBinaryFile();
+ if (d.isCompleteCoverageResultWanted()) {
+ CovView.displayCovResults(binaryPath);
+ } else {
+ CovView.displayCovDetailedResult(binaryPath, gcda.getAbsolutePath());
+ }
+ }
+
+ private String getDefaultBinary(IPath file) {
+ File gmonFile = file.toFile();
+ File parent = gmonFile.getParentFile();
+ File info = new File(parent,"AnalysisInfo.txt");
+ IProject project = null;
+ IFile ifile = null;
+ try {
+ String line;
+ String tab[];
+ if (info.exists()) {
+ BufferedReader br = new BufferedReader(new FileReader(info.toString()));
+
+ while ((line = br.readLine())!= null){
+ tab = line.split("=");
+ String name="", value="";
+ if (tab.length > 1){
+ name=tab[0];
+ value=tab[1].trim();
+ if (name.equals("Project Name ")){
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject(value);
+ }
+ else if (name.equals("Program Name ")){
+ if(project != null){
+ ifile = project.getFile(value);
+ br.close();
+ if (ifile.exists()) {
+ return ifile.getLocation().toString();
+ }
+ }
+ }
+ }
+ }
+ }else{
+ IFile c = ResourcesPlugin.getWorkspace().getRoot()
+ .getFileForLocation(file);
+ if (c != null) {
+ project = c.getProject();
+ if (project != null && project.exists()) {
+ ICProject cproject = CoreModel.getDefault().create(project);
+ if (cproject != null) {
+ try {
+ IBinary[] b = cproject.getBinaryContainer()
+ .getBinaries();
+ if (b != null && b.length > 0 && b[0] != null) {
+ IResource r = b[0].getResource();
+ return r.getLocation().toOSString();
+ }
+ } catch (CModelException _) {
+ }
+ }
+ }
+ }
+ }
+ } catch (FileNotFoundException e) {
+ Status status = new Status(
+ Status.WARNING,
+ Activator.PLUGIN_ID,
+ IStatus.WARNING,
+ e.getMessage(),
+ e
+ );
+ Activator.getDefault().getLog().log(status);
+ } catch (IOException e) {
+ Status status = new Status(
+ Status.ERROR,
+ Activator.PLUGIN_ID,
+ IStatus.ERROR,
+ e.getMessage(),
+ e
+ );
+ Activator.getDefault().getLog().log(status);
+ }
+ return "";
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/action/SwitchContentProviderAction.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/action/SwitchContentProviderAction.java
new file mode 100644
index 0000000..b1ac0f2
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/action/SwitchContentProviderAction.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.action;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.viewers.ColumnViewer;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.linuxtools.gcov.Activator;
+
+
+ /**
+ * This action changes the content provider
+ */
+
+ public class SwitchContentProviderAction extends Action {
+
+ private final ColumnViewer viewer;
+ private final IContentProvider provider;
+
+ public SwitchContentProviderAction(String name, String iconPath, ColumnViewer viewer, IContentProvider provider) {
+ super(name, AS_RADIO_BUTTON);
+ this.setImageDescriptor(Activator.getImageDescriptor(iconPath));
+ this.setToolTipText(name);
+ this.viewer = viewer;
+ this.provider = provider;
+ }
+
+ @Override
+ public void run() {
+ viewer.getControl().setRedraw(false);
+ viewer.setContentProvider(provider);
+ ((TreeViewer)viewer).expandToLevel(2);
+ viewer.getControl().setRedraw(true);
+ }
+ } \ No newline at end of file
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/dialog/OpenGCDialog.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/dialog/OpenGCDialog.java
new file mode 100644
index 0000000..5b69b71
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/dialog/OpenGCDialog.java
@@ -0,0 +1,303 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.dialog;
+
+import java.io.File;
+
+import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.variables.IStringVariableManager;
+import org.eclipse.core.variables.VariablesPlugin;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.linuxtools.binutils.utils.STSymbolManager;
+import org.eclipse.linuxtools.gcov.Activator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
+import org.eclipse.ui.dialogs.ISelectionStatusValidator;
+import org.eclipse.ui.model.WorkbenchContentProvider;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.eclipse.ui.views.navigator.ResourceComparator;
+
+
+/**
+ * This dialog box is opened when user clicks on a gcno/gcda file.
+ * it allows the user to choose the binary file who produced the gcno/gcda file.
+ * @author Xavier Raynaud <xavier.raynaud@st.com>
+ *
+ */
+public class OpenGCDialog extends Dialog {
+
+ /* Inputs */
+ private Text binText;
+ private String binValue;
+
+ private Button openThisFileOnlyButton;
+ private Button openCoverageSummaryButton;
+ private boolean openCoverageSummary = true;
+
+ /* buttons */
+ private Button binBrowseWorkspaceButton;
+ private Button binBrowseFileSystemButton;
+
+ /* error label */
+ private Label errorLabel;
+
+ /* validation boolean */
+ private boolean binaryValid;
+
+ /* internal listener */
+ private final BinaryModifyListener binModifyListener = new BinaryModifyListener();
+
+ private final String defaultValue;
+ private final IPath gcFile;
+
+ /**
+ * Constructor
+ * @param parentShell
+ * @param binPath the path to a binary file.
+ */
+ public OpenGCDialog(Shell parentShell, String binPath, IPath gcFile) {
+ super(parentShell);
+ this.gcFile = gcFile;
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ this.defaultValue = binPath;
+ }
+
+ /**
+ * Gets the Binary file selected by the user
+ * @return a path to a binary file
+ */
+ public String getBinaryFile() {
+ return binValue;
+ }
+
+ /**
+ * Gets whether the user wants a complete coverage result, or a result specific file to the given gcFile.
+ */
+ public boolean isCompleteCoverageResultWanted() {
+ return openCoverageSummary;
+ }
+
+
+ protected Control createContents(Composite parent) {
+ Control composite = super.createContents(parent);
+ validateBinary();
+ return composite;
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ this.getShell().setText("Gcov - Open coverage results...");
+ Composite composite = (Composite) super.createDialogArea(parent);
+
+ /* first line */
+ Group c = new Group(composite, SWT.NONE);
+ c.setText("Binary File");
+ c.setToolTipText("Please enter here the binary file which produced the coverage data.");
+ GridLayout layout = new GridLayout(2,false);
+ c.setLayout(layout);
+ GridData data = new GridData(GridData.FILL_BOTH);
+ c.setLayoutData(data);
+
+ Label binLabel = new Label(c,SWT.NONE);
+ binLabel.setText("Please enter here the binary file which produced the coverage data.");
+ data = new GridData();
+ data.horizontalSpan = 2;
+ binLabel.setLayoutData(data);
+
+ binText = new Text(c,SWT.BORDER);
+ binText.setText(this.defaultValue);
+ data = new GridData(GridData.FILL_HORIZONTAL);
+ data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
+ binText.setLayoutData(data);
+ binText.addModifyListener(binModifyListener);
+
+ Composite cbBin = new Composite(c,SWT.NONE);
+ data = new GridData(GridData.HORIZONTAL_ALIGN_END);
+ cbBin.setLayoutData(data);
+ cbBin.setLayout(new GridLayout(2, true));
+ binBrowseWorkspaceButton = new Button(cbBin, SWT.PUSH);
+ binBrowseWorkspaceButton.setText("&Workspace...");
+ binBrowseWorkspaceButton.addSelectionListener(
+ new SelectionAdapter()
+ {
+ public void widgetSelected(SelectionEvent sev)
+ {
+ handleBrowseWorkspace("Open Binary file...", binText);
+ }
+ }
+ );
+ binBrowseFileSystemButton = new Button(cbBin, SWT.PUSH);
+ binBrowseFileSystemButton.setText("&File System...");
+ binBrowseFileSystemButton.addSelectionListener(
+ new SelectionAdapter()
+ {
+ public void widgetSelected(SelectionEvent sev)
+ {
+ handleBrowse("Open Binary file...", binText);
+ }
+ }
+ );
+
+ Group covMode = new Group(composite, SWT.NONE);
+ covMode.setText("Coverage result");
+ covMode.setToolTipText("Please choose the result scope.");
+ GridData covModeData = new GridData(GridData.FILL_BOTH);
+ covMode.setLayoutData(covModeData);
+ covMode.setLayout(new GridLayout());
+ openThisFileOnlyButton = new Button(covMode, SWT.RADIO);
+ openThisFileOnlyButton.setLayoutData(new GridData());
+ openCoverageSummaryButton = new Button(covMode, SWT.RADIO);
+ openCoverageSummaryButton.setLayoutData(new GridData());
+ String cFile = gcFile.removeFileExtension().lastSegment() + ".c";
+
+ openThisFileOnlyButton.setText("Show coverage details for \"" + cFile + "\" only.");
+ openCoverageSummaryButton.setText("Show coverage for the whole selected binary file");
+
+ openCoverageSummaryButton.setSelection(true);
+
+ SelectionAdapter sa = new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent sev)
+ {
+ openCoverageSummary = openCoverageSummaryButton.getSelection();
+ }
+ };
+ openCoverageSummaryButton.addSelectionListener(sa);
+ openThisFileOnlyButton.addSelectionListener(sa);
+
+
+ /* 2sd line */
+ errorLabel = new Label(composite,SWT.NONE);
+ data = new GridData(GridData.FILL_HORIZONTAL);
+ data.horizontalSpan = 3;
+ errorLabel.setLayoutData(data);
+ errorLabel.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
+
+ c.layout();
+
+ return composite;
+ }
+
+ private void validateBinary() {
+ binValue = binText.getText();
+ IStringVariableManager mgr = VariablesPlugin.getDefault().getStringVariableManager();
+ try {
+ binValue = mgr.performStringSubstitution(binValue, false);
+ } catch (CoreException _) {
+ // do nothing: never occurs
+ }
+
+ File f = new File(binValue);
+ if (f.exists()) {
+ IBinaryObject binary = STSymbolManager.sharedInstance.getBinaryObject(new Path(binValue));
+ if (binary == null) {
+ MessageDialog.openError(
+ PlatformUI.getWorkbench().getDisplay().getActiveShell(),
+ "Invalid binary file",
+ binText.getText() + " is not a valid binary file.");
+ return;
+ }
+ binaryValid = true;
+ getButton(IDialogConstants.OK_ID).setEnabled(binaryValid);
+ errorLabel.setText("");
+ } else {
+ binaryValid = false;
+ getButton(IDialogConstants.OK_ID).setEnabled(false);
+ if (!binValue.equals("")) {
+ errorLabel.setText("\"" + binText.getText() + "\" doesn't exist");
+ } else {
+ errorLabel.setText("Please enter a binary file");
+ }
+ return;
+ }
+ }
+
+ private class BinaryModifyListener implements ModifyListener
+ {
+ public void modifyText(ModifyEvent e) {
+ validateBinary();
+ }
+
+ }
+
+ protected void handleBrowseWorkspace(String msg, Text text) {
+ ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
+ dialog.setTitle(msg);
+ dialog.setMessage(msg);
+ dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
+ dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
+ dialog.setAllowMultiple(false);
+ IContainer c = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(this.gcFile);
+ if (c != null) dialog.setInitialSelection(c.getProject());
+ dialog.setValidator(new ISelectionStatusValidator() {
+ public IStatus validate(Object[] selection)
+ {
+ if (selection.length != 1) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
+ }
+ if (!(selection[0] instanceof IFile)) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
+ }
+ return new Status(IStatus.OK, Activator.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
+ }
+ });
+ if (dialog.open() == IDialogConstants.OK_ID) {
+ IResource resource = (IResource) dialog.getFirstResult();
+ text.setText("${resource_loc:" + resource.getFullPath() + "}");
+ }
+ }
+
+
+ protected void handleBrowse(String msg, Text text)
+ {
+ FileDialog dialog = new FileDialog(this.getShell(),SWT.OPEN);
+ dialog.setText(msg);
+ String t = text.getText();
+ IStringVariableManager mgr = VariablesPlugin.getDefault().getStringVariableManager();
+ try {
+ t = mgr.performStringSubstitution(t, false);
+ } catch (CoreException _) {
+ // do nothing: never occurs
+ }
+ File f = new File(t);
+ t = f.getParent();
+ if (t == null || t.length() == 0) {
+ t = this.gcFile.removeLastSegments(1).toOSString();
+ }
+ dialog.setFilterPath(t);
+ String s = dialog.open();
+ if (s != null) text.setText(s);
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/AbstractTreeElement.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/AbstractTreeElement.java
new file mode 100644
index 0000000..0fcce34
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/AbstractTreeElement.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.model;
+
+import java.util.LinkedList;
+
+public abstract class AbstractTreeElement implements TreeElement{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -4911602250295116203L;
+ private final TreeElement parent;
+ private final LinkedList<TreeElement> children = new LinkedList<TreeElement>();
+ private final String name;
+ private final int totalLines;
+ private final int executedLines;
+ private final int instrumentedLines;
+
+ public AbstractTreeElement(TreeElement parent, String name, int totalLines,
+ int executedLines, int instrumentedLines) {
+ this.parent = parent;
+ this.name = name;
+ this.totalLines = totalLines;
+ this.executedLines = executedLines;
+ this.instrumentedLines = instrumentedLines;
+ }
+
+ public TreeElement getParent() {
+ return parent;
+ }
+
+ public boolean hasChildren() {
+ return (children.size()>0);
+ }
+
+ public LinkedList<? extends TreeElement> getChildren() {
+ return children;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public TreeElement getRoot() {
+ if (parent == null) return this;
+ return parent.getRoot();
+ }
+
+ public int getExecutedLines() {
+ return executedLines;
+ }
+
+ public int getInstrumentedLines() {
+ return instrumentedLines;
+ }
+
+ public float getCoveragePercentage() {
+ if (instrumentedLines !=0 )
+ return (100.f*executedLines)/(instrumentedLines);
+ else return 0;
+ }
+
+ public void addChild(TreeElement child){
+ children.add(child);
+ }
+
+ public int getTotalLines() {
+ return totalLines;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovFileTreeElement.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovFileTreeElement.java
new file mode 100644
index 0000000..5bfa929
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovFileTreeElement.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.model;
+
+
+public class CovFileTreeElement extends AbstractTreeElement {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -5017234616535899796L;
+
+ public CovFileTreeElement(TreeElement parent,
+ String name, int totalLines, int executedLines, int instrumentedLines) {
+ super(parent, name, totalLines, executedLines, instrumentedLines);
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovFolderTreeElement.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovFolderTreeElement.java
new file mode 100644
index 0000000..8bfafdf
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovFolderTreeElement.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.model;
+
+public class CovFolderTreeElement extends AbstractTreeElement {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 583359546284716138L;
+
+ public CovFolderTreeElement(TreeElement parent,
+ String name, int totalLines, int executedLines, int instrumentedLines) {
+ super(parent, name, totalLines, executedLines, instrumentedLines);
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovFunctionTreeElement.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovFunctionTreeElement.java
new file mode 100644
index 0000000..3f5e32e
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovFunctionTreeElement.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.model;
+
+import java.util.LinkedList;
+
+
+public class CovFunctionTreeElement extends AbstractTreeElement {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -2025221943523670378L;
+ private final String sourceFilePath;
+ private final long firstLnNmbr;
+
+ public CovFunctionTreeElement(TreeElement parent, String name, String sourceFilePath,
+ long firstLnNmbr, int executedLines, int instrumentedLines) {
+ super(parent, name, 0, executedLines, instrumentedLines);
+ this.sourceFilePath = sourceFilePath;
+ this.firstLnNmbr = firstLnNmbr;
+ }
+
+
+ /* no children for functions*/
+
+ public boolean hasChildren() {
+ return false;
+ }
+
+ public LinkedList<? extends TreeElement> getChildren() {
+ return null;
+ }
+
+ public void addChild(TreeElement child){
+ }
+
+
+ /* specific methods for functions*/
+
+ public String getSourceFilePath() {
+ return sourceFilePath;
+ }
+
+ public long getFirstLnNmbr() {
+ return firstLnNmbr;
+ }
+
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovRootTreeElement.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovRootTreeElement.java
new file mode 100644
index 0000000..57d879e
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovRootTreeElement.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.model;
+
+import java.io.Serializable;
+
+public class CovRootTreeElement extends AbstractTreeElement implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 877070271548608926L;
+
+ public CovRootTreeElement(String name, int totalLines, int executedLines,
+ int instrumentedLines) {
+ super(null, name, totalLines, executedLines, instrumentedLines);
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/TreeElement.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/TreeElement.java
new file mode 100644
index 0000000..d489010
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/TreeElement.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.model;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+
+public interface TreeElement extends Serializable{
+ TreeElement getParent();
+ LinkedList<? extends TreeElement> getChildren();
+ boolean hasChildren();
+ TreeElement getRoot();
+
+ String getName();
+ int getExecutedLines();
+ int getInstrumentedLines();
+ int getTotalLines();
+ float getCoveragePercentage();
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Arc.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Arc.java
new file mode 100644
index 0000000..848462b
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Arc.java
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.parser;
+
+import java.io.Serializable;
+import java.util.List;
+
+public class Arc implements Serializable{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4104429137191407662L;
+
+ private static final int VCOV_ARC_ON_TREE = (1 << 0);
+ private static final int VCOV_ARC_FAKE = (1 << 1);
+ private static final int VCOV_ARC_FALLTHROUGH = (1 << 2);
+
+ private final Block srcBlock;
+ private final Block dstnatnBlock;
+ private final long flag;
+ private final boolean fake;
+ private final boolean onTree;
+ private final boolean fallthrough;
+
+ private long count = 0;
+ private boolean countValid = false;
+ private boolean isCallNonReturn = false; // Arc is for a function that abnormally returns
+ private boolean isNonLoclaReturn = false; // Arc is for catch/setjump
+ private boolean isUnconditionnal = false; // Is an unconditional branch.
+
+ /**
+ * Constructor
+ */
+ public Arc(int srcBlockIndice, int dstnatnBlockIndice, long flag, List<Block> otherArcParams) {
+ this.flag = flag;
+ this.dstnatnBlock = otherArcParams.get(dstnatnBlockIndice);
+ this.srcBlock = otherArcParams.get(srcBlockIndice);
+ this.count = 0;
+ this.countValid = false;
+ if ((flag & VCOV_ARC_ON_TREE) != 0) {
+ onTree = true;
+ fake = false;
+ fallthrough = false;
+ } else if ((flag & VCOV_ARC_FAKE) != 0) {
+ onTree = false;
+ fake = true;
+ fallthrough = true;
+ } else if ((flag & VCOV_ARC_FALLTHROUGH) != 0) {
+ onTree = false;
+ fake = false;
+ fallthrough = true;
+ } else {
+ onTree = false;
+ fake = false;
+ fallthrough = false;
+ }
+ }
+
+ public Block getDstnatnBlock() {
+ return dstnatnBlock;
+ }
+
+ public long getFlag() {
+ return flag;
+ }
+
+ public boolean isFake() {
+ return fake;
+ }
+
+ public boolean isOnTree() {
+ return onTree;
+ }
+
+ public boolean isFallthrough() {
+ return fallthrough;
+ }
+
+ public boolean isUnconditionnal() {
+ return isUnconditionnal;
+ }
+
+ public boolean isNonLoclaReturn() {
+ return isNonLoclaReturn;
+ }
+
+ public boolean isCallNonReturn() {
+ return isCallNonReturn;
+ }
+
+ public void setCallNonReturn(boolean isCallNonReturn) {
+ this.isCallNonReturn = isCallNonReturn;
+ }
+
+ public void setNonLoclaReturn(boolean isNonLoclaReturn) {
+ this.isNonLoclaReturn = isNonLoclaReturn;
+ }
+
+ public void setUnconditionnal(boolean isUnconditionnal) {
+ this.isUnconditionnal = isUnconditionnal;
+ }
+
+ public Block getSrcBlock() {
+ return srcBlock;
+ }
+
+ public void setCount(long count) {
+ this.count = count;
+ }
+
+ public void setCountValid(boolean countValid) {
+ this.countValid = countValid;
+ }
+
+ public long getCount() {
+ return count;
+ }
+
+ public boolean isCountValid() {
+ return countValid;
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Block.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Block.java
new file mode 100644
index 0000000..495ebfe
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Block.java
@@ -0,0 +1,177 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.parser;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+public class Block implements Serializable{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -7665287885679756014L;
+ private final ArrayList<Arc> entryArcs = new ArrayList<Arc>();
+ private final ArrayList<Arc> exitArcs = new ArrayList<Arc>();
+ private final long flag;
+ private long numSuccs = 0;
+ private long numPreds = 0;
+ private long count = 0;
+ private boolean isCallSite = false;// Does the call
+ private boolean isCallReturn = false; // Is the return
+ private boolean isNonLocalReturn = false;
+ private boolean validChain = false;
+ private boolean invalidChain = false;
+ private boolean countValid = false;
+ private final BlkLine blkline = new BlkLine();
+
+ /**
+ * Constructor
+ */
+ public Block(long flag) {
+ this.flag = flag;
+ }
+
+
+ /* getters & setters */
+ public long getFlag() {
+ return flag;
+ }
+
+ public ArrayList<Arc> getEntryArcs() {
+ return entryArcs;
+ }
+
+ public ArrayList<Arc> getExitArcs() {
+ return exitArcs;
+ }
+
+ public boolean isCallSite() {
+ return isCallSite;
+ }
+
+ public boolean isCallReturn() {
+ return isCallReturn;
+ }
+
+ public boolean isNonLocalReturn() {
+ return isNonLocalReturn;
+ }
+
+ public void addEntryArcs(Arc arcEntry) {
+ this.entryArcs.add(arcEntry);
+ }
+
+ public void addExitArcs(Arc arcExit) {
+ this.exitArcs.add(arcExit);
+ }
+
+ public void setCallSite(boolean isCallSite) {
+ this.isCallSite = isCallSite;
+ }
+
+ public void setCallReturn(boolean isCallReturn) {
+ this.isCallReturn = isCallReturn;
+ }
+
+ public void setNonLocalReturn(boolean isNonLocalReturn) {
+ this.isNonLocalReturn = isNonLocalReturn;
+ }
+
+ public void decNumSuccs() {
+ this.numSuccs--;
+ }
+
+ public void decNumPreds() {
+ this.numPreds--;
+ }
+
+ public void incNumPreds() {
+ this.numPreds++;
+ }
+
+ public void incNumSuccs() {
+ this.numSuccs++;
+ }
+
+ public boolean isValidChain() {
+ return validChain;
+ }
+
+ public void setValidChain(boolean validChain) {
+ this.validChain = validChain;
+ }
+
+ public boolean isInvalidChain() {
+ return invalidChain;
+ }
+
+ public void setInvalidChain(boolean invalidChain) {
+ this.invalidChain = invalidChain;
+ }
+
+ public long getCount() {
+ return count;
+ }
+
+ public void setCount(long count) {
+ this.count = count;
+ }
+
+ public void setCountValid(boolean countValid) {
+ this.countValid = countValid;
+ }
+
+ public boolean isCountValid() {
+ return countValid;
+ }
+
+ public long getNumSuccs() {
+ return numSuccs;
+ }
+
+ public long getNumPreds() {
+ return numPreds;
+ }
+
+ public void setNumSuccs(long numSuccs) {
+ this.numSuccs = numSuccs;
+ }
+
+ public void setNumPreds(long numPreds) {
+ this.numPreds = numPreds;
+ }
+
+ public long[] getEncoding() {
+ return blkline.encoding;
+ }
+
+ public void setEncoding(long[] lineNos) {
+ this.blkline.encoding = lineNos;
+ }
+
+ public int getLineNum() {
+ return blkline.num;
+ }
+
+ public void setNumLine(int numline) {
+ this.blkline.num = numline;
+ }
+
+ class BlkLine implements Serializable{
+ /**
+ *
+ */
+ private static final long serialVersionUID = 2757557929188979686L;
+ public long[] encoding;
+ public int num;
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/CovManager.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/CovManager.java
new file mode 100644
index 0000000..0379e3c
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/CovManager.java
@@ -0,0 +1,372 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.parser;
+
+import java.io.BufferedInputStream;
+import java.io.DataInput;
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.io.PrintStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.binutils.utils.STSymbolManager;
+import org.eclipse.linuxtools.gcov.Activator;
+import org.eclipse.linuxtools.gcov.model.CovFileTreeElement;
+import org.eclipse.linuxtools.gcov.model.CovFolderTreeElement;
+import org.eclipse.linuxtools.gcov.model.CovFunctionTreeElement;
+import org.eclipse.linuxtools.gcov.model.CovRootTreeElement;
+import org.tizen.common.util.OSChecker;
+import org.tizen.nativecommon.build.SmartBuildInterface;
+
+/**
+ * @author Xavier Raynaud <xavier.raynaud@st.com>
+ *
+ */
+public class CovManager implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5582066617970911413L;
+ // input
+ private final String binaryPath;
+ // results
+ private final ArrayList<Folder> allFolders = new ArrayList<Folder>();
+ private final ArrayList<SourceFile> allSrcs = new ArrayList<SourceFile>();
+ private final ArrayList<GcnoFunction> allFnctns = new ArrayList<GcnoFunction>();
+ private final HashMap<String, SourceFile> sourceMap = new HashMap<String, SourceFile>();
+ private long nbrPgmRuns = 0;
+ // for view
+ private CovRootTreeElement rootNode;
+
+ /**
+ * Constructor
+ * @param binaryPath
+ */
+ public CovManager(String binaryPath) {
+ this.binaryPath = binaryPath;
+ }
+
+
+ /**
+ * parse coverage files, execute resolve graph algorithm, process counts for functions,
+ * lines and folders.
+ * @param List of coverage files paths
+ * @throws CoreException, IOException, InterruptedException
+ */
+
+ public void processCovFiles(List<String> covFilesPaths) throws CoreException, IOException, InterruptedException {
+ GcdaRecordsParser daRcrd = null;
+ DataInput traceFile;
+ for (String gcdaPath: covFilesPaths) {
+ String gcnoPath = gcdaPath.replace(".gcda", ".gcno");
+ // parse GCNO file
+ traceFile = OpenTraceFileStream(gcnoPath);
+ GcnoRecordsParser noRcrd = new GcnoRecordsParser(sourceMap, allSrcs);
+ noRcrd.parseData(traceFile);
+
+ // add new functions parsed to AllSrcs array
+ for (GcnoFunction f: noRcrd.getFnctns()) {
+ allFnctns.add(f);
+ }
+
+ //close the input stream
+ if(traceFile.getClass() == DataInputStream.class)
+ ((DataInputStream)traceFile).close();
+
+ // parse GCDA file
+ traceFile = OpenTraceFileStream(gcdaPath);
+ if (noRcrd.getFnctns().isEmpty()){
+ String message = gcnoPath + " doesn't contain any function:\n";
+ Status status = new Status(Status.ERROR, Activator.PLUGIN_ID, message);
+ throw new CoreException(status);
+ }
+ daRcrd = new GcdaRecordsParser(noRcrd.getFnctns());
+ daRcrd.parseGcdaRecord(traceFile);
+
+ //close the input stream
+ if(traceFile.getClass() == DataInputStream.class)
+ ((DataInputStream)traceFile).close();
+ }
+
+ // to fill the view title
+ if (daRcrd != null)
+ nbrPgmRuns = daRcrd.getObjSmryNbrPgmRuns();
+ /* process counts from data parsed */
+
+ // solve graph for each function
+ for (GcnoFunction gf : allFnctns) {
+ gf.solveGraphFnctn();
+ }
+
+ // allocate lines
+ for (SourceFile sourceFile: allSrcs) {
+ sourceFile.createLines();
+ }
+
+ // add line counts
+ for (GcnoFunction gf : allFnctns) {
+ gf.addLineCounts(allSrcs);
+ }
+
+ // accumulate lines
+ for (SourceFile sf: allSrcs) {
+ sf.accumulateLineCounts();
+ }
+
+ /* compute counts by folder*/
+
+ // make the folders list
+ for (SourceFile sf : allSrcs) {
+ File srcFile = new File (sf.getName());
+ String folderName = srcFile.getParent();
+ if (folderName == null) folderName = "?";
+ Folder folder = null;
+ for (Folder f: allFolders) {
+ if (f.getPath().equals(folderName))
+ folder = f;
+ }
+ if (folder == null){
+ folder = new Folder(folderName);
+ allFolders.add(folder);
+ }
+ folder.addSrcFiles(sf);
+ }
+
+ // assign sourcesList for each folder
+ for (Folder f : allFolders) {
+ f.accumulateSourcesCounts();
+ }
+ }
+
+
+ /**
+ * fill the model by count results
+ * @throws CoreException, IOException, InterruptedException
+ */
+
+ public void fillGcovView() {
+ // process counts for summary level
+ int summaryTotal = 0, summaryInstrumented = 0, summaryExecuted = 0;
+ for (Folder f : allFolders) {
+ summaryTotal+=f.getNumLines();
+ summaryInstrumented+=f.getLinesInstrumented();
+ summaryExecuted+=f.getLinesExecuted();
+ }
+
+ // fill rootNode model: the entry of the contentProvider
+ rootNode = new CovRootTreeElement("Summary", summaryTotal,summaryExecuted,
+ summaryInstrumented);
+ IBinaryObject binaryObject = STSymbolManager.sharedInstance.getBinaryObject(new Path(binaryPath));
+
+ for (Folder fldr : allFolders) {
+ String folderLocation = fldr.getPath();
+ CovFolderTreeElement fldrTreeElem = new CovFolderTreeElement(
+ rootNode, folderLocation, fldr.getNumLines(), fldr.getLinesExecuted(),
+ fldr.getLinesInstrumented());
+ rootNode.addChild(fldrTreeElem);
+
+ for (SourceFile src : fldr.getSrcFiles()) {
+ CovFileTreeElement srcTreeElem = new CovFileTreeElement(
+ fldrTreeElem, src.getName(), src.getNumLines(), src
+ .getLinesExecuted(), src.getLinesInstrumented());
+ fldrTreeElem.addChild(srcTreeElem);
+
+ for (GcnoFunction fnctn : src.getFnctns()) {
+ String name = fnctn.getName();
+ name = STSymbolManager.sharedInstance.demangle(binaryObject, name);
+ srcTreeElem.addChild(new CovFunctionTreeElement(
+ srcTreeElem, name, fnctn.getSrcFile(), fnctn
+ .getFirstLineNmbr(), fnctn.getCvrge()
+ .getLinesExecuted(), fnctn.getCvrge()
+ .getLinesInstrumented()));
+ }
+ }
+ }
+ }
+
+ // transform String path to stream
+ private DataInput OpenTraceFileStream(String filePath) throws FileNotFoundException{
+
+ FileInputStream fis = new FileInputStream(filePath);
+ InputStream inputStream = new BufferedInputStream(fis);
+
+ return new DataInputStream(inputStream);
+ }
+
+
+ public ArrayList<SourceFile> getAllSrcs() {
+ return allSrcs;
+ }
+
+ public ArrayList<GcnoFunction> getAllFnctns() {
+ return allFnctns;
+ }
+
+ public CovRootTreeElement getRootNode() {
+ return rootNode;
+ }
+
+ public String getBinaryPath() {
+ return binaryPath;
+ }
+
+ public SourceFile getSourceFile(String sourcePath){
+ return sourceMap.get(sourcePath);
+ }
+
+ public long getNbrPgmRuns() {
+ return nbrPgmRuns;
+ }
+
+ /**
+ * Retrieve a list containing gcda paths from a binary file
+ * @return
+ * @throws CoreException
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ public List<String> getGCDALocations() throws CoreException, IOException, InterruptedException
+ {
+ IBinaryObject binaryObject = STSymbolManager.sharedInstance.getBinaryObject(new Path(binaryPath));
+ String binaryPath = binaryObject.getPath().toOSString();
+ List<String> l = new LinkedList<String>();
+ String cpu = binaryObject.getCPU();
+ Process p;
+ if ("sh".equals(cpu)) {
+ String stringsTool = "sh4strings";
+ p = getStringsProcess(stringsTool, binaryPath);
+ if ( p == null) p = getStringsProcess("sh4-linux-strings", binaryPath);
+ } else if ("stxp70".equals(cpu)) {
+ String stringsTool = "stxp70v3-strings";
+ p = getStringsProcess(stringsTool, binaryPath);
+ } else if ("st200".equals(cpu)){
+ String stringsTool = cpu + "strings";
+ p = getStringsProcess(stringsTool, binaryPath);
+ } else {
+ String stringsTool;
+ if (OSChecker.isWindows()) {
+ stringsTool = SmartBuildInterface.getMingwBinPath() + "/strings";
+ } else {
+ stringsTool = "strings";
+ }
+ p = getStringsProcess(stringsTool, binaryPath);
+ }
+ if (p == null) {
+ Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR,
+ "An error occured during analysis: unable to retrieve gcov data", new IOException());
+ Activator.getDefault().getLog().log(status);
+ return l;
+ }
+ ThreadConsumer t = new ThreadConsumer(p, l);
+ t.start();
+ p.waitFor();
+ t.join();
+ return l;
+ }
+
+
+ private Process getStringsProcess(String stringsTool, String binaryPath) {
+ try {
+ Process p = Runtime.getRuntime().exec(new String[] {stringsTool, binaryPath });
+ return p;
+ } catch (Exception _) {
+ return null;
+ }
+ }
+
+
+
+ private final class ThreadConsumer extends Thread
+ {
+ private final Process p;
+ private final List<String> list;
+ ThreadConsumer(Process p, List<String> files)
+ {
+ super();
+ this.p = p;
+ this.list = files;
+ }
+
+ public void run()
+ {
+ try {
+ populateGCDAFiles(p.getInputStream());
+ } catch (Exception _) {
+ }
+ }
+
+ private void populateGCDAFiles(InputStream s) throws IOException
+ {
+ InputStreamReader isr = new InputStreamReader(s);
+ LineNumberReader lnr = new LineNumberReader(isr);
+ String line = null;
+ while ((line =lnr.readLine()) != null) {
+ if (line.endsWith(".gcda"))
+ {
+ // absolute .gcda filepaths retrieved using the "strings" tool may
+ // be prefixed by random printable characters so strip leading
+ // characters until the filepath starts with "X:/", "X:\", "/" or "\"
+ // FIXME: need a more robust mechanism to locate .gcda files [Bugzilla 329710]
+ while ((line.length() > 6) && !line.matches("^([A-Za-z]:)?[/\\\\].*")) {
+ line = line.substring(1);
+ }
+ IPath p = new Path(line);
+ String filename = p.toString();
+ if (!list.contains(filename)) list.add(filename);
+ }
+ }
+ }
+ }
+
+ public void dumpProcessCovFilesResult(PrintStream ps) throws FileNotFoundException {
+ ps.println("Parse gcda and gcno files done, resolve graph algorithm executed, now display results");
+ ps.println("- PRINT FUNCTIONS ARRAY : ");
+ for (int i = 0; i < allFnctns.size(); i++) {
+ ps.println("-- FUNCTION " +i);
+ ps.println(" name = " + allFnctns.get(i).getName());
+ ps.println(" instrumentd lines = " + allFnctns.get(i).getCvrge().getLinesInstrumented());
+ ps.println(" executed lines = "+ allFnctns.get(i).getCvrge().getLinesExecuted());
+ }
+ ps.println("- PRINT SRCS ARRAY : ");
+ for (int i = 0; i < allSrcs.size(); i++) {
+ ps.println("-- FILE " + i);
+ ps.println(" name = " + allSrcs.get(i).getName());
+ ps.println(" total lines = " + allSrcs.get(i).getNumLines());
+ ps.println(" instrumentd lines = "+ allSrcs.get(i).getLinesInstrumented());
+ ps.println(" executed lines = "+ allSrcs.get(i).getLinesExecuted());
+ }
+ }
+
+
+ /**
+ * @return the sourceMap
+ */
+ public HashMap<String, SourceFile> getSourceMap() {
+ return sourceMap;
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/CoverageInfo.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/CoverageInfo.java
new file mode 100644
index 0000000..1595635
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/CoverageInfo.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.parser;
+
+import java.io.Serializable;
+
+public class CoverageInfo implements Serializable{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -6067335353999481231L;
+
+ private int linesInstrumented = 0;
+ private int linesExecuted = 0;
+
+ /**
+ * Constructor
+ */
+ public CoverageInfo() {
+
+ }
+
+
+ /*getters & setters */
+
+ public int getLinesInstrumented() {
+ return linesInstrumented;
+ }
+
+ public int getLinesExecuted() {
+ return linesExecuted;
+ }
+
+ public void incLinesInstrumented(){
+ this.linesInstrumented++;
+ }
+
+ public void incLinesExecuted(){
+ this.linesExecuted++;
+ }
+
+
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Folder.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Folder.java
new file mode 100644
index 0000000..482ae81
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Folder.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.parser;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+public class Folder implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5155033391199109661L;
+ private final String path;
+ private final ArrayList<SourceFile> srcFiles = new ArrayList<SourceFile>();
+ private int numLines = 0;
+ private int linesInstrumented = 0;
+ private int linesExecuted = 0;
+
+ /**
+ * Constructor
+ */
+ public Folder(String path) {
+ this.path = path;
+ }
+
+
+ public void accumulateSourcesCounts(){
+ for (int i = 0; i < srcFiles.size(); i++) {
+ numLines += (srcFiles.get(i)).getNumLines();
+ linesInstrumented += (srcFiles.get(i)).getLinesInstrumented();
+ linesExecuted += (srcFiles.get(i)).getLinesExecuted();
+ }
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public ArrayList<SourceFile> getSrcFiles() {
+ return srcFiles;
+ }
+
+ public void addSrcFiles(SourceFile srcFile) {
+ this.srcFiles.add(srcFile);
+ }
+
+ public int getNumLines() {
+ return numLines;
+ }
+ public int getLinesExecuted() {
+ return linesExecuted;
+ }
+ public int getLinesInstrumented() {
+ return linesInstrumented;
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/GcdaRecordsParser.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/GcdaRecordsParser.java
new file mode 100644
index 0000000..a82d724
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/GcdaRecordsParser.java
@@ -0,0 +1,272 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.parser;
+
+import java.io.DataInput;
+import java.io.DataInputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.gcov.Activator;
+import org.eclipse.linuxtools.gcov.utils.BEDataInputStream;
+import org.eclipse.linuxtools.gcov.utils.LEDataInputStream;
+import org.eclipse.linuxtools.gcov.utils.MasksGenerator;
+
+
+
+public class GcdaRecordsParser {
+
+
+ private static final int GCOV_DATA_MAGIC = 0x67636461; // en ASCII: 67=g 63=c 64=d 61=a
+ private static final int GCOV_TAG_FUNCTION = 0x01000000;
+ private static final int GCOV_COUNTER_ARCS = 0x01a10000;
+ private static final int GCOV_TAG_OBJECT_SYMMARY = 0xa1000000;
+ private static final int GCOV_TAG_PROGRAM_SUMMARY = 0xa3000000;
+
+ private final ArrayList<GcnoFunction> fnctns;
+ private long objSmryNbrPgmRuns = 0;
+ private long pgmSmryChksm = 0;
+ private long objSmryChksm = 0;
+ private long objSmryArcCnts = 0;
+ private long objSmrytotalCnts = 0;
+ private long objSmryRunMax = 0;
+ private long objSmrySumMax = 0;
+
+
+ public GcdaRecordsParser(ArrayList<GcnoFunction> fnctns) {
+ this.fnctns = fnctns;
+ }
+
+ public void parseGcdaRecord(DataInput stream) throws IOException, CoreException {
+ // header data
+ int magic = 0;
+
+ // data & flags to process tests
+ GcnoFunction currentFnctn = null;
+
+ //read magic
+ magic = stream.readInt();
+ //read version
+ //version = stream.readInt();
+ stream.readInt();
+ //read stamp
+ //stamp = stream.readInt();
+ stream.readInt();
+
+ if (magic == GCOV_DATA_MAGIC){
+ stream = new BEDataInputStream((DataInputStream) stream);
+ }else{
+ magic = (magic >> 16) | (magic << 16);
+ magic = ((magic & 0xff00ff) << 8) | ((magic >> 8) & 0xff00ff);
+ if (magic == GCOV_DATA_MAGIC){
+ stream = new LEDataInputStream((DataInputStream) stream);
+ }else{
+ String message = magic + " :desn't correspond to a correct data file header\n";
+ Status status = new Status(Status.ERROR, Activator.PLUGIN_ID, message);
+ throw new CoreException(status);
+ }
+ }
+
+ while (true) {
+ try {
+ // parse header
+ int tag = stream.readInt();
+ long length = (stream.readInt() & MasksGenerator.UNSIGNED_INT_MASK);
+ // parse gcda data
+ switch ((int) tag) {
+ case GCOV_TAG_FUNCTION: {
+ long fnctnId = stream.readInt() & MasksGenerator.UNSIGNED_INT_MASK;
+ if (!fnctns.isEmpty()) {
+ boolean fnctnFound = false;
+ for (GcnoFunction f: fnctns) {
+ if (f.getIdent() == fnctnId) {
+ fnctnFound = true;
+ currentFnctn = f;
+ long fnctnChksm = stream.readInt()& MasksGenerator.UNSIGNED_INT_MASK;
+ if (f.getCheksum() != fnctnChksm){
+ String message = "Checksums don't correspond for " +
+ currentFnctn.getName() + " (Id: " + fnctnId + ")\n";
+ Status status = new Status(Status.ERROR, Activator.PLUGIN_ID, message);
+ throw new CoreException(status);
+ }
+ break;
+ }
+ }
+
+ if (fnctnFound == false){
+ currentFnctn = null;
+ String message = "Function with Id: " + fnctnId +
+ " not found in function list\n";
+ Status status = new Status(Status.ERROR, Activator.PLUGIN_ID, message);
+ throw new CoreException(status);
+ }
+
+ }
+ break;
+ }
+
+ case GCOV_COUNTER_ARCS: {
+ if (currentFnctn == null){
+ String message = "Missing function or duplicate counter tag\n";
+ Status status = new Status(Status.ERROR, Activator.PLUGIN_ID, message);
+ throw new CoreException(status);
+ }
+
+ if (length != 2 * (currentFnctn.getNumCounts())){
+ String message = "GCDA content is inconsistent\n";
+ Status status = new Status(Status.ERROR, Activator.PLUGIN_ID, message);
+ throw new CoreException(status);
+ }
+
+ ArrayList<Block> fnctnBlcks = currentFnctn.getFunctionBlocks();
+ if (fnctnBlcks.isEmpty()){
+ String message = "Function block list is empty\n";
+ Status status = new Status(Status.ERROR, Activator.PLUGIN_ID, message);
+ throw new CoreException(status);
+ }
+
+ for (int i = 0; i < fnctnBlcks.size(); i++) {
+ Block b = fnctnBlcks.get(i);
+ int nonFakeExit = 0;
+
+ ArrayList<Arc> arcsExit = b.getExitArcs();
+ for (Arc extArc: arcsExit) {
+ if (extArc.isFake() == false)
+ nonFakeExit++;
+ if (extArc.isOnTree() == false) {
+ long arcsCnts = stream.readLong();
+ extArc.setCount(arcsCnts);
+ extArc.setCountValid(true);
+ b.decNumSuccs();
+ extArc.getDstnatnBlock().decNumPreds();
+ }
+ }
+
+ // If there is only one non-fake exit, it is an
+ // unconditional branch.
+ if (nonFakeExit == 1) {
+ for (Arc extArc: arcsExit) {
+ if (extArc.isFake() == false) {
+ extArc.setUnconditionnal(true);
+
+ // If this block is instrumenting a call, it might be
+ // an artificial block. It is not artificial if it has
+ // a non-fallthrough exit, or the destination of this
+ // arc has more than one entry. Mark the destination
+ // block as a return site, if none of those conditions hold.
+
+ if (b.isCallSite() == true
+ && extArc.isFallthrough() == true
+ && extArc.getDstnatnBlock()
+ .getEntryArcs().get(0)
+ .equals(extArc)
+ && extArc.getDstnatnBlock()
+ .getEntryArcs().size() == 1)
+ extArc.getDstnatnBlock()
+ .setCallReturn(true);
+ }
+ }
+ }
+ }
+
+ // counters arcs process data reset
+ currentFnctn = null;
+ break;
+ }
+
+ case GCOV_TAG_OBJECT_SYMMARY: {
+ objSmryChksm = (stream.readInt() & MasksGenerator.UNSIGNED_INT_MASK);
+ objSmryArcCnts = (stream.readInt() & MasksGenerator.UNSIGNED_INT_MASK);
+ objSmryNbrPgmRuns = (stream.readInt() & MasksGenerator.UNSIGNED_INT_MASK);
+ objSmrytotalCnts = stream.readLong();
+ objSmryRunMax = stream.readLong();
+ objSmrySumMax = stream.readLong();
+ break;
+ }
+
+ // program summary tag
+ case GCOV_TAG_PROGRAM_SUMMARY: {
+ //long[] pgmSmryskips = new long[(int) length];
+ pgmSmryChksm = (stream.readInt() & MasksGenerator.UNSIGNED_INT_MASK);
+ for (int i = 0; i < length - 1; i++) {
+ //pgmSmryskips[i] = (stream.readInt() & MasksGenerator.UNSIGNED_INT_MASK);
+ stream.readInt();
+ }
+ break;
+ }
+
+ default: {
+ //System.out.println("wrong gcda tag");
+ break;
+ }
+ }
+ }
+ catch (EOFException _) {
+ break;
+ }
+ }
+ }
+
+ /**
+ * @return the objSmryNbrPgmRuns
+ */
+ public long getObjSmryNbrPgmRuns() {
+ return objSmryNbrPgmRuns;
+ }
+
+ /**
+ * @return the objSmryChksm
+ */
+ public long getObjSmryChksm() {
+ return objSmryChksm;
+ }
+
+ /**
+ * @return the objSmryArcCnts
+ */
+ public long getObjSmryArcCnts() {
+ return objSmryArcCnts;
+ }
+
+ /**
+ * @return the objSmrytotalCnts
+ */
+ public long getObjSmrytotalCnts() {
+ return objSmrytotalCnts;
+ }
+
+ /**
+ * @return the objSmryRunMax
+ */
+ public long getObjSmryRunMax() {
+ return objSmryRunMax;
+ }
+
+ /**
+ * @return the objSmrySumMax
+ */
+ public long getObjSmrySumMax() {
+ return objSmrySumMax;
+ }
+
+ /**
+ * @return the pgmSmryChksm
+ */
+ public long getPgmSmryChksm() {
+ return pgmSmryChksm;
+ }
+
+
+
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/GcnoFunction.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/GcnoFunction.java
new file mode 100644
index 0000000..2549883
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/GcnoFunction.java
@@ -0,0 +1,255 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.parser;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+public class GcnoFunction implements Serializable, Comparable<GcnoFunction> {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -4159055012321132651L;
+
+ private final long ident;
+ private final long cheksum;
+ private final long firstLineNmbr;
+ private final String name;
+ private final String srcFile;
+ private ArrayList<Block> functionBlocks = new ArrayList<Block>();
+ private int numCounts = 0, blocksExecuted = 0, numBlocks = 0;;
+ private final CoverageInfo cvrge = new CoverageInfo();
+
+ public GcnoFunction(long fnctnIdent, long fnctnChksm, String fnctnName, String fnctnSrcFle, long fnctnFrstLnNmbr) {
+ this.ident = fnctnIdent;
+ this.cheksum = fnctnChksm;
+ this.name = fnctnName;
+ this.srcFile = fnctnSrcFle;
+ this.firstLineNmbr = fnctnFrstLnNmbr;
+ }
+
+ @Override
+ public int compareTo(GcnoFunction o) {
+ if (getFirstLineNmbr()>o.getFirstLineNmbr()) return 1;
+ else if (getFirstLineNmbr()<o.getFirstLineNmbr()) return -1;
+ return 0;
+ }
+
+
+ public void addLineCounts(ArrayList<SourceFile> srcs) {
+ for (int i = 0; i != numBlocks; i++) {
+ Block blk = functionBlocks.get(i);
+ SourceFile fileSrc = null;
+ if ((blk.getCount() != 0) && (i != 0) && (i + 1 != numBlocks))
+ blocksExecuted++;
+
+ long[] enc = blk.getEncoding();
+ for (int j = 0, k = 0; j != blk.getLineNum(); j++, k++) {
+ if (enc[k] == 0) {
+ int srcn = (int) enc[++k];
+ for (SourceFile sf : srcs) {
+ if (sf.getIndex() == srcn) {
+ fileSrc = sf;
+ break;
+ }
+ }
+ j++;
+ } else if ((fileSrc != null) && enc[k] < fileSrc.getLines().size()) {
+ Line line = fileSrc.getLines().get((int) enc[k]);
+ if (line.isExists() == false)
+ cvrge.incLinesInstrumented();
+ if ((line.getCount() == 0) && (blk.getCount() != 0))
+ cvrge.incLinesExecuted();
+ line.setExists(true);
+ line.setCount(line.getCount()+ blk.getCount());
+ }
+ }
+ }
+ }
+
+ public void solveGraphFnctn() {
+ ArrayList<Block> fnctnBlcks = this.functionBlocks;
+ ArrayList<Block> validBlocks = new ArrayList<Block>();
+ ArrayList<Block> invalidBlocks = new ArrayList<Block>();
+
+
+ // Function should contain at least one block
+ if (fnctnBlcks.size() >= 2){
+ if (fnctnBlcks.get(0).getNumPreds() == 0)
+ fnctnBlcks.get(0).setNumPreds(50000);
+ if (fnctnBlcks.get(fnctnBlcks.size() - 1).getNumSuccs() == 0)
+ fnctnBlcks.get(fnctnBlcks.size() - 1).setNumSuccs(50000);
+ }
+
+
+ for (int i = 0; i < fnctnBlcks.size(); i++) {
+ Block b = fnctnBlcks.get(i);
+ b.setInvalidChain(true);
+ invalidBlocks.add(b);
+ }
+
+ while (validBlocks.isEmpty() == false
+ || invalidBlocks.isEmpty() == false) {
+
+ if (invalidBlocks.isEmpty() == false) {
+ for (int i = invalidBlocks.size() - 1; i >= 0; i--) {
+ Block invb = invalidBlocks.get(i);
+ long total = 0;
+ invalidBlocks.remove(i);
+ invb.setInvalidChain(false);
+
+ if (invb.getNumSuccs() == 0) {
+ ArrayList<Arc> extArcs = invb.getExitArcs();
+ for (Arc arc : extArcs)
+ total += arc.getCount();
+ } else if (invb.getNumPreds() == 0) {
+ ArrayList<Arc> entrArcs = invb.getEntryArcs();
+ for (Arc arc : entrArcs)
+ total += arc.getCount();
+ } else
+ continue;
+
+ invb.setCount(total);
+ invb.setCountValid(true);
+ invb.setValidChain(true);
+ validBlocks.add(invb);
+ }
+ }/*else
+ System.out.println("NO, invalid blocks = 0");
+ */
+ while (validBlocks.isEmpty() == false) {
+ int last = validBlocks.size() - 1;
+ Block vb = validBlocks.get(last);
+ Arc invarc = null;
+ int total = 0;
+ validBlocks.remove(last);
+
+ vb.setValidChain(false);
+
+ if (vb.getNumSuccs() == 1) {
+ Block blcksdst;
+ total = (int) vb.getCount();
+
+ for (Arc extAr : vb.getExitArcs()) {
+ total -= extAr.getCount();
+ if (extAr.isCountValid() == false)
+ invarc = extAr;
+ }
+ blcksdst = invarc.getDstnatnBlock();
+ invarc.setCountValid(true);
+ invarc.setCount(total);
+ vb.decNumSuccs();
+ blcksdst.decNumPreds();
+
+ if (blcksdst.isCountValid() == true) {
+ if (blcksdst.getNumPreds() == 1
+ && blcksdst.isValidChain() == false) {
+ blcksdst.setValidChain(true);
+ validBlocks.add(blcksdst);
+ }
+ } else {
+ if (blcksdst.getNumPreds() == 0
+ && blcksdst.isInvalidChain() == false) {
+ blcksdst.setInvalidChain(true);
+ invalidBlocks.add(blcksdst);
+ }
+ }
+ }
+
+ if (vb.getNumPreds() == 1) {
+ Block blcksrc;
+ total = (int) vb.getCount();
+ invarc = null;
+
+ for (Arc entrAr: vb.getEntryArcs()) {
+ total -= entrAr.getCount();
+ if (entrAr.isCountValid() == false)
+ invarc = entrAr;
+ }
+
+ blcksrc = invarc.getSrcBlock();
+ invarc.setCountValid(true);
+ invarc.setCount(total);
+ vb.decNumPreds();
+ blcksrc.decNumSuccs();
+
+ if (blcksrc.isCountValid() == true) {
+ if (blcksrc.getNumSuccs() == 1
+ && blcksrc.isInvalidChain() == false) {
+ blcksrc.setValidChain(true);
+ validBlocks.add(blcksrc);
+ }
+ } else if (blcksrc.getNumSuccs() == 0
+ && blcksrc.isInvalidChain() == false) {
+ blcksrc.setInvalidChain(true);
+ invalidBlocks.add(blcksrc);
+ }
+ }
+ }
+ }
+ }
+
+ /* getters & setters */
+
+ public long getIdent() {
+ return ident;
+ }
+
+ public long getCheksum() {
+ return cheksum;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getSrcFile() {
+ return srcFile;
+ }
+
+ public long getFirstLineNmbr() {
+ return firstLineNmbr;
+ }
+
+ public ArrayList<Block> getFunctionBlocks() {
+ return functionBlocks;
+ }
+
+ public Block getFunctionBlock(int i) {
+ return functionBlocks.get(i);
+ }
+
+ public void setFunctionBlocks(ArrayList<Block> functionBlocks) {
+ this.functionBlocks = functionBlocks;
+ }
+
+ public void incNumCounts() {
+ this.numCounts++;
+ }
+
+ public int getNumCounts() {
+ return numCounts;
+ }
+
+ public int getNumBlocks() {
+ return numBlocks;
+ }
+
+ public void setNumBlocks(int numBlocks) {
+ this.numBlocks = numBlocks;
+ }
+
+ public CoverageInfo getCvrge() {
+ return cvrge;
+ }
+
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/GcnoRecordsParser.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/GcnoRecordsParser.java
new file mode 100644
index 0000000..c21e16f
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/GcnoRecordsParser.java
@@ -0,0 +1,241 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.parser;
+
+import java.io.DataInput;
+import java.io.DataInputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.gcov.Activator;
+import org.eclipse.linuxtools.gcov.utils.BEDataInputStream;
+import org.eclipse.linuxtools.gcov.utils.GcovStringReader;
+import org.eclipse.linuxtools.gcov.utils.LEDataInputStream;
+import org.eclipse.linuxtools.gcov.utils.MasksGenerator;
+
+
+public class GcnoRecordsParser {
+
+ private static final int GCOV_NOTE_MAGIC = 0x67636e6f; // en ASCII: 67=g 63=c 6e=n 6f=o
+ private static final int GCOV_TAG_FUNCTION = 0x01000000;
+ private static final int GCOV_TAG_BLOCKS = 0x01410000;
+ private static final int GCOV_TAG_ARCS = 0x01430000;
+ private static final int GCOV_TAG_LINES = 0x01450000;
+
+ private GcnoFunction fnctn = null;
+ private final ArrayList<GcnoFunction> fnctns = new ArrayList<GcnoFunction>();
+ private final ArrayList<SourceFile> currentAllSrcs;
+ private final HashMap<String, SourceFile> sourceMap;
+
+ public GcnoRecordsParser(HashMap<String, SourceFile> sourceMap, ArrayList<SourceFile> AllSrcs){
+ this.sourceMap = sourceMap;
+ this.currentAllSrcs = AllSrcs;
+ }
+
+ private SourceFile findOrAdd (String fileName, ArrayList<SourceFile> srcs)
+ {
+ SourceFile newsrc = sourceMap.get(fileName);
+ if (newsrc == null) {
+ newsrc = new SourceFile(fileName, srcs.size()+1);
+ srcs.add(newsrc);
+ sourceMap.put(fileName, newsrc);
+ }
+ return newsrc; //return the new added element
+ }
+
+
+ public void parseData(DataInput stream) throws IOException, CoreException{
+ // header data
+ int magic = 0;
+ // blocks data
+ ArrayList<Block> blocks = null;
+ // source file data
+ SourceFile source = null;
+ // flag
+ boolean parseFirstFnctn = false;
+
+ magic = stream.readInt();
+ //version = stream.readInt();
+ stream.readInt();
+ //stamp = stream.readInt();
+ stream.readInt();
+
+ if (magic == GCOV_NOTE_MAGIC){
+ stream = new BEDataInputStream((DataInputStream) stream);
+ }else{
+ magic = (magic >> 16) | (magic << 16);
+ magic = ((magic & 0xff00ff) << 8) | ((magic >> 8) & 0xff00ff);
+ if (magic == GCOV_NOTE_MAGIC){
+ stream = new LEDataInputStream((DataInputStream) stream);
+ }else{
+ String message = magic + " :desn't correspond to a correct note file header\n";
+ Status status = new Status(Status.ERROR, Activator.PLUGIN_ID, message);
+ throw new CoreException(status);
+ }
+ }
+
+ /*------------------------------------------------------------------------------
+ System.out.println("Gcno LE, Magic "+magic+" version "+version+" stamp "+stamp);
+ */
+
+ while (true){
+ try{
+ int tag;
+ // parse header
+ while (true){
+ tag=stream.readInt();
+ if (tag == GCOV_TAG_FUNCTION || tag == GCOV_TAG_BLOCKS ||
+ tag == GCOV_TAG_ARCS || tag == GCOV_TAG_LINES)
+ break;
+ }
+ int length=stream.readInt();
+
+ // parse gcno data
+ if ((int)tag == GCOV_TAG_FUNCTION){
+ // before parse new function, add current function to functions list
+ if (parseFirstFnctn == true) fnctns.add(fnctn);
+
+ long fnctnIdent = (stream.readInt()&MasksGenerator.UNSIGNED_INT_MASK);
+ long fnctnChksm = (stream.readInt()&MasksGenerator.UNSIGNED_INT_MASK);
+ String fnctnName = GcovStringReader.readString(stream);
+ String fnctnSrcFle = GcovStringReader.readString(stream);
+ long fnctnFrstLnNmbr= (stream.readInt()&MasksGenerator.UNSIGNED_INT_MASK);
+
+ fnctn = new GcnoFunction(fnctnIdent, fnctnChksm, fnctnName, fnctnSrcFle, fnctnFrstLnNmbr);
+ SourceFile srcFle2 = findOrAdd (fnctn.getSrcFile(),currentAllSrcs);
+ if (fnctn.getFirstLineNmbr() >= srcFle2.getNumLines()){
+ srcFle2.setNumLines((int)fnctn.getFirstLineNmbr()+1);
+ }
+ srcFle2.addFnctn(fnctn);
+ parseFirstFnctn = true;
+ continue;
+ }
+
+ else if ((int)tag == GCOV_TAG_BLOCKS){
+ blocks = new ArrayList<Block>();
+ for (int i = 0; i < length; i++) {
+ long BlckFlag = stream.readInt()& MasksGenerator.UNSIGNED_INT_MASK;
+ Block blck = new Block(BlckFlag);
+ blocks.add(blck);
+ }
+ fnctn.setNumBlocks(length);
+ continue;
+ }
+ else if (tag == GCOV_TAG_ARCS){
+ int srcBlockIndice = stream.readInt();
+ int nmbrArcs = (length-1)/2;
+ ArrayList<Arc> arcs = new ArrayList<Arc>(nmbrArcs);
+
+ for (int i = 0; i < nmbrArcs; i++) {
+ int dstnatnBlockIndice = stream.readInt();
+ long flag = (stream.readInt()&MasksGenerator.UNSIGNED_INT_MASK);
+ Arc arc = new Arc(srcBlockIndice, dstnatnBlockIndice, flag, blocks);
+ arcs.add(arc);
+ }
+
+ // each arc, register it as exit of the src block
+ Block srcBlk = blocks.get(srcBlockIndice);
+ for (Arc a : arcs) {
+ srcBlk.addExitArcs(a);
+ srcBlk.incNumSuccs();
+ }
+
+ // each arc, register it as entry of its dstntn block
+ for (Arc a : arcs) {
+ Block dstntnBlk = a.getDstnatnBlock();
+ dstntnBlk.addEntryArcs(a);
+ dstntnBlk.incNumPreds();
+ }
+
+ for (Arc a : arcs) {
+ if (a.isFake() == true) {
+ if (a.getSrcBlock() != null ) {
+ // Exceptional exit from this function, the
+ // source block must be a call.
+ srcBlk = blocks.get((int)srcBlockIndice);
+ srcBlk.setCallSite(true);
+ a.setCallNonReturn(true);
+ } else {
+ a.setNonLoclaReturn(true);
+ Block dstntnBlk = a.getDstnatnBlock();
+ dstntnBlk.setNonLocalReturn(true);
+ }
+ }
+
+ if (a.isOnTree() == false)
+ fnctn.incNumCounts();
+ //nbrCounts++;
+ }
+
+ fnctn.setFunctionBlocks(blocks);
+ continue;
+ }
+
+
+ else if (tag == GCOV_TAG_LINES) {
+ int numBlock = stream.readInt();
+ long[] lineNos = new long[length-1];
+ int ix = 0;
+ do {
+ long lineNumber = stream.readInt()&MasksGenerator.UNSIGNED_INT_MASK;
+ if (lineNumber != 0){
+ if (ix == 0){
+ lineNos[ix++] = 0;
+ lineNos[ix++] = source.getIndex();
+ }
+ lineNos[ix++]=lineNumber;
+ if (lineNumber >= source.getNumLines()){
+ source.setNumLines((int)lineNumber+1);
+ }
+ } else {
+ String fileName = GcovStringReader.readString(stream);
+ if (fileName == "NULL string")
+ break;
+
+ source = findOrAdd (fileName, currentAllSrcs);
+ lineNos[ix++]=0;
+ lineNos[ix++]=source.getIndex();
+ }
+ } while (true);
+
+ fnctn.getFunctionBlocks().get(((int)numBlock))
+ .setEncoding(lineNos);
+
+ fnctn.getFunctionBlocks().get(((int)numBlock))
+ .setNumLine(ix);
+
+ continue;
+ }
+ }
+ catch (EOFException e) {
+
+ fnctn.setFunctionBlocks(blocks);
+ fnctns.add(fnctn);
+
+ break;
+
+ }
+ }//while
+ }
+
+ /* Getters */
+ public ArrayList<GcnoFunction> getFnctns() {
+ return fnctns;
+ }
+
+ public ArrayList<SourceFile> getcurrentAllSrcs() {
+ return currentAllSrcs;
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Line.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Line.java
new file mode 100644
index 0000000..e2b0c4a
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Line.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.parser;
+
+import java.io.Serializable;
+
+
+public class Line implements Serializable{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 8804878976767948267L;
+ private boolean exists = false;
+ private long count = 0;
+
+ /**
+ * Constructor
+ */
+ public Line() {
+ }
+
+
+ /*Getters & setters*/
+
+ public boolean isExists() {
+ return exists;
+ }
+
+ public void setExists(boolean exists) {
+ this.exists = exists;
+ }
+
+ public void setCount(long count) {
+ this.count = count;
+ }
+
+ public long getCount() {
+ return count;
+ }
+
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/SourceFile.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/SourceFile.java
new file mode 100644
index 0000000..3ba9d68
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/SourceFile.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.parser;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+public class SourceFile implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -9182882194956475711L;
+ private final String name;
+ private final int index;
+ private final ArrayList<Line> lines = new ArrayList<Line>();
+ private final TreeSet<GcnoFunction> fnctns = new TreeSet<GcnoFunction>();
+ private int numLines = 1;
+ private final CoverageInfo cvrge = new CoverageInfo();
+ private long maxCount = -1;
+
+ /**
+ * Constructor
+ */
+ public SourceFile(String name, int index) {
+ this.name = name;
+ this.index = index;
+ }
+
+
+ public void accumulateLineCounts() {
+ for (Line line : lines) {
+ if (line.isExists()) {
+ cvrge.incLinesInstrumented();
+ if (line.getCount() != 0)
+ cvrge.incLinesExecuted();
+ }
+ }
+ }
+
+ public long getmaxLineCount() {
+ if (maxCount < 0) {
+ for (Line line : lines) {
+ if (line.getCount() > maxCount)
+ maxCount = line.getCount();
+ }
+ }
+ return maxCount;
+ }
+
+ /* getters & setters */
+
+
+
+ public int getLinesExecuted() {
+ return cvrge.getLinesExecuted();
+ }
+
+ public int getLinesInstrumented() {
+ return cvrge.getLinesInstrumented();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public ArrayList<Line> getLines() {
+ return lines;
+ }
+
+ public SortedSet<GcnoFunction> getFnctns() {
+ return fnctns;
+ }
+
+ public void addFnctn(GcnoFunction fnctn) {
+ this.fnctns.add(fnctn);
+ }
+
+ public int getNumLines() {
+ return numLines;
+ }
+
+ public void setNumLines(int numLines) {
+ this.numLines = numLines;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public void createLines() {
+ int n = getNumLines();
+ lines.ensureCapacity(n);
+ for (int j = 0; j<n ; j++) {
+ lines.add(new Line());
+ }
+ }
+
+
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/BEDataInputStream.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/BEDataInputStream.java
new file mode 100644
index 0000000..9765c94
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/BEDataInputStream.java
@@ -0,0 +1,191 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.utils;
+
+import java.io.DataInput;
+import java.io.DataInputStream;
+import java.io.IOException;
+/**
+ *
+ */
+public class BEDataInputStream implements DataInput {
+
+ private final DataInputStream in;
+ private final byte[] buffer = new byte[8];
+
+ /**
+ * Constructor
+ * @param in
+ */
+ public BEDataInputStream(DataInputStream in) {
+ this.in = in;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readShort()
+ */
+ public final short readShort() throws IOException
+ {
+ return in.readShort();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readUnsignedShort()
+ */
+ public final int readUnsignedShort() throws IOException
+ {
+ return in.readUnsignedShort();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readChar()
+ */
+ public final char readChar() throws IOException
+ {
+ return in.readChar();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readInt()
+ */
+ public final int readInt() throws IOException
+ {
+ return in.readInt();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readLong()
+ */
+ public final long readLong() throws IOException
+ {
+ in.readFully(buffer, 0, 8);
+ return (((long)buffer[7] << 32) +
+ ((long)(buffer[6] & 255) << 40) +
+ ((long)(buffer[5] & 255) << 48) +
+ ((long)(buffer[4] & 255) << 56) +
+ ((long)(buffer[3] & 255) << 0) +
+ ((buffer[2] & 255) << 8) +
+ ((buffer[1] & 255) << 16) +
+ ((buffer[0] & 255) << 24));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readFloat()
+ */
+ public final float readFloat() throws IOException
+ {
+ return Float.intBitsToFloat(readInt());
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readDouble()
+ */
+ public final double readDouble() throws IOException
+ {
+ return Double.longBitsToDouble(readLong());
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readBoolean()
+ */
+ public boolean readBoolean() throws IOException {
+ return in.readBoolean();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readByte()
+ */
+ public byte readByte() throws IOException {
+ return in.readByte();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readFully(byte[])
+ */
+ public void readFully(byte[] b) throws IOException {
+ in.readFully(b);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readFully(byte[], int, int)
+ */
+ public void readFully(byte[] b, int off, int len) throws IOException {
+ in.readFully(b,off,len);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readLine()
+ */
+ @Deprecated
+ public String readLine() throws IOException {
+ return in.readLine();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readUTF()
+ */
+ public String readUTF() throws IOException {
+ return in.readUTF();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readUnsignedByte()
+ */
+ public int readUnsignedByte() throws IOException {
+ return in.readUnsignedByte();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#skipBytes(int)
+ */
+ public int skipBytes(int n) throws IOException {
+ return in.skipBytes(n);
+ }
+
+ /**
+ * Close this stream.
+ */
+ public void close() throws IOException {
+ in.close();
+ }
+
+ public final long readUnsignedInt() throws IOException
+ {
+ in.readFully(buffer, 0, 4);
+ return
+ ((
+ (buffer[0]) << 24 |
+ (buffer[1]&0xff) << 16 |
+ (buffer[2]&0xff) << 8 |
+ (buffer[3]&0xff)
+ )
+ & MasksGenerator.UNSIGNED_INT_MASK );
+ }
+
+
+
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/GcovStringReader.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/GcovStringReader.java
new file mode 100644
index 0000000..e6b13a6
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/GcovStringReader.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.utils;
+
+import java.io.DataInput;
+import java.io.IOException;
+
+public class GcovStringReader {
+
+
+ public static String readString(DataInput stream) throws IOException {
+ String res = "NULL string";
+ long length = stream.readInt()&MasksGenerator.UNSIGNED_INT_MASK;
+ if (length != 0) {
+ int ln = ((int) length) << 2;
+ byte[] name = new byte[ln];
+ stream.readFully(name);
+ StringBuffer sb = new StringBuffer();
+ for(int j=0; j < ln; j++){
+ if(name[j]!=0){
+ char c = (char) name[j];
+ sb.append(c);
+ }
+ }
+ res = sb.toString();
+ }
+ return res;
+ }
+
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/LEDataInputStream.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/LEDataInputStream.java
new file mode 100644
index 0000000..51648e5
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/LEDataInputStream.java
@@ -0,0 +1,208 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.utils;
+
+import java.io.DataInput;
+import java.io.DataInputStream;
+import java.io.IOException;
+/**
+ * Little-endian implementation of DataInputStream
+ * @author Xavier Raynaud <xavier.raynaud@st.com>
+ *
+ */
+public class LEDataInputStream implements DataInput {
+
+ private final DataInputStream in;
+ private final byte[] buffer = new byte[8];
+
+ /**
+ * Constructor
+ * @param in
+ */
+ public LEDataInputStream(DataInputStream in) {
+ this.in = in;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readShort()
+ */
+ public final short readShort() throws IOException
+ {
+ in.readFully(buffer, 0, 2);
+ return (short)(
+ (buffer[1]&0xff) << 8 |
+ (buffer[0]&0xff));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readUnsignedShort()
+ */
+ public final int readUnsignedShort() throws IOException
+ {
+ in.readFully(buffer, 0, 2);
+ return (
+ (buffer[1]&0xff) << 8 |
+ (buffer[0]&0xff));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readChar()
+ */
+ public final char readChar() throws IOException
+ {
+ in.readFully(buffer, 0, 2);
+ return (char) (
+ (buffer[1]&0xff) << 8 |
+ (buffer[0]&0xff));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readInt()
+ */
+ public final int readInt() throws IOException
+ {
+ in.readFully(buffer, 0, 4);
+ return
+ (buffer[3]) << 24 |
+ (buffer[2]&0xff) << 16 |
+ (buffer[1]&0xff) << 8 |
+ (buffer[0]&0xff);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readLong()
+ */
+ public final long readLong() throws IOException
+ {
+ in.readFully(buffer, 0, 8);
+ return
+ (long)(buffer[7]) << 56 | /* long cast needed or shift done modulo 32 */
+ (long)(buffer[6]&0xff) << 48 |
+ (long)(buffer[5]&0xff) << 40 |
+ (long)(buffer[4]&0xff) << 32 |
+ (long)(buffer[3]&0xff) << 24 |
+ (long)(buffer[2]&0xff) << 16 |
+ (long)(buffer[1]&0xff) << 8 |
+ (long)(buffer[0]&0xff);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readFloat()
+ */
+ public final float readFloat() throws IOException
+ {
+ return Float.intBitsToFloat(readInt());
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readDouble()
+ */
+ public final double readDouble() throws IOException
+ {
+ return Double.longBitsToDouble(readLong());
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readBoolean()
+ */
+ public boolean readBoolean() throws IOException {
+ return in.readBoolean();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readByte()
+ */
+ public byte readByte() throws IOException {
+ return in.readByte();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readFully(byte[])
+ */
+ public void readFully(byte[] b) throws IOException {
+ in.readFully(b);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readFully(byte[], int, int)
+ */
+ public void readFully(byte[] b, int off, int len) throws IOException {
+ in.readFully(b,off,len);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readLine()
+ */
+ @Deprecated
+ public String readLine() throws IOException {
+ return in.readLine();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readUTF()
+ */
+ public String readUTF() throws IOException {
+ return in.readUTF();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#readUnsignedByte()
+ */
+ public int readUnsignedByte() throws IOException {
+ return in.readUnsignedByte();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.io.DataInput#skipBytes(int)
+ */
+ public int skipBytes(int n) throws IOException {
+ return in.skipBytes(n);
+ }
+
+ /**
+ * Close this stream.
+ */
+ public void close() throws IOException {
+ in.close();
+ }
+
+ public final long readUnsignedInt() throws IOException
+ {
+ in.readFully(buffer, 0, 4);
+ return
+ ((
+ (buffer[3]) << 24 |
+ (buffer[2]&0xff) << 16 |
+ (buffer[1]&0xff) << 8 |
+ (buffer[0]&0xff)
+ )
+ & MasksGenerator.UNSIGNED_INT_MASK );
+ }
+
+
+
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/MasksGenerator.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/MasksGenerator.java
new file mode 100644
index 0000000..4b8adf5
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/MasksGenerator.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.utils;
+
+public class MasksGenerator {
+ public static final long UNSIGNED_INT_MASK = 0xffffffffL;
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/STGcovProgramChecker.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/STGcovProgramChecker.java
new file mode 100644
index 0000000..c47cf07
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/STGcovProgramChecker.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.WeakHashMap;
+
+import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.linuxtools.binutils.utils.STNMFactory;
+import org.eclipse.linuxtools.binutils.utils.STNMSymbolsHandler;
+import org.eclipse.linuxtools.binutils.utils.STSymbolManager;
+
+public class STGcovProgramChecker implements STNMSymbolsHandler {
+
+ private boolean gcovFound = false;
+ private long timestamp;
+ private final static WeakHashMap<File, STGcovProgramChecker> map = new WeakHashMap<File, STGcovProgramChecker>();
+
+ /** Private Constructor */
+ private STGcovProgramChecker(long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ private static STGcovProgramChecker getProgramChecker(IBinaryObject object) throws IOException {
+ File program = object.getPath().toFile();
+ STGcovProgramChecker pg = map.get(program);
+ if (pg == null) {
+ pg = new STGcovProgramChecker(program.lastModified());
+ STNMFactory.getNM(object.getCPU(), object.getPath().toOSString(), pg);
+ map.put(program, pg);
+ } else {
+ long fileTime = program.lastModified();
+ if (fileTime > pg.timestamp) {
+ pg.timestamp = fileTime;
+ pg.gcovFound = false;
+ STNMFactory.getNM(object.getCPU(), object.getPath().toOSString(), pg);
+ }
+ }
+ return pg;
+ }
+
+ public static boolean isGCovCompatible(String s) throws IOException {
+ IBinaryObject object = STSymbolManager.sharedInstance.getBinaryObject(new Path(s));
+ if (object == null) return false;
+ return isGCovCompatible(object);
+ }
+
+ public static boolean isGCovCompatible(IBinaryObject object) throws IOException {
+ STGcovProgramChecker pg = getProgramChecker(object);
+ return pg.gcovFound;
+ }
+
+ @Override
+ public void foundBssSymbol(String symbol, String address) {
+ }
+
+ @Override
+ public void foundDataSymbol(String symbol, String address) {
+ }
+
+ @Override
+ public void foundTextSymbol(String symbol, String address) {
+ if ("gcov_read_words".equals(symbol) || "_gcov_read_words".equals(symbol))
+ {
+ gcovFound = true;
+ }
+ }
+
+ @Override
+ public void foundUndefSymbol(String symbol) {
+ }
+
+
+
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovFileContentProvider.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovFileContentProvider.java
new file mode 100644
index 0000000..1f011bc
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovFileContentProvider.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.view;
+
+import java.util.LinkedList;
+
+import org.eclipse.linuxtools.gcov.model.CovFolderTreeElement;
+import org.eclipse.linuxtools.gcov.model.CovRootTreeElement;
+import org.eclipse.linuxtools.gcov.model.TreeElement;
+
+
+
+public class CovFileContentProvider extends CovFolderContentProvider {
+
+ public static final CovFileContentProvider sharedInstance = new CovFileContentProvider();
+
+ /**
+ * Constructor
+ */
+ protected CovFileContentProvider() {
+ }
+
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof CovRootTreeElement) {
+ CovRootTreeElement root = (CovRootTreeElement) parentElement;
+ LinkedList<? extends TreeElement> ret = getElementChildrenList(root);
+ return ret.toArray();
+ }
+ return super.getChildren(parentElement);
+ }
+
+ protected LinkedList<? extends TreeElement> getElementChildrenList(CovRootTreeElement root) {
+ LinkedList<TreeElement> ret = new LinkedList<TreeElement>();
+ LinkedList<? extends TreeElement> list = root.getChildren();
+ for (TreeElement folderlist : list) {
+ LinkedList<? extends TreeElement> partialList = folderlist.getChildren();
+ ret.addAll(partialList);
+ }
+ return ret;
+ }
+
+ @Override
+ public Object getParent(Object element) {
+ Object o = super.getParent(element);
+ if (o instanceof CovFolderTreeElement) {
+ o = super.getParent(o);
+ }
+ return o;
+ }
+
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovFolderContentProvider.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovFolderContentProvider.java
new file mode 100644
index 0000000..f3fbfc1
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovFolderContentProvider.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.view;
+
+
+import java.util.LinkedList;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.linuxtools.gcov.model.TreeElement;
+import org.eclipse.linuxtools.gcov.parser.CovManager;
+
+
+public class CovFolderContentProvider implements ITreeContentProvider {
+
+ /** Shared instance: this class is implemented as a Singleton */
+ public static final CovFolderContentProvider sharedInstance = new CovFolderContentProvider();
+
+
+ protected CovFolderContentProvider(){
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ TreeElement elem = (TreeElement) parentElement;
+ LinkedList<? extends TreeElement> list = elem.getChildren();
+ if (list != null)
+ return list.toArray();
+ else return null;
+ }
+
+ public Object getParent(Object element) {
+ TreeElement elem = (TreeElement) element;
+ return elem.getParent();
+ }
+
+ public boolean hasChildren(Object element) {
+ TreeElement elem = (TreeElement) element;
+ return elem.hasChildren();
+ }
+
+ public Object[] getElements(Object inputElement) {
+ if (inputElement == null) return new Object[0];
+ CovManager cvrgMnger = (CovManager)inputElement;
+ return new Object[] {
+ cvrgMnger.getRootNode()
+ };
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovFunctionContentProvider.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovFunctionContentProvider.java
new file mode 100644
index 0000000..8093b2a
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovFunctionContentProvider.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.view;
+
+import java.util.LinkedList;
+
+import org.eclipse.linuxtools.gcov.model.CovFileTreeElement;
+import org.eclipse.linuxtools.gcov.model.CovRootTreeElement;
+import org.eclipse.linuxtools.gcov.model.TreeElement;
+
+
+
+
+public class CovFunctionContentProvider extends CovFileContentProvider {
+
+ public static final CovFunctionContentProvider sharedInstance = new CovFunctionContentProvider();
+
+ /**
+ * Constructor
+ */
+ protected CovFunctionContentProvider() {
+ }
+
+ protected LinkedList<? extends TreeElement> getElementChildrenList(CovRootTreeElement root) {
+ LinkedList<? extends TreeElement> list = super.getElementChildrenList(root);
+ LinkedList<TreeElement> ret = new LinkedList<TreeElement>();
+ for (TreeElement histTreeElem : list) {
+ LinkedList<? extends TreeElement> partialList = histTreeElem.getChildren();
+ ret.addAll(partialList);
+ }
+ return ret;
+ }
+
+
+ @Override
+ public Object getParent(Object element) {
+ Object o = super.getParent(element);
+ if (o instanceof CovFileTreeElement) {
+ o = super.getParent(o);
+ }
+ return o;
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovView.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovView.java
new file mode 100644
index 0000000..fd88d1e
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovView.java
@@ -0,0 +1,279 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.view;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.linuxtools.dataviewers.abstractview.AbstractSTDataView;
+import org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractSTViewer;
+import org.eclipse.linuxtools.dataviewers.abstractviewers.STDataViewersImages;
+import org.eclipse.linuxtools.dataviewers.actions.STExportToCSVAction;
+import org.eclipse.linuxtools.dataviewers.charts.actions.ChartAction;
+import org.eclipse.linuxtools.gcov.Activator;
+import org.eclipse.linuxtools.gcov.action.SwitchContentProviderAction;
+import org.eclipse.linuxtools.gcov.parser.CovManager;
+import org.eclipse.linuxtools.gcov.parser.SourceFile;
+import org.eclipse.linuxtools.gcov.view.annotatedsource.OpenSourceFileAction;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * @author Xavier Raynaud <xavier.raynaud@st.com>
+ *
+ */
+public class CovView extends AbstractSTDataView {
+
+ private String defaultCSVPath = "gcov.csv";
+
+ private Label label;
+
+ private Action folderAction;
+ private Action fileAction;
+ private Action functionAction;
+ static CovView cvrgeView;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractview.AbstractSTDataView#createAbstractSTViewer
+ * (org.eclipse.swt.widgets.Composite)
+ */
+ protected AbstractSTViewer createAbstractSTViewer(Composite parent) {
+ return new CovViewer(parent);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractview.AbstractSTDataViewer#contributeToToolbar(org.eclipse.jface.action.IToolBarManager)
+ */
+ @Override
+ protected void contributeToToolbar(IToolBarManager manager) {
+ super.contributeToToolbar(manager);
+ manager.add(new Separator());
+ manager.add(new Separator());
+ manager.add(folderAction);
+ manager.add(fileAction);
+ manager.add(functionAction);
+ manager.add(new Separator());
+ manager.add(new ChartAction(getViewSite().getShell(), getSTViewer()));
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractview.AbstractSTDataViewer#createActions()
+ */
+ @Override
+ protected void createActions() {
+ STDataViewersImages.getImageDescriptor(""); // workaround a bug
+ super.createActions();
+ folderAction = new SwitchContentProviderAction(
+ "Sort coverage per folder",
+ "icons/directory_obj.gif",
+ getSTViewer().getViewer(),
+ CovFolderContentProvider.sharedInstance);
+
+ fileAction = new SwitchContentProviderAction(
+ "Sort coverage per file",
+ "icons/c_file_obj.gif",
+ getSTViewer().getViewer(),
+ CovFileContentProvider.sharedInstance);
+ fileAction.setChecked(true);
+
+ functionAction = new SwitchContentProviderAction(
+ "Sort coverage per function",
+ "icons/function_obj.gif",
+ getSTViewer().getViewer(),
+ CovFunctionContentProvider.sharedInstance);
+ }
+
+ /**
+ * This is a callback that will allow us
+ * to create the viewer and initialize it.
+ */
+ public void createPartControl(Composite parent) {
+ STDataViewersImages.getImageDescriptor(""); // workaround a bug
+ super.createPartControl(parent);
+ GridLayout l = (GridLayout) parent.getLayout();
+ l.horizontalSpacing = 0;
+ l.verticalSpacing = 0;
+ l.marginHeight = 0;
+ l.marginWidth = 0;
+ }
+
+ protected void createTitle(Composite parent) {
+ label = new Label(parent, SWT.WRAP);
+ GridData data = new GridData(SWT.FILL, SWT.BEGINNING, true, false, 1, 1);
+ label.setLayoutData(data);
+ }
+
+ public static void setCovViewTitle(CovView view, String title,
+ String binaryPath) {
+ view.label.setText(" \n program runs = " + title
+ + " \n program file : " + binaryPath + "\n ");
+ view.label.getParent().layout(true);
+ }
+
+
+ public static void displayCovDetailedResult(String binaryPath, String gcdaFile) {
+ try {
+ // parse and process coverage data
+ CovManager cvrgeMnger = new CovManager(binaryPath);
+ List<String> gcdaPaths = new LinkedList<String>();
+ gcdaPaths.add(gcdaFile);
+ cvrgeMnger.processCovFiles(gcdaPaths);
+ // generate model for view
+ cvrgeMnger.fillGcovView();
+
+ for (SourceFile sf : cvrgeMnger.getSourceMap().values()) {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IFile binary = root.getFileForLocation(new Path(binaryPath));
+ IProject project = null;
+ if (binary != null) project = binary.getProject();
+ OpenSourceFileAction.sharedInstance.openAnnotatedSourceFile(project,
+ binary, sf, 0);
+ }
+ } catch (Exception _) {
+ final String message = "An error has occured when parsing "
+ + "the coverage data files :\n" + _.getMessage();
+ Status status = new Status(Status.ERROR, Activator.PLUGIN_ID,
+ IStatus.ERROR, message, _);
+
+ Activator.getDefault().getLog().log(status);
+ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ Shell s = PlatformUI.getWorkbench().getDisplay().getActiveShell();
+ MessageDialog.openError(s, "Gcov Parsing Error", message);
+ }
+ });
+ return;
+ }
+ }
+
+ public static CovView displayCovResults(String binaryPath) {
+ try {
+ // parse and process coverage data
+ CovManager cvrgeMnger = new CovManager(binaryPath);
+ List<String> gcdaPaths = cvrgeMnger.getGCDALocations();
+ cvrgeMnger.processCovFiles(gcdaPaths);
+ // generate model for view
+ cvrgeMnger.fillGcovView();
+ //load an Eclipse view
+ CovView cvrgeView = displayCovResults(cvrgeMnger);
+ return cvrgeView;
+ } catch (Exception _) {
+ final String message = "An error has occured when parsing "
+ + "the coverage data files :\n" + _.getMessage();
+ Status status = new Status(Status.ERROR, Activator.PLUGIN_ID,
+ IStatus.ERROR, message, _);
+
+ Activator.getDefault().getLog().log(status);
+ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ Shell s = PlatformUI.getWorkbench().getDisplay().getActiveShell();
+ MessageDialog.openError(s, "Gcov Parsing Error", message);
+ }
+ });
+ }
+ return null;
+ }
+
+ /**
+ * Used by Test engine and OpenSerAction
+ * @param cvrgeMnger
+ */
+ public static CovView displayCovResults(final CovManager cvrgeMnger) throws PartInitException {
+ //load an Eclipse view
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if( window == null){
+ window = PlatformUI.getWorkbench().getWorkbenchWindows()[0];
+ }
+ final IWorkbenchPage page = window.getActivePage();
+
+ final Shell shell = window.getShell();
+ if (shell != null) {
+ shell.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ try {
+ cvrgeView = (CovView) page.showView("org.eclipse.linuxtools.gcov.view");
+ } catch (PartInitException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ //view title
+ CovView.setCovViewTitle(cvrgeView, Integer
+ .toString((int) cvrgeMnger.getNbrPgmRuns()), cvrgeMnger
+ .getBinaryPath());
+
+ // load the controller
+ cvrgeView.setInput(cvrgeMnger);
+ CovViewer stviewer = (CovViewer) cvrgeView.getSTViewer();
+ stviewer.getViewer().expandToLevel(2);
+ }
+ });
+ }
+
+
+ return cvrgeView;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractview.AbstractSTDataView#createExportToCSVAction()
+ */
+ @Override
+ protected IAction createExportToCSVAction() {
+ IAction action = new STExportToCSVAction(this.getSTViewer()) {
+ public void run() {
+ Object o = getSTViewer().getInput();
+ if (o instanceof CovManager) {
+ getExporter().setFilePath(getDefaultCSVPath());
+ }
+ super.run();
+ }
+
+ };
+ return action;
+ }
+
+ /**
+ * @return the defaultCSVPath
+ */
+ public String getDefaultCSVPath() {
+ return defaultCSVPath;
+ }
+
+ /**
+ * @param defaultCSVPath the defaultCSVPath to set
+ */
+ public void setDefaultCSVPath(String defaultCSVPath) {
+ this.defaultCSVPath = defaultCSVPath;
+ }
+
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovViewer.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovViewer.java
new file mode 100644
index 0000000..5ec9694
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovViewer.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.view;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractSTTreeViewer;
+import org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField;
+import org.eclipse.linuxtools.gcov.model.CovFileTreeElement;
+import org.eclipse.linuxtools.gcov.model.CovFunctionTreeElement;
+import org.eclipse.linuxtools.gcov.model.TreeElement;
+import org.eclipse.linuxtools.gcov.parser.CovManager;
+import org.eclipse.linuxtools.gcov.parser.SourceFile;
+import org.eclipse.linuxtools.gcov.view.annotatedsource.OpenSourceFileAction;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+
+
+
+public class CovViewer extends AbstractSTTreeViewer {
+
+ private ISTDataViewersField[] fields;
+
+ /**
+ * Constructor
+ * @param parent
+ */
+ public CovViewer(Composite parent) {
+ super(parent, SWT.BORDER | SWT.H_SCROLL| SWT.V_SCROLL | SWT.MULTI |
+ SWT.FULL_SELECTION);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractSTViewer#createContentProvider()
+ */
+ @Override
+ protected IContentProvider createContentProvider() {
+ return CovFileContentProvider.sharedInstance;
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractSTViewer#getAllFields()
+ */
+ @Override
+ public ISTDataViewersField[] getAllFields() {
+ if (fields == null) {
+ fields = new ISTDataViewersField[] {
+ new FieldName(),
+ new FieldTotalLines(),
+ new FieldInstrumentedLines(),
+ new FieldExecutedLines(),
+ new FieldCoveragePercentage() };
+ }
+ return fields;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractSTViewer#getDialogSettings()
+ */
+ public IDialogSettings getDialogSettings() {
+ return org.eclipse.linuxtools.gcov.Activator.getDefault().getDialogSettings();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractSTViewer#handleOpenEvent(org.eclipse.jface.viewers.OpenEvent)
+ */
+ protected void handleOpenEvent(OpenEvent event) {
+
+ IStructuredSelection selection = (IStructuredSelection) event
+ .getSelection();
+ TreeElement element = (TreeElement) selection.getFirstElement();
+
+ if (element != null) {
+ if (element.getParent() != null) {
+ String sourceLoc = "";
+ long lineNumber = 0;
+
+ if (element.getClass() == CovFileTreeElement.class)
+ sourceLoc = element.getName();
+
+ else if (element.getClass() == CovFunctionTreeElement.class) {
+ sourceLoc = ((CovFunctionTreeElement) element).getSourceFilePath();
+ lineNumber =((CovFunctionTreeElement)element).getFirstLnNmbr();
+ }
+ CovManager cvm = (CovManager) this.getInput();
+ SourceFile sourceFile = cvm.getSourceFile(sourceLoc);
+ if (sourceFile != null) {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ String binaryLoc = cvm.getBinaryPath();
+ IPath binaryPath = new Path(binaryLoc);
+ IFile binary = root.getFileForLocation(binaryPath);
+ IProject project = null;
+ if (binary != null) project = binary.getProject();
+
+ OpenSourceFileAction.sharedInstance.openAnnotatedSourceFile(project,
+ binary, sourceFile, (int)lineNumber);
+ }
+ }
+ }
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldCoveragePercentage.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldCoveragePercentage.java
new file mode 100644
index 0000000..aef5074
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldCoveragePercentage.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.view;
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+
+import org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractPercentageDrawerField;
+import org.eclipse.linuxtools.dataviewers.charts.provider.IChartField;
+import org.eclipse.linuxtools.gcov.model.CovRootTreeElement;
+import org.eclipse.linuxtools.gcov.model.TreeElement;
+
+
+
+public class FieldCoveragePercentage extends AbstractPercentageDrawerField implements IChartField {
+
+ public final static NumberFormat nf = new DecimalFormat("##0.0#");
+
+
+ public String getColumnHeaderText() {
+ return "Coverage %";
+ }
+
+ @Override
+ public String getValue(Object obj) {
+ float f = getPercentage(obj);
+ if (f < 0)
+ f = 0.0f;
+ return nf.format(f);
+ }
+
+
+ /**
+ * Gets the percentage value to display
+ * @param obj
+ * @return the percentage value to display, as a float
+ */
+ public float getPercentage(Object obj) {
+ TreeElement e = (TreeElement) obj;
+ return e.getCoveragePercentage();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractPercentageDrawerField#getNumberFormat()
+ */
+ @Override
+ public NumberFormat getNumberFormat() {
+ return nf;
+ }
+
+ @Override
+ public boolean isSettedNumberFormat() {
+ return true;
+ }
+
+ public String getToolTipText(Object element) {
+ TreeElement e = (TreeElement) element;
+ String s =" Coverage % = "+Integer.toString((int)e.getCoveragePercentage());
+ return s ;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare(Object obj1, Object obj2) {
+ TreeElement e1 = (TreeElement) obj1;
+ TreeElement e2 = (TreeElement) obj2;
+ float f1 = e1.getCoveragePercentage();
+ float f2 = e2.getCoveragePercentage();
+ return Float.compare(f1, f2);
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.charts.provider.IChartField#getNumber(java.lang.Object)
+ */
+ public Number getNumber(Object obj) {
+ TreeElement e = (TreeElement) obj;
+ float f = getPercentage(obj);
+ if (e.getClass() == CovRootTreeElement.class)
+ return 0;
+ else {
+ if (f < 0)
+ f = 0.0f;
+ return f;
+ }
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldExecutedLines.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldExecutedLines.java
new file mode 100644
index 0000000..718a117
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldExecutedLines.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.view;
+
+import org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractSTDataViewersField;
+import org.eclipse.linuxtools.dataviewers.charts.provider.IChartField;
+import org.eclipse.linuxtools.gcov.model.TreeElement;
+
+
+public class FieldExecutedLines extends AbstractSTDataViewersField implements IChartField{
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField#getColumnHeaderText()
+ */
+ public String getColumnHeaderText() {
+ return "Executed Lines";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField#getValue(java.lang.Object)
+ */
+ public String getValue(Object obj) {
+ TreeElement e = (TreeElement) obj;
+ return Integer.toString(e.getExecutedLines());
+ }
+
+ @Override
+ public String getToolTipText(Object element) {
+ TreeElement e = (TreeElement) element;
+ String s = "Executed lines number = "
+ + Integer.toString(e.getExecutedLines());
+ return s;
+ }
+
+ public int compare(Object obj1, Object obj2) {
+ TreeElement e1 = (TreeElement) obj1;
+ TreeElement e2 = (TreeElement) obj2;
+ String s1 = Integer.toString(e1.getExecutedLines());
+ String s2 = Integer.toString(e2.getExecutedLines());
+ if (s1 == null) {
+ if (s2 == null)
+ return 0;
+ return -1;
+ }
+ if (s2 == null)
+ return 1;
+ return s1.compareTo(s2);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.charts.provider.IChartField#getNumber(java.lang.Object)
+ */
+ public Number getNumber(Object obj) {
+ TreeElement e = (TreeElement) obj;
+ return e.getExecutedLines();
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldInstrumentedLines.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldInstrumentedLines.java
new file mode 100644
index 0000000..3d478dd
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldInstrumentedLines.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.view;
+
+import org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractSTDataViewersField;
+import org.eclipse.linuxtools.dataviewers.charts.provider.IChartField;
+import org.eclipse.linuxtools.gcov.model.TreeElement;
+
+
+
+public class FieldInstrumentedLines extends AbstractSTDataViewersField implements IChartField{
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField#getColumnHeaderText()
+ */
+ public String getColumnHeaderText() {
+ return "Instrumented Lines";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField#getValue(java.lang.Object)
+ */
+ public String getValue(Object obj) {
+ TreeElement e = (TreeElement) obj;
+ return Integer.toString(e.getInstrumentedLines());
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractSTDataViewersField#getToolTipText(java.lang.Object)
+ */
+ @Override
+ public String getToolTipText(Object element) {
+ TreeElement e = (TreeElement) element;
+ String s = "Instrumented lines number = "+Integer.toString(e.getInstrumentedLines());
+ return s;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare(Object obj1, Object obj2) {
+ TreeElement e1 = (TreeElement) obj1;
+ TreeElement e2 = (TreeElement) obj2;
+ String s1 = Integer.toString(e1.getInstrumentedLines());
+ String s2 = Integer.toString(e2.getInstrumentedLines());
+ if (s1 == null) {
+ if (s2 == null) return 0;
+ return -1;
+ }
+ if (s2 == null) return 1;
+ return s1.compareTo(s2);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.charts.provider.IChartField#getNumber(java.lang.Object)
+ */
+ public Number getNumber(Object obj) {
+ TreeElement e = (TreeElement) obj;
+ return e.getInstrumentedLines();
+ }
+
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldName.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldName.java
new file mode 100644
index 0000000..7193628
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldName.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.view;
+
+import org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractSTDataViewersField;
+import org.eclipse.linuxtools.gcov.model.TreeElement;
+
+
+public class FieldName extends AbstractSTDataViewersField {
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField#getColumnHeaderText()
+ */
+ @Override
+ public String getColumnHeaderText() {
+ return "Name";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField#getValue(java.lang.Object)
+ */
+ @Override
+ public String getValue(Object obj) {
+ TreeElement e = (TreeElement) obj;
+ String nm = e.getName();
+ nm = nm.substring(nm.lastIndexOf('/')+1);
+ nm = nm.substring(nm.lastIndexOf('\\')+1);
+ return nm;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractSTDataViewersField#getToolTipText(java.lang.Object)
+ */
+ @Override
+ public String getToolTipText(Object element) {
+ TreeElement elem = (TreeElement) element;
+ String s = elem.getName();
+ return s;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField#compare(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public int compare(Object obj1, Object obj2) {
+ String s1 = getValue(obj1);
+ String s2 = getValue(obj2);
+ if (s1 == null) {
+ if (s2 == null)
+ return 0;
+ return -1;
+ }
+ if (s2 == null)
+ return 1;
+ return s1.compareTo(s2);
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldTotalLines.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldTotalLines.java
new file mode 100644
index 0000000..993679b
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldTotalLines.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.view;
+
+
+import org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractSTDataViewersField;
+import org.eclipse.linuxtools.gcov.model.CovFileTreeElement;
+import org.eclipse.linuxtools.gcov.model.CovFunctionTreeElement;
+import org.eclipse.linuxtools.gcov.model.TreeElement;
+
+
+
+public class FieldTotalLines extends AbstractSTDataViewersField {
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField#getColumnHeaderText()
+ */
+ @Override
+ public String getColumnHeaderText() {
+ return "Total Lines";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField#getValue(java.lang.Object)
+ */
+ @Override
+ public String getValue(Object obj) {
+ TreeElement e = (TreeElement) obj;
+ if (e.getClass() != CovFunctionTreeElement.class)
+ return Integer.toString(e.getTotalLines());
+ else
+ return "";
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractSTDataViewersField#getToolTipText(java.lang.Object)
+ */
+ @Override
+ public String getToolTipText(Object element) {
+ TreeElement e = (TreeElement) element;
+ if (e.getClass() != CovFunctionTreeElement.class)
+ return "Total lines number = "+Integer.toString(e.getTotalLines());
+ else
+ return "";
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField#compare(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public int compare(Object obj1, Object obj2) {
+ TreeElement e1 = (TreeElement) obj1;
+ TreeElement e2 = (TreeElement) obj2;
+
+ if (e1.getClass() == CovFileTreeElement.class) {
+ String s1 = Integer.toString(((CovFileTreeElement)e1).getTotalLines());
+ String s2 = Integer.toString(((CovFileTreeElement)e2).getTotalLines());
+ if (s1 == null) {
+ if (s2 == null)
+ return 0;
+ return -1;
+ }
+ if (s2 == null)
+ return 1;
+ return s1.compareTo(s2);
+ }
+ else return 0;
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/CoverageAnnotationColumn.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/CoverageAnnotationColumn.java
new file mode 100644
index 0000000..8e098b5
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/CoverageAnnotationColumn.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.view.annotatedsource;
+
+
+import java.util.ArrayList;
+
+import org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.ISTAnnotationColumn;
+import org.eclipse.linuxtools.gcov.parser.Line;
+import org.eclipse.linuxtools.gcov.parser.SourceFile;
+
+
+public class CoverageAnnotationColumn implements ISTAnnotationColumn {
+
+
+ private final ArrayList<Line> lines;
+
+ public CoverageAnnotationColumn(SourceFile sourceFile) {
+ lines = sourceFile.getLines();
+ }
+
+ @Override
+ public String getAnnotation(int index) {
+ try {
+ Line l = lines.get(index+1);
+ if (!l.isExists()) {
+ return "";
+ } else {
+ return Long.toString(l.getCount());
+ }
+ } catch (IndexOutOfBoundsException _) {
+ return "";
+ }
+ }
+
+ @Override
+ public String getLongDescription(int line) {
+ return null;
+ }
+
+ @Override
+ public String getTitle() {
+ return "Coverage";
+ }
+
+
+ @Override
+ public String getHeaderTooltip() {
+ return "Coverage";
+ }
+
+ @Override
+ public String getTooltip(int index) {
+ try {
+ Line l = lines.get(index+1);
+ if (!l.isExists()) {
+ return "non executable line";
+ } else {
+ long count = l.getCount();
+ if (count == 0) return "line never executed";
+ if (count == 1) return "line executed 1 time";
+ return "line executed "
+ + Long.toString(count)
+ + " times";
+ }
+ } catch (IndexOutOfBoundsException _) {
+ return "non executable line";
+ }
+ }
+
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/OpenSourceFileAction.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/OpenSourceFileAction.java
new file mode 100644
index 0000000..4852144
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/OpenSourceFileAction.java
@@ -0,0 +1,136 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.view.annotatedsource;
+
+import java.net.URI;
+
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.linuxtools.binutils.link2source.STLink2SourceSupport;
+import org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.AbstractSTAnnotatedSourceEditorInput;
+import org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.actions.AbstractOpenSourceFileAction;
+import org.eclipse.linuxtools.gcov.Activator;
+import org.eclipse.linuxtools.gcov.parser.SourceFile;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IURIEditorInput;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+
+public class OpenSourceFileAction {
+
+ /**
+ * Shared instance of this class
+ */
+ public static final OpenSourceFileAction sharedInstance = new OpenSourceFileAction();
+
+ private OpenSourceFileAction() {
+ }
+
+
+ // FIXME: move this method in binutils plugin.
+ private IFileStore getFileStore(IProject project, IPath path) {
+ IEditorInput input = STLink2SourceSupport.sharedInstance.getEditorInput(path, project);
+ if (input instanceof IURIEditorInput) {
+ IURIEditorInput editorInput = (IURIEditorInput) input;
+ URI uri = editorInput.getURI();
+ try {
+ IFileStore fs = EFS.getStore(uri);
+ return fs;
+ } catch (CoreException _) {
+ return null;
+ }
+ }
+ return null;
+ }
+
+
+ private AbstractSTAnnotatedSourceEditorInput getInput(SourceFile sourceFile,
+ IFileStore fs) {
+ AbstractSTAnnotatedSourceEditorInput input = new STAnnotatedSourceEditorInput(
+ fs, sourceFile);
+ IWorkbenchPage p = CUIPlugin.getActivePage();
+ IEditorPart editorPart = p.findEditor(input);
+ if (editorPart != null)
+ p.closeEditor(editorPart, false);
+ return input;
+ }
+
+ public void openAnnotatedSourceFile(IProject project, IFile binary, SourceFile sourceFile, int lineNumber) {
+ if (sourceFile == null) return;
+ String pathName = sourceFile.getName();
+ if (pathName == null) return;
+ IPath path = new Path(pathName);
+ openAnnotatedSourceFile(project, binary, sourceFile, path, lineNumber);
+ }
+
+ public void openAnnotatedSourceFile(IProject project, IFile binary, SourceFile sourceFile, IPath realLocation, int lineNumber) {
+ IWorkbenchPage page = CUIPlugin.getActivePage();
+ if (page != null) {
+ IFileStore fs = getFileStore(project, realLocation);
+ if (fs == null && !realLocation.isAbsolute() && binary != null) {
+ IPath p = binary.getProjectRelativePath().removeLastSegments(1);
+ fs = getFileStore(project, p.append(realLocation));
+ }
+ if (fs == null) {
+ try {
+ page.openEditor(new STAnnotatedSourceNotFoundEditorInput(project,sourceFile,
+ realLocation, lineNumber),
+ STAnnotatedSourceNotFoundEditor.ID, true);
+ } catch (PartInitException e) {
+ Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ IStatus.ERROR, "Error when opening annotated source view",
+ e);
+ Activator.getDefault().getLog().log(s);
+ }
+ } else {
+ IEditorInput input = getInput(sourceFile, fs);
+ try {
+ IEditorPart editor = page.openEditor(input,
+ AbstractOpenSourceFileAction.EDITOR_ID, true);
+ if (lineNumber > 0 && editor instanceof ITextEditor) {
+ IDocumentProvider provider = ((ITextEditor) editor).getDocumentProvider();
+ IDocument document = provider.getDocument(editor.getEditorInput());
+ try {
+ int start = document.getLineOffset(lineNumber - 1);
+ ((ITextEditor) editor).selectAndReveal(start, 0);
+ } catch (BadLocationException _) {
+ // ignore
+ }
+ IWorkbenchPage p = editor.getSite().getPage();
+ p.activate(editor);
+ }
+ } catch (PartInitException e) {
+ Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ IStatus.ERROR, "Error when opening annotated source view",
+ e);
+ Activator.getDefault().getLog().log(s);
+ }
+ }
+ }
+ }
+
+
+
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/STAnnotatedSourceEditorInput.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/STAnnotatedSourceEditorInput.java
new file mode 100644
index 0000000..a74bc69
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/STAnnotatedSourceEditorInput.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.view.annotatedsource;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.AbstractSTAnnotatedSourceEditorInput;
+import org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.ISTAnnotationColumn;
+import org.eclipse.linuxtools.gcov.parser.Line;
+import org.eclipse.linuxtools.gcov.parser.SourceFile;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
+
+
+
+public class STAnnotatedSourceEditorInput extends
+AbstractSTAnnotatedSourceEditorInput {
+
+ private final SourceFile sourceFile;
+ private final int lineCount;
+ private final ArrayList<ISTAnnotationColumn> columns = new ArrayList<ISTAnnotationColumn>();
+
+ public static final Color GREEN = new Color(PlatformUI.getWorkbench().getDisplay(), 0 ,128, 0);
+
+ // FIXME: dispose colors ?
+ private static final Color[] greenColors = new Color[129];
+
+
+ public STAnnotatedSourceEditorInput(IFileStore fileStore, SourceFile sourceFile){
+ super(fileStore);
+ this.sourceFile = sourceFile;
+ lineCount = sourceFile.getLines().size();
+ this.columns.add(new CoverageAnnotationColumn(sourceFile));
+ }
+
+ @Override
+ public Color getColor(int ln) {
+ final int index = ln + 1;
+ Display display = PlatformUI.getWorkbench().getDisplay();
+ if (index < lineCount){
+ ArrayList<Line> lines = sourceFile.getLines();
+ Line line = lines.get(index);
+ if (line.isExists()) {
+ long count = line.getCount();
+ if (count == 0) return display.getSystemColor(SWT.COLOR_RED);;
+ if (count == sourceFile.getmaxLineCount()) return GREEN;
+ int colorIndex = 128 - (int) ((128*count)/sourceFile.getmaxLineCount());
+ if (greenColors[colorIndex] == null) {
+ greenColors[colorIndex] = new Color(display, colorIndex,127+colorIndex,colorIndex);
+ }
+ return greenColors[colorIndex];
+ }
+ }
+ return display.getSystemColor(SWT.COLOR_WHITE);
+ }
+
+ @Override
+ public ArrayList<ISTAnnotationColumn> getColumns() {
+ return columns;
+ }
+
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/STAnnotatedSourceNotFoundEditor.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/STAnnotatedSourceNotFoundEditor.java
new file mode 100644
index 0000000..b73a617
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/STAnnotatedSourceNotFoundEditor.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.gcov.view.annotatedsource;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.linuxtools.binutils.link2source.STCSourceNotFoundEditor;
+import org.eclipse.linuxtools.gcov.parser.SourceFile;
+import org.eclipse.ui.IEditorInput;
+
+
+/**
+ * @author Xavier Raynaud <xavier.raynaud@st.com>
+ *
+ */
+public class STAnnotatedSourceNotFoundEditor extends
+ STCSourceNotFoundEditor {
+
+ public static final String ID = "org.eclipse.linuxtools.gcov.view.annotatedsource.STAnnotatedSourceNotFoundEditor";
+
+ public STAnnotatedSourceNotFoundEditor() {
+
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.binutils.link2source.STCSourceNotFoundEditor#openSourceFileAtLocation(org.eclipse.core.resources.IProject, org.eclipse.core.runtime.IPath, int)
+ */
+ protected void openSourceFileAtLocation(IProject project, IPath sourceLoc,
+ int lineNumber) {
+ IEditorInput input = this.getEditorInput();
+ if (input instanceof STAnnotatedSourceNotFoundEditorInput) {
+ STAnnotatedSourceNotFoundEditorInput editorInput = (STAnnotatedSourceNotFoundEditorInput) input;
+ SourceFile sf = editorInput.getSourceFile();
+ OpenSourceFileAction.sharedInstance.openAnnotatedSourceFile(project, null, sf, sourceLoc, lineNumber);
+ } else {
+ super.openSourceFileAtLocation(project, sourceLoc, lineNumber);
+ }
+ }
+}
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/STAnnotatedSourceNotFoundEditorInput.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/STAnnotatedSourceNotFoundEditorInput.java
new file mode 100644
index 0000000..fb34914
--- /dev/null
+++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/STAnnotatedSourceNotFoundEditorInput.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2009 STMicroelectronics.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.gcov.view.annotatedsource;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.linuxtools.binutils.link2source.STCSourceNotFoundEditorInput;
+import org.eclipse.linuxtools.gcov.parser.SourceFile;
+
+
+public class STAnnotatedSourceNotFoundEditorInput extends STCSourceNotFoundEditorInput {
+
+ private final SourceFile sourceFile;
+
+ public STAnnotatedSourceNotFoundEditorInput(IProject project,
+ SourceFile sourceFile,
+ IPath sourcePath, int lineNumber) {
+ super(project, sourcePath, lineNumber);
+ this.sourceFile = sourceFile;
+ }
+
+ /**
+ * @return the sourceFile
+ */
+ public SourceFile getSourceFile() {
+ return sourceFile;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result
+ + ((sourceFile == null) ? 0 : sourceFile.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final STAnnotatedSourceNotFoundEditorInput other = (STAnnotatedSourceNotFoundEditorInput) obj;
+ if (sourceFile == null) {
+ if (other.sourceFile != null)
+ return false;
+ } else if (!sourceFile.equals(other.sourceFile))
+ return false;
+ return true;
+ }
+
+}