2 * This file is part of ltrace.
3 * Copyright (C) 2012,2013 Petr Machata, Red Hat Inc.
4 * Copyright (C) 1998,1999,2003,2004,2008,2009 Juan Cespedes
5 * Copyright (C) 2006 Ian Wienand
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
35 /*****************************************************************************/
37 static struct dict *name_cache = NULL;
40 my_demangle(const char *function_name) {
41 #ifdef USE_CXA_DEMANGLE
42 extern char *__cxa_demangle(const char *, char *, size_t *, int *);
45 debug(DEBUG_FUNCTION, "my_demangle(name=%s)", function_name);
47 if (name_cache == NULL) {
48 name_cache = malloc(sizeof(*name_cache));
49 if (name_cache != NULL)
50 DICT_INIT(name_cache, char *, const char *,
51 dict_hash_string, dict_eq_string, NULL);
54 const char *tmp = NULL;
55 if (name_cache != NULL
56 && DICT_FIND_VAL(name_cache, &function_name, &tmp) == 0)
60 tmp = cplus_demangle(function_name,
61 DMGL_ANSI | DMGL_PARAMS);
62 #elif defined USE_CXA_DEMANGLE
64 tmp = __cxa_demangle(function_name, NULL, NULL, &status);
66 if (name_cache == NULL || tmp == NULL) {
73 const char *fn_copy = strdup(function_name);
77 if (DICT_INSERT(name_cache, &fn_copy, &tmp) < 0) {
78 free((char *)fn_copy);