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]

[Fwd: Re: gcov in cross-compile: have a patch, seek direction]


Here's the patch that I incorrectly sent to thw wrong list earlier.

As I wrote below, comments are welcome.

Proposed ChangeLog entry :
2007-05-16  Danny Backx  <danny.backx@scarlet.be>
	* doc/gcov.texi : Add description of new compiler command line
	option -fcoverage-base.
	* toplev.h (-fcoverage-base, coverage_base) : Add new command
	line option and variable.
	* coverage.c (build_gcov_info) : Add code so the new variable
	overrides the directory name used to store coverage files.
	* common.opt : Add declaration for new command line option.
	* libgcov.c (gcov_exit) : call another error handler than stderr
	when running on Windows CE.

The last entry is not really part of the new functionality. I would
rather expect a comment to either remove this or to propose this as
another patch entirely.

	Danny

-------- Forwarded Message --------
> From: Danny Backx <danny.backx@scarlet.be>
> To: Ben Elliston <bje@au1.ibm.com>
> Cc: gcc@gcc.gnu.org
> Subject: Re: gcov in cross-compile: have a patch, seek direction
> Date: Thu, 10 May 2007 21:36:49 +0200
> 
> On Fri, 2007-05-04 at 09:49 +1000, Ben Elliston wrote:
> > On Thu, 2007-05-03 at 19:55 +0200, Danny Backx wrote:
> > 
> > > Ok, a command line option is what I have. I'll try to clean up my
> > > patch shortly, and see if it still applies cleanly in a recent gcc
> > > tree. Our current version is based on gcc-4.1.0. Or is a patch against
> > > that ok ?
> > 
> > This feature would not be accepted into GCC 4.1 or 4.2, so please bring
> > your patch up to date with mainline and then submit it.  I'd be
> > surprised if it's much work to do that.
> 
> As you said, it isn't much work.
> 
> Attached is a patch with a small amount of documentation but lacking a
> ChangeLog entry. I'm sending it now already for you to comment on.
> 
> A usage example :
> dannypc: {49} make
> /home/danny/src/gcc/svn@gcc.gnu.org/build/gcc/xgcc
> -B/home/danny/src/gcc/svn@gcc.gnu.org/build/gcc --coverage -c t.c
> -fcoverage-base=/tmp  -o t1.o
> /home/danny/src/gcc/svn@gcc.gnu.org/build/gcc/xgcc
> -B/home/danny/src/gcc/svn@gcc.gnu.org/build/gcc --coverage -c t.c -o
> t2.o
> strings t1.o >t1.strings
> strings t2.o >t2.strings
> dannypc: {50} more *.strings
> ::::::::::::::
> t1.strings
> ::::::::::::::
> e304
> Hello, world !
> /tmp/t1.gcda
> ::::::::::::::
> t2.strings
> ::::::::::::::
> e304
> Hello, world !
> /home/danny/t/t2.gcda
> dannypc: {51} 
> 
> If I need to change the implementation in some way, please advise.
> 
> 	Danny
> 
-- 
Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info
Index: doc/gcov.texi
===================================================================
--- doc/gcov.texi	(revision 124505)
+++ doc/gcov.texi	(working copy)
@@ -543,9 +543,14 @@
 absolute directory structure on the target system. The program will try
 to create the needed directory structure, if it is not already present.
 
-To support cross-profiling, a program compiled with @option{-fprofile-arcs}
-can relocate the data files based on two environment variables: 
+There are two options to support cross-profiling. A command line argument
+to the compiler (-fcoverage-base) allows you to override the directory
+stored in the object file; this happens at compile time. Alternatively,
+two runtime environment variables allow you to relocate the data files.
+Both options have effect only on programs compiled with @option{-fprofile-arcs}.
 
+The two environment variables: 
+
 @itemize @bullet
 @item
 GCOV_PREFIX contains the prefix to add to the absolute paths 
