Print this page
6375 Add native name demangling support
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Richard Lowe <richlowe@richlowe.net>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/sgs/prof/common/prof.c
          +++ new/usr/src/cmd/sgs/prof/common/prof.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
       25 + * Copyright 2018 Jason King
  25   26   */
  26   27  
  27   28  /*      Copyright (c) 1988 AT&T */
  28   29  /*        All Rights Reserved   */
  29   30  
  30   31  /*
  31   32   *      Program profiling report generator.
  32   33   *
  33   34   *      Usage:
  34   35   *
  35      - *      prof [-ChsVz] [-a | c | n | t]  [-o  |  x]   [-g  |  l]
       36 + *      prof [-ChsVz] [-a | c | n | t]  [-o  |  x]   [-g  |  l]
  36   37   *          [-m mdata] [prog]
  37   38   *
  38   39   *      Where "prog" is the program that was profiled; "a.out" by default.
  39   40   *      Options are:
  40   41   *
  41   42   *      -n      Sort by symbol name.
  42   43   *      -t      Sort by decreasing time.
  43   44   *      -c      Sort by decreasing number of calls.
  44   45   *      -a      Sort by increasing symbol address.
  45   46   *
↓ open down ↓ 83 lines elided ↑ open up ↑
 129  130          (((ELF32_ST_TYPE(i) == STT_FUNC) ||             \
 130  131                          (ELF32_ST_TYPE(i) == STT_NOTYPE)) &&    \
 131  132                  ((ELF32_ST_BIND(i) == STB_GLOBAL) ||            \
 132  133                          (gflag && (ELF32_ST_BIND(i) == STB_LOCAL))))
 133  134  
 134  135  #define TXTSYM(s, i)    (TS1(s) && TS2(i))
 135  136  
 136  137  int gflag = 0;                  /*  replaces gmatch and gmask */
 137  138  int Cflag = 0;
 138  139  
 139      -PROF_FILE       *ldptr;                 /* For program ("a.out") file. */
      140 +PROF_FILE       *ldptr;         /* For program ("a.out") file. */
 140  141  
 141  142  FILE    *mon_iop;               /* For profile (MON_OUT) file. */
 142  143  char    *sym_fn = "a.out";      /* Default program file name. */
 143  144  char    *mon_fn = MON_OUT;      /* Default profile file name. */
 144  145                                  /* May be changed by "-m file". */
 145  146  
 146  147  long bias;      /* adjusted bias */
 147  148  long temp;      /* for bias adjust */
 148  149  
 149  150  extern void profver(void);
↓ open down ↓ 40 lines elided ↑ open up ↑
 190  191          long sl_count;          /* Count of subroutine calls */
 191  192          float sl_time;          /* Count of clock ticks in this routine, */
 192  193                                  /*              converted to secs. */
 193  194  };
 194  195  
 195  196          /* local structure for tracking synonyms in our symbol list */
 196  197  struct snymEntry {
 197  198          char    *sym_addr;      /* address which has a synonym */
 198  199          int     howMany;        /* # of synonyms for this symbol */
 199  200          int     snymReported;   /* 'was printed in a report line already'  */
 200      -                                /*      flag, */
      201 +                                /*      flag, */
 201  202                                  /*   > 0 report line printed for these syns. */
 202  203                                  /*  == 0 not printed yet. */
 203  204          long    tot_sl_count;   /* total subr calls for these snyms */
 204  205          float   tot_sl_time;    /* total clock ticks (a la sl_time) */
 205  206  };
 206  207  
 207  208  
 208  209  #define AOUTHSZ         (filhdr.f_opthdr)
 209  210  PROF_FILE       filhdr;                 /* profile file descriptor */
 210  211  Elf32_Shdr      *scnhdrp;       /* pointer to first section header */
↓ open down ↓ 1093 lines elided ↑ open up ↑
1304 1305  
1305 1306  char *format_buf;
1306 1307  #define FORMAT_BUF      "%s\n\t\t\t\t\t    [%s]"
1307 1308  
1308 1309  static char *
1309 1310  demangled_name(char *s)
1310 1311  {
1311 1312          const char *name;
1312 1313          size_t  len;
1313 1314  
1314      -        name = conv_demangle_name(s);
1315      -
1316      -        if (strcmp(name, s) == 0)
     1315 +        if ((name = conv_demangle_name(s)) == s)
1317 1316                  return (s);
1318 1317  
1319 1318          if (format_buf != NULL)
1320 1319                  free(format_buf);
1321 1320  
1322 1321          len = strlen(name) + strlen(FORMAT_BUF) + strlen(s) + 1;
1323 1322          format_buf = malloc(len);
1324 1323          if (format_buf == NULL)
1325 1324                  return (s);
1326 1325          (void) snprintf(format_buf, len, FORMAT_BUF, name, s);
     1326 +        free((void *)name);
1327 1327          return (format_buf);
1328 1328  }
1329 1329  
1330 1330  /* getname - get the name of a symbol in a permanent fashion */
1331 1331  static char *
1332 1332  getname(PROF_FILE *ldpter, PROF_SYMBOL symbol)
1333 1333  {
1334 1334          static char *strtable = NULL;   /* space for names */
1335 1335          static int sp_used = 0;         /* space used so far */
1336 1336          static int size = 0;            /* size of string table */
↓ open down ↓ 35 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX