This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gprof patches for IA-64


Here are some unreviewed gprof patches for IA-64 from David Mosberger.
I haven't tried any of these patches; I haven't had time to look at them yet.
I believe all of the gcc patches needed to make these work have already been
applied, but I haven't checked.  I am providing these patches in case someone
wants to volunteer to work on them.

There are three messages included here.

*************************************************************************
First message:

Here is a first gprof-related patch.  There will be more over the next
couple of days, but this is a start.

This patch fixes gprof so it will work correctly when running it on a
32-bit platform to analyze data that was collected on a 64-bit
platform.  I tested this on Linux/x86 with a Linux/ia64-produced data
file and it the results looked right.

	--david

2000-04-07  David Mosberger  <davidm@hpl.hp.com>

	* gmon_io.c (put_vma): Declare "static".
	(get_vma): Ditto.
	(gmon_io_write): New function.
	(gmon_io_write_8): Ditto.
	(gmon_io_write_16): Ditto.
	(gmon_io_write_32): Ditto.
	(gmon_io_write_vma): Ditto.
	(gmon_io_read): Ditto.
	(gmon_io_read_16): Ditto.
	(gmon_io_read_32): Ditto.
	(gmon_io_read_vma): Ditto.

	* basic_blocks.c (bb_read_rec): Use
	gmon_io_read*()/gmon_io_write*() to read/write data file in a more
	portable fashion.
	(bb_write_blocks): Ditto.
	* call_graph.c (cg_read_rec): Ditto.
	(cg_write_arcs): Ditto.
	* hist.c (hist_read_rec): Ditto.
	* hist.c (hist_write_hist): Ditto.

diff -urN cygnus-000323/src/gprof/basic_blocks.c cygnus-000323-lia/src/gprof/basic_blocks.c
--- cygnus-000323/src/gprof/basic_blocks.c	Wed Aug 12 12:06:24 1998
+++ cygnus-000323-lia/src/gprof/basic_blocks.c	Fri Apr  7 23:55:55 2000
@@ -3,6 +3,7 @@
  * to/from gmon.out; computing and formatting of basic-block related
  * statistics.
  */
+#include <inttypes.h>
 #include <stdio.h>
 #include <unistd.h>
 #include "basic_blocks.h"
@@ -124,18 +125,17 @@
 void
 DEFUN (bb_read_rec, (ifp, filename), FILE * ifp AND const char *filename)
 {
-  int nblocks, b;
-  bfd_vma addr;
-  unsigned long ncalls;
+  int32_t nblocks, b;
+  bfd_vma addr, ncalls;
   Sym *sym;
 
-  if (fread (&nblocks, sizeof (nblocks), 1, ifp) != 1)
+  if (gmon_io_read_32 (ifp, &nblocks))
     {
-      fprintf (stderr, _("%s: %s: unexpected end of file\n"), whoami, filename);
+      fprintf (stderr, _("%s: %s: unexpected end of file\n"),
+	       whoami, filename);
       done (1);
     }
 
-  nblocks = bfd_get_32 (core_bfd, (bfd_byte *) & nblocks);
   if (gmon_file_version == 0)
     {
       fskip_string (ifp);
@@ -160,14 +160,11 @@
 	      done (1);
 	    }
 	}
