This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

[PATCH] fix BSD-style old format gmon.out reading


The codepath in gprof for reading the old BSD style gmon.out file format
seems to have bitrotted, specifically the histogram data handling.  This
codepath does not go through hist.c:read_histogram_header() or
hist.c:hist_read_rec() but instead happens all in
gmon_io.c:gmon_out_read().  At issue are two global variables
num_histograms and hist_scale which don't get set.  This causes the
later logic to think that there is no histogram data even though it has
been successfully read.  The attached patch fixes the issue.

This came up because a Cygwin user reported that gprof didn't function
at all for them.  Debugging revealed bugs in both the Cygwin side as
well as the gprof side.  Ideally it might be nice to update Cygwin to
write the more modern GNU format gmon.out format, but since the
profiling code there is lifted from the BSDs it currently writes the old
format.

Brian
2008-08-04  Brian Dessent  <brian@dessent.net>

	* gmon_io.c (gmon_out_read): When reading old format gmon.out,
	set num_histograms and hist_scale.

Index: gmon_io.c
===================================================================
RCS file: /cvs/src/src/gprof/gmon_io.c,v
retrieving revision 1.24
diff -u -p -r1.24 gmon_io.c
--- gmon_io.c	6 Jul 2007 10:40:34 -0000	1.24
+++ gmon_io.c	5 Aug 2008 04:48:00 -0000
@@ -493,10 +493,13 @@ gmon_out_read (const char *filename)
 
       if (!histograms)
 	{
+	  num_histograms = 1;
 	  histograms = xmalloc (sizeof (struct histogram));
 	  histograms->lowpc = tmp.low_pc;
 	  histograms->highpc = tmp.high_pc;
 	  histograms->num_bins = hist_num_bins;
+	  hist_scale = (double)((tmp.high_pc - tmp.low_pc) / sizeof (UNIT))
+	    / hist_num_bins;
 	  histograms->sample = xmalloc (hist_num_bins * sizeof (int));
 	  memset (histograms->sample, 0, 
 		  hist_num_bins * sizeof (int));

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