@@ -568,6 +573,12 @@
 @samp{GCOV_PREFIX=/target/run} and @samp{GCOV_PREFIX_STRIP=1}.  Such a
 setting will name the data file @file{/target/run/build/foo.gcda}.
 
+The build time command line option can be used like this :
+
+@smallexample
+gcc -fcoverage-base=/target/run -fprofile-arcs -o t.exe t.c
+@end smallexample
+
 You must move the data files to the expected directory tree in order to
 use them for profile directed optimizations (@option{--use-profile}), or to
 use the @command{gcov} tool.
Index: toplev.h
===================================================================
--- toplev.h	(revision 124505)
+++ toplev.h	(working copy)
@@ -133,6 +133,7 @@
 extern int flag_unswitch_loops;
 extern int flag_cprop_registers;
 extern int time_report;
+extern char *coverage_base;
 
 /* Things to do with target switches.  */
 extern void print_version (FILE *, const char *);
Index: opts.c
===================================================================
--- opts.c	(revision 124505)
+++ opts.c	(working copy)
@@ -1425,6 +1425,10 @@
       fix_register (arg, 0, 0);
       break;
 
+    case OPT_fcoverage_base_:
+      coverage_base = xstrdup(arg);
+      break;
+
     case OPT_fdiagnostics_show_location_:
       if (!strcmp (arg, "once"))
 	diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
Index: coverage.c
===================================================================
--- coverage.c	(revision 124505)
+++ coverage.c	(working copy)
@@ -89,6 +89,7 @@
 static char *bbg_file_name;
 static unsigned bbg_file_opened;
 static int bbg_function_announced;
+char *coverage_base = NULL;
 
 /* Name of the count data file.  */
 static char *da_file_name;
@@ -826,12 +827,24 @@
   field = build_decl (FIELD_DECL, NULL_TREE, string_type);
   TREE_CHAIN (field) = fields;
   fields = field;
-  filename = getpwd ();
-  filename = (filename && da_file_name[0] != '/'
+
+  /* Additional command line argument for cross-development */
+  if (coverage_base)
+    {
+      filename = concat (coverage_base, "/", da_file_name, NULL);
+      filename_len = strlen (filename);
+      filename_string = build_string (filename_len + 1, filename);
+    }
+  else
+    {
+      filename = getpwd ();
+      filename = (filename && da_file_name[0] != '/'
 	      ? concat (filename, "/", da_file_name, NULL)
 	      : da_file_name);
-  filename_len = strlen (filename);
-  filename_string = build_string (filename_len + 1, filename);
+      filename_len = strlen (filename);
+      filename_string = build_string (filename_len + 1, filename);
+    }
+
   if (filename != da_file_name)
     free (filename);
   TREE_TYPE (filename_string) = build_array_type
Index: common.opt
===================================================================
--- common.opt	(revision 124505)
+++ common.opt	(working copy)
@@ -364,6 +364,10 @@
 Common Report Var(flag_no_common,0) Optimization
 Do not put uninitialized globals in the common section
 
+fcoverage-base=
+Common Joined Var(flag_coverage_base)
+Directory in which to put coverage analysis files, for cross-compiler environments
+
 fcprop-registers
 Common Report Var(flag_cprop_registers) Optimization
 Perform a register copy-propagation optimization pass
Index: libgcov.c
===================================================================
--- libgcov.c	(revision 124505)
+++ libgcov.c	(working copy)
@@ -312,7 +312,17 @@
 #endif
 	  if (!gcov_open (gi_filename))
 	    {
+#ifndef	UNDER_CE
               fprintf (stderr, "profiling:%s:Cannot open\n", gi_filename);
+#else
+	      {
+		wchar_t	x[256];
+		int	l = strlen(gi_filename);
+		l = (l < 256) ? l : 255;
+		mbstowcs(x, gi_filename, l);
+	        MessageBoxW(0, x, L"gcov_open couldn't open file", 0);
+	      }
+#endif
 	      continue;
 	    }
 	}

Attachment: signature.asc
Description: This is a digitally signed message part


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