summaryrefslogtreecommitdiff
path: root/gprof/gmon_io.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2001-03-14 03:14:56 +0000
committerAlan Modra <amodra@gmail.com>2001-03-14 03:14:56 +0000
commit0eee5820aa0f68b2283b40f5a3fb09aefcfb1575 (patch)
tree849fb8ae327bfed38a9afe6c45bed35e4a96703a /gprof/gmon_io.c
parent04847a4d3e1cf5c5c811f8fbbdeeca498de51dc4 (diff)
David Mosberger's fixes for cross compiling gprof.
Diffstat (limited to 'gprof/gmon_io.c')
-rw-r--r--gprof/gmon_io.c174
1 files changed, 137 insertions, 37 deletions
diff --git a/gprof/gmon_io.c b/gprof/gmon_io.c
index f0f238ff1b..d7618894ce 100644
--- a/gprof/gmon_io.c
+++ b/gprof/gmon_io.c
@@ -1,6 +1,6 @@
/* gmon_io.c - Input and output from/to gmon.out files.
- Copyright 2000 Free Software Foundation, Inc.
+ Copyright 2000, 2001 Free Software Foundation, Inc.
This file is part of GNU Binutils.
@@ -35,9 +35,113 @@
int gmon_input = 0;
int gmon_file_version = 0; /* 0 == old (non-versioned) file format. */
-/* This probably ought to be in libbfd. */
+int
+DEFUN (gmon_io_read_vma, (ifp, valp), FILE * ifp AND bfd_vma *valp)
+{
+ char buf[8];
+ bfd_vma val;
+
+ switch (GMON_PTR_SIZE)
+ {
+ case 4:
+ if (fread (buf, 1, 4, ifp) != 4)
+ return 1;
+ val = bfd_get_32 (core_bfd, buf);
+ break;
+
+ case 8:
+ if (fread (buf, 1, 8, ifp) != 8)
+ return 1;
+ val = bfd_get_64 (core_bfd, buf);
+ break;
+
+ default:
+ fprintf (stderr, _("%s: GMON_PTR_SIZE has unexpected value of %u\n"),
+ whoami, GMON_PTR_SIZE);
+ done (1);
+ }
+ *valp = val;
+ return 0;
+}
-bfd_vma
+int
+DEFUN (gmon_io_read_32, (ifp, valp), FILE * ifp AND unsigned int *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, (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 (GMON_PTR_SIZE)
+ {
+ case 4:
+ bfd_put_32 (core_bfd, val, buf);
+ if (fwrite (buf, 1, 4, ofp) != 4)
+ return 1;
+ break;
+
+ case 8:
+ bfd_put_64 (core_bfd, val, buf);
+ if (fwrite (buf, 1, 8, ofp) != 8)
+ return 1;
+ break;
+
+ default:
+ fprintf (stderr, _("%s: GMON_PTR_SIZE has unexpected value of %u\n"),
+ whoami, GMON_PTR_SIZE);
+ done (1);
+ }
+ return 0;
+}
+
+int
+DEFUN (gmon_io_write_32, (ofp, valp), FILE * ofp AND unsigned int 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_8, (ofp, valp), FILE * ofp AND unsigned char 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*))
@@ -53,10 +157,7 @@ DEFUN (get_vma, (abfd, addr), bfd * abfd AND bfd_byte * addr)
}
}
-
-/* This probably ought to be in libbfd. */
-
-void
+static void
DEFUN (put_vma, (abfd, val, addr), bfd * abfd AND bfd_vma val AND bfd_byte * addr)
{
switch (sizeof (char*))
@@ -74,7 +175,6 @@ DEFUN (put_vma, (abfd, val, addr), bfd * abfd AND bfd_vma val AND bfd_byte * add
}
}
-
void
DEFUN (gmon_out_read, (filename), const char *filename)
{
@@ -94,14 +194,14 @@ DEFUN (gmon_out_read, (filename), const char *filename)
else
{
ifp = fopen (filename, FOPEN_RB);
-
+
if (!ifp)
{
perror (filename);
done (1);
}
}
-
+
if (fread (&ghdr, sizeof (struct gmon_hdr), 1, ifp) != 1)
{
fprintf (stderr, _("%s: file too short to be a gmon file\n"),
@@ -109,8 +209,8 @@ DEFUN (gmon_out_read, (filename), const char *filename)
done (1);
}
- if ((file_format == FF_MAGIC) ||
- (file_format == FF_AUTO && !strncmp (&ghdr.cookie[0], GMON_MAGIC, 4)))
+ if ((file_format == FF_MAGIC)
+ || (file_format == FF_AUTO && !strncmp (&ghdr.cookie[0], GMON_MAGIC, 4)))
{
if (file_format == FF_MAGIC && strncmp (&ghdr.cookie[0], GMON_MAGIC, 4))
{
@@ -121,7 +221,7 @@ DEFUN (gmon_out_read, (filename), const char *filename)
/* Right magic, so it's probably really a new gmon.out file. */
gmon_file_version = bfd_get_32 (core_bfd, (bfd_byte *) ghdr.version);
-
+
if (gmon_file_version != GMON_VERSION && gmon_file_version != 0)
{
fprintf (stderr,
@@ -181,18 +281,18 @@ DEFUN (gmon_out_read, (filename), const char *filename)
struct hdr tmp;
/* Information from a gmon.out file is in two parts: an array of
- sampling hits within pc ranges, and the arcs. */
+ sampling hits within pc ranges, and the arcs. */
gmon_input = INPUT_HISTOGRAM | INPUT_CALL_GRAPH;
/* This fseek() ought to work even on stdin as long as it's
- not an interactive device (heck, is there anybody who would
- want to type in a gmon.out at the terminal?). */
+ not an interactive device (heck, is there anybody who would
+ want to type in a gmon.out at the terminal?). */
if (fseek (ifp, 0, SEEK_SET) < 0)
{
perror (filename);
done (1);
}
-
+
if (fread (&raw, 1, sizeof (struct raw_phdr), ifp)
!= sizeof (struct raw_phdr))
{
@@ -200,7 +300,7 @@ DEFUN (gmon_out_read, (filename), const char *filename)
filename);
done (1);
}
-
+
tmp.low_pc = get_vma (core_bfd, (bfd_byte *) &raw.low_pc[0]);
tmp.high_pc = get_vma (core_bfd, (bfd_byte *) &raw.high_pc[0]);
tmp.ncnt = bfd_get_32 (core_bfd, (bfd_byte *) &raw.ncnt[0]);
@@ -212,7 +312,7 @@ DEFUN (gmon_out_read, (filename), const char *filename)
/* 4.4BSD format header. */
profrate = bfd_get_32 (core_bfd, (bfd_byte *) &raw.profrate[0]);
-
+
if (!s_highpc)
hz = profrate;
else if (hz != profrate)
@@ -244,14 +344,14 @@ DEFUN (gmon_out_read, (filename), const char *filename)
header_size = sizeof (struct old_raw_phdr);
}
- if (s_highpc && (tmp.low_pc != h.low_pc ||
- tmp.high_pc != h.high_pc || tmp.ncnt != h.ncnt))
+ if (s_highpc && (tmp.low_pc != h.low_pc
+ || tmp.high_pc != h.high_pc || tmp.ncnt != h.ncnt))
{
fprintf (stderr, _("%s: incompatible with first gmon file\n"),
filename);
done (1);
}
-
+
h = tmp;
s_lowpc = (bfd_vma) h.low_pc;
s_highpc = (bfd_vma) h.high_pc;
@@ -259,7 +359,7 @@ DEFUN (gmon_out_read, (filename), const char *filename)
highpc = (bfd_vma) h.high_pc / sizeof (UNIT);
samp_bytes = h.ncnt - header_size;
hist_num_bins = samp_bytes / sizeof (UNIT);
-
+
DBG (SAMPLEDEBUG,
printf ("[gmon_out_read] lowpc 0x%lx highpc 0x%lx ncnt %d\n",
(unsigned long) h.low_pc, (unsigned long) h.high_pc,
@@ -273,12 +373,12 @@ DEFUN (gmon_out_read, (filename), const char *filename)
/* Make sure that we have sensible values. */
if (samp_bytes < 0 || lowpc > highpc)
- {
- fprintf (stderr,
+ {
+ fprintf (stderr,
_("%s: file '%s' does not appear to be in gmon.out format\n"),
whoami, filename);
- done (1);
- }
+ done (1);
+ }
if (hist_num_bins)
++nhist;
@@ -287,7 +387,7 @@ DEFUN (gmon_out_read, (filename), const char *filename)
{
hist_sample =
(int *) xmalloc (hist_num_bins * sizeof (hist_sample[0]));
-
+
memset (hist_sample, 0, hist_num_bins * sizeof (hist_sample[0]));
}
@@ -300,7 +400,7 @@ DEFUN (gmon_out_read, (filename), const char *filename)
whoami, --i, hist_num_bins);
done (1);
}
-
+
hist_sample[i] += bfd_get_16 (core_bfd, (bfd_byte *) raw_bin_count);
}
@@ -312,15 +412,15 @@ DEFUN (gmon_out_read, (filename), const char *filename)
from_pc = get_vma (core_bfd, (bfd_byte *) raw_arc.from_pc);
self_pc = get_vma (core_bfd, (bfd_byte *) raw_arc.self_pc);
count = bfd_get_32 (core_bfd, (bfd_byte *) raw_arc.count);
-
+
DBG (SAMPLEDEBUG,
printf ("[gmon_out_read] frompc 0x%lx selfpc 0x%lx count %lu\n",
(unsigned long) from_pc, (unsigned long) self_pc, count));
-
+
/* Add this arc. */
cg_tally (from_pc, self_pc, count);
}
-
+
fclose (ifp);
if (hz == HZ_WRONG)
@@ -328,7 +428,7 @@ DEFUN (gmon_out_read, (filename), const char *filename)
/* How many ticks per second? If we can't tell, report
time in ticks. */
hz = hertz ();
-
+
if (hz == HZ_WRONG)
{
hz = 1;
@@ -377,7 +477,7 @@ DEFUN (gmon_out_write, (filename), const char *filename)
memcpy (&ghdr.cookie[0], GMON_MAGIC, 4);
bfd_put_32 (core_bfd, GMON_VERSION, (bfd_byte *) ghdr.version);
-
+
if (fwrite (&ghdr, sizeof (ghdr), 1, ofp) != 1)
{
perror (filename);
@@ -413,8 +513,8 @@ DEFUN (gmon_out_write, (filename), const char *filename)
(bfd_byte *) &h.ncnt);
/* Write header. Use new style BSD format is explicitly
- specified, or if the profiling rate is non-standard;
- otherwise, use the old BSD format. */
+ specified, or if the profiling rate is non-standard;
+ otherwise, use the old BSD format. */
if (file_format == FF_BSD44
|| hz != hertz ())
{
@@ -467,7 +567,7 @@ DEFUN (gmon_out_write, (filename), const char *filename)
(unsigned long) arc->child->addr, arc->count));
}
}
-
+
fclose (ofp);
}
else