2000-07-25 04:59:04 +08:00
|
|
|
|
/* gmon_io.c - Input and output from/to gmon.out files.
|
|
|
|
|
|
2005-03-03 20:05:13 +08:00
|
|
|
|
Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005
|
|
|
|
|
Free Software Foundation, Inc.
|
2000-07-25 04:59:04 +08:00
|
|
|
|
|
|
|
|
|
This file is part of GNU Binutils.
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-05-09 14:55:25 +08:00
|
|
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
|
|
|
|
|
02110-1301, USA. */
|
2000-07-25 04:59:04 +08:00
|
|
|
|
|
2002-01-31 20:56:08 +08:00
|
|
|
|
#include "gprof.h"
|
|
|
|
|
#include "search_list.h"
|
|
|
|
|
#include "source.h"
|
|
|
|
|
#include "symtab.h"
|
1999-05-03 15:29:11 +08:00
|
|
|
|
#include "cg_arcs.h"
|
|
|
|
|
#include "basic_blocks.h"
|
|
|
|
|
#include "corefile.h"
|
|
|
|
|
#include "call_graph.h"
|
|
|
|
|
#include "gmon_io.h"
|
|
|
|
|
#include "gmon_out.h"
|
2000-07-25 04:59:04 +08:00
|
|
|
|
#include "gmon.h" /* Fetch header for old format. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
#include "hertz.h"
|
|
|
|
|
#include "hist.h"
|
|
|
|
|
#include "libiberty.h"
|
|
|
|
|
|
2003-04-01 03:01:04 +08:00
|
|
|
|
enum gmon_ptr_size {
|
|
|
|
|
ptr_32bit,
|
|
|
|
|
ptr_64bit
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum gmon_ptr_signedness {
|
|
|
|
|
ptr_signed,
|
|
|
|
|
ptr_unsigned
|
|
|
|
|
};
|
|
|
|
|
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 12:55:55 +08:00
|
|
|
|
static enum gmon_ptr_size gmon_get_ptr_size (void);
|
|
|
|
|
static enum gmon_ptr_signedness gmon_get_ptr_signedness (void);
|
2003-04-01 03:01:04 +08:00
|
|
|
|
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#ifdef BFD_HOST_U_64_BIT
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 12:55:55 +08:00
|
|
|
|
static int gmon_io_read_64 (FILE *, BFD_HOST_U_64_BIT *);
|
|
|
|
|
static int gmon_io_write_64 (FILE *, BFD_HOST_U_64_BIT);
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#endif
|
2002-02-01 16:24:16 +08:00
|
|
|
|
static int gmon_read_raw_arc
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 12:55:55 +08:00
|
|
|
|
(FILE *, bfd_vma *, bfd_vma *, unsigned long *);
|
2002-02-01 16:24:16 +08:00
|
|
|
|
static int gmon_write_raw_arc
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 12:55:55 +08:00
|
|
|
|
(FILE *, bfd_vma, bfd_vma, unsigned long);
|
2002-02-01 16:24:16 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
int gmon_input = 0;
|
2000-07-25 04:59:04 +08:00
|
|
|
|
int gmon_file_version = 0; /* 0 == old (non-versioned) file format. */
|
|
|
|
|
|
2003-04-01 03:01:04 +08:00
|
|
|
|
static enum gmon_ptr_size
|
|
|
|
|
gmon_get_ptr_size ()
|
|
|
|
|
{
|
|
|
|
|
int size;
|
|
|
|
|
|
|
|
|
|
/* Pick best size for pointers. Start with the ELF size, and if not
|
|
|
|
|
elf go with the architecture's address size. */
|
|
|
|
|
size = bfd_get_arch_size (core_bfd);
|
|
|
|
|
if (size == -1)
|
|
|
|
|
size = bfd_arch_bits_per_address (core_bfd);
|
|
|
|
|
|
|
|
|
|
switch (size)
|
|
|
|
|
{
|
|
|
|
|
case 32:
|
|
|
|
|
return ptr_32bit;
|
|
|
|
|
|
|
|
|
|
case 64:
|
|
|
|
|
return ptr_64bit;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
fprintf (stderr, _("%s: address size has unexpected value of %u\n"),
|
|
|
|
|
whoami, size);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static enum gmon_ptr_signedness
|
|
|
|
|
gmon_get_ptr_signedness ()
|
|
|
|
|
{
|
|
|
|
|
int sext;
|
|
|
|
|
|
|
|
|
|
/* Figure out whether to sign extend. If BFD doesn't know, assume no. */
|
|
|
|
|
sext = bfd_get_sign_extend_vma (core_bfd);
|
|
|
|
|
if (sext == -1)
|
|
|
|
|
return ptr_unsigned;
|
|
|
|
|
return (sext ? ptr_signed : ptr_unsigned);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-14 11:14:56 +08:00
|
|
|
|
int
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 12:55:55 +08:00
|
|
|
|
gmon_io_read_32 (FILE *ifp, unsigned int *valp)
|
2002-02-01 02:37:58 +08:00
|
|
|
|
{
|
|
|
|
|
char buf[4];
|
|
|
|
|
|
|
|
|
|
if (fread (buf, 1, 4, ifp) != 4)
|
|
|
|
|
return 1;
|
|
|
|
|
*valp = bfd_get_32 (core_bfd, buf);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#ifdef BFD_HOST_U_64_BIT
|
2002-02-01 16:24:16 +08:00
|
|
|
|
static int
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 12:55:55 +08:00
|
|
|
|
gmon_io_read_64 (FILE *ifp, BFD_HOST_U_64_BIT *valp)
|
2001-03-14 11:14:56 +08:00
|
|
|
|
{
|
|
|
|
|
char buf[8];
|
|
|
|
|
|
2002-02-01 02:37:58 +08:00
|
|
|
|
if (fread (buf, 1, 8, ifp) != 8)
|
|
|
|
|
return 1;
|
|
|
|
|
*valp = bfd_get_64 (core_bfd, buf);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#endif
|
2002-02-01 02:37:58 +08:00
|
|
|
|
|
|
|
|
|
int
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 12:55:55 +08:00
|
|
|
|
gmon_io_read_vma (FILE *ifp, bfd_vma *valp)
|
2002-02-01 02:37:58 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned int val32;
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#ifdef BFD_HOST_U_64_BIT
|
2002-02-01 02:37:58 +08:00
|
|
|
|
BFD_HOST_U_64_BIT val64;
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#endif
|
2002-02-01 02:37:58 +08:00
|
|
|
|
|
2003-04-01 03:01:04 +08:00
|
|
|
|
switch (gmon_get_ptr_size ())
|
2001-03-14 11:14:56 +08:00
|
|
|
|
{
|
2003-04-01 03:01:04 +08:00
|
|
|
|
case ptr_32bit:
|
2002-02-01 02:37:58 +08:00
|
|
|
|
if (gmon_io_read_32 (ifp, &val32))
|
2001-03-14 11:14:56 +08:00
|
|
|
|
return 1;
|
2003-04-01 03:01:04 +08:00
|
|
|
|
if (gmon_get_ptr_signedness () == ptr_signed)
|
|
|
|
|
*valp = (int) val32;
|
|
|
|
|
else
|
|
|
|
|
*valp = val32;
|
2001-03-14 11:14:56 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#ifdef BFD_HOST_U_64_BIT
|
2003-04-01 03:01:04 +08:00
|
|
|
|
case ptr_64bit:
|
2002-02-01 02:37:58 +08:00
|
|
|
|
if (gmon_io_read_64 (ifp, &val64))
|
2001-03-14 11:14:56 +08:00
|
|
|
|
return 1;
|
2003-04-01 03:01:04 +08:00
|
|
|
|
#ifdef BFD_HOST_64_BIT
|
|
|
|
|
if (gmon_get_ptr_signedness () == ptr_signed)
|
|
|
|
|
*valp = (BFD_HOST_64_BIT) val64;
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
*valp = val64;
|
2001-03-14 11:14:56 +08:00
|
|
|
|
break;
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#endif
|
2001-03-14 11:14:56 +08:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2001-03-14 11:14:56 +08:00
|
|
|
|
int
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 12:55:55 +08:00
|
|
|
|
gmon_io_read (FILE *ifp, char *buf, size_t n)
|
2002-02-01 02:37:58 +08:00
|
|
|
|
{
|
|
|
|
|
if (fread (buf, 1, n, ifp) != n)
|
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 12:55:55 +08:00
|
|
|
|
gmon_io_write_32 (FILE *ofp, unsigned int val)
|
2001-03-14 11:14:56 +08:00
|
|
|
|
{
|
|
|
|
|
char buf[4];
|
|
|
|
|
|
2002-02-01 16:24:16 +08:00
|
|
|
|
bfd_put_32 (core_bfd, (bfd_vma) val, buf);
|
2002-02-01 02:37:58 +08:00
|
|
|
|
if (fwrite (buf, 1, 4, ofp) != 4)
|
2001-03-14 11:14:56 +08:00
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#ifdef BFD_HOST_U_64_BIT
|
2002-02-01 16:24:16 +08:00
|
|
|
|
static int
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 12:55:55 +08:00
|
|
|
|
gmon_io_write_64 (FILE *ofp, BFD_HOST_U_64_BIT val)
|
2001-03-14 11:14:56 +08:00
|
|
|
|
{
|
2002-02-01 02:37:58 +08:00
|
|
|
|
char buf[8];
|
|
|
|
|
|
2002-02-01 16:24:16 +08:00
|
|
|
|
bfd_put_64 (core_bfd, (bfd_vma) val, buf);
|
2002-02-01 02:37:58 +08:00
|
|
|
|
if (fwrite (buf, 1, 8, ofp) != 8)
|
2001-03-14 11:14:56 +08:00
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#endif
|
2001-03-14 11:14:56 +08:00
|
|
|
|
|
|
|
|
|
int
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 12:55:55 +08:00
|
|
|
|
gmon_io_write_vma (FILE *ofp, bfd_vma val)
|
2001-03-14 11:14:56 +08:00
|
|
|
|
{
|
|
|
|
|
|
2003-04-01 03:01:04 +08:00
|
|
|
|
switch (gmon_get_ptr_size ())
|
2001-03-14 11:14:56 +08:00
|
|
|
|
{
|
2003-04-01 03:01:04 +08:00
|
|
|
|
case ptr_32bit:
|
2002-02-01 02:37:58 +08:00
|
|
|
|
if (gmon_io_write_32 (ofp, (unsigned int) val))
|
2001-03-14 11:14:56 +08:00
|
|
|
|
return 1;
|
|
|
|
|
break;
|
|
|
|
|
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#ifdef BFD_HOST_U_64_BIT
|
2003-04-01 03:01:04 +08:00
|
|
|
|
case ptr_64bit:
|
2002-02-01 02:37:58 +08:00
|
|
|
|
if (gmon_io_write_64 (ofp, (BFD_HOST_U_64_BIT) val))
|
2001-03-14 11:14:56 +08:00
|
|
|
|
return 1;
|
|
|
|
|
break;
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#endif
|
2001-03-14 11:14:56 +08:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 12:55:55 +08:00
|
|
|
|
gmon_io_write_8 (FILE *ofp, unsigned int val)
|
2001-03-14 11:14:56 +08:00
|
|
|
|
{
|
|
|
|
|
char buf[1];
|
|
|
|
|
|
|
|
|
|
bfd_put_8 (core_bfd, val, buf);
|
|
|
|
|
if (fwrite (buf, 1, 1, ofp) != 1)
|
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 12:55:55 +08:00
|
|
|
|
gmon_io_write (FILE *ofp, char *buf, size_t n)
|
2001-03-14 11:14:56 +08:00
|
|
|
|
{
|
|
|
|
|
if (fwrite (buf, 1, n, ofp) != n)
|
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-01 16:24:16 +08:00
|
|
|
|
static int
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 12:55:55 +08:00
|
|
|
|
gmon_read_raw_arc (FILE *ifp, bfd_vma *fpc, bfd_vma *spc, unsigned long *cnt)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#ifdef BFD_HOST_U_64_BIT
|
2002-02-01 02:37:58 +08:00
|
|
|
|
BFD_HOST_U_64_BIT cnt64;
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#endif
|
2002-02-01 02:37:58 +08:00
|
|
|
|
unsigned int cnt32;
|
|
|
|
|
|
|
|
|
|
if (gmon_io_read_vma (ifp, fpc)
|
|
|
|
|
|| gmon_io_read_vma (ifp, spc))
|
|
|
|
|
return 1;
|
|
|
|
|
|
2003-04-01 03:01:04 +08:00
|
|
|
|
switch (gmon_get_ptr_size ())
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2003-04-01 03:01:04 +08:00
|
|
|
|
case ptr_32bit:
|
2002-02-01 02:37:58 +08:00
|
|
|
|
if (gmon_io_read_32 (ifp, &cnt32))
|
|
|
|
|
return 1;
|
|
|
|
|
*cnt = cnt32;
|
|
|
|
|
break;
|
|
|
|
|
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#ifdef BFD_HOST_U_64_BIT
|
2003-04-01 03:01:04 +08:00
|
|
|
|
case ptr_64bit:
|
2002-02-01 02:37:58 +08:00
|
|
|
|
if (gmon_io_read_64 (ifp, &cnt64))
|
|
|
|
|
return 1;
|
|
|
|
|
*cnt = cnt64;
|
|
|
|
|
break;
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#endif
|
2005-03-14 20:32:02 +08:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return 1;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
2002-02-01 02:37:58 +08:00
|
|
|
|
return 0;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-01 16:24:16 +08:00
|
|
|
|
static int
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 12:55:55 +08:00
|
|
|
|
gmon_write_raw_arc (FILE *ofp, bfd_vma fpc, bfd_vma spc, unsigned long cnt)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2002-02-01 02:37:58 +08:00
|
|
|
|
|
|
|
|
|
if (gmon_io_write_vma (ofp, fpc)
|
|
|
|
|
|| gmon_io_write_vma (ofp, spc))
|
|
|
|
|
return 1;
|
|
|
|
|
|
2003-04-01 03:01:04 +08:00
|
|
|
|
switch (gmon_get_ptr_size ())
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2003-04-01 03:01:04 +08:00
|
|
|
|
case ptr_32bit:
|
2002-02-01 02:37:58 +08:00
|
|
|
|
if (gmon_io_write_32 (ofp, (unsigned int) cnt))
|
|
|
|
|
return 1;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
break;
|
2002-02-01 02:37:58 +08:00
|
|
|
|
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#ifdef BFD_HOST_U_64_BIT
|
2003-04-01 03:01:04 +08:00
|
|
|
|
case ptr_64bit:
|
2002-02-01 02:37:58 +08:00
|
|
|
|
if (gmon_io_write_64 (ofp, (BFD_HOST_U_64_BIT) cnt))
|
|
|
|
|
return 1;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
break;
|
2002-08-21 07:47:26 +08:00
|
|
|
|
#endif
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
2002-02-01 02:37:58 +08:00
|
|
|
|
return 0;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 12:55:55 +08:00
|
|
|
|
gmon_out_read (const char *filename)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
FILE *ifp;
|
|
|
|
|
struct gmon_hdr ghdr;
|
|
|
|
|
unsigned char tag;
|
|
|
|
|
int nhist = 0, narcs = 0, nbbs = 0;
|
|
|
|
|
|
2000-07-25 04:59:04 +08:00
|
|
|
|
/* Open gmon.out file. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (strcmp (filename, "-") == 0)
|
|
|
|
|
{
|
|
|
|
|
ifp = stdin;
|
2000-05-26 21:11:57 +08:00
|
|
|
|
#ifdef SET_BINARY
|
|
|
|
|
SET_BINARY (fileno (stdin));
|
|
|
|
|
#endif
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ifp = fopen (filename, FOPEN_RB);
|
2001-03-14 11:14:56 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (!ifp)
|
|
|
|
|
{
|
|
|
|
|
perror (filename);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-03-14 11:14:56 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (fread (&ghdr, sizeof (struct gmon_hdr), 1, ifp) != 1)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, _("%s: file too short to be a gmon file\n"),
|
|
|
|
|
filename);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-14 11:14:56 +08:00
|
|
|
|
if ((file_format == FF_MAGIC)
|
|
|
|
|
|| (file_format == FF_AUTO && !strncmp (&ghdr.cookie[0], GMON_MAGIC, 4)))
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
if (file_format == FF_MAGIC && strncmp (&ghdr.cookie[0], GMON_MAGIC, 4))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, _("%s: file `%s' has bad magic cookie\n"),
|
|
|
|
|
whoami, filename);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-25 04:59:04 +08:00
|
|
|
|
/* Right magic, so it's probably really a new gmon.out file. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
gmon_file_version = bfd_get_32 (core_bfd, (bfd_byte *) ghdr.version);
|
2001-03-14 11:14:56 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (gmon_file_version != GMON_VERSION && gmon_file_version != 0)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr,
|
|
|
|
|
_("%s: file `%s' has unsupported version %d\n"),
|
|
|
|
|
whoami, filename, gmon_file_version);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-25 04:59:04 +08:00
|
|
|
|
/* Read in all the records. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
while (fread (&tag, sizeof (tag), 1, ifp) == 1)
|
|
|
|
|
{
|
|
|
|
|
switch (tag)
|
|
|
|
|
{
|
|
|
|
|
case GMON_TAG_TIME_HIST:
|
|
|
|
|
++nhist;
|
|
|
|
|
gmon_input |= INPUT_HISTOGRAM;
|
|
|
|
|
hist_read_rec (ifp, filename);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GMON_TAG_CG_ARC:
|
|
|
|
|
++narcs;
|
|
|
|
|
gmon_input |= INPUT_CALL_GRAPH;
|
|
|
|
|
cg_read_rec (ifp, filename);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GMON_TAG_BB_COUNT:
|
|
|
|
|
++nbbs;
|
|
|
|
|
gmon_input |= INPUT_BB_COUNTS;
|
|
|
|
|
bb_read_rec (ifp, filename);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
fprintf (stderr,
|
|
|
|
|
_("%s: %s: found bad tag %d (file corrupted?)\n"),
|
|
|
|
|
whoami, filename, tag);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (file_format == FF_AUTO
|
|
|
|
|
|| file_format == FF_BSD
|
|
|
|
|
|| file_format == FF_BSD44)
|
|
|
|
|
{
|
|
|
|
|
struct hdr
|
|
|
|
|
{
|
|
|
|
|
bfd_vma low_pc;
|
|
|
|
|
bfd_vma high_pc;
|
2005-02-22 20:59:21 +08:00
|
|
|
|
unsigned int ncnt;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
};
|
2005-02-22 20:59:21 +08:00
|
|
|
|
unsigned int i;
|
|
|
|
|
int samp_bytes, header_size = 0;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
unsigned long count;
|
|
|
|
|
bfd_vma from_pc, self_pc;
|
|
|
|
|
UNIT raw_bin_count;
|
|
|
|
|
struct hdr tmp;
|
2005-02-22 20:59:21 +08:00
|
|
|
|
unsigned int version;
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 15:57:31 +08:00
|
|
|
|
unsigned int hist_num_bins;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2000-07-25 04:59:04 +08:00
|
|
|
|
/* Information from a gmon.out file is in two parts: an array of
|
2001-03-14 11:14:56 +08:00
|
|
|
|
sampling hits within pc ranges, and the arcs. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
gmon_input = INPUT_HISTOGRAM | INPUT_CALL_GRAPH;
|
|
|
|
|
|
2000-07-25 04:59:04 +08:00
|
|
|
|
/* This fseek() ought to work even on stdin as long as it's
|
2001-03-14 11:14:56 +08:00
|
|
|
|
not an interactive device (heck, is there anybody who would
|
|
|
|
|
want to type in a gmon.out at the terminal?). */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (fseek (ifp, 0, SEEK_SET) < 0)
|
|
|
|
|
{
|
|
|
|
|
perror (filename);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
2001-03-14 11:14:56 +08:00
|
|
|
|
|
2002-02-01 02:37:58 +08:00
|
|
|
|
/* The beginning of the old BSD header and the 4.4BSD header
|
|
|
|
|
are the same: lowpc, highpc, ncnt */
|
|
|
|
|
if (gmon_io_read_vma (ifp, &tmp.low_pc)
|
|
|
|
|
|| gmon_io_read_vma (ifp, &tmp.high_pc)
|
|
|
|
|
|| gmon_io_read_32 (ifp, &tmp.ncnt))
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2002-02-01 02:37:58 +08:00
|
|
|
|
bad_gmon_file:
|
|
|
|
|
fprintf (stderr, _("%s: file too short to be a gmon file\n"),
|
1999-05-03 15:29:11 +08:00
|
|
|
|
filename);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
2001-03-14 11:14:56 +08:00
|
|
|
|
|
2002-02-01 02:37:58 +08:00
|
|
|
|
/* Check to see if this a 4.4BSD-style header. */
|
|
|
|
|
if (gmon_io_read_32 (ifp, &version))
|
|
|
|
|
goto bad_gmon_file;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2002-02-01 02:37:58 +08:00
|
|
|
|
if (version == GMONVERSION)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2005-02-22 20:59:21 +08:00
|
|
|
|
unsigned int profrate;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
/* 4.4BSD format header. */
|
2002-02-01 02:37:58 +08:00
|
|
|
|
if (gmon_io_read_32 (ifp, &profrate))
|
|
|
|
|
goto bad_gmon_file;
|
2001-03-14 11:14:56 +08:00
|
|
|
|
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 15:57:31 +08:00
|
|
|
|
if (!histograms)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
hz = profrate;
|
2005-02-22 20:59:21 +08:00
|
|
|
|
else if (hz != (int) profrate)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
fprintf (stderr,
|
|
|
|
|
_("%s: profiling rate incompatible with first gmon file\n"),
|
|
|
|
|
filename);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-01 03:01:04 +08:00
|
|
|
|
switch (gmon_get_ptr_size ())
|
2002-02-01 02:37:58 +08:00
|
|
|
|
{
|
2003-04-01 03:01:04 +08:00
|
|
|
|
case ptr_32bit:
|
2002-02-01 02:37:58 +08:00
|
|
|
|
header_size = GMON_HDRSIZE_BSD44_32;
|
|
|
|
|
break;
|
|
|
|
|
|
2003-04-01 03:01:04 +08:00
|
|
|
|
case ptr_64bit:
|
2002-02-01 02:37:58 +08:00
|
|
|
|
header_size = GMON_HDRSIZE_BSD44_64;
|
|
|
|
|
break;
|
|
|
|
|
}
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2000-07-25 04:59:04 +08:00
|
|
|
|
/* Old style BSD format. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (file_format == FF_BSD44)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, _("%s: file `%s' has bad magic cookie\n"),
|
|
|
|
|
whoami, filename);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-01 03:01:04 +08:00
|
|
|
|
switch (gmon_get_ptr_size ())
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2003-04-01 03:01:04 +08:00
|
|
|
|
case ptr_32bit:
|
2002-02-01 02:37:58 +08:00
|
|
|
|
header_size = GMON_HDRSIZE_OLDBSD_32;
|
|
|
|
|
break;
|
|
|
|
|
|
2003-04-01 03:01:04 +08:00
|
|
|
|
case ptr_64bit:
|
2002-02-01 02:37:58 +08:00
|
|
|
|
header_size = GMON_HDRSIZE_OLDBSD_64;
|
|
|
|
|
break;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
2002-02-01 02:37:58 +08:00
|
|
|
|
}
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2002-02-01 02:37:58 +08:00
|
|
|
|
/* Position the file to after the header. */
|
|
|
|
|
if (fseek (ifp, header_size, SEEK_SET) < 0)
|
|
|
|
|
{
|
|
|
|
|
perror (filename);
|
|
|
|
|
done (1);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 15:57:31 +08:00
|
|
|
|
samp_bytes = tmp.ncnt - header_size;
|
|
|
|
|
hist_num_bins = samp_bytes / sizeof (UNIT);
|
|
|
|
|
if (histograms && (tmp.low_pc != histograms->lowpc
|
|
|
|
|
|| tmp.high_pc != histograms->highpc
|
|
|
|
|
|| (hist_num_bins != histograms->num_bins)))
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, _("%s: incompatible with first gmon file\n"),
|
|
|
|
|
filename);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
2001-03-14 11:14:56 +08:00
|
|
|
|
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 15:57:31 +08:00
|
|
|
|
if (!histograms)
|
|
|
|
|
{
|
|
|
|
|
histograms = 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_num_bins * sizeof (int));
|
|
|
|
|
}
|
2001-03-14 11:14:56 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
DBG (SAMPLEDEBUG,
|
|
|
|
|
printf ("[gmon_out_read] lowpc 0x%lx highpc 0x%lx ncnt %d\n",
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 15:57:31 +08:00
|
|
|
|
(unsigned long) tmp.low_pc, (unsigned long) tmp.high_pc,
|
|
|
|
|
tmp.ncnt);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
printf ("[gmon_out_read] samp_bytes %d hist_num_bins %d\n",
|
|
|
|
|
samp_bytes, hist_num_bins));
|
|
|
|
|
|
1999-09-24 17:03:49 +08:00
|
|
|
|
/* Make sure that we have sensible values. */
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 15:57:31 +08:00
|
|
|
|
if (samp_bytes < 0 || histograms->lowpc > histograms->highpc)
|
2001-03-14 11:14:56 +08:00
|
|
|
|
{
|
|
|
|
|
fprintf (stderr,
|
1999-09-24 17:03:49 +08:00
|
|
|
|
_("%s: file '%s' does not appear to be in gmon.out format\n"),
|
|
|
|
|
whoami, filename);
|
2001-03-14 11:14:56 +08:00
|
|
|
|
done (1);
|
|
|
|
|
}
|
1999-09-24 17:03:49 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (hist_num_bins)
|
2000-07-25 04:59:04 +08:00
|
|
|
|
++nhist;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < hist_num_bins; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (fread (raw_bin_count, sizeof (raw_bin_count), 1, ifp) != 1)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr,
|
|
|
|
|
_("%s: unexpected EOF after reading %d/%d bins\n"),
|
|
|
|
|
whoami, --i, hist_num_bins);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
2001-03-14 11:14:56 +08:00
|
|
|
|
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 15:57:31 +08:00
|
|
|
|
histograms->sample[i]
|
|
|
|
|
+= bfd_get_16 (core_bfd, (bfd_byte *) raw_bin_count);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-25 04:59:04 +08:00
|
|
|
|
/* The rest of the file consists of a bunch of
|
|
|
|
|
<from,self,count> tuples. */
|
2002-02-01 02:37:58 +08:00
|
|
|
|
while (gmon_read_raw_arc (ifp, &from_pc, &self_pc, &count) == 0)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
++narcs;
|
2001-03-14 11:14:56 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
DBG (SAMPLEDEBUG,
|
|
|
|
|
printf ("[gmon_out_read] frompc 0x%lx selfpc 0x%lx count %lu\n",
|
1999-07-01 06:38:30 +08:00
|
|
|
|
(unsigned long) from_pc, (unsigned long) self_pc, count));
|
2001-03-14 11:14:56 +08:00
|
|
|
|
|
2000-07-25 04:59:04 +08:00
|
|
|
|
/* Add this arc. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
cg_tally (from_pc, self_pc, count);
|
|
|
|
|
}
|
2001-03-14 11:14:56 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
fclose (ifp);
|
|
|
|
|
|
|
|
|
|
if (hz == HZ_WRONG)
|
|
|
|
|
{
|
2000-07-25 04:59:04 +08:00
|
|
|
|
/* How many ticks per second? If we can't tell, report
|
|
|
|
|
time in ticks. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
hz = hertz ();
|
2001-03-14 11:14:56 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (hz == HZ_WRONG)
|
|
|
|
|
{
|
|
|
|
|
hz = 1;
|
|
|
|
|
fprintf (stderr, _("time is in ticks, not seconds\n"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, _("%s: don't know how to deal with file format %d\n"),
|
|
|
|
|
whoami, file_format);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (output_style & STYLE_GMON_INFO)
|
|
|
|
|
{
|
|
|
|
|
printf (_("File `%s' (version %d) contains:\n"),
|
|
|
|
|
filename, gmon_file_version);
|
2002-01-04 05:32:36 +08:00
|
|
|
|
printf (nhist == 1 ?
|
|
|
|
|
_("\t%d histogram record\n") :
|
|
|
|
|
_("\t%d histogram records\n"), nhist);
|
|
|
|
|
printf (narcs == 1 ?
|
|
|
|
|
_("\t%d call-graph record\n") :
|
|
|
|
|
_("\t%d call-graph records\n"), narcs);
|
|
|
|
|
printf (nbbs == 1 ?
|
|
|
|
|
_("\t%d basic-block count record\n") :
|
|
|
|
|
_("\t%d basic-block count records\n"), nbbs);
|
2002-11-30 16:39:46 +08:00
|
|
|
|
first_output = FALSE;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 12:55:55 +08:00
|
|
|
|
gmon_out_write (const char *filename)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
FILE *ofp;
|
|
|
|
|
struct gmon_hdr ghdr;
|
|
|
|
|
|
|
|
|
|
ofp = fopen (filename, FOPEN_WB);
|
|
|
|
|
if (!ofp)
|
|
|
|
|
{
|
|
|
|
|
perror (filename);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (file_format == FF_AUTO || file_format == FF_MAGIC)
|
|
|
|
|
{
|
2000-07-25 04:59:04 +08:00
|
|
|
|
/* Write gmon header. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
memcpy (&ghdr.cookie[0], GMON_MAGIC, 4);
|
2002-02-01 16:24:16 +08:00
|
|
|
|
bfd_put_32 (core_bfd, (bfd_vma) GMON_VERSION, (bfd_byte *) ghdr.version);
|
2001-03-14 11:14:56 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (fwrite (&ghdr, sizeof (ghdr), 1, ofp) != 1)
|
|
|
|
|
{
|
|
|
|
|
perror (filename);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-25 04:59:04 +08:00
|
|
|
|
/* Write execution time histogram if we have one. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (gmon_input & INPUT_HISTOGRAM)
|
2000-07-25 04:59:04 +08:00
|
|
|
|
hist_write_hist (ofp, filename);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2000-07-25 04:59:04 +08:00
|
|
|
|
/* Write call graph arcs if we have any. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (gmon_input & INPUT_CALL_GRAPH)
|
2000-07-25 04:59:04 +08:00
|
|
|
|
cg_write_arcs (ofp, filename);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2000-07-25 04:59:04 +08:00
|
|
|
|
/* Write basic-block info if we have it. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (gmon_input & INPUT_BB_COUNTS)
|
2000-07-25 04:59:04 +08:00
|
|
|
|
bb_write_blocks (ofp, filename);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
else if (file_format == FF_BSD || file_format == FF_BSD44)
|
|
|
|
|
{
|
|
|
|
|
UNIT raw_bin_count;
|
2005-02-22 20:59:21 +08:00
|
|
|
|
unsigned int i, hdrsize;
|
2002-02-01 02:37:58 +08:00
|
|
|
|
unsigned padsize;
|
|
|
|
|
char pad[3*4];
|
1999-05-03 15:29:11 +08:00
|
|
|
|
Arc *arc;
|
|
|
|
|
Sym *sym;
|
|
|
|
|
|
2002-02-01 02:37:58 +08:00
|
|
|
|
memset (pad, 0, sizeof (pad));
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2002-02-01 02:37:58 +08:00
|
|
|
|
hdrsize = 0;
|
|
|
|
|
/* Decide how large the header will be. Use the 4.4BSD format
|
|
|
|
|
header if explicitly specified, or if the profiling rate is
|
|
|
|
|
non-standard. Otherwise, use the old BSD format. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (file_format == FF_BSD44
|
2002-02-01 02:37:58 +08:00
|
|
|
|
|| hz != hertz())
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2002-02-01 02:37:58 +08:00
|
|
|
|
padsize = 3*4;
|
2003-04-01 03:01:04 +08:00
|
|
|
|
switch (gmon_get_ptr_size ())
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2003-04-01 03:01:04 +08:00
|
|
|
|
case ptr_32bit:
|
2002-02-01 02:37:58 +08:00
|
|
|
|
hdrsize = GMON_HDRSIZE_BSD44_32;
|
|
|
|
|
break;
|
|
|
|
|
|
2003-04-01 03:01:04 +08:00
|
|
|
|
case ptr_64bit:
|
2002-02-01 02:37:58 +08:00
|
|
|
|
hdrsize = GMON_HDRSIZE_BSD44_64;
|
|
|
|
|
break;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2002-02-01 02:37:58 +08:00
|
|
|
|
padsize = 0;
|
2003-04-01 03:01:04 +08:00
|
|
|
|
switch (gmon_get_ptr_size ())
|
2002-02-01 02:37:58 +08:00
|
|
|
|
{
|
2003-04-01 03:01:04 +08:00
|
|
|
|
case ptr_32bit:
|
2002-02-01 02:37:58 +08:00
|
|
|
|
hdrsize = GMON_HDRSIZE_OLDBSD_32;
|
|
|
|
|
break;
|
|
|
|
|
|
2003-04-01 03:01:04 +08:00
|
|
|
|
case ptr_64bit:
|
2002-02-01 02:37:58 +08:00
|
|
|
|
hdrsize = GMON_HDRSIZE_OLDBSD_64;
|
|
|
|
|
/* FIXME: Checking host compiler defines here means that we can't
|
|
|
|
|
use a cross gprof alpha OSF. */
|
|
|
|
|
#if defined(__alpha__) && defined (__osf__)
|
|
|
|
|
padsize = 4;
|
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Write the parts of the headers that are common to both the
|
|
|
|
|
old BSD and 4.4BSD formats. */
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 15:57:31 +08:00
|
|
|
|
if (gmon_io_write_vma (ofp, histograms->lowpc)
|
|
|
|
|
|| gmon_io_write_vma (ofp, histograms->highpc)
|
|
|
|
|
|| gmon_io_write_32 (ofp, histograms->num_bins
|
|
|
|
|
* sizeof (UNIT) + hdrsize))
|
2002-02-01 02:37:58 +08:00
|
|
|
|
{
|
|
|
|
|
perror (filename);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Write out the 4.4BSD header bits, if that's what we're using. */
|
|
|
|
|
if (file_format == FF_BSD44
|
|
|
|
|
|| hz != hertz())
|
|
|
|
|
{
|
|
|
|
|
if (gmon_io_write_32 (ofp, GMONVERSION)
|
2002-02-01 16:24:16 +08:00
|
|
|
|
|| gmon_io_write_32 (ofp, (unsigned int) hz))
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
perror (filename);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-01 02:37:58 +08:00
|
|
|
|
/* Now write out any necessary padding after the meaningful
|
|
|
|
|
header bits. */
|
|
|
|
|
if (padsize != 0
|
|
|
|
|
&& fwrite (pad, 1, padsize, ofp) != padsize)
|
|
|
|
|
{
|
|
|
|
|
perror (filename);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-25 04:59:04 +08:00
|
|
|
|
/* Dump the samples. */
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 15:57:31 +08:00
|
|
|
|
for (i = 0; i < histograms->num_bins; ++i)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 15:57:31 +08:00
|
|
|
|
bfd_put_16 (core_bfd, (bfd_vma) histograms->sample[i],
|
2002-02-01 16:24:16 +08:00
|
|
|
|
(bfd_byte *) &raw_bin_count[0]);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (fwrite (&raw_bin_count[0], sizeof (raw_bin_count), 1, ofp) != 1)
|
|
|
|
|
{
|
|
|
|
|
perror (filename);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-25 04:59:04 +08:00
|
|
|
|
/* Dump the normalized raw arc information. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
for (sym = symtab.base; sym < symtab.limit; ++sym)
|
|
|
|
|
{
|
|
|
|
|
for (arc = sym->cg.children; arc; arc = arc->next_child)
|
|
|
|
|
{
|
2002-02-01 02:37:58 +08:00
|
|
|
|
if (gmon_write_raw_arc (ofp, arc->parent->addr,
|
|
|
|
|
arc->child->addr, arc->count))
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
perror (filename);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
DBG (SAMPLEDEBUG,
|
|
|
|
|
printf ("[dumpsum] frompc 0x%lx selfpc 0x%lx count %lu\n",
|
1999-07-01 06:38:30 +08:00
|
|
|
|
(unsigned long) arc->parent->addr,
|
|
|
|
|
(unsigned long) arc->child->addr, arc->count));
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-03-14 11:14:56 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
fclose (ofp);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, _("%s: don't know how to deal with file format %d\n"),
|
|
|
|
|
whoami, file_format);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
}
|