public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "marxin at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
Date: Fri, 28 May 2021 11:41:28 +0000	[thread overview]
Message-ID: <bug-100751-4-znd4VttRUM@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-100751-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #23 from Martin Liška <marxin at gcc dot gnu.org> ---
> 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 ?

Oh, I actually wrongly updated the documentation. When __gcov_reset is called,
run-time counters are reset to zero AND __gcov_dump can be called again (or
profile will be saved at exit).

Slightly modified test-case does now:

$ cat sample-prog.c
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>

extern void __gcov_reset(void);
extern void __gcov_flush(void);
extern void __gcov_dump( void);

int main()
{
    unsigned char c;
    int count=0;
        c = 'g';

        do {
    printf ("c: '%c'\n", c);

                if(c == 'g'){
                        __gcov_dump();
                        printf("__gcov_dump() invoked!\n");
                        c = 'r';
                }
                else if(c == 'r'){
                        __gcov_reset();
                        printf("__gcov_reset() invoked!\n");
                        c = 'f';
                }
                if(count == 2)
                        c = 'g';
                else if (count > 10)
                        c = 'e';
                count++;
        }while(c != 'e');

        return 0;
}

$ gcc sample-prog.c --coverage -g && ./a.out && gcov -t sample-prog.c
c: 'g'
__gcov_dump() invoked!
c: 'r'
__gcov_reset() invoked!
c: 'f'
c: 'g'
__gcov_dump() invoked!
c: 'r'
__gcov_reset() invoked!
c: 'f'
c: 'f'
c: 'f'
c: 'f'
c: 'f'
c: 'f'
c: 'f'
        -:    0:Source:sample-prog.c
        -:    0:Graph:sample-prog.gcno
        -:    0:Data:sample-prog.gcda
        -:    0:Runs: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 {
       10:   16:    printf ("c: '%c'\n", c);
        -:   17:   
       10:   18:                if(c == 'g'){
        2:   19:                        __gcov_dump();
    #####:   20:                        printf("__gcov_dump() invoked!\n");
    #####:   21:                        c = 'r';
        -:   22:                }
        8:   23:                else if(c == 'r'){
    #####:   24:                        __gcov_reset();
        2:   25:                        printf("__gcov_reset() invoked!\n");
        2:   26:                        c = 'f';
        -:   27:                }
       10:   28:                if(count == 2)
        1:   29:                        c = 'g';
        9:   30:                else if (count > 10)
        1:   31:                        c = 'e';
       10:   32:                count++;
       10:   33:        }while(c != 'e');
        -:   34:    
        1:   35:        return 0;
        -:   36:}

Which should be correct in my oppinion.

  parent reply	other threads:[~2021-05-28 11:41 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-25  6:54 [Bug gcov-profile/100751] New: " gejoed at rediffmail dot com
2021-05-25  6:58 ` [Bug gcov-profile/100751] " gejoed at rediffmail dot com
2021-05-25  7:01 ` gejoed at rediffmail dot com
2021-05-25  7:56 ` marxin at gcc dot gnu.org
2021-05-25 10:57 ` gejoed at rediffmail dot com
2021-05-25 12:14 ` gejoed at rediffmail dot com
2021-05-25 12:52 ` marxin at gcc dot gnu.org
2021-05-25 12:53 ` marxin at gcc dot gnu.org
2021-05-25 18:40 ` gejoed at rediffmail dot com
2021-05-26  7:31 ` marxin at gcc dot gnu.org
2021-05-26  7:34 ` cvs-commit at gcc dot gnu.org
2021-05-26  7:34 ` marxin at gcc dot gnu.org
2021-05-26 15:13 ` gejoed at rediffmail dot com
2021-05-27 13:53 ` gejoed at rediffmail dot com
2021-05-27 13:57 ` marxin at gcc dot gnu.org
2021-05-27 13:58 ` marxin at gcc dot gnu.org
2021-05-28  5:49 ` gejoed at rediffmail dot com
2021-05-28  6:15 ` gejoed at rediffmail dot com
2021-05-28  6:18 ` gejoed at rediffmail dot com
2021-05-28  6:22 ` gejoed at rediffmail dot com
2021-05-28  7:30 ` marxin at gcc dot gnu.org
2021-05-28  9:57 ` gejoed at rediffmail dot com
2021-05-28 11:38 ` cvs-commit at gcc dot gnu.org
2021-05-28 11:41 ` marxin at gcc dot gnu.org [this message]
2021-06-01  5:25 ` gejoed at rediffmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-100751-4-znd4VttRUM@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).