From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A894D3987C13; Fri, 28 May 2021 11:41:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A894D3987C13 From: "marxin at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: gcov-profile X-Bugzilla-Version: 8.3.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: marxin at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: WORKSFORME X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: marxin at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 May 2021 11:41:28 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100751 --- Comment #23 from Martin Li=C5=A1ka --- > So, for either a one time call of __gcov_dump (though we may attempt to c= all > __gcov_dump many times) or at the exit of the program execution, the mer= ge > 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 call= ed, 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 #include #include extern void __gcov_reset(void); extern void __gcov_flush(void); extern void __gcov_dump( void); int main() { unsigned char c; int count=3D0; c =3D 'g'; do { printf ("c: '%c'\n", c); if(c =3D=3D 'g'){ __gcov_dump(); printf("__gcov_dump() invoked!\n"); c =3D 'r'; } else if(c =3D=3D 'r'){ __gcov_reset(); printf("__gcov_reset() invoked!\n"); c =3D 'f'; } if(count =3D=3D 2) c =3D 'g'; else if (count > 10) c =3D 'e'; count++; }while(c !=3D '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 -: 2:#include -: 3:#include -: 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=3D0; 1: 13: c =3D 'g'; -: 14: -: 15: do { 10: 16: printf ("c: '%c'\n", c); -: 17:=20=20=20 10: 18: if(c =3D=3D 'g'){ 2: 19: __gcov_dump(); #####: 20: printf("__gcov_dump() invoked!\n"); #####: 21: c =3D 'r'; -: 22: } 8: 23: else if(c =3D=3D 'r'){ #####: 24: __gcov_reset(); 2: 25: printf("__gcov_reset() invoked!\n"); 2: 26: c =3D 'f'; -: 27: } 10: 28: if(count =3D=3D 2) 1: 29: c =3D 'g'; 9: 30: else if (count > 10) 1: 31: c =3D 'e'; 10: 32: count++; 10: 33: }while(c !=3D 'e'); -: 34:=20=20=20=20 1: 35: return 0; -: 36:} Which should be correct in my oppinion.=