demangle.c revision 8d1b92ba755f6d6229f5e230fc43d958b13836f8
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 "common.h" 10 11#ifdef USE_DEMANGLE 12 13/*****************************************************************************/ 14 15static Dict *d = NULL; 16 17const char * 18my_demangle(const char *function_name) { 19 const char *tmp, *fn_copy; 20#if !defined HAVE_LIBIBERTY && defined HAVE_LIBSUPC__ 21 extern char *__cxa_demangle(const char *, char *, size_t *, int *); 22 int status = 0; 23#endif 24 25 debug(DEBUG_FUNCTION, "my_demangle(name=%s)", function_name); 26 27 if (!d) 28 d = dict_init(dict_key2hash_string, dict_key_cmp_string); 29 30 tmp = dict_find_entry(d, (void *)function_name); 31 if (!tmp) { 32 fn_copy = strdup(function_name); 33#ifdef HAVE_LIBIBERTY 34 tmp = cplus_demangle(function_name, DMGL_ANSI | DMGL_PARAMS); 35#elif defined HAVE_LIBSUPC__ 36 tmp = __cxa_demangle(function_name, NULL, NULL, &status); 37#endif 38 if (!tmp) 39 tmp = fn_copy; 40 if (tmp) 41 dict_enter(d, (void *)fn_copy, (void *)tmp); 42 } 43 return tmp; 44} 45 46#endif 47