Print this page
cleanup
libconv

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/sgs/gprof/common/printgprof.c
          +++ new/usr/src/cmd/sgs/gprof/common/printgprof.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 + *
       26 + * Copyright 2018 Jason King
  25   27   */
  26   28  
  27      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  28      -
  29   29  #include <ctype.h>
  30   30  #include <string.h>
  31   31  #include <sys/param.h>
  32   32  #include <stdlib.h>
  33   33  #include "conv.h"
  34   34  #include "gprof.h"
  35   35  
  36   36  void print_demangled_name(int, nltype *);
  37   37  void striped_name(char *, nltype **);
  38   38  
↓ open down ↓ 454 lines elided ↑ open up ↑
 493  493          }
 494  494  }
 495  495  
 496  496  void
 497  497  printname(nltype *selfp)
 498  498  {
 499  499          const char  *c;
 500  500          c = demangled_name(selfp);
 501  501  
 502  502          if (selfp->name != 0) {
 503      -                if (!Cflag)
 504      -                        (void) printf("%s", selfp->name);
 505      -                else
 506      -                        (void) printf("%s", c);
      503 +                (void) printf("%s", c);
 507  504  
 508  505  #ifdef DEBUG
 509  506                  if (debug & DFNDEBUG)
 510  507                          (void) printf("{%d} ", selfp->toporder);
 511  508  
 512  509                  if (debug & PROPDEBUG)
 513  510                          (void) printf("%5.2f%% ", selfp->propfraction);
 514  511  #endif /* DEBUG */
 515  512          }
 516  513  
 517  514          if (selfp->cycleno != 0)
 518  515                  (void) printf("\t<cycle %d>", selfp->cycleno);
 519  516  
 520  517          if (selfp->index != 0) {
 521  518                  if (selfp->printflag)
 522  519                          (void) printf(" [%d]", selfp->index);
 523  520                  else
 524  521                          (void) printf(" (%d)", selfp->index);
 525  522          }
      523 +
      524 +        if (c != selfp->name)
      525 +                free((void *)c);
 526  526  }
 527  527  
 528  528  void
 529  529  print_demangled_name(int n, nltype *selfp)
 530  530  {
 531      -        char *c;
      531 +        char *c = (char *)demangled_name(selfp);
 532  532          int i;
 533  533  
 534      -        c = selfp->name;
 535      -
 536      -        if (strcmp(c, demangled_name(selfp)) == 0)
      534 +        if (c == selfp->name)
 537  535                  return;
 538      -        else {
 539      -                (void) printf("\n");
 540      -                for (i = 1; i < n; i++)
 541      -                        (void) printf(" ");
 542      -                (void) printf("[%s]", selfp->name);
 543      -        }
      536 +
      537 +        (void) printf("\n");
      538 +        for (i = 1; i < n; i++)
      539 +                (void) printf(" ");
      540 +        (void) printf("[%s]", selfp->name);
      541 +
      542 +        free(c);
 544  543  }
 545  544  
 546  545  void
 547  546  sortchildren(nltype *parentp)
 548  547  {
 549  548          arctype *arcp;
 550  549          arctype *detachedp;
 551  550          arctype sorted;
 552  551          arctype *prevp;
 553  552  
↓ open down ↓ 321 lines elided ↑ open up ↑
 875  874          else {
 876  875                  striped_name(s1, npp1);
 877  876                  striped_name(s2, npp2);
 878  877                  return (strcmp(s1, s2));
 879  878          }
 880  879  }
 881  880  
 882  881  void
 883  882  striped_name(char *s, nltype **npp)
 884  883  {
 885      -        const char *d;
      884 +        const char *name, *d;
 886  885          char *c;
 887  886  
 888  887          c = (char *)s;
 889      -        d = demangled_name(*npp);
      888 +        name = d = demangled_name(*npp);
 890  889  
 891  890          while ((*d != '(') && (*d != '\0')) {
 892  891                  if (*d != ':')
 893  892                          *c++ = *d++;
 894  893                  else
 895  894                          d++;
 896  895          }
 897  896          *c = '\0';
      897 +
      898 +        if ((*npp)->name != name)
      899 +                free((void *)name);
 898  900  }
 899  901  
 900  902  /*
 901  903   * Checks if the current symbol name is the same as its neighbour and
 902  904   * returns TRUE if it is.
 903  905   */
 904  906  static bool
 905  907  does_clash(nltype **nlp, int ndx, int nnames)
 906  908  {
 907  909          /*
↓ open down ↓ 123 lines elided ↑ open up ↑
1031 1033                                  (void) sprintf(peterbuffer, "[%d]", nlp->index);
1032 1034                          else
1033 1035                                  (void) sprintf(peterbuffer, "(%d)", nlp->index);
1034 1036  
1035 1037                          if (i < nnames) {
1036 1038                                  const char *d = demangled_name(nlp);
1037 1039  
1038 1040                                  if (does_clash(namesortnlp, i, nnames)) {
1039 1041                                          (void) printf("%6.6s %d:%s\n",
1040 1042                                              peterbuffer, nlp->module->id, d);
1041      -                                } else
     1043 +                                } else {
1042 1044                                          (void) printf("%6.6s %s\n", peterbuffer,
1043 1045                                              d);
     1046 +                                }
1044 1047  
1045      -                                if (d != nlp->name)
     1048 +                                if (d != nlp->name) {
1046 1049                                          (void) printf("%6.6s   [%s]", "",
1047 1050                                              nlp->name);
     1051 +                                        free((void *)d);
     1052 +                                }
1048 1053                          } else {
1049 1054                                  (void) printf("%6.6s ", peterbuffer);
1050 1055                                  (void) sprintf(peterbuffer, "<cycle %d>",
1051 1056                                      nlp->cycleno);
1052 1057                                  (void) printf("%-33.33s", peterbuffer);
1053 1058                          }
1054 1059                  }
1055 1060                  (void) printf("\n");
1056 1061          }
1057 1062          free(namesortnlp);
1058 1063  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX