Back to index

cell-binutils  2.17cvs20070401
utils.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1983, 1993, 2001
00003  *      The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 #include "demangle.h"
00030 #include "gprof.h"
00031 #include "search_list.h"
00032 #include "source.h"
00033 #include "symtab.h"
00034 #include "cg_arcs.h"
00035 #include "utils.h"
00036 
00037 
00038 /*
00039  * Print name of symbol.  Return number of characters printed.
00040  */
00041 int
00042 print_name_only (Sym *self)
00043 {
00044   const char *name = self->name;
00045   const char *filename;
00046   char *demangled = 0;
00047   char buf[PATH_MAX];
00048   int size = 0;
00049 
00050   if (name)
00051     {
00052       if (!bsd_style_output)
00053        {
00054          if (name[0] == '_' && name[1] && discard_underscores)
00055            {
00056              name++;
00057            }
00058          if (demangle)
00059            {
00060              demangled = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS);
00061              if (demangled)
00062               {
00063                 name = demangled;
00064               }
00065            }
00066        }
00067       printf ("%s", name);
00068       size = strlen (name);
00069       if (line_granularity && self->file)
00070        {
00071          filename = self->file->name;
00072          if (!print_path)
00073            {
00074              filename = strrchr (filename, '/');
00075              if (filename)
00076               {
00077                 ++filename;
00078               }
00079              else
00080               {
00081                 filename = self->file->name;
00082               }
00083            }
00084          sprintf (buf, " (%s:%d @ %lx)", filename, self->line_num,
00085                  (unsigned long) self->addr);
00086          printf ("%s", buf);
00087          size += strlen (buf);
00088        }
00089       if (demangled)
00090        {
00091          free (demangled);
00092        }
00093       DBG (DFNDEBUG, printf ("{%d} ", self->cg.top_order));
00094       DBG (PROPDEBUG, printf ("%4.0f%% ", 100.0 * self->cg.prop.fract));
00095     }
00096   return size;
00097 }
00098 
00099 
00100 void
00101 print_name (Sym *self)
00102 {
00103   print_name_only (self);
00104 
00105   if (self->cg.cyc.num != 0)
00106     {
00107       printf (_(" <cycle %d>"), self->cg.cyc.num);
00108     }
00109   if (self->cg.index != 0)
00110     {
00111       if (self->cg.print_flag)
00112        {
00113          printf (" [%d]", self->cg.index);
00114        }
00115       else
00116        {
00117          printf (" (%d)", self->cg.index);
00118        }
00119     }
00120 }