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/[EMAIL PROTECTED]/build/gcc/xgcc -B/home/danny/src/gcc/[EMAIL PROTECTED]/build/gcc --coverage -c t.c -fcoverage-base=/tmp -o t1.o /home/danny/src/gcc/[EMAIL PROTECTED]/build/gcc/xgcc -B/home/danny/src/gcc/[EMAIL PROTECTED]/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 : + [EMAIL PROTECTED] +gcc -fcoverage-base=/target/run -fprofile-arcs -o t.exe t.c [EMAIL PROTECTED] 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; } }
signature.asc
Description: This is a digitally signed message part