2000-07-27 03:59:35 +08:00
|
|
|
|
/* bb_exit_func.c - dumps all the basic-block statistics linked into
|
|
|
|
|
the bb_head chain to .d files.
|
|
|
|
|
|
2018-01-03 13:17:27 +08:00
|
|
|
|
Copyright (C) 2000-2018 Free Software Foundation, Inc.
|
2000-07-27 03:59:35 +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
|
2007-07-06 18:40:34 +08:00
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
2000-07-27 03:59:35 +08:00
|
|
|
|
(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-27 03:59:35 +08:00
|
|
|
|
|
|
|
|
|
This code was contributed by:
|
|
|
|
|
|
|
|
|
|
David Mosberger-Tang <David.Mosberger@acm.org> */
|
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <strings.h>
|
|
|
|
|
#include "bfd.h"
|
|
|
|
|
#include "gmon_out.h"
|
|
|
|
|
|
|
|
|
|
/* structure emitted by -a */
|
2001-03-14 11:14:56 +08:00
|
|
|
|
struct bb
|
|
|
|
|
{
|
|
|
|
|
long zero_word;
|
|
|
|
|
const char *filename;
|
|
|
|
|
long *counts;
|
|
|
|
|
long ncounts;
|
|
|
|
|
struct bb *next;
|
|
|
|
|
const unsigned long *addresses;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
};
|
|
|
|
|
|
2001-03-14 11:14:56 +08:00
|
|
|
|
struct bb *__bb_head = (struct bb *) 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
|
|
|
|
__bb_exit_func ()
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2001-03-14 11:14:56 +08:00
|
|
|
|
const int version = GMON_VERSION;
|
|
|
|
|
struct gmon_hdr ghdr;
|
|
|
|
|
struct bb *ptr;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
/* GEN_GMON_CNT_FILE should be defined on systems with mcleanup()
|
|
|
|
|
functions that do not write basic-block to gmon.out. In such
|
|
|
|
|
cases profiling with "-pg -a" would result in a gmon.out file
|
|
|
|
|
without basic-block info (because the file written here would be
|
|
|
|
|
overwritten. Thus, a separate file is generated instead. The
|
|
|
|
|
two files can easily be combined by specifying them on gprof's
|
|
|
|
|
command line (and possibly generating a gmon.sum file with "gprof
|
|
|
|
|
-s"). */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
#ifndef GEN_GMON_CNT_FILE
|
|
|
|
|
# define OUT_NAME "gmon.out"
|
|
|
|
|
#else
|
|
|
|
|
# define OUT_NAME "gmon.cnt"
|
|
|
|
|
#endif
|
2001-03-14 11:14:56 +08:00
|
|
|
|
fp = fopen (OUT_NAME, "wb");
|
|
|
|
|
if (!fp)
|
|
|
|
|
{
|
|
|
|
|
perror (OUT_NAME);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
memcpy (&ghdr.cookie[0], GMON_MAGIC, 4);
|
|
|
|
|
memcpy (&ghdr.version, &version, sizeof (version));
|
|
|
|
|
fwrite (&ghdr, sizeof (ghdr), 1, fp);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2001-03-14 11:14:56 +08:00
|
|
|
|
for (ptr = __bb_head; ptr != 0; ptr = ptr->next)
|
|
|
|
|
{
|
|
|
|
|
u_int ncounts = ptr->ncounts;
|
|
|
|
|
u_char tag;
|
|
|
|
|
u_int i;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2001-03-14 11:14:56 +08:00
|
|
|
|
tag = GMON_TAG_BB_COUNT;
|
|
|
|
|
fwrite (&tag, sizeof (tag), 1, fp);
|
|
|
|
|
fwrite (&ncounts, sizeof (ncounts), 1, fp);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2001-03-14 11:14:56 +08:00
|
|
|
|
for (i = 0; i < ncounts; ++i)
|
|
|
|
|
{
|
|
|
|
|
fwrite (&ptr->addresses[i], sizeof (ptr->addresses[0]), 1, fp);
|
|
|
|
|
fwrite (&ptr->counts[i], sizeof (ptr->counts[0]), 1, fp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fclose (fp);
|
|
|
|
|
}
|