diff options
author | Anas Nashif <anas.nashif@intel.com> | 2012-11-13 07:28:12 -0800 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2012-11-13 07:28:12 -0800 |
commit | 59749d048d9e452f049f9151735b5256756919c3 (patch) | |
tree | 9b0935c93a3b028fd1dd35a2c632510743e7826f /demangle.c | |
download | ltrace-59749d048d9e452f049f9151735b5256756919c3.tar.gz ltrace-59749d048d9e452f049f9151735b5256756919c3.tar.bz2 ltrace-59749d048d9e452f049f9151735b5256756919c3.zip |
Imported Upstream version 0.5.3upstream/0.5.3
Diffstat (limited to 'demangle.c')
-rw-r--r-- | demangle.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/demangle.c b/demangle.c new file mode 100644 index 0000000..5825e28 --- /dev/null +++ b/demangle.c @@ -0,0 +1,44 @@ +#include "config.h" + +#include <string.h> +#include <stdlib.h> +#include <stdio.h> + +#include "common.h" + +#ifdef USE_DEMANGLE + +/*****************************************************************************/ + +static Dict *d = NULL; + +const char * +my_demangle(const char *function_name) { + const char *tmp, *fn_copy; +#if !defined HAVE_LIBIBERTY && defined HAVE_LIBSUPC__ + extern char *__cxa_demangle(const char *, char *, size_t *, int *); + int status = 0; +#endif + + debug(DEBUG_FUNCTION, "my_demangle(name=%s)", function_name); + + if (!d) + d = dict_init(dict_key2hash_string, dict_key_cmp_string); + + tmp = dict_find_entry(d, (void *)function_name); + if (!tmp) { + fn_copy = strdup(function_name); +#ifdef HAVE_LIBIBERTY + tmp = cplus_demangle(function_name, DMGL_ANSI | DMGL_PARAMS); +#elif defined HAVE_LIBSUPC__ + tmp = __cxa_demangle(function_name, NULL, NULL, &status); +#endif + if (!tmp) + tmp = fn_copy; + if (tmp) + dict_enter(d, (void *)fn_copy, (void *)tmp); + } + return tmp; +} + +#endif |