Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

/users/u3/mtikir/PMaCInstrumentor_v1601/src/DemangleWrapper.C

Go to the documentation of this file.
00001 #include <Base.h>
00002 #include <DemangleWrapper.h>
00003 #include <BinaryFile.h>
00004 
00005 #define DMGL_NO_OPTS     0              /* For readability... */
00006 #define DMGL_PARAMS      (1 << 0)       /* Include function args */
00007 #define DMGL_ANSI        (1 << 1)       /* Include const, volatile, etc */
00008 #define DMGL_JAVA        (1 << 2)       /* Demangle as Java rather than C++. */
00009 #define DMGL_VERBOSE     (1 << 3)       /* Include implementation details.  */
00010 #define DMGL_TYPES       (1 << 4)       /* Also try to demangle type encodings.  */
00011 #define DMGL_AUTO        (1 << 8)
00012 #define DMGL_GNU         (1 << 9)
00013 #define DMGL_LUCID       (1 << 10)
00014 #define DMGL_ARM         (1 << 11)
00015 #define DMGL_HP          (1 << 12)       /* For the HP aCC compiler; */
00016 #define DMGL_EDG         (1 << 13)
00017 #define DMGL_GNU_V3      (1 << 14)
00018 #define DMGL_GNAT        (1 << 15)
00019 #define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT)
00020 
00021 
00022 #ifdef USE_DEMANGLERS
00023 
00024 extern "C" char* cplus_demangle(const char *mangled, int32_t options);
00025 
00026 typedef struct {} *Name;
00027 extern "C" Name* demangle(char*, char**, uint32_t);
00028 extern "C" char* text(Name*);
00029 
00030 #endif
00031 
00032 void DemangleWrapper::init(){
00033 }
00034 
00035 
00036 void DemangleWrapper::dest(){
00037 }
00038 
00039 const char* __gnu_identifier__ = "GNU";
00040 const char* __xlc_identifier__ = "XLC";
00041 const char* __non_identifier__ = "NON";
00042 
00043 char* DemangleWrapper::demangle_combined(char* name,const char** which){
00044     if(demangled){
00045         free(demangled);
00046         demangled = NULL;
00047     }
00048 
00049 #ifdef USE_DEMANGLERS
00050 
00051     if ('\0' == name[0])
00052         return name;
00053 
00054     char* pre = name;
00055     while (*name == '.')
00056         ++name;
00057     uint32_t pre_len = name - pre;
00058 
00059     char* alloc = NULL;
00060     char* suf = strchr (name, '@');
00061     if (suf)
00062     {
00063         alloc = (char*)malloc(suf - name + 1);
00064         memcpy(alloc, name, suf - name);
00065         alloc[suf - name] = '\0';
00066         name = alloc;
00067     }
00068 
00069     if(which) *which = __non_identifier__;
00070 
00071     demangled = cplus_demangle(name,DMGL_PARAMS|DMGL_ANSI);
00072     if(!demangled){
00073         char* rest = NULL;
00074         Name* n = demangle(name,&rest,0x1f);
00075         if(n){
00076             demangled = text(n);
00077             if(which) *which = __xlc_identifier__;
00078         }
00079     } else {
00080         if(which) *which = __gnu_identifier__;
00081     }
00082 
00083     if(!demangled){
00084         if (alloc)
00085             free(alloc);
00086 
00087         return pre;
00088     }
00089 
00090     if (pre_len || suf)
00091     {
00092         uint32_t len;
00093         uint32_t suf_len;
00094         char *final;
00095 
00096         if (alloc)
00097             free(alloc);
00098 
00099         len = strlen (demangled);
00100         if (!suf)
00101             suf = demangled + len;
00102         suf_len = strlen (suf) + 1;
00103         final = (char*)malloc(pre_len + len + suf_len);
00104 
00105         memcpy (final, pre, pre_len);
00106         memcpy (final + pre_len, demangled, len);
00107         memcpy (final + pre_len + len, suf, suf_len);
00108         free(demangled);
00109         demangled = final;
00110     }
00111     return demangled;
00112 #else
00113     if(which) *which = __non_identifier__;
00114     return name;
00115 #endif
00116 }

Generated on Mon Jan 28 11:08:32 2008 for PMaCInstrumentor by doxygen 1.3.5