aboutsummaryrefslogtreecommitdiff
path: root/binutils/budemang.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2002-07-02 04:21:25 +0000
committerAlan Modra <amodra@gmail.com>2002-07-02 04:21:25 +0000
commita6637ec0ed383a4658dfddbf625dee74af000f06 (patch)
tree2ad7332d153a8e7ab118192f27b1a9557dcad961 /binutils/budemang.c
parent793011ca4e1df774bacdbb1bd731d77779c6d9c0 (diff)
downloadgdb-a6637ec0ed383a4658dfddbf625dee74af000f06.zip
gdb-a6637ec0ed383a4658dfddbf625dee74af000f06.tar.gz
gdb-a6637ec0ed383a4658dfddbf625dee74af000f06.tar.bz2
* budemang.c: New file, "demangle" function.
* budemang.h: New file. * addr2line.c (translate_addresses): Use "demangle". * nm.c (print_symname): Likewise. * objdump.c (objdump_print_symname): Likewise. (dump_symbols): Likewise. Also, don't use bfd_asymbol_name macro here since that obfuscates. * rdcoff.c: Don't #include demangle.h. * Makefile.am (CFILES): Add budemang.c, emul_aix.c, emul_vanilla.c. Remove emul_$(EMULATION).c. Sort. (HFILES): Add budemang.h. Sort. (nm_new_SOURCES, objdump_SOURCES, addr2line_SOURCES): Add budemang.c. Run "make dep-am". * Makefile.in: Regenerate. * po/POTFILES.in: Regenerate.
Diffstat (limited to 'binutils/budemang.c')
-rw-r--r--binutils/budemang.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/binutils/budemang.c b/binutils/budemang.c
new file mode 100644
index 0000000..7e0b612
--- /dev/null
+++ b/binutils/budemang.c
@@ -0,0 +1,69 @@
+/* demangle.c -- A wrapper calling libiberty cplus_demangle
+ Copyright 2002 Free Software Foundation, Inc.
+
+ This file is part of GNU Binutils.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA. */
+
+#include <stdlib.h>
+#include "bfd.h"
+#include "libiberty.h"
+#include "demangle.h"
+#include "budemang.h"
+
+/* Wrapper around cplus_demangle. Strips leading underscores and
+ other such chars that would otherwise confuse the demangler. */
+
+char *
+demangle (abfd, name)
+ bfd *abfd;
+ const char *name;
+{
+ char *res;
+ const char *p;
+
+ if (abfd != NULL && bfd_get_symbol_leading_char (abfd) == 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);
+}