* gmon.h, gprof.h: structs of chars used to hold external
authorSteve Chamberlain <sac@cygnus>
Wed, 16 Jun 1993 19:58:37 +0000 (19:58 +0000)
committerSteve Chamberlain <sac@cygnus>
Wed, 16 Jun 1993 19:58:37 +0000 (19:58 +0000)
representations.
* gprof.c (getpfile, openpfile, readsamples): Swap data in using
new structures.

gprof/ChangeLog
gprof/gmon.h
gprof/gprof.c
gprof/gprof.h

index 5419bfcf919f038b7e2d8ed13673f9e9b221791f..2ca8f74f214221469699af15dcfa69bf139af0e7 100644 (file)
@@ -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.
index c89a721972bd86f96db187c2f553b31bf666f438..2c88a6300d2e10425ebee59880036fd2d7f9c365 100644 (file)
@@ -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.
      */
index ca63f1686851a9554bddcbdc58a3c94cffdcc659..5264eea2ca9c53fc62b7c7eee60e4411c5550230 100644 (file)
@@ -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 <from,self,count> 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;
index 8431a9d921ad4f79f2686c4db7a5c04efb3ba00e..c1b91ad355ccfbc7e08d7b483058c66794615354 100644 (file)
@@ -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 */
This page took 0.029443 seconds and 4 git commands to generate.