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/dump/common/dump.c
          +++ new/usr/src/cmd/sgs/dump/common/dump.c
↓ open down ↓ 16 lines elided ↑ open up ↑
  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 (c) 1988 AT&T
  24   24   *        All Rights Reserved
  25   25   *
  26   26   * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
       27 + * Copyright 2018, Joyent, Inc.
  27   28   */
  28   29  
  29   30  /* Get definitions for the relocation types supported. */
  30   31  #define ELF_TARGET_ALL
  31   32  
  32   33  #include <stdio.h>
  33   34  #include <stdlib.h>
  34   35  #include <locale.h>
  35   36  #include <unistd.h>
  36   37  #include <libelf.h>
↓ open down ↓ 433 lines elided ↑ open up ↑
 470  471                  (void) printf("\n");
 471  472                  ndx++;
 472  473          }
 473  474  }
 474  475  
 475  476  /* demangle C++ names */
 476  477  static char *
 477  478  demangled_name(char *s)
 478  479  {
 479  480          static char     *buf = NULL;
 480      -        const char      *dn;
      481 +        size_t          buflen = 0;
      482 +        char            *dn;
 481  483          size_t          len;
 482  484  
 483      -        dn = conv_demangle_name(s);
      485 +        dn = (char *)conv_demangle_name(s);
 484  486  
 485  487          /*
 486  488           * If not demangled, just return the symbol name
 487  489           */
 488      -        if (strcmp(s, dn) == 0)
      490 +        if (dn == s)
 489  491                  return (s);
 490  492  
      493 +        len = strlen(dn) + strlen(s) + 4;
      494 +
      495 +        if (buflen < len) {
      496 +                free(buf);
      497 +                if ((buf = malloc(len)) == NULL)
      498 +                        return (s);
      499 +                buflen = len;
      500 +        }
      501 +
 491  502          /*
 492  503           * Demangled. Format it
 493  504           */
 494      -        if (buf != NULL)
 495      -                free(buf);
 496      -
 497      -        len = strlen(dn) + strlen(s) + 4;
 498      -        if ((buf = malloc(len)) == NULL)
 499      -                return (s);
 500      -
 501      -        (void) snprintf(buf, len, "%s\t[%s]", dn, s);
      505 +        (void) snprintf(buf, buflen, "%s\t[%s]", dn, s);
      506 +        free(dn);
 502  507          return (buf);
 503  508  }
 504  509  
 505  510  /*
 506  511   * Print the symbol table.  Input is an ELF file descriptor, a
 507  512   * pointer to the symbol table SCNTAB structure,
 508  513   * the number of symbols, a range of symbols to print,
 509  514   * an index which is the number of the
 510  515   * section in the file, and the filename.  The number of sections,
 511  516   * the range, and the index are set in
↓ open down ↓ 7 lines elided ↑ open up ↑
 519  524          int adj = 0;            /* field adjustment for elf64 */
 520  525          Elf32_Word      *symshndx = 0;
 521  526          unsigned int    nosymshndx = 0;
 522  527          Conv_inv_buf_t  inv_buf;
 523  528  
 524  529  
 525  530          if (gelf_getclass(elf_file) == ELFCLASS64)
 526  531                  adj = 8;
 527  532  
 528  533          while (range > 0) {
 529      -                char            *sym_name = (char *)0;
      534 +                char            *sym_name = NULL;
 530  535                  int             type, bind;
 531  536                  int             specsec;
 532  537                  unsigned int    shndx;
 533  538  
 534  539                  (void) gelf_getsym(sym_data, index, &sym);
 535  540                  type = (int)GELF_ST_TYPE(sym.st_info);
 536  541                  bind = (int)GELF_ST_BIND(sym.st_info);
 537  542  
 538  543                  if ((sym.st_shndx == SHN_XINDEX) &&
 539  544                      (symshndx == 0) && (nosymshndx == 0)) {
↓ open down ↓ 1592 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX