From: Steve Chamberlain Date: Wed, 16 Jun 1993 19:58:37 +0000 (+0000) Subject: * gmon.h, gprof.h: structs of chars used to hold external X-Git-Tag: gdb-4_18~18789 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=73fbbeead4ad2f978769a43cd9582ef1104f6732;p=external%2Fbinutils.git * gmon.h, gprof.h: structs of chars used to hold external representations. * gprof.c (getpfile, openpfile, readsamples): Swap data in using new structures. --- diff --git a/gprof/ChangeLog b/gprof/ChangeLog index 5419bfc..2ca8f74 100644 --- a/gprof/ChangeLog +++ b/gprof/ChangeLog @@ -1,3 +1,10 @@ +Wed Jun 16 12:54:53 1993 Steve Chamberlain (sac@phydeaux.cygnus.com) + + * gmon.h, gprof.h: structs of chars used to hold external + representations. + * gprof.c (getpfile, openpfile, readsamples): Swap data in using + new structures. + Tue Jun 15 23:09:17 1993 Ken Raeburn (raeburn@cambridge.cygnus.com) * Makefile.in (.c.o): Look in ../include, not ../bfd, for bfd.h. diff --git a/gprof/gmon.h b/gprof/gmon.h index c89a721..2c88a63 100644 --- a/gprof/gmon.h +++ b/gprof/gmon.h @@ -98,6 +98,12 @@ struct rawarc { long raw_count; }; +struct veryrawarc { + char raw_frompc[4]; + char raw_selfpc[4]; + char raw_count[4]; +}; + /* * general rounding functions. */ diff --git a/gprof/gprof.c b/gprof/gprof.c index ca63f16..5264eea 100644 --- a/gprof/gprof.c +++ b/gprof/gprof.c @@ -339,6 +339,7 @@ getpfile(filename) FILE *pfile; FILE *openpfile(); struct rawarc arc; + struct veryrawarc rawarc; pfile = openpfile(filename); readsamples(pfile); @@ -346,10 +347,10 @@ getpfile(filename) * the rest of the file consists of * a bunch of tuples. */ - while ( fread( &arc , sizeof arc , 1 , pfile ) == 1 ) { - arc.raw_frompc = bfd_get_32 (abfd, (bfd_byte *) &arc.raw_frompc); - arc.raw_selfpc = bfd_get_32 (abfd, (bfd_byte *) &arc.raw_selfpc); - arc.raw_count = bfd_get_32 (abfd, (bfd_byte *) &arc.raw_count); + while ( fread( &rawarc , sizeof rawarc , 1 , pfile ) == 1 ) { + arc.raw_frompc = bfd_get_32 (abfd, (bfd_byte *) rawarc.raw_frompc); + arc.raw_selfpc = bfd_get_32 (abfd, (bfd_byte *) rawarc.raw_selfpc); + arc.raw_count = bfd_get_32 (abfd, (bfd_byte *) rawarc.raw_count); # ifdef DEBUG if ( debug & SAMPLEDEBUG ) { printf( "[getpfile] frompc 0x%x selfpc 0x%x count %d\n" , @@ -369,16 +370,21 @@ openpfile(filename) char *filename; { struct hdr tmp; + struct rawhdr raw; FILE *pfile; if((pfile = fopen(filename, "r")) == NULL) { perror(filename); done(); } - fread(&tmp, sizeof(struct hdr), 1, pfile); - tmp.lowpc = (UNIT *)bfd_get_32 (abfd, (bfd_byte *) &tmp.lowpc); - tmp.highpc = (UNIT *)bfd_get_32 (abfd, (bfd_byte *) &tmp.highpc); - tmp.ncnt = bfd_get_32 (abfd, (bfd_byte *) &tmp.ncnt); + if (sizeof(struct rawhdr) != fread(&raw, 1, sizeof(struct rawhdr), pfile)) + { + fprintf(stderr, "%s: file too short to be a gmon file\n", filename); + done(); + } + tmp.lowpc = (UNIT *)bfd_get_32 (abfd, (bfd_byte *) &raw.lowpc[0]); + tmp.highpc = (UNIT *)bfd_get_32 (abfd, (bfd_byte *) &raw.highpc[0]); + tmp.ncnt = bfd_get_32 (abfd, (bfd_byte *) &raw.ncnt[0]); if ( s_highpc != 0 && ( tmp.lowpc != h.lowpc || tmp.highpc != h.highpc || tmp.ncnt != h.ncnt ) ) { @@ -390,7 +396,7 @@ openpfile(filename) s_highpc = (unsigned long) h.highpc; lowpc = (unsigned long)h.lowpc / sizeof(UNIT); highpc = (unsigned long)h.highpc / sizeof(UNIT); - sampbytes = h.ncnt - sizeof(struct hdr); + sampbytes = h.ncnt - sizeof(struct rawhdr); nsamples = sampbytes / sizeof (UNIT); # ifdef DEBUG if ( debug & SAMPLEDEBUG ) { @@ -497,31 +503,33 @@ valcmp(p1, p2) readsamples(pfile) FILE *pfile; { - register i; - UNIT sample; + register i; + + if (samples == 0) { + samples = (int *) calloc (nsamples, sizeof(int)); if (samples == 0) { - samples = (UNIT *) malloc (sampbytes * sizeof(UNIT)); - if (samples == 0) { - fprintf( stderr , "%s: No room for %d sample pc's\n", - whoami , sampbytes / sizeof (UNIT)); - done(); - } - memset (samples, 0, sampbytes * sizeof(UNIT)); - } - for (i = 0; i < nsamples; i++) { - fread(&sample, sizeof (UNIT), 1, pfile); - sample = bfd_get_16 (abfd, (bfd_byte *) &sample); - if (feof(pfile)) - break; - samples[i] += sample; + fprintf( stderr , "%s: No room for %d sample pc's\n", + whoami , nsamples); + done(); } - if (i != nsamples) { - fprintf(stderr, + } + for (i = 0; i < nsamples; i++) { + UNIT raw; + int value; + + fread(raw, sizeof (raw), 1, pfile); + value = bfd_get_16 (abfd, (bfd_byte *) raw); + if (feof(pfile)) + break; + samples[i] += value; + } + if (i != nsamples) { + fprintf(stderr, "%s: unexpected EOF after reading %d/%d samples\n", - whoami , --i , nsamples ); - done(); - } + whoami , --i , nsamples ); + done(); + } } /* @@ -559,7 +567,7 @@ readsamples(pfile) asgnsamples() { register int j; - UNIT ccnt; + int ccnt; double time; unsigned long pcl, pch; register int i; diff --git a/gprof/gprof.h b/gprof/gprof.h index 8431a9d..c1b91ad 100644 --- a/gprof/gprof.h +++ b/gprof/gprof.h @@ -59,7 +59,7 @@ typedef int bool; */ long hz; -typedef unsigned short UNIT; /* unit of profiling */ +typedef unsigned char UNIT[2]; /* unit of profiling */ char *a_outname; #define A_OUTNAME "a.out" @@ -147,6 +147,13 @@ struct hdr { int ncnt; }; + +struct rawhdr { + char lowpc[4]; + char highpc[4]; + char ncnt[4]; +}; + struct hdr h; int debug; @@ -155,7 +162,7 @@ int debug; * Each discretized pc sample has * a count of the number of samples in its range */ -UNIT *samples; +int *samples; unsigned long s_lowpc; /* lowpc from the profile file */ unsigned long s_highpc; /* highpc from the profile file */