This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Create x.gcov file for binary w/o x.gcda file (PR, gcov-profile/65831)


Hi.

Following patch is grabbed from the PR, where I just applied the patch
and wrote a test-case which removes x.gcda file before running gcov tool.

Ready to be installed?
Martin
>From 0e8a129302eaf8b5950b7b1a6de560b9c2ee4354 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 4 Aug 2016 14:04:36 +0200
Subject: [PATCH] Create x.gcov file for binary w/o x.gcda file (PR
 gcov-profile/65831)

gcc/testsuite/ChangeLog:

2016-08-04  Martin Liska  <mliska@suse.cz>

	* g++.dg/gcov/gcov-16.C: New test.
	* lib/gcov.exp: Support new argument for run-gcov function.

gcc/ChangeLog:

2016-08-04  Martin Liska  <mliska@suse.cz>
	    Adam Fineman  <afineman@afineman.com>

	* gcov.c (process_file): Create .gcov file when .gcda
	file is missing.
---
 gcc/gcov.c                          |  2 +-
 gcc/testsuite/g++.dg/gcov/gcov-16.C | 10 ++++++++++
 gcc/testsuite/lib/gcov.exp          | 28 ++++++++++++++++++++++++----
 3 files changed, 35 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/gcov/gcov-16.C

diff --git a/gcc/gcov.c b/gcc/gcov.c
index 417b4f4..50061c7 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -725,7 +725,7 @@ process_file (const char *file_name)
 
       fns = fn->next;
       fn->next = NULL;
-      if (fn->counts)
+      if (fn->counts || no_data_file)
 	{
 	  unsigned src = fn->src;
 	  unsigned line = fn->line;
diff --git a/gcc/testsuite/g++.dg/gcov/gcov-16.C b/gcc/testsuite/g++.dg/gcov/gcov-16.C
new file mode 100644
index 0000000..f09d406
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gcov/gcov-16.C
@@ -0,0 +1,10 @@
+// PR gcov-profile/64634
+// { dg-options "-fprofile-arcs -ftest-coverage" }
+// { dg-do run { target native } }
+
+int main()
+{
+  return 0;   /* count(#####) */
+}
+
+// { dg-final { run-gcov remove-gcda gcov-16.C } }
diff --git a/gcc/testsuite/lib/gcov.exp b/gcc/testsuite/lib/gcov.exp
index dfc1301..02bc6b9 100644
--- a/gcc/testsuite/lib/gcov.exp
+++ b/gcc/testsuite/lib/gcov.exp
@@ -20,15 +20,27 @@
 global GCOV
 
 #
+# clean-gcov-file -- delete a working file the compiler creates for gcov
+#
+# TESTCASE is the name of the test.
+# SUFFIX is file suffix
+
+proc clean-gcov-file { testcase suffix } {
+    set basename [file tail $testcase]
+    set base [file rootname $basename]
+    remote_file host delete $base.$suffix
+}
+
+#
 # clean-gcov -- delete the working files the compiler creates for gcov
 #
 # TESTCASE is the name of the test.
 #
 proc clean-gcov { testcase } {
-    set basename [file tail $testcase]
-    set base [file rootname $basename]
-    remote_file host delete $base.gcno $base.gcda \
-	$basename.gcov $base.h.gcov
+    clean-gcov-file $testcase "gcno"
+    clean-gcov-file $testcase "gcda"
+    clean-gcov-file $testcase "gcov"
+    clean-gcov-file $testcase "h.gcov"
 }
 
 #
@@ -305,6 +317,7 @@ proc run-gcov { args } {
     set gcov_verify_branches 0
     set gcov_verify_lines 1
     set gcov_verify_intermediate 0
+    set gcov_remove_gcda 0
     set xfailed 0
 
     foreach a $args {
@@ -317,6 +330,8 @@ proc run-gcov { args } {
 	  set gcov_verify_calls 0
 	  set gcov_verify_branches 0
 	  set gcov_verify_lines 0
+	} elseif { $a == "remove-gcda" } {
+	  set gcov_remove_gcda 1
 	} elseif { $gcov_args == "" } {
 	    set gcov_args $a
 	} else {
@@ -332,6 +347,11 @@ proc run-gcov { args } {
     # Extract the test file name from the arguments.
     set testcase [lindex $gcov_args end]
 
+    if { $gcov_remove_gcda } {
+	verbose "Removing $testcase.gcda"
+	clean-gcov-file $testcase "gcda"
+    }
+
     verbose "Running $GCOV $testcase" 2
     set testcase [remote_download host $testcase]
     set result [remote_exec host $GCOV $gcov_args]
-- 
2.9.2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]