Lots of changes from David Mosberger-Tang; see ChangeLog and NOTES for details:
[deliverable/binutils-gdb.git] / gprof / utils.c
1 /*
2 * Copyright (c) 1983 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 "cg_arcs.h"
22 #include "symtab.h"
23
24
25 /*
26 * Print name of symbol. Return number of characters printed.
27 */
28 int
29 DEFUN(print_name_only, (self), Sym *self)
30 {
31 const char *name = self->name;
32 const char *filename;
33 char *demangled = 0;
34 char buf[PATH_MAX];
35 int size = 0;
36
37 if (name) {
38 if (!bsd_style_output) {
39 if (name[0] == '_' && name[1] && discard_underscores) {
40 name++;
41 } /* if */
42 demangled = cplus_demangle(name, DMGL_ANSI|DMGL_PARAMS);
43 if (demangled) {
44 name = demangled;
45 } /* if */
46 } /* if */
47 printf("%s", name);
48 size = strlen(name);
49 if (line_granularity && self->file) {
50 filename = self->file->name;
51 if (!print_path) {
52 filename = strrchr(filename, '/');
53 if (filename) {
54 ++filename;
55 } else {
56 filename = self->file->name;
57 } /* if */
58 } /* if */
59 sprintf(buf, " (%s:%d)", filename, self->line_num);
60 printf(buf);
61 size += strlen(buf);
62 } /* if */
63 if (demangled) {
64 free(demangled);
65 } /* if */
66 DBG(DFNDEBUG, printf("{%d} ", self->cg.top_order));
67 DBG(PROPDEBUG, printf("%4.0f%% ", 100.0 * self->cg.prop.fract));
68 } /* if */
69 return size;
70 } /* print_name_only */
71
72
73 void
74 DEFUN(print_name, (self), Sym *self)
75 {
76 print_name_only(self);
77
78 if (self->cg.cyc.num != 0) {
79 printf(" <cycle %d>", self->cg.cyc.num);
80 } /* if */
81 if (self->cg.index != 0) {
82 if (self->cg.print_flag) {
83 printf(" [%d]", self->cg.index);
84 } else {
85 printf(" (%d)", self->cg.index);
86 } /* if */
87 } /* if */
88 } /* print_name */
89
90 /*** end of utils.c ***/
This page took 0.031628 seconds and 5 git commands to generate.