This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
gcov reports error in Mingw
- To: <gcc-bugs at gcc dot gnu dot org>
- Subject: gcov reports error in Mingw
- From: "Nakai Akiya" <nakai dot akiya at canon dot co dot jp>
- Date: Mon, 5 Nov 2001 11:25:11 +0900
- Cc: "Nakai Akiya" <nakai dot akiya at canon dot co dot jp>
I'm using Mingw-gcc and tring to use 'gcov'.
In some sources, gcov reports an error and no coverage measurment is done.
I found the code '0x0a' was expanded to '0x0a 0x0d' in *.bb *.bbg *.da binary files,
and fix some gcc source code to output data files in binary mode.
Now 'gcov' is running quite well with the change.
It might be a trouble for Mingw(PC)environment only,
but I hope to fix it in next release of Mingw-gcc because making 'gcc' in
non-Unix machine was very troublesome.
The situation is below.
The Version of GCC:
gcc -v says
gcc version 2.95.3-5 (mingw special)
I got Mingw-1.0.1-20010726.tar.gz
from http://sourceforge.net/project/showfiles.php?group_id=2435
and using gcc and gcov in it.
The System Type:
The machine is a PC of Dell.
The OS is Windows-2000 5.00.2195 Service Pack 1
The Options given when GCC was configured/built.
I don't know because I got binary 'gcc.exe' and 'gcov.exe' from Mingw site.
The complete command line that triggers the bug.
> gcc -o sample.exe -g -fprofile-arcs -ftest-coverage sample.c
> sample.exe
> gcov sample.c
abnormal program termination <--- this is the error message.
The compiler output (errors etc...)
gcc reports no errors and warnings.
A sample source code causes the error.
------ sample.c from here ------
/*
* A sample code causes gcov error.
* Comment lines are significant,
* without them, gcov run well.
* In my enviroment, source lines terminated with CR LF.
*/
int subfunc(int i)
{
if(i&1){
return i;
}else{
return i+1;
}
}
main()
{
int i,o;
/* comment */
for(i=0;i<10;i++){
/* comment */
o=subfunc(i); /* comment */
}
}
------- end of source file ------
The code I fixed to run 'gcov':
I changed the file open mode "w" and "r" to "wb" and "rb"
in 8 lines below.
----- changed lines -----
gcc/profile.c:init_branch_prob (filename)
if ((bb_file = fopen (data_file, "w")) == 0)
if ((bbg_file = fopen (bbg_file_name, "w")) == 0)
if ((da_file = fopen (da_file_name, "r")) == 0)
gcc/libgcc2.c:__bb_exit_func (void)
if ((da_file = fopen (ptr->filename, "r")) != 0)
if ((da_file = fopen (ptr->filename, "w")) == 0)
gcc/gcov.c:open_files ()
bb_file = fopen (bb_file_name, "r");
da_file = fopen (da_file_name, "r");
bbg_file = fopen (bbg_file_name, "r");
----- end of changed lines -----