demangle.c revision f13505251e6402460f6cc7ec84e0d8ca91607b4f
1#if HAVE_CONFIG_H 2#include "config.h" 3#endif 4 5#include <string.h> 6#include <stdlib.h> 7#include <stdio.h> 8 9#include "options.h" 10#include "output.h" 11#include "demangle.h" 12 13#include "dict.h" 14 15#ifdef USE_DEMANGLE 16 17/*****************************************************************************/ 18 19static struct dict *d = NULL; 20 21const char * 22my_demangle(const char *function_name) { 23 const char *tmp, *fn_copy; 24#if !defined HAVE_LIBIBERTY && defined HAVE_LIBSUPC__ 25 extern char *__cxa_demangle(const char *, char *, size_t *, int *); 26 int status = 0; 27#endif 28 29 if (!d) 30 d = dict_init(dict_key2hash_string, dict_key_cmp_string); 31 32 tmp = dict_find_entry(d, (void *)function_name); 33 if (!tmp) { 34 fn_copy = strdup(function_name); 35#ifdef HAVE_LIBIBERTY 36 tmp = cplus_demangle(function_name, DMGL_ANSI | DMGL_PARAMS); 37#elif defined HAVE_LIBSUPC__ 38 tmp = __cxa_demangle(function_name, NULL, NULL, &status); 39#endif 40 if (!tmp) 41 tmp = fn_copy; 42 if (tmp) 43 dict_enter(d, (void *)fn_copy, (void *)tmp); 44 } 45 return tmp; 46} 47 48#endif 49