* alpha.c (alpha_Instruction): Don't use.
[external/binutils.git] / gprof / utils.c
1 /*
2  * Copyright (c) 1983, 1998, 2001 Regents of the University of California.
3  * All rights reserved.
4  *
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.
18  */
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
26
27 /*
28  * Print name of symbol.  Return number of characters printed.
29  */
30 int
31 DEFUN (print_name_only, (self), Sym * self)
32 {
33   const char *name = self->name;
34   const char *filename;
35   char *demangled = 0;
36   char buf[PATH_MAX];
37   int size = 0;
38
39   if (name)
40     {
41       if (!bsd_style_output)
42         {
43           if (name[0] == '_' && name[1] && discard_underscores)
44             {
45               name++;
46             }
47           if (demangle)
48             {
49               demangled = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS);
50               if (demangled)
51                 {
52                   name = demangled;
53                 }
54             }
55         }
56       printf ("%s", name);
57       size = strlen (name);
58       if (line_granularity && self->file)
59         {
60           filename = self->file->name;
61           if (!print_path)
62             {
63               filename = strrchr (filename, '/');
64               if (filename)
65                 {
66                   ++filename;
67                 }
68               else
69                 {
70                   filename = self->file->name;
71                 }
72             }
73           sprintf (buf, " (%s:%d @ %lx)", filename, self->line_num,
74                    (unsigned long) self->addr);
75           printf ("%s", buf);
76           size += strlen (buf);
77         }
78       if (demangled)
79         {
80           free (demangled);
81         }
82       DBG (DFNDEBUG, printf ("{%d} ", self->cg.top_order));
83       DBG (PROPDEBUG, printf ("%4.0f%% ", 100.0 * self->cg.prop.fract));
84     }
85   return size;
86 }
87
88
89 void
90 DEFUN (print_name, (self), Sym * self)
91 {
92   print_name_only (self);
93
94   if (self->cg.cyc.num != 0)
95     {
96       printf (_(" <cycle %d>"), self->cg.cyc.num);
97     }
98   if (self->cg.index != 0)
99     {
100       if (self->cg.print_flag)
101         {
102           printf (" [%d]", self->cg.index);
103         }
104       else
105         {
106           printf (" (%d)", self->cg.index);
107         }
108     }
109 }