2002-02-18 Daniel Jacobowitz <drow@mvista.com>
[binutils.git] / gprof / utils.c
blobb18216fe960d3bfffbc4fd44492e1e9e66724ae7
1 /*
2 * Copyright (c) 1983, 1998, 2001 Regents of the University of California.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that: (1) source distributions retain this entire copyright
7 * notice and comment, and (2) distributions including binaries display
8 * the following acknowledgement: ``This product includes software
9 * developed by the University of California, Berkeley and its contributors''
10 * in the documentation or other materials provided with the distribution
11 * and in all advertising materials mentioning features or use of this
12 * software. Neither the name of the University nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 #include "demangle.h"
20 #include "gprof.h"
21 #include "search_list.h"
22 #include "source.h"
23 #include "symtab.h"
24 #include "cg_arcs.h"
25 #include "utils.h"
29 * Print name of symbol. Return number of characters printed.
31 int
32 print_name_only (self)
33 Sym *self;
35 const char *name = self->name;
36 const char *filename;
37 char *demangled = 0;
38 char buf[PATH_MAX];
39 int size = 0;
41 if (name)
43 if (!bsd_style_output)
45 if (name[0] == '_' && name[1] && discard_underscores)
47 name++;
49 if (demangle)
51 demangled = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS);
52 if (demangled)
54 name = demangled;
58 printf ("%s", name);
59 size = strlen (name);
60 if (line_granularity && self->file)
62 filename = self->file->name;
63 if (!print_path)
65 filename = strrchr (filename, '/');
66 if (filename)
68 ++filename;
70 else
72 filename = self->file->name;
75 sprintf (buf, " (%s:%d @ %lx)", filename, self->line_num,
76 (unsigned long) self->addr);
77 printf ("%s", buf);
78 size += strlen (buf);
80 if (demangled)
82 free (demangled);
84 DBG (DFNDEBUG, printf ("{%d} ", self->cg.top_order));
85 DBG (PROPDEBUG, printf ("%4.0f%% ", 100.0 * self->cg.prop.fract));
87 return size;
91 void
92 print_name (self)
93 Sym *self;
95 print_name_only (self);
97 if (self->cg.cyc.num != 0)
99 printf (_(" <cycle %d>"), self->cg.cyc.num);
101 if (self->cg.index != 0)
103 if (self->cg.print_flag)
105 printf (" [%d]", self->cg.index);
107 else
109 printf (" (%d)", self->cg.index);