From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 53683383EC69; Fri, 10 Jun 2022 10:21:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 53683383EC69 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: Have gmondump support ssp-generated gmon.out X-Act-Checkin: newlib-cygwin X-Git-Author: Mark Geisert X-Git-Refname: refs/heads/master X-Git-Oldrev: 866f6c909faaaf6be39e5b4fab9d84c327fac0cb X-Git-Newrev: aa460cc0ca4a028c6544f88e4e187ef8ec3c6684 Message-Id: <20220610102111.53683383EC69@sourceware.org> Date: Fri, 10 Jun 2022 10:21:11 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Jun 2022 10:21:11 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Daa460cc0ca4= a028c6544f88e4e187ef8ec3c6684 commit aa460cc0ca4a028c6544f88e4e187ef8ec3c6684 Author: Mark Geisert Date: Wed Jun 8 21:47:31 2022 -0700 Cygwin: Have gmondump support ssp-generated gmon.out =20 Cygwin tool ssp generates gmon.out files with different address resolution than other tools do. Two address bytes per bucket rather than the usual four address bytes. Gprof can deal with the difference but gmondump can't because the latter's gmon.out header validation fails. =20 - Remove the offending portion of the header validation code. - Make sure all code can handle differing address resolutions. - Display address resolution in verbose data dumps. - Change "rawarc" to "struct rawarc" in certain sizeof expressions to avoid buffer overrun faults. - When "-v" (verbose) is specified, note when there is missing bucket data or rawarc data. Diff: --- winsup/utils/gmondump.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/winsup/utils/gmondump.c b/winsup/utils/gmondump.c index 2d29e826d..16b99594a 100644 --- a/winsup/utils/gmondump.c +++ b/winsup/utils/gmondump.c @@ -103,6 +103,7 @@ error (int geterrno, const char *fmt, ...) void gmondump1 (char *filename) { + int addrincr; ushort *bucket =3D NULL; int fd; struct gmonhdr hdr; @@ -134,16 +135,15 @@ gmondump1 (char *filename) if (hdr.lpc >=3D hdr.hpc) goto notgmon; numbuckets =3D (hdr.ncnt - sizeof (hdr)) / sizeof (short); - if (numbuckets !=3D (hdr.hpc - hdr.lpc) / 4) - goto notgmon; + addrincr =3D (hdr.hpc - hdr.lpc) / numbuckets; numrawarcs =3D 0; if (stat.st_size !=3D hdr.ncnt) { numrawarcs =3D stat.st_size - hdr.ncnt; - if (numrawarcs !=3D - (int) sizeof (rawarc) * (numrawarcs / (int) sizeof (rawarc))) + if (numrawarcs !=3D (int) sizeof (struct rawarc) * + (numrawarcs / (int) sizeof (struct rawarc))) goto notgmon; - numrawarcs /=3D (int) sizeof (rawarc); + numrawarcs /=3D (int) sizeof (struct rawarc); } =20 /* Looks good, so read and display the profiling info. */ @@ -162,7 +162,8 @@ gmondump1 (char *filename) =20 note ("file %s, gmon version 0x%x, sample rate %d\n", filename, hdr.version, hdr.profrate); - note (" address range %p..%p\n", hdr.lpc, hdr.hpc); + note (" address range %p..%p, address increment %d/bucket\n", + hdr.lpc, hdr.hpc, addrincr); note (" numbuckets %d, hitbuckets %d, hitcount %d, numrawarcs %d\n", numbuckets, hitbuckets, hitcount, numrawarcs); =20 @@ -171,27 +172,31 @@ gmondump1 (char *filename) { if (hitbuckets) note (" bucket data follows...\n"); + else + note (" no bucket data present\n"); char *addr =3D (char *) hdr.lpc; - int incr =3D (hdr.hpc - hdr.lpc) / numbuckets; - for (res =3D 0; res < numbuckets; ++bucket, ++res, addr +=3D incr) + for (res =3D 0; res < numbuckets; ++bucket, ++res, addr +=3D addrinc= r) if (*bucket) note (" address %p, hitcount %d\n", addr, *bucket); bucket -=3D numbuckets; =20 if (numrawarcs) { - rawarc =3D (struct rawarc *) calloc (numrawarcs, sizeof (rawarc)= ); - res =3D read (fd, rawarc, numrawarcs * (int) sizeof (rawarc)); - if (res !=3D numrawarcs * (int) sizeof (rawarc)) + rawarc =3D (struct rawarc *) calloc (numrawarcs, + sizeof (struct rawarc)); + res =3D read (fd, rawarc, numrawarcs * (int) sizeof (struct rawa= rc)); + if (res !=3D numrawarcs * (int) sizeof (struct rawarc)) error (0, "unable to read rawarc data"); note (" rawarc data follows...\n"); for (res =3D 0; res < numrawarcs; ++rawarc, ++res) note (" from %p, self %p, count %d\n", rawarc->raw_frompc, rawarc->raw_selfpc, rawarc->raw_coun= t); + rawarc -=3D numrawarcs; } + else + note (" no rawarc data present\n"); } =20 - note ("\n"); if (0) { notgmon: @@ -261,7 +266,11 @@ main(int argc, char **argv) usage1 (ofile); =20 for (int i =3D optind; i < argc; i++) - gmondump1 (argv[i]); + { + gmondump1 (argv[i]); + if ((i + 1) < argc) + note ("\n"); + } =20 return 0; }