X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gprof%2Fgmon_io.c;h=c827ae67d05b85afbbf69156d395136c15ccc6de;hb=fb324ee93a26dcf0560a911074c97dcfb9b3eeb4;hp=463993229794451609f4ca79fefa3c141883466d;hpb=651dbc76f217e10b4b03933f86fe9e5b39d382be;p=deliverable%2Fbinutils-gdb.git diff --git a/gprof/gmon_io.c b/gprof/gmon_io.c index 4639932297..c827ae67d0 100644 --- a/gprof/gmon_io.c +++ b/gprof/gmon_io.c @@ -1,7 +1,6 @@ /* gmon_io.c - Input and output from/to gmon.out files. - Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 - Free Software Foundation, Inc. + Copyright (C) 1999-2016 Free Software Foundation, Inc. This file is part of GNU Binutils. @@ -21,6 +20,7 @@ 02110-1301, USA. */ #include "gprof.h" +#include "binary-io.h" #include "search_list.h" #include "source.h" #include "symtab.h" @@ -61,7 +61,7 @@ int gmon_input = 0; int gmon_file_version = 0; /* 0 == old (non-versioned) file format. */ static enum gmon_ptr_size -gmon_get_ptr_size () +gmon_get_ptr_size (void) { int size; @@ -87,7 +87,7 @@ gmon_get_ptr_size () } static enum gmon_ptr_signedness -gmon_get_ptr_signedness () +gmon_get_ptr_signedness (void) { int sext; @@ -300,9 +300,7 @@ gmon_out_read (const char *filename) if (strcmp (filename, "-") == 0) { ifp = stdin; -#ifdef SET_BINARY SET_BINARY (fileno (stdin)); -#endif } else { @@ -493,12 +491,15 @@ gmon_out_read (const char *filename) if (!histograms) { - histograms = xmalloc (sizeof (struct histogram)); + num_histograms = 1; + histograms = (struct histogram *) xmalloc (sizeof (struct histogram)); histograms->lowpc = tmp.low_pc; histograms->highpc = tmp.high_pc; histograms->num_bins = hist_num_bins; - histograms->sample = xmalloc (hist_num_bins * sizeof (int)); - memset (histograms->sample, 0, + hist_scale = (double)((tmp.high_pc - tmp.low_pc) / sizeof (UNIT)) + / hist_num_bins; + histograms->sample = (int *) xmalloc (hist_num_bins * sizeof (int)); + memset (histograms->sample, 0, hist_num_bins * sizeof (int)); } @@ -531,7 +532,7 @@ gmon_out_read (const char *filename) done (1); } - histograms->sample[i] + histograms->sample[i] += bfd_get_16 (core_bfd, (bfd_byte *) raw_bin_count); } @@ -549,8 +550,6 @@ gmon_out_read (const char *filename) cg_tally (from_pc, self_pc, count); } - fclose (ifp); - if (hz == HZ_WRONG) { /* How many ticks per second? If we can't tell, report @@ -571,6 +570,9 @@ gmon_out_read (const char *filename) done (1); } + if (ifp != stdin) + fclose (ifp); + if (output_style & STYLE_GMON_INFO) { printf (_("File `%s' (version %d) contains:\n"), @@ -669,7 +671,7 @@ gmon_out_write (const char *filename) case ptr_64bit: hdrsize = GMON_HDRSIZE_OLDBSD_64; /* FIXME: Checking host compiler defines here means that we can't - use a cross gprof alpha OSF. */ + use a cross gprof alpha OSF. */ #if defined(__alpha__) && defined (__osf__) padsize = 4; #endif @@ -681,7 +683,7 @@ gmon_out_write (const char *filename) old BSD and 4.4BSD formats. */ if (gmon_io_write_vma (ofp, histograms->lowpc) || gmon_io_write_vma (ofp, histograms->highpc) - || gmon_io_write_32 (ofp, histograms->num_bins + || gmon_io_write_32 (ofp, histograms->num_bins * sizeof (UNIT) + hdrsize)) { perror (filename);