| 1 | /* demangle.c -- A wrapper calling libiberty cplus_demangle
|
|---|
| 2 | Copyright 2002 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Binutils.
|
|---|
| 5 |
|
|---|
| 6 | This program is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2 of the License, or
|
|---|
| 9 | (at your option) any later version.
|
|---|
| 10 |
|
|---|
| 11 | This program is distributed in the hope that it will be useful,
|
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | GNU General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with this program; if not, write to the Free Software
|
|---|
| 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|---|
| 19 | 02111-1307, USA. */
|
|---|
| 20 |
|
|---|
| 21 | #include "config.h"
|
|---|
| 22 | #include <stdlib.h>
|
|---|
| 23 | #ifdef HAVE_STRING_H
|
|---|
| 24 | #include <string.h>
|
|---|
| 25 | #else
|
|---|
| 26 | #ifdef HAVE_STRINGS_H
|
|---|
| 27 | #include <strings.h>
|
|---|
| 28 | #endif
|
|---|
| 29 | #endif
|
|---|
| 30 | #include "bfd.h"
|
|---|
| 31 | #include "libiberty.h"
|
|---|
| 32 | #include "demangle.h"
|
|---|
| 33 | #include "budemang.h"
|
|---|
| 34 |
|
|---|
| 35 | /* Wrapper around cplus_demangle. Strips leading underscores and
|
|---|
| 36 | other such chars that would otherwise confuse the demangler. */
|
|---|
| 37 |
|
|---|
| 38 | char *
|
|---|
| 39 | demangle (abfd, name)
|
|---|
| 40 | bfd *abfd;
|
|---|
| 41 | const char *name;
|
|---|
| 42 | {
|
|---|
| 43 | char *res;
|
|---|
| 44 | const char *p;
|
|---|
| 45 |
|
|---|
| 46 | if (abfd != NULL && bfd_get_symbol_leading_char (abfd) == name[0])
|
|---|
| 47 | ++name;
|
|---|
| 48 |
|
|---|
| 49 | /* This is a hack for better error reporting on XCOFF, PowerPC64-ELF
|
|---|
| 50 | or the MS PE format. These formats have a number of leading '.'s
|
|---|
| 51 | on at least some symbols, so we remove all dots to avoid
|
|---|
| 52 | confusing the demangler. */
|
|---|
| 53 | p = name;
|
|---|
| 54 | while (*p == '.')
|
|---|
| 55 | ++p;
|
|---|
| 56 |
|
|---|
| 57 | res = cplus_demangle (p, DMGL_ANSI | DMGL_PARAMS);
|
|---|
| 58 | if (res)
|
|---|
| 59 | {
|
|---|
| 60 | size_t dots = p - name;
|
|---|
| 61 |
|
|---|
| 62 | /* Now put back any stripped dots. */
|
|---|
| 63 | if (dots != 0)
|
|---|
| 64 | {
|
|---|
| 65 | size_t len = strlen (res) + 1;
|
|---|
| 66 | char *add_dots = xmalloc (len + dots);
|
|---|
| 67 |
|
|---|
| 68 | memcpy (add_dots, name, dots);
|
|---|
| 69 | memcpy (add_dots + dots, res, len);
|
|---|
| 70 | free (res);
|
|---|
| 71 | res = add_dots;
|
|---|
| 72 | }
|
|---|
| 73 | return res;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | return xstrdup (name);
|
|---|
| 77 | }
|
|---|