https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #21 from Gejoe <gejoed at rediffmail dot com> ---
(In reply to Martin Liška from comment #20)
> > I'm trying to understand line #22 to #26 specifically of .c.gcov file(as
> > shown in commment #16. Let me know if the steps followed in compilation or
> > execution had any thing wrong.
> 
> What is wrong with that? What values are expected?

Actually if we look at line #22 should have the value 16 (after a.out run) and
line #24,25 should have values 4 each instead of what is actually present there
in comment#16.Instead the value of 16,4,4 are shown for line # 24,26,27
respectively. That was my query.

Is that because of some difference with source files and .gcda files as shown
there (in .c.gcov file in Comment #16) as follows ? 
    0:Source is newer than graph

I did delete the gcda file and did the same compilation steps again :
$ gcc -v -save-temps  -fprofile-arcs -ftest-coverage sample-prog.c
$ gcc   -fprofile-arcs -ftest-coverage sample-prog.o
$./a.out

The output was :
$ ./a.out 
__gcov_dump() invoked!
__gcov_reset() invoked!
__gcov_dump() invoked!
__gcov_reset() invoked!

The sample-prog.c.gcov file contents now look fine :
        -:    0:Source:sample-prog.c
        -:    0:Graph:sample-prog.gcno
        -:    0:Data:sample-prog.gcda
        -:    0:Runs:1
        -:    0:Programs:1
        -:    1:#include <stdio.h>
        -:    2:#include <ctype.h>
        -:    3:#include <unistd.h>
        -:    4:
        -:    5:extern void __gcov_reset(void);
        -:    6:extern void __gcov_flush(void);
        -:    7:extern void __gcov_dump( void);
        -:    8:
        1:    9:int main()
        -:   10:{
        -:   11:    unsigned char c;
        1:   12:    int count=0;
        1:   13:        c = 'g';
        -:   14:
        -:   15:        do {
        -:   16:   
       10:   17:                if(c == 'g'){
        2:   18:                        __gcov_dump();
    #####:   19:                        printf("__gcov_dump() invoked!\n");
    #####:   20:                        c = 'r';
        -:   21:                }
        8:   22:                else if(c == 'r'){
    #####:   23:                        __gcov_reset();
        2:   24:                        printf("__gcov_reset() invoked!\n");
        2:   25:                        c = 'f';
        -:   26:                }
       10:   27:                if(count == 2)
        1:   28:                        c = 'g';
        9:   29:                else if (count > 10)
        1:   30:                        c = 'e';
       10:   31:                count++;
       10:   32:        }while(c != 'e');
        -:   33:    
        1:   34:        return 0;
        -:   35:}
==========================================================

So, for either a one time call of __gcov_dump (though we may attempt to call
__gcov_dump many times)  or at the exit of the program execution, the merge of
profile happens due to which __gcov_reset doesn't get reflected at all. Am I
right ?

Thanks again!

Reply via email to