1 /* demangle.c -- A wrapper calling libiberty cplus_demangle
2 Copyright 2002, 2003, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
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.
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.
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
31 #include "libiberty.h"
35 /* Wrapper around cplus_demangle. Strips leading underscores and
36 other such chars that would otherwise confuse the demangler. */
39 demangle (bfd *abfd, const char *name)
42 const char *pre, *suf;
45 if (abfd != NULL && bfd_get_symbol_leading_char (abfd) == name[0])
48 /* This is a hack for better error reporting on XCOFF, PowerPC64-ELF
49 or the MS PE format. These formats have a number of leading '.'s
50 on at least some symbols, so we remove all dots to avoid
51 confusing the demangler. */
58 suf = strchr (name, '@');
61 alloc = xmalloc (suf - name + 1);
62 memcpy (alloc, name, suf - name);
63 alloc[suf - name] = '\0';
67 res = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS);
70 /* Now put back any suffix, or stripped dots. */
71 if (pre_len != 0 || suf != NULL)
83 suf_len = strlen (suf) + 1;
84 final = xmalloc (pre_len + len + suf_len);
86 memcpy (final, pre, pre_len);
87 memcpy (final + pre_len, res, len);
88 memcpy (final + pre_len + len, suf, suf_len);