demangle_symbol.cpp

Go to the documentation of this file.
00001 
00011 #include <cstdlib>
00012 
00013 #include "config.h"
00014 
00015 #include "demangle_symbol.h"
00016 #include "demangle_java_symbol.h"
00017 #include "op_regex.h"
00018 
00019 // from libiberty
00021 #ifndef DMGL_PARAMS
00022 # define DMGL_PARAMS     (1 << 0)        
00023 #endif
00024 #ifndef DMGL_ANSI
00025 # define DMGL_ANSI       (1 << 1)        
00026 #endif
00027 
00028 extern "C" char * cplus_demangle(char const * mangled, int options);
00029 
00030 using namespace std;
00031 
00032 namespace options {
00033     extern demangle_type demangle;
00034 }
00035 
00036 string const demangle_symbol(string const & name)
00037 {
00038     if (options::demangle == dmt_none)
00039         return name;
00040 
00041     // Do not try to strip leading underscore, as this leads to many
00042     // C++ demangling failures. However we strip off a leading '.'
00043         // as generated on PPC64
00044     string const & tmp = (name[0] == '.' ? name.substr(1) : name);
00045     char * unmangled = cplus_demangle(tmp.c_str(), DMGL_PARAMS | DMGL_ANSI);
00046 
00047     if (!unmangled) {
00048         string result = demangle_java_symbol(name);
00049         if (!result.empty())
00050             return result;
00051         return name;
00052     }
00053 
00054     string result(unmangled);
00055     free(unmangled);
00056 
00057     if (options::demangle == dmt_smart) {
00058         static bool init = false;
00059         static regular_expression_replace regex;
00060         if (init == false) {
00061             setup_regex(regex, OP_DATADIR "/stl.pat");
00062             init = true;
00063         }
00064         // we don't protect against exception here, pattern must be
00065         // right and user can easily work-around by using -d
00066         regex.execute(result);
00067     }
00068 
00069     return result;
00070 }

Generated on 8 Nov 2012 for Oprofile by  doxygen 1.6.1