00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00033
00034 #ifndef GROOVX_RUTZ_DEMANGLE_CC_UTC20050626084020_DEFINED
00035 #define GROOVX_RUTZ_DEMANGLE_CC_UTC20050626084020_DEFINED
00036
00037 #include "rutz/demangle.h"
00038
00039 #if defined(GVX_NO_TYPENAME_MANGLING)
00040
00041 namespace
00042 {
00043 const char* demangle_impl(const char* in) { return in; }
00044 }
00045
00046 # define DEMANGLE_IMPL demangle_impl
00047
00048 #else // !defined(GVX_NO_TYPENAME_MANGLING)
00049
00050
00051
00052
00053
00054
00055 # if defined(HAVE_CXXABI_H)
00056 # include "rutz/demangle_gcc_v3.h"
00057 # define DEMANGLE_IMPL demangle_gcc_v3
00058 # elif defined(__GNUC__) && __GNUC__ < 3
00059 # include "rutz/demangle_gcc_v2.h"
00060 # define DEMANGLE_IMPL demangle_gcc_v2
00061 # elif defined(GVX_HAVE_PROG_CXXFILT)
00062 # include "rutz/demangle_cxxfilt.h"
00063 # define DEMANGLE_IMPL demangle_cxxfilt
00064 # else
00065
00066 # include "rutz/demangle_gcc_v3.h"
00067 # define DEMANGLE_IMPL demangle_gcc_v3
00068 # endif
00069 #endif // !defined(GVX_NO_TYPENAME_MANGLING)
00070
00071 #include "rutz/mutex.h"
00072 #include "rutz/trace.h"
00073
00074 #include <map>
00075 #include <pthread.h>
00076 #include <string>
00077
00078 namespace
00079 {
00080
00081
00082
00083 typedef std::map<std::string, std::string> cache_type;
00084 cache_type* g_name_cache = 0;
00085 pthread_once_t g_name_cache_init_once = PTHREAD_ONCE_INIT;
00086 pthread_mutex_t g_name_cache_mutex = PTHREAD_MUTEX_INITIALIZER;
00087
00088 void name_cache_init()
00089 {
00090 GVX_ASSERT(g_name_cache == 0);
00091 g_name_cache = new cache_type;
00092 }
00093 }
00094
00095 const char* rutz::demangled_name(const std::type_info& info)
00096 {
00097 GVX_TRACE("rutz::demangled_name");
00098
00099 pthread_once(&g_name_cache_init_once, &name_cache_init);
00100 GVX_ASSERT(g_name_cache != 0);
00101
00102 const std::string mangled = info.name();
00103
00104 GVX_MUTEX_LOCK(&g_name_cache_mutex);
00105
00106 cache_type::iterator itr = g_name_cache->find(mangled);
00107
00108 if (itr != g_name_cache->end())
00109 {
00110 return (*itr).second.c_str();
00111 }
00112
00113 const std::string demangled = DEMANGLE_IMPL(info.name());
00114
00115 std::pair<cache_type::iterator, bool> result =
00116 g_name_cache->insert(cache_type::value_type(mangled, demangled));
00117
00118 GVX_ASSERT(result.second == true);
00119
00120 return (*result.first).second.c_str();
00121 }
00122
00123 static const char __attribute__((used)) vcid_groovx_rutz_demangle_cc_utc20050626084020[] = "$Id: demangle.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00124 #endif // !GROOVX_RUTZ_DEMANGLE_CC_UTC20050626084020_DEFINED