}
}
}
- else if (file_format == FF_AUTO || file_format == FF_BSD)
+ else if (file_format == FF_AUTO
+ || file_format == FF_BSD
+ || file_format == FF_BSD44)
{
struct hdr
{
bfd_vma high_pc;
int ncnt;
};
- int i, samp_bytes;
+ int i, samp_bytes, header_size;
unsigned long count;
bfd_vma from_pc, self_pc;
struct raw_arc raw_arc;
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]);
-#ifdef BSD44_FORMAT
- {
- int profrate;
-
- profrate = bfd_get_32 (core_bfd, (bfd_byte *) &raw.profrate[0]);
- if (!s_highpc)
- hz = profrate;
- else if (hz != profrate)
- {
- fprintf (stderr,
- _("%s: profiling rate incompatible with first gmon file\n"),
- filename);
- done (1);
- }
- }
-#endif
+ if (bfd_get_32 (core_bfd, (bfd_byte *) &raw.version[0])
+ == GMONVERSION)
+ {
+ int profrate;
+
+ /* 4.4BSD format header. */
+
+ profrate = bfd_get_32 (core_bfd, (bfd_byte *) &raw.profrate[0]);
+ if (!s_highpc)
+ hz = profrate;
+ else if (hz != profrate)
+ {
+ fprintf (stderr,
+ _("%s: profiling rate incompatible with first gmon file\n"),
+ filename);
+ done (1);
+ }
+
+ header_size = sizeof (struct raw_phdr);
+ }
+ else
+ {
+ /* old style BSD format. */
+ if (file_format == FF_BSD44)
+ {
+ fprintf (stderr, _("%s: file `%s' has bad magic cookie\n"),
+ whoami, filename);
+ done (1);
+ }
+
+ if (fseek (ifp, sizeof (struct old_raw_phdr), SEEK_SET) < 0)
+ {
+ perror (filename);
+ done (1);
+ }
+
+ 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))
s_highpc = (bfd_vma) h.high_pc;
lowpc = (bfd_vma) h.low_pc / sizeof (UNIT);
highpc = (bfd_vma) h.high_pc / sizeof (UNIT);
- samp_bytes = h.ncnt - sizeof (struct raw_phdr);
+ 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",
- h.low_pc, h.high_pc, h.ncnt);
+ (unsigned long) h.low_pc, (unsigned long) h.high_pc,
+ h.ncnt);
printf ("[gmon_out_read] s_lowpc 0x%lx s_highpc 0x%lx\n",
- s_lowpc, s_highpc);
+ (unsigned long) s_lowpc, (unsigned long) s_highpc);
printf ("[gmon_out_read] lowpc 0x%lx highpc 0x%lx\n",
- lowpc, highpc);
+ (unsigned long) lowpc, (unsigned long) highpc);
printf ("[gmon_out_read] samp_bytes %d hist_num_bins %d\n",
samp_bytes, hist_num_bins));
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",
- from_pc, self_pc, count));
+ (unsigned long) from_pc, (unsigned long) self_pc, count));
/* add this arc: */
cg_tally (from_pc, self_pc, count);
}
bb_write_blocks (ofp, filename);
}
}
- else if (file_format == FF_BSD)
+ else if (file_format == FF_BSD || file_format == FF_BSD44)
{
struct raw_arc raw_arc;
UNIT raw_bin_count;
- bfd_vma lpc, hpc;
- int i, ncnt;
+ struct raw_phdr h;
+ int i;
Arc *arc;
Sym *sym;
- put_vma (core_bfd, s_lowpc, (bfd_byte *) & lpc);
- put_vma (core_bfd, s_highpc, (bfd_byte *) & hpc);
+ memset (&h, 0, sizeof h);
+ put_vma (core_bfd, s_lowpc, (bfd_byte *) &h.low_pc);
+ put_vma (core_bfd, s_highpc, (bfd_byte *) &h.high_pc);
bfd_put_32 (core_bfd,
hist_num_bins * sizeof (UNIT) + sizeof (struct raw_phdr),
- (bfd_byte *) & ncnt);
+ (bfd_byte *) &h.ncnt);
- /* write header: */
- if (fwrite (&lpc, sizeof (lpc), 1, ofp) != 1
- || fwrite (&hpc, sizeof (hpc), 1, ofp) != 1
- || fwrite (&ncnt, sizeof (ncnt), 1, ofp) != 1)
+ /* Write header. Use new style BSD format is explicitly
+ specified, or if the profiling rate is non-standard;
+ otherwise, use the old BSD format. */
+ if (file_format == FF_BSD44
+ || hz != hertz ())
{
- perror (filename);
- done (1);
+ bfd_put_32 (core_bfd, GMONVERSION, (bfd_byte *) &h.version);
+ bfd_put_32 (core_bfd, hz, (bfd_byte *) &h.profrate);
+ if (fwrite (&h, sizeof (struct raw_phdr), 1, ofp) != 1)
+ {
+ perror (filename);
+ done (1);
+ }
+ }
+ else
+ {
+ if (fwrite (&h, sizeof (struct old_raw_phdr), 1, ofp) != 1)
+ {
+ perror (filename);
+ done (1);
+ }
}
/* dump the samples: */
}
DBG (SAMPLEDEBUG,
printf ("[dumpsum] frompc 0x%lx selfpc 0x%lx count %lu\n",
- arc->parent->addr, arc->child->addr, arc->count));
+ (unsigned long) arc->parent->addr,
+ (unsigned long) arc->child->addr, arc->count));
}
}
fclose (ofp);