12a6b7db3Sskrll /*
22a6b7db3Sskrll * Copyright (c) 1983, 1993, 2001
32a6b7db3Sskrll * The Regents of the University of California. All rights reserved.
42a6b7db3Sskrll *
52a6b7db3Sskrll * Redistribution and use in source and binary forms, with or without
62a6b7db3Sskrll * modification, are permitted provided that the following conditions
72a6b7db3Sskrll * are met:
82a6b7db3Sskrll * 1. Redistributions of source code must retain the above copyright
92a6b7db3Sskrll * notice, this list of conditions and the following disclaimer.
102a6b7db3Sskrll * 2. Redistributions in binary form must reproduce the above copyright
112a6b7db3Sskrll * notice, this list of conditions and the following disclaimer in the
122a6b7db3Sskrll * documentation and/or other materials provided with the distribution.
132a6b7db3Sskrll * 3. Neither the name of the University nor the names of its contributors
142a6b7db3Sskrll * may be used to endorse or promote products derived from this software
152a6b7db3Sskrll * without specific prior written permission.
162a6b7db3Sskrll *
172a6b7db3Sskrll * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
182a6b7db3Sskrll * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
192a6b7db3Sskrll * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
202a6b7db3Sskrll * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
212a6b7db3Sskrll * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
222a6b7db3Sskrll * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
232a6b7db3Sskrll * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
242a6b7db3Sskrll * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
252a6b7db3Sskrll * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
262a6b7db3Sskrll * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
272a6b7db3Sskrll * SUCH DAMAGE.
282a6b7db3Sskrll */
292a6b7db3Sskrll #include "gprof.h"
302a6b7db3Sskrll #include "demangle.h"
312a6b7db3Sskrll #include "search_list.h"
322a6b7db3Sskrll #include "source.h"
332a6b7db3Sskrll #include "symtab.h"
342a6b7db3Sskrll #include "cg_arcs.h"
352a6b7db3Sskrll #include "utils.h"
362a6b7db3Sskrll #include "corefile.h"
372a6b7db3Sskrll
382a6b7db3Sskrll
392a6b7db3Sskrll /*
402a6b7db3Sskrll * Print name of symbol. Return number of characters printed.
412a6b7db3Sskrll */
422a6b7db3Sskrll int
print_name_only(Sym * self)432a6b7db3Sskrll print_name_only (Sym *self)
442a6b7db3Sskrll {
452a6b7db3Sskrll const char *name = self->name;
462a6b7db3Sskrll char *demangled = 0;
472a6b7db3Sskrll int size = 0;
482a6b7db3Sskrll
492a6b7db3Sskrll if (name)
502a6b7db3Sskrll {
512a6b7db3Sskrll if (!bsd_style_output && demangle)
522a6b7db3Sskrll {
532a6b7db3Sskrll demangled = bfd_demangle (core_bfd, name, DMGL_ANSI | DMGL_PARAMS);
542a6b7db3Sskrll if (demangled)
552a6b7db3Sskrll name = demangled;
562a6b7db3Sskrll }
572a6b7db3Sskrll printf ("%s", name);
582a6b7db3Sskrll size = strlen (name);
595ba6b03cSchristos if ((line_granularity || inline_file_names) && self->file)
602a6b7db3Sskrll {
61*f22f0ef4Schristos const char *filename = self->file->name;
62*f22f0ef4Schristos char *buf;
63*f22f0ef4Schristos
642a6b7db3Sskrll if (!print_path)
652a6b7db3Sskrll {
662a6b7db3Sskrll filename = strrchr (filename, '/');
672a6b7db3Sskrll if (filename)
682a6b7db3Sskrll {
692a6b7db3Sskrll ++filename;
702a6b7db3Sskrll }
712a6b7db3Sskrll else
722a6b7db3Sskrll {
732a6b7db3Sskrll filename = self->file->name;
742a6b7db3Sskrll }
752a6b7db3Sskrll }
76*f22f0ef4Schristos buf = xmalloc (strlen (filename) + 8 + 20 + 16);
775ba6b03cSchristos if (line_granularity)
785ba6b03cSchristos {
792a6b7db3Sskrll sprintf (buf, " (%s:%d @ %lx)", filename, self->line_num,
802a6b7db3Sskrll (unsigned long) self->addr);
815ba6b03cSchristos }
825ba6b03cSchristos else
835ba6b03cSchristos {
845ba6b03cSchristos sprintf (buf, " (%s:%d)", filename, self->line_num);
855ba6b03cSchristos }
862a6b7db3Sskrll printf ("%s", buf);
872a6b7db3Sskrll size += strlen (buf);
88*f22f0ef4Schristos free (buf);
892a6b7db3Sskrll }
902a6b7db3Sskrll free (demangled);
912a6b7db3Sskrll DBG (DFNDEBUG, printf ("{%d} ", self->cg.top_order));
922a6b7db3Sskrll DBG (PROPDEBUG, printf ("%4.0f%% ", 100.0 * self->cg.prop.fract));
932a6b7db3Sskrll }
942a6b7db3Sskrll return size;
952a6b7db3Sskrll }
962a6b7db3Sskrll
972a6b7db3Sskrll
982a6b7db3Sskrll void
print_name(Sym * self)992a6b7db3Sskrll print_name (Sym *self)
1002a6b7db3Sskrll {
1012a6b7db3Sskrll print_name_only (self);
1022a6b7db3Sskrll
1032a6b7db3Sskrll if (self->cg.cyc.num != 0)
1042a6b7db3Sskrll {
1052a6b7db3Sskrll printf (_(" <cycle %d>"), self->cg.cyc.num);
1062a6b7db3Sskrll }
1072a6b7db3Sskrll if (self->cg.index != 0)
1082a6b7db3Sskrll {
1092a6b7db3Sskrll if (self->cg.print_flag)
1102a6b7db3Sskrll {
1112a6b7db3Sskrll printf (" [%d]", self->cg.index);
1122a6b7db3Sskrll }
1132a6b7db3Sskrll else
1142a6b7db3Sskrll {
1152a6b7db3Sskrll printf (" (%d)", self->cg.index);
1162a6b7db3Sskrll }
1172a6b7db3Sskrll }
1182a6b7db3Sskrll }
119