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

*** 22,31 **** --- 22,32 ---- /* * Copyright (c) 1988 AT&T * All Rights Reserved * * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2018, Joyent, Inc. */ /* Get definitions for the relocation types supported. */ #define ELF_TARGET_ALL
*** 475,506 **** /* demangle C++ names */ static char * demangled_name(char *s) { static char *buf = NULL; ! const char *dn; size_t len; ! dn = conv_demangle_name(s); /* * If not demangled, just return the symbol name */ ! if (strcmp(s, dn) == 0) return (s); - /* - * Demangled. Format it - */ - if (buf != NULL) - free(buf); - len = strlen(dn) + strlen(s) + 4; if ((buf = malloc(len)) == NULL) return (s); ! (void) snprintf(buf, len, "%s\t[%s]", dn, s); return (buf); } /* * Print the symbol table. Input is an ELF file descriptor, a --- 476,511 ---- /* demangle C++ names */ static char * demangled_name(char *s) { static char *buf = NULL; ! size_t buflen = 0; ! char *dn; size_t len; ! dn = (char *)conv_demangle_name(s); /* * If not demangled, just return the symbol name */ ! if (dn == s) return (s); len = strlen(dn) + strlen(s) + 4; + + if (buflen < len) { + free(buf); if ((buf = malloc(len)) == NULL) return (s); + buflen = len; + } ! /* ! * Demangled. Format it ! */ ! (void) snprintf(buf, buflen, "%s\t[%s]", dn, s); ! free(dn); return (buf); } /* * Print the symbol table. Input is an ELF file descriptor, a
*** 524,534 **** if (gelf_getclass(elf_file) == ELFCLASS64) adj = 8; while (range > 0) { ! char *sym_name = (char *)0; int type, bind; int specsec; unsigned int shndx; (void) gelf_getsym(sym_data, index, &sym); --- 529,539 ---- if (gelf_getclass(elf_file) == ELFCLASS64) adj = 8; while (range > 0) { ! char *sym_name = NULL; int type, bind; int specsec; unsigned int shndx; (void) gelf_getsym(sym_data, index, &sym);