-      else
+      else if (gmon_io_read_vma (ifp, &addr) ||
+	       gmon_io_read_vma (ifp, &ncalls))
 	{
-	  if (fread (&addr, sizeof (addr), 1, ifp) != 1
-	      || fread (&ncalls, sizeof (ncalls), 1, ifp) != 1)
-	    {
-	      perror (filename);
-	      done (1);
-	    }
+	  perror (filename);
+	  done (1);
 	}
 
       /*
@@ -176,12 +173,6 @@
        */
       if (line_granularity)
 	{
-
-	  /* convert from target to host endianness: */
-
-	  addr = get_vma (core_bfd, (bfd_byte *) & addr);
-	  ncalls = bfd_get_32 (core_bfd, (bfd_byte *) &ncalls);
-
 	  sym = sym_lookup (&symtab, addr);
 
 	  if (sym)
@@ -229,9 +220,8 @@
 DEFUN (bb_write_blocks, (ofp, filename), FILE * ofp AND const char *filename)
 {
   const unsigned char tag = GMON_TAG_BB_COUNT;
-  int nblocks = 0;
-  bfd_vma addr;
-  unsigned long ncalls;
+  int32_t nblocks = 0;
+  bfd_vma addr, ncalls;
   Sym *sym;
   int i;
 
@@ -245,24 +235,16 @@
     }
 
   /* write header: */
-  bfd_put_32 (core_bfd, nblocks, (bfd_byte *) & nblocks);
-  if (fwrite (&tag, sizeof (tag), 1, ofp) != 1
-      || fwrite (&nblocks, sizeof (nblocks), 1, ofp) != 1)
-    {
-      perror (filename);
-      done (1);
-    }
+  gmon_io_write_8 (ofp, GMON_TAG_BB_COUNT);
+  gmon_io_write_32 (ofp, nblocks);
 
   /* write counts: */
   for (sym = symtab.base; sym < symtab.limit; ++sym)
     {
       for (i = 0; i < NBBS && sym->bb_addr[i]; i++)
 	{
-	  put_vma (core_bfd, sym->bb_addr[i], (bfd_byte *) & addr);
-	  bfd_put_32 (core_bfd, sym->bb_calls[i], (bfd_byte *) & ncalls);
-
-	  if (fwrite (&addr, sizeof (addr), 1, ofp) != 1
-	      || fwrite (&ncalls, sizeof (ncalls), 1, ofp) != 1)
+	  if (gmon_io_write_vma (ofp, addr) ||
+	      gmon_io_write_vma (ofp, sym->bb_calls[i]))
 	    {
 	      perror (filename);
 	      done (1);
diff -urN cygnus-000323/src/gprof/call_graph.c cygnus-000323-lia/src/gprof/call_graph.c
--- cygnus-000323/src/gprof/call_graph.c	Wed Aug 12 12:06:24 1998
+++ cygnus-000323-lia/src/gprof/call_graph.c	Fri Apr  7 23:45:02 2000
@@ -62,18 +62,16 @@
 DEFUN (cg_read_rec, (ifp, filename), FILE * ifp AND CONST char *filename)
 {
   bfd_vma from_pc, self_pc;
-  struct gmon_cg_arc_record arc;
   unsigned long count;
 
-  if (fread (&arc, sizeof (arc), 1, ifp) != 1)
+  if (gmon_io_read_vma (ifp, &from_pc) ||
+      gmon_io_read_vma (ifp, &self_pc) ||
+      gmon_io_read_32 (ifp, &count))
     {
       fprintf (stderr, _("%s: %s: unexpected end of file\n"),
 	       whoami, filename);
       done (1);
     }
-  from_pc = get_vma (core_bfd, (bfd_byte *) arc.from_pc);
-  self_pc = get_vma (core_bfd, (bfd_byte *) arc.self_pc);
-  count = bfd_get_32 (core_bfd, (bfd_byte *) arc.count);
   DBG (SAMPLEDEBUG,
        printf ("[cg_read_rec] frompc 0x%lx selfpc 0x%lx count %lu\n",
 	       from_pc, self_pc, count));
@@ -90,8 +88,6 @@
 void
 DEFUN (cg_write_arcs, (ofp, filename), FILE * ofp AND const char *filename)
 {
-  const unsigned char tag = GMON_TAG_CG_ARC;
-  struct gmon_cg_arc_record raw_arc;
   Arc *arc;
   Sym *sym;
 
@@ -99,11 +95,10 @@
     {
       for (arc = sym->cg.children; arc; arc = arc->next_child)
 	{
-	  put_vma (core_bfd, arc->parent->addr, (bfd_byte *) raw_arc.from_pc);
-	  put_vma (core_bfd, arc->child->addr, (bfd_byte *) raw_arc.self_pc);
-	  bfd_put_32 (core_bfd, arc->count, (bfd_byte *) raw_arc.count);
-	  if (fwrite (&tag, sizeof (tag), 1, ofp) != 1
-	      || fwrite (&raw_arc, sizeof (raw_arc), 1, ofp) != 1)
+	  if (gmon_io_write_8 (ofp, GMON_TAG_CG_ARC) ||
+	      gmon_io_write_vma (ofp, arc->parent->addr) ||
+	      gmon_io_write_vma (ofp, arc->child->addr) ||
+	      gmon_io_write_32 (ofp, arc->count))
 	    {
 	      perror (filename);
 	      done (1);
diff -urN cygnus-000323/src/gprof/gmon_io.c cygnus-000323-lia/src/gprof/gmon_io.c
--- cygnus-000323/src/gprof/gmon_io.c	Thu Sep 23 19:05:17 1999
+++ cygnus-000323-lia/src/gprof/gmon_io.c	Fri Apr  7 23:58:03 2000
@@ -1,6 +1,8 @@
 /*
  * Input and output from/to gmon.out files.
  */
+#include <inttypes.h>
+
 #include "cg_arcs.h"
 #include "basic_blocks.h"
 #include "bfd.h"
@@ -16,11 +18,137 @@
 
 int gmon_input = 0;
 int gmon_file_version = 0;	/* 0 == old (non-versioned) file format */
+int vma_size;
+
+int
+DEFUN (gmon_io_read_vma, (ifp, valp), FILE * ifp AND bfd_vma *valp)
+{
+  char buf[8];
+  bfd_vma val;
+
+  switch (vma_size)
+    {
+    case 32:
+      if (fread (buf, 1, 4, ifp) != 4)
+	return 1;
+      val = bfd_get_32 (core_bfd, buf);
+      break;
+
+    case 64:
+      if (fread (buf, 1, 8, ifp) != 8)
+	return 1;
+      val = bfd_get_64 (core_bfd, buf);
+      break;
+
+    default:
+      fprintf (stderr, _("%s: bfd_vma has unexpected size of %Zu bits\n"),
+	       whoami, 8*sizeof (char*));
+      done (1);
+    }
+  *valp = val;
+  return 0;
+}
+
+int
+DEFUN (gmon_io_read_32, (ifp, valp), FILE * ifp AND u_int32_t *valp)
+{
+  char buf[4];
+
+  if (fread (buf, 1, 4, ifp) != 4)
+    return 1;
+  *valp = bfd_get_32 (core_bfd, buf);
+  return 0;
+}
+
+int
+DEFUN (gmon_io_read_16, (ifp, valp), FILE * ifp AND u_int16_t *valp)
+{
+  char buf[2];
+
+  if (fread (buf, 1, 2, ifp) != 2)
+    return 1;
+  *valp = bfd_get_16 (core_bfd, buf);
+  return 0;
+}
 
-/*
- * This probably ought to be in libbfd.
- */
-bfd_vma
+int
+DEFUN (gmon_io_read, (ifp, valp), FILE * ifp AND char *buf AND size_t n)
+{
+  if (fread (buf, 1, n, ifp) != n)
+    return 1;
+  return 0;
+}
+
+int
+DEFUN (gmon_io_write_vma, (ofp, valp), FILE * ofp AND bfd_vma val)
+{
+  char buf[8];
+
+  switch (vma_size)
+    {
+    case 32:
+      bfd_put_32 (core_bfd, val, buf);
+      if (fwrite (buf, 1, 4, ofp) != 4)
+	return 1;
+      break;
+
+    case 64:
+      bfd_put_64 (core_bfd, val, buf);
+      if (fwrite (buf, 1, 8, ofp) != 8)
+	return 1;
+      break;
+
+    default:
+      fprintf (stderr, _("%s: bfd_vma has unexpected size of %Zu bits\n"),
+	       whoami, 8*sizeof (char*));
+      done (1);
+    }
+  return 0;
+}
+
+int
+DEFUN (gmon_io_write_32, (ofp, valp), FILE * ofp AND u_int32_t val)
+{
+  char buf[4];
+
+  bfd_put_32 (core_bfd, val, buf);
+  if (fwrite (buf, 1, 4, ofp) != 4)
+    return 1;
+  return 0;
+}
+
+int
+DEFUN (gmon_io_write_16, (ofp, valp), FILE * ofp AND u_int16_t val)
+{
+  char buf[2];
+
+  bfd_put_16 (core_bfd, val, buf);
+  if (fwrite (buf, 1, 2, ofp) != 2)
+    return 1;
+  return 0;
+}
+
+int
+DEFUN (gmon_io_write_8, (ofp, valp), FILE * ofp AND u_int8_t val)
+{
+  char buf[1];
+
+  bfd_put_8 (core_bfd, val, buf);
+  if (fwrite (buf, 1, 1, ofp) != 1)
+    return 1;
+  return 0;
+}
+
+int
+DEFUN (gmon_io_write, (ofp, valp), FILE * ofp AND char *buf AND size_t n)
+{
+  if (fwrite (buf, 1, n, ofp) != n)
+    return 1;
+  return 0;
+}
+
+/* get_vma and put_vma are for backwards compatibility only */
+static bfd_vma
 DEFUN (get_vma, (abfd, addr), bfd * abfd AND bfd_byte * addr)
 {
   switch (sizeof (char*))
@@ -37,11 +165,9 @@
 }
 
 
-/*
- * This probably ought to be in libbfd.
- */
-void
-DEFUN (put_vma, (abfd, val, addr), bfd * abfd AND bfd_vma val AND bfd_byte * addr)
+static void
+DEFUN (put_vma, (abfd, val, addr), bfd * abfd AND bfd_vma val AND
+       bfd_byte * addr)
 {
   switch (sizeof (char*))
     {
@@ -58,7 +184,6 @@
     }
 }
 
-
 void
 DEFUN (gmon_out_read, (filename), const char *filename)
 {
@@ -67,6 +192,8 @@
   unsigned char tag;
   int nhist = 0, narcs = 0, nbbs = 0;
 
+  vma_size = bfd_arch_bits_per_address (core_bfd);
+
   /* open gmon.out file: */
 
   if (strcmp (filename, "-") == 0)
@@ -342,6 +469,8 @@
 {
   FILE *ofp;
   struct gmon_hdr ghdr;
+
+  vma_size = bfd_arch_bits_per_address (core_bfd);
 
   ofp = fopen (filename, FOPEN_WB);
   if (!ofp)
diff -urN cygnus-000323/src/gprof/gmon_io.h cygnus-000323-lia/src/gprof/gmon_io.h
--- cygnus-000323/src/gprof/gmon_io.h	Tue Feb  7 18:35:10 1995
+++ cygnus-000323-lia/src/gprof/gmon_io.h	Wed Apr  5 22:19:15 2000
@@ -1,6 +1,8 @@
 #ifndef gmon_io_h
 #define gmon_io_h
 
+#include <inttypes.h>
+
 #include "bfd.h"
 #include "gmon.h"
 
@@ -11,8 +13,15 @@
 extern int gmon_input;		/* what input did we see? */
 extern int gmon_file_version;	/* file version are we dealing with */
 
-extern bfd_vma get_vma PARAMS ((bfd * abfd, bfd_byte * addr));
-extern void put_vma PARAMS ((bfd * abfd, bfd_vma val, bfd_byte * addr));
+extern int gmon_io_read_vma PARAMS ((FILE *ifp, bfd_vma *valp));
+extern int gmon_io_read_32 PARAMS ((FILE *ifp, u_int32_t *valp));
+extern int gmon_io_read_16 PARAMS ((FILE *ifp, u_int16_t *valp));
+extern int gmon_io_read PARAMS ((FILE *ifp, char *buf, size_t n));
+extern int gmon_io_write_vma PARAMS ((FILE *ifp, bfd_vma val));
+extern int gmon_io_write_32 PARAMS ((FILE *ifp, u_int32_t val));
+extern int gmon_io_write_16 PARAMS ((FILE *ifp, u_int16_t val));
+extern int gmon_io_write_8 PARAMS ((FILE *ifp, u_int8_t val));
+extern int gmon_io_write PARAMS ((FILE *ifp, char *buf, size_t n));
 
 extern void gmon_out_read PARAMS ((const char *filename));
 extern void gmon_out_write PARAMS ((const char *filename));
diff -urN cygnus-000323/src/gprof/hist.c cygnus-000323-lia/src/gprof/hist.c
--- cygnus-000323/src/gprof/hist.c	Wed Aug 12 12:06:24 1998
+++ cygnus-000323-lia/src/gprof/hist.c	Fri Apr  7 23:47:16 2000
@@ -95,26 +95,22 @@
 void
 DEFUN (hist_read_rec, (ifp, filename), FILE * ifp AND const char *filename)
 {
-  struct gmon_hist_hdr hdr;
   bfd_vma n_lowpc, n_highpc;
   int i, ncnt, profrate;
   UNIT count;
 
-  if (fread (&hdr, sizeof (hdr), 1, ifp) != 1)
+  if (gmon_io_read_vma (ifp, &n_lowpc) ||
+      gmon_io_read_vma (ifp, &n_highpc) ||
+      gmon_io_read_32 (ifp, &ncnt) ||
+      gmon_io_read_32 (ifp, &profrate) ||
+      gmon_io_read (ifp, hist_dimension, 15) ||
+      gmon_io_read (ifp, &hist_dimension_abbrev, 1))
     {
       fprintf (stderr, _("%s: %s: unexpected end of file\n"),
 	       whoami, filename);
       done (1);
     }
 
-  n_lowpc = (bfd_vma) get_vma (core_bfd, (bfd_byte *) hdr.low_pc);
-  n_highpc = (bfd_vma) get_vma (core_bfd, (bfd_byte *) hdr.high_pc);
-  ncnt = bfd_get_32 (core_bfd, (bfd_byte *) hdr.hist_size);
-  profrate = bfd_get_32 (core_bfd, (bfd_byte *) hdr.prof_rate);
-  strncpy (hist_dimension, hdr.dimen, sizeof (hdr.dimen));
-  hist_dimension[sizeof (hdr.dimen)] = '\0';
-  hist_dimension_abbrev = hdr.dimen_abbrev;
-
   if (!s_highpc)
     {
 
@@ -171,23 +167,19 @@
 void
 DEFUN (hist_write_hist, (ofp, filename), FILE * ofp AND const char *filename)
 {
-  struct gmon_hist_hdr hdr;
   unsigned char tag;
   UNIT count;
   int i;
 
   /* write header: */
 
-  tag = GMON_TAG_TIME_HIST;
-  put_vma (core_bfd, s_lowpc, (bfd_byte *) hdr.low_pc);
-  put_vma (core_bfd, s_highpc, (bfd_byte *) hdr.high_pc);
-  bfd_put_32 (core_bfd, hist_num_bins, (bfd_byte *) hdr.hist_size);
-  bfd_put_32 (core_bfd, hz, (bfd_byte *) hdr.prof_rate);
-  strncpy (hdr.dimen, hist_dimension, sizeof (hdr.dimen));
-  hdr.dimen_abbrev = hist_dimension_abbrev;
-
-  if (fwrite (&tag, sizeof (tag), 1, ofp) != 1
-      || fwrite (&hdr, sizeof (hdr), 1, ofp) != 1)
+  if (gmon_io_write_8 (ofp, GMON_TAG_TIME_HIST) ||
+      gmon_io_write_vma (ofp, s_lowpc) ||
+      gmon_io_write_vma (ofp, s_highpc) ||
+      gmon_io_write_32 (ofp, hist_num_bins) ||
+      gmon_io_write_32 (ofp, hz) ||
+      gmon_io_write (ofp, hist_dimension, 15) ||
+      gmon_io_write (ofp, &hist_dimension_abbrev, 1))
     {
       perror (filename);
       done (1);

*************************************************************************
Second message:

Here is a patch that makes gprof able to use a 32-bit host to analyze
files produces on a 64-bit system.

	--david

diff -urN orig/gprof/ChangeLog src/gprof/ChangeLog
--- orig/gprof/ChangeLog	Thu Sep 23 19:05:16 1999
+++ src/gprof/ChangeLog	Fri Apr  7 23:47:26 2000
@@ -1,3 +1,26 @@
+2000-04-07  David Mosberger  <davidm@hpl.hp.com>
+
+	* gmon_io.c (put_vma): Declare "static".
+	(get_vma): Ditto.
+	(gmon_io_write): New function.
+	(gmon_io_write_8): Ditto.
+	(gmon_io_write_16): Ditto.
+	(gmon_io_write_32): Ditto.
+	(gmon_io_write_vma): Ditto.
+	(gmon_io_read): Ditto.
+	(gmon_io_read_16): Ditto.
+	(gmon_io_read_32): Ditto.
+	(gmon_io_read_vma): Ditto.
+
+	* basic_blocks.c (bb_read_rec): Use
+	gmon_io_read*()/gmon_io_write*() to read/write data file in a more
+	portable fashion.
+	(bb_write_blocks): Ditto.
+	* call_graph.c (cg_read_rec): Ditto.
+	(cg_write_arcs): Ditto.
+	* hist.c (hist_read_rec): Ditto.
+	* hist.c (hist_write_hist): Ditto.
+
 1999-09-24  Nick Clifton  <nickc@cygnus.com>
 
 	* gmon_io.c (gmon_out_read): Make sure that sensible values
diff -urN orig/gprof/basic_blocks.c src/gprof/basic_blocks.c
--- orig/gprof/basic_blocks.c	Wed Aug 12 12:06:24 1998
+++ src/gprof/basic_blocks.c	Fri Apr  7 23:55:55 2000
@@ -3,6 +3,7 @@
  * to/from gmon.out; computing and formatting of basic-block related
  * statistics.
  */
+#include <inttypes.h>
 #include <stdio.h>
 #include <unistd.h>
 #include "basic_blocks.h"
@@ -124,18 +125,17 @@
 void
 DEFUN (bb_read_rec, (ifp, filename), FILE * ifp AND const char *filename)
 {
-  int nblocks, b;
-  bfd_vma addr;
-  unsigned long ncalls;
+  int32_t nblocks, b;
+  bfd_vma addr, ncalls;
   Sym *sym;
 
-  if (fread (&nblocks, sizeof (nblocks), 1, ifp) != 1)
+  if (gmon_io_read_32 (ifp, &nblocks))
     {
-      fprintf (stderr, _("%s: %s: unexpected end of file\n"), whoami, filename);
+      fprintf (stderr, _("%s: %s: unexpected end of file\n"),
+	       whoami, filename);
       done (1);
     }
 
-  nblocks = bfd_get_32 (core_bfd, (bfd_byte *) & nblocks);
   if (gmon_file_version == 0)
     {
       fskip_string (ifp);
@@ -160,14 +160,11 @@
 	      done (1);
 	    }
 	}
-      else
+      else if (gmon_io_read_vma (ifp, &addr) ||
+	       gmon_io_read_vma (ifp, &ncalls))
 	{
-	  if (fread (&addr, sizeof (addr), 1, ifp) != 1
-	      || fread (&ncalls, sizeof (ncalls), 1, ifp) != 1)
-	    {
-	      perror (filename);
-	      done (1);
-	    }
+	  perror (filename);
+	  done (1);
 	}
 
       /*
@@ -176,12 +173,6 @@
        */
       if (line_granularity)
 	{
-
-	  /* convert from target to host endianness: */
-
-	  addr = get_vma (core_bfd, (bfd_byte *) & addr);
-	  ncalls = bfd_get_32 (core_bfd, (bfd_byte *) &ncalls);
-
 	  sym = sym_lookup (&symtab, addr);
 
 	  if (sym)
@@ -229,9 +220,8 @@
 DEFUN (bb_write_blocks, (ofp, filename), FILE * ofp AND const char *filename)
 {
   const unsigned char tag = GMON_TAG_BB_COUNT;
-  int nblocks = 0;
-  bfd_vma addr;
-  unsigned long ncalls;
+  int32_t nblocks = 0;
+  bfd_vma addr, ncalls;
   Sym *sym;
   int i;
 
@@ -245,24 +235,16 @@
     }
 
   /* write header: */
-  bfd_put_32 (core_bfd, nblocks, (bfd_byte *) & nblocks);
-  if (fwrite (&tag, sizeof (tag), 1, ofp) != 1
-      || fwrite (&nblocks, sizeof (nblocks), 1, ofp) != 1)
-    {
-      perror (filename);
-      done (1);
-    }
+  gmon_io_write_8 (ofp, GMON_TAG_BB_COUNT);
+  gmon_io_write_32 (ofp, nblocks);
 
   /* write counts: */
   for (sym = symtab.base; sym < symtab.limit; ++sym)
     {
       for (i = 0; i < NBBS && sym->bb_addr[i]; i++)
 	{
-	  put_vma (core_bfd, sym->bb_addr[i], (bfd_byte *) & addr);
-	  bfd_put_32 (core_bfd, sym->bb_calls[i], (bfd_byte *) & ncalls);
-
-	  if (fwrite (&addr, sizeof (addr), 1, ofp) != 1
-	      || fwrite (&ncalls, sizeof (ncalls), 1, ofp) != 1)
+	  if (gmon_io_write_vma (ofp, addr) ||
+	      gmon_io_write_vma (ofp, sym->bb_calls[i]))
 	    {
 	      perror (filename);
 	      done (1);
diff -urN orig/gprof/call_graph.c src/gprof/call_graph.c
--- orig/gprof/call_graph.c	Wed Aug 12 12:06:24 1998
+++ src/gprof/call_graph.c	Fri Apr  7 23:45:02 2000
@@ -62,18 +62,16 @@
 DEFUN (cg_read_rec, (ifp, filename), FILE * ifp AND CONST char *filename)
 {
   bfd_vma from_pc, self_pc;
-  struct gmon_cg_arc_record arc;
   unsigned long count;
 
-  if (fread (&arc, sizeof (arc), 1, ifp) != 1)
+  if (gmon_io_read_vma (ifp, &from_pc) ||
+      gmon_io_read_vma (ifp, &self_pc) ||
+      gmon_io_read_32 (ifp, &count))
     {
       fprintf (stderr, _("%s: %s: unexpected end of file\n"),
 	       whoami, filename);
       done (1);
     }
-  from_pc = get_vma (core_bfd, (bfd_byte *) arc.from_pc);
-  self_pc = get_vma (core_bfd, (bfd_byte *) arc.self_pc);
-  count = bfd_get_32 (core_bfd, (bfd_byte *) arc.count);
   DBG (SAMPLEDEBUG,
        printf ("[cg_read_rec] frompc 0x%lx selfpc 0x%lx count %lu\n",
 	       from_pc, self_pc, count));
@@ -90,8 +88,6 @@
 void
 DEFUN (cg_write_arcs, (ofp, filename), FILE * ofp AND const char *filename)
 {
-  const unsigned char tag = GMON_TAG_CG_ARC;
-  struct gmon_cg_arc_record raw_arc;
   Arc *arc;
   Sym *sym;
 
@@ -99,11 +95,10 @@
     {
       for (arc = sym->cg.children; arc; arc = arc->next_child)
 	{
-	  put_vma (core_bfd, arc->parent->addr, (bfd_byte *) raw_arc.from_pc);
-	  put_vma (core_bfd, arc->child->addr, (bfd_byte *) raw_arc.self_pc);
-	  bfd_put_32 (core_bfd, arc->count, (bfd_byte *) raw_arc.count);
-	  if (fwrite (&tag, sizeof (tag), 1, ofp) != 1
-	      || fwrite (&raw_arc, sizeof (raw_arc), 1, ofp) != 1)
+	  if (gmon_io_write_8 (ofp, GMON_TAG_CG_ARC) ||
+	      gmon_io_write_vma (ofp, arc->parent->addr) ||
+	      gmon_io_write_vma (ofp, arc->child->addr) ||
+	      gmon_io_write_32 (ofp, arc->count))
 	    {
 	      perror (filename);
 	      done (1);
diff -urN orig/gprof/gmon_io.c src/gprof/gmon_io.c
--- orig/gprof/gmon_io.c	Thu Sep 23 19:05:17 1999
+++ src/gprof/gmon_io.c	Fri Apr  7 23:58:03 2000
@@ -1,6 +1,8 @@
 /*
  * Input and output from/to gmon.out files.
  */
+#include <inttypes.h>
+
 #include "cg_arcs.h"
 #include "basic_blocks.h"
 #include "bfd.h"
@@ -16,11 +18,137 @@
 
 int gmon_input = 0;
 int gmon_file_version = 0;	/* 0 == old (non-versioned) file format */
+int vma_size;
+
+int
+DEFUN (gmon_io_read_vma, (ifp, valp), FILE * ifp AND bfd_vma *valp)
+{
+  char buf[8];
+  bfd_vma val;
+
+  switch (vma_size)
+    {
+    case 32:
+      if (fread (buf, 1, 4, ifp) != 4)
+	return 1;
+      val = bfd_get_32 (core_bfd, buf);
+      break;
+
+    case 64:
+      if (fread (buf, 1, 8, ifp) != 8)
+	return 1;
+      val = bfd_get_64 (core_bfd, buf);
+      break;
+
+    default:
+      fprintf (stderr, _("%s: bfd_vma has unexpected size of %Zu bits\n"),
+	       whoami, 8*sizeof (char*));
+      done (1);
+    }
+  *valp = val;
+  return 0;
+}
+
+int
+DEFUN (gmon_io_read_32, (ifp, valp), FILE * ifp AND u_int32_t *valp)
+{
+  char buf[4];
+
+  if (fread (buf, 1, 4, ifp) != 4)
+    return 1;
+  *valp = bfd_get_32 (core_bfd, buf);
+  return 0;
+}
+
+int
+DEFUN (gmon_io_read_16, (ifp, valp), FILE * ifp AND u_int16_t *valp)
+{
+  char buf[2];
+
+  if (fread (buf, 1, 2, ifp) != 2)
+    return 1;
+  *valp = bfd_get_16 (core_bfd, buf);
+  return 0;
+}
 
-/*
- * This probably ought to be in libbfd.
- */
-bfd_vma
+int
+DEFUN (gmon_io_read, (ifp, valp), FILE * ifp AND char *buf AND size_t n)
+{
+  if (fread (buf, 1, n, ifp) != n)
+    return 1;
+  return 0;
+}
+
+int
+DEFUN (gmon_io_write_vma, (ofp, valp), FILE * ofp AND bfd_vma val)
+{
+  char buf[8];
+
+  switch (vma_size)
+    {
+    case 32:
+      bfd_put_32 (core_bfd, val, buf);
+      if (fwrite (buf, 1, 4, ofp) != 4)
+	return 1;
+      break;
+
+    case 64:
+      bfd_put_64 (core_bfd, val, buf);
+      if (fwrite (buf, 1, 8, ofp) != 8)
+	return 1;
+      break;
+
+    default:
+      fprintf (stderr, _("%s: bfd_vma has unexpected size of %Zu bits\n"),
+	       whoami, 8*sizeof (char*));
+      done (1);
+    }
+  return 0;
+}
+
+int
+DEFUN (gmon_io_write_32, (ofp, valp), FILE * ofp AND u_int32_t val)
+{
+  char buf[4];
+
+  bfd_put_32 (core_bfd, val, buf);
+  if (fwrite (buf, 1, 4, ofp) != 4)
+    return 1;
+  return 0;
+}
+
+int
+DEFUN (gmon_io_write_16, (ofp, valp), FILE * ofp AND u_int16_t val)
+{
+  char buf[2];
+
+  bfd_put_16 (core_bfd, val, buf);
+  if (fwrite (buf, 1, 2, ofp) != 2)
+    return 1;
+  return 0;
+}
+
+int
+DEFUN (gmon_io_write_8, (ofp, valp), FILE * ofp AND u_int8_t val)
+{
+  char buf[1];
+
+  bfd_put_8 (core_bfd, val, buf);
+  if (fwrite (buf, 1, 1, ofp) != 1)
+    return 1;
+  return 0;
+}
+
+int
+DEFUN (gmon_io_write, (ofp, valp), FILE * ofp AND char *buf AND size_t n)
+{
+  if (fwrite (buf, 1, n, ofp) != n)
+    return 1;
+  return 0;
+}
+
+/* get_vma and put_vma are for backwards compatibility only */
+static bfd_vma
 DEFUN (get_vma, (abfd, addr), bfd * abfd AND bfd_byte * addr)
 {
   switch (sizeof (char*))
@@ -37,11 +165,9 @@
 }
 
 
-/*
- * This probably ought to be in libbfd.
- */
-void
-DEFUN (put_vma, (abfd, val, addr), bfd * abfd AND bfd_vma val AND bfd_byte * addr)
+static void
+DEFUN (put_vma, (abfd, val, addr), bfd * abfd AND bfd_vma val AND
+       bfd_byte * addr)
 {
   switch (sizeof (char*))
     {
@@ -58,7 +184,6 @@
     }
 }
 
-
 void
 DEFUN (gmon_out_read, (filename), const char *filename)
 {
@@ -67,6 +192,8 @@
   unsigned char tag;
   int nhist = 0, narcs = 0, nbbs = 0;
 
+  vma_size = bfd_arch_bits_per_address (core_bfd);
+
   /* open gmon.out file: */
 
   if (strcmp (filename, "-") == 0)
@@ -342,6 +469,8 @@
 {
   FILE *ofp;
   struct gmon_hdr ghdr;
+
+  vma_size = bfd_arch_bits_per_address (core_bfd);
 
   ofp = fopen (filename, FOPEN_WB);
   if (!ofp)
diff -urN orig/gprof/gmon_io.h src/gprof/gmon_io.h
--- orig/gprof/gmon_io.h	Tue Feb  7 18:35:10 1995
+++ src/gprof/gmon_io.h	Wed Apr  5 22:19:15 2000
@@ -1,6 +1,8 @@
 #ifndef gmon_io_h
 #define gmon_io_h
 
+#include <inttypes.h>
+
 #include "bfd.h"
 #include "gmon.h"
 
@@ -11,8 +13,15 @@
 extern int gmon_input;		/* what input did we see? */
 extern int gmon_file_version;	/* file version are we dealing with */
 
-extern bfd_vma get_vma PARAMS ((bfd * abfd, bfd_byte * addr));
-extern void put_vma PARAMS ((bfd * abfd, bfd_vma val, bfd_byte * addr));
+extern int gmon_io_read_vma PARAMS ((FILE *ifp, bfd_vma *valp));
+extern int gmon_io_read_32 PARAMS ((FILE *ifp, u_int32_t *valp));
+extern int gmon_io_read_16 PARAMS ((FILE *ifp, u_int16_t *valp));
+extern int gmon_io_read PARAMS ((FILE *ifp, char *buf, size_t n));
+extern int gmon_io_write_vma PARAMS ((FILE *ifp, bfd_vma val));
+extern int gmon_io_write_32 PARAMS ((FILE *ifp, u_int32_t val));
+extern int gmon_io_write_16 PARAMS ((FILE *ifp, u_int16_t val));
+extern int gmon_io_write_8 PARAMS ((FILE *ifp, u_int8_t val));
+extern int gmon_io_write PARAMS ((FILE *ifp, char *buf, size_t n));
 
 extern void gmon_out_read PARAMS ((const char *filename));
 extern void gmon_out_write PARAMS ((const char *filename));
diff -urN orig/gprof/hist.c src/gprof/hist.c
--- orig/gprof/hist.c	Wed Aug 12 12:06:24 1998
+++ src/gprof/hist.c	Fri Apr  7 23:47:16 2000
@@ -95,26 +95,22 @@
 void
 DEFUN (hist_read_rec, (ifp, filename), FILE * ifp AND const char *filename)
 {
-  struct gmon_hist_hdr hdr;
   bfd_vma n_lowpc, n_highpc;
   int i, ncnt, profrate;
   UNIT count;
 
-  if (fread (&hdr, sizeof (hdr), 1, ifp) != 1)
+  if (gmon_io_read_vma (ifp, &n_lowpc) ||
+      gmon_io_read_vma (ifp, &n_highpc) ||
+      gmon_io_read_32 (ifp, &ncnt) ||
+      gmon_io_read_32 (ifp, &profrate) ||
+      gmon_io_read (ifp, hist_dimension, 15) ||
+      gmon_io_read (ifp, &hist_dimension_abbrev, 1))
     {
       fprintf (stderr, _("%s: %s: unexpected end of file\n"),
 	       whoami, filename);
       done (1);
     }
 
-  n_lowpc = (bfd_vma) get_vma (core_bfd, (bfd_byte *) hdr.low_pc);
-  n_highpc = (bfd_vma) get_vma (core_bfd, (bfd_byte *) hdr.high_pc);
-  ncnt = bfd_get_32 (core_bfd, (bfd_byte *) hdr.hist_size);
-  profrate = bfd_get_32 (core_bfd, (bfd_byte *) hdr.prof_rate);
-  strncpy (hist_dimension, hdr.dimen, sizeof (hdr.dimen));
-  hist_dimension[sizeof (hdr.dimen)] = '\0';
-  hist_dimension_abbrev = hdr.dimen_abbrev;
-
   if (!s_highpc)
     {
 
@@ -171,23 +167,19 @@
 void
 DEFUN (hist_write_hist, (ofp, filename), FILE * ofp AND const char *filename)
 {
-  struct gmon_hist_hdr hdr;
   unsigned char tag;
   UNIT count;
   int i;
 
   /* write header: */
 
-  tag = GMON_TAG_TIME_HIST;
-  put_vma (core_bfd, s_lowpc, (bfd_byte *) hdr.low_pc);
-  put_vma (core_bfd, s_highpc, (bfd_byte *) hdr.high_pc);
-  bfd_put_32 (core_bfd, hist_num_bins, (bfd_byte *) hdr.hist_size);
-  bfd_put_32 (core_bfd, hz, (bfd_byte *) hdr.prof_rate);
-  strncpy (hdr.dimen, hist_dimension, sizeof (hdr.dimen));
-  hdr.dimen_abbrev = hist_dimension_abbrev;
-
-  if (fwrite (&tag, sizeof (tag), 1, ofp) != 1
-      || fwrite (&hdr, sizeof (hdr), 1, ofp) != 1)
+  if (gmon_io_write_8 (ofp, GMON_TAG_TIME_HIST) ||
+      gmon_io_write_vma (ofp, s_lowpc) ||
+      gmon_io_write_vma (ofp, s_highpc) ||
+      gmon_io_write_32 (ofp, hist_num_bins) ||
+      gmon_io_write_32 (ofp, hz) ||
+      gmon_io_write (ofp, hist_dimension, 15) ||
+      gmon_io_write (ofp, &hist_dimension_abbrev, 1))
     {
       perror (filename);
       done (1);

*************************************************************************
Third message:

Here is a small fix for gprof.  It fixes a bug that caused garbage
bits in the top 32 bits of the call counts when running 64-bit
platforms.

	--david

2000-05-04  David Mosberger  <davidm@hpl.hp.com>

	* call_graph.c (cg_read_rec): Adjust type of "count" from
	"unsigned long" to "u_int32_t".

--- call_graph.c~	Fri Apr  7 23:45:02 2000
+++ call_graph.c	Thu May  4 13:42:14 2000
@@ -62,7 +62,7 @@
 DEFUN (cg_read_rec, (ifp, filename), FILE * ifp AND CONST char *filename)
 {
   bfd_vma from_pc, self_pc;
-  unsigned long count;
+  u_int32_t count;
 
   if (gmon_io_read_vma (ifp, &from_pc) ||
       gmon_io_read_vma (ifp, &self_pc) ||
@@ -74,7 +74,7 @@
     }
   DBG (SAMPLEDEBUG,
        printf ("[cg_read_rec] frompc 0x%lx selfpc 0x%lx count %lu\n",
-	       from_pc, self_pc, count));
+	       from_pc, self_pc, (unsigned long) count));
   /* add this arc: */
   cg_tally (from_pc, self_pc, count);
 }



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]