From: Alan Modra Date: Tue, 2 Jul 2002 04:21:57 +0000 (+0000) Subject: * ldmisc.c (demangle): Move so that it doesn't intrude between X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b7b482a3f590cab2512787437ce5c77452bd8e48;p=binutils-gdb.git * ldmisc.c (demangle): Move so that it doesn't intrude between vfinfo comment and body. Add comment. --- diff --git a/ld/ChangeLog b/ld/ChangeLog index 0b91fb9d500..ef7323f6c26 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,8 @@ +2002-07-02 Alan Modra + + * ldmisc.c (demangle): Move so that it doesn't intrude between + vfinfo comment and body. Add comment. + 2002-07-01 John David Anglin * emulparams/vax.sh (OUTPUT_FORMAT): Use a.out-vax-bsd format. diff --git a/ld/ldmisc.c b/ld/ldmisc.c index b24678e917e..2869ba9233c 100644 --- a/ld/ldmisc.c +++ b/ld/ldmisc.c @@ -65,46 +65,6 @@ static void vfinfo PARAMS ((FILE *, const char *, va_list)); %u integer, like printf */ -char * -demangle (string) - const char *string; -{ - char *res; - const char *p; - - if (output_bfd != NULL - && bfd_get_symbol_leading_char (output_bfd) == string[0]) - ++string; - - /* This is a hack for better error reporting on XCOFF, PowerPC64-ELF - or the MS PE format. These formats have a number of leading '.'s - on at least some symbols, so we remove all dots to avoid - confusing the demangler. */ - p = string; - while (*p == '.') - ++p; - - res = cplus_demangle (p, DMGL_ANSI | DMGL_PARAMS); - if (res) - { - size_t dots = p - string; - - /* Now put back any stripped dots. */ - if (dots != 0) - { - size_t len = strlen (res) + 1; - char *add_dots = xmalloc (len + dots); - - memcpy (add_dots, string, dots); - memcpy (add_dots + dots, res, len); - free (res); - res = add_dots; - } - return res; - } - return xstrdup (string); -} - static void vfinfo (fp, fmt, arg) FILE *fp; @@ -425,6 +385,49 @@ vfinfo (fp, fmt, arg) xexit (1); } +/* Wrapper around cplus_demangle. Strips leading underscores and + other such chars that would otherwise confuse the demangler. */ + +char * +demangle (name) + const char *name; +{ + char *res; + const char *p; + + if (output_bfd != NULL + && bfd_get_symbol_leading_char (output_bfd) == name[0]) + ++name; + + /* This is a hack for better error reporting on XCOFF, PowerPC64-ELF + or the MS PE format. These formats have a number of leading '.'s + on at least some symbols, so we remove all dots to avoid + confusing the demangler. */ + p = name; + while (*p == '.') + ++p; + + res = cplus_demangle (p, DMGL_ANSI | DMGL_PARAMS); + if (res) + { + size_t dots = p - name; + + /* Now put back any stripped dots. */ + if (dots != 0) + { + size_t len = strlen (res) + 1; + char *add_dots = xmalloc (len + dots); + + memcpy (add_dots, name, dots); + memcpy (add_dots + dots, res, len); + free (res); + res = add_dots; + } + return res; + } + return xstrdup (name); +} + /* Format info message and print on stdout. */ /* (You would think this should be called just "info", but then you