175fd0b74Schristos /*
275fd0b74Schristos * Copyright (c) 1983, 1993, 2001
375fd0b74Schristos * The Regents of the University of California. All rights reserved.
475fd0b74Schristos *
575fd0b74Schristos * Redistribution and use in source and binary forms, with or without
675fd0b74Schristos * modification, are permitted provided that the following conditions
775fd0b74Schristos * are met:
875fd0b74Schristos * 1. Redistributions of source code must retain the above copyright
975fd0b74Schristos * notice, this list of conditions and the following disclaimer.
1075fd0b74Schristos * 2. Redistributions in binary form must reproduce the above copyright
1175fd0b74Schristos * notice, this list of conditions and the following disclaimer in the
1275fd0b74Schristos * documentation and/or other materials provided with the distribution.
1375fd0b74Schristos * 3. Neither the name of the University nor the names of its contributors
1475fd0b74Schristos * may be used to endorse or promote products derived from this software
1575fd0b74Schristos * without specific prior written permission.
1675fd0b74Schristos *
1775fd0b74Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1875fd0b74Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1975fd0b74Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2075fd0b74Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2175fd0b74Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2275fd0b74Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2375fd0b74Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2475fd0b74Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2575fd0b74Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2675fd0b74Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2775fd0b74Schristos * SUCH DAMAGE.
2875fd0b74Schristos */
2975fd0b74Schristos #include "gprof.h"
3075fd0b74Schristos #include "demangle.h"
3175fd0b74Schristos #include "search_list.h"
3275fd0b74Schristos #include "source.h"
3375fd0b74Schristos #include "symtab.h"
3475fd0b74Schristos #include "cg_arcs.h"
3575fd0b74Schristos #include "utils.h"
3675fd0b74Schristos #include "corefile.h"
3775fd0b74Schristos
3875fd0b74Schristos
3975fd0b74Schristos /*
4075fd0b74Schristos * Print name of symbol. Return number of characters printed.
4175fd0b74Schristos */
4275fd0b74Schristos int
print_name_only(Sym * self)4375fd0b74Schristos print_name_only (Sym *self)
4475fd0b74Schristos {
4575fd0b74Schristos const char *name = self->name;
4675fd0b74Schristos char *demangled = 0;
4775fd0b74Schristos int size = 0;
4875fd0b74Schristos
4975fd0b74Schristos if (name)
5075fd0b74Schristos {
5175fd0b74Schristos if (!bsd_style_output && demangle)
5275fd0b74Schristos {
5375fd0b74Schristos demangled = bfd_demangle (core_bfd, name, DMGL_ANSI | DMGL_PARAMS);
5475fd0b74Schristos if (demangled)
5575fd0b74Schristos name = demangled;
5675fd0b74Schristos }
5775fd0b74Schristos printf ("%s", name);
5875fd0b74Schristos size = strlen (name);
5975fd0b74Schristos if ((line_granularity || inline_file_names) && self->file)
6075fd0b74Schristos {
61*e992f068Schristos const char *filename = self->file->name;
62*e992f068Schristos char *buf;
63*e992f068Schristos
6475fd0b74Schristos if (!print_path)
6575fd0b74Schristos {
6675fd0b74Schristos filename = strrchr (filename, '/');
6775fd0b74Schristos if (filename)
6875fd0b74Schristos {
6975fd0b74Schristos ++filename;
7075fd0b74Schristos }
7175fd0b74Schristos else
7275fd0b74Schristos {
7375fd0b74Schristos filename = self->file->name;
7475fd0b74Schristos }
7575fd0b74Schristos }
76*e992f068Schristos buf = xmalloc (strlen (filename) + 8 + 20 + 16);
7775fd0b74Schristos if (line_granularity)
7875fd0b74Schristos {
7975fd0b74Schristos sprintf (buf, " (%s:%d @ %lx)", filename, self->line_num,
8075fd0b74Schristos (unsigned long) self->addr);
8175fd0b74Schristos }
8275fd0b74Schristos else
8375fd0b74Schristos {
8475fd0b74Schristos sprintf (buf, " (%s:%d)", filename, self->line_num);
8575fd0b74Schristos }
8675fd0b74Schristos printf ("%s", buf);
8775fd0b74Schristos size += strlen (buf);
88*e992f068Schristos free (buf);
8975fd0b74Schristos }
9075fd0b74Schristos free (demangled);
9175fd0b74Schristos DBG (DFNDEBUG, printf ("{%d} ", self->cg.top_order));
9275fd0b74Schristos DBG (PROPDEBUG, printf ("%4.0f%% ", 100.0 * self->cg.prop.fract));
9375fd0b74Schristos }
9475fd0b74Schristos return size;
9575fd0b74Schristos }
9675fd0b74Schristos
9775fd0b74Schristos
9875fd0b74Schristos void
print_name(Sym * self)9975fd0b74Schristos print_name (Sym *self)
10075fd0b74Schristos {
10175fd0b74Schristos print_name_only (self);
10275fd0b74Schristos
10375fd0b74Schristos if (self->cg.cyc.num != 0)
10475fd0b74Schristos {
10575fd0b74Schristos printf (_(" <cycle %d>"), self->cg.cyc.num);
10675fd0b74Schristos }
10775fd0b74Schristos if (self->cg.index != 0)
10875fd0b74Schristos {
10975fd0b74Schristos if (self->cg.print_flag)
11075fd0b74Schristos {
11175fd0b74Schristos printf (" [%d]", self->cg.index);
11275fd0b74Schristos }
11375fd0b74Schristos else
11475fd0b74Schristos {
11575fd0b74Schristos printf (" (%d)", self->cg.index);
11675fd0b74Schristos }
11775fd0b74Schristos }
11875fd0b74Schristos }
119