00001
00002
00003 #ifndef _GSYMLOOKUP_H_
00004 #define _GSYMLOOKUP_H_
00005
00006 #include "execinfo.h"
00007 #include "GProcess.h"
00008
00010 class GSymLookup
00011 {
00012 public:
00013 #if __LP64__
00014 typedef long int Addr;
00015 #else
00016 typedef int Addr;
00017 #endif
00018
00019 GSymLookup()
00020 {
00021 }
00022
00023 ~GSymLookup()
00024 {
00025 }
00026
00027 bool GetStatus()
00028 {
00029 return true;
00030 }
00031
00034 bool Lookup
00035 (
00037 char *buf,
00039 int buflen,
00041 Addr *Ip,
00043 int IpLen
00044 )
00045 {
00046 void *ip = (void*) Ip;
00047 char **Sym = backtrace_symbols((void* const*)&ip, IpLen);
00048 if (!Sym)
00049 return false;
00050
00051 for (int i=0; Sym[i] && i<IpLen; i++)
00052 {
00053 char *s = strrchr(Sym[i], '('), *e;
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 {
00091 int CopyLen = strlen(Sym[i]);
00092 strsafecpy(buf, Sym[i], buflen);
00093 buflen -= CopyLen;
00094 buf += CopyLen;
00095 }
00096
00097 if (buflen > 1)
00098 {
00099 *buf++ = '\n';
00100 *buf = 0;
00101 }
00102 }
00103
00104 free(Sym);
00105 return true;
00106 }
00107
00109 int BackTrace(int Epb, int Eip, Addr *addr, int len)
00110 {
00111 return backtrace((void**)addr, len);
00112 }
00113 };
00114
00115 #endif