1 #include <lib/base/eerror.h>
2 #include <lib/base/elock.h>
12 pthread_mutex_t memLock =
13 PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
17 AllocList::iterator i;
18 unsigned int totalSize = 0;
24 char *buffer = (char*)malloc(1024);
25 for(i = allocList->begin(); i != allocList->end(); i++)
28 printf("%s\tLINE %d\tADDRESS %p\t%d unfreed\ttype %d (btcount %d)\n",
29 i->second.file, i->second.line, (void*)i->second.address, i->second.size, i->second.type, i->second.btcount);
30 totalSize += i->second.size;
31 char **bt_string = backtrace_symbols( i->second.backtrace, i->second.btcount );
32 for ( tmp=0; tmp < i->second.btcount; tmp++ )
36 char *beg = strchr(bt_string[tmp], '(');
39 std::string tmp1(beg+1);
40 int pos1=tmp1.find('+'), pos2=tmp1.find(')');
41 if ( pos1 != std::string::npos && pos2 != std::string::npos )
43 std::string tmp2(tmp1.substr(pos1,(pos2-pos1)));
48 abi::__cxa_demangle(tmp1.c_str(), buffer, &len, &state);
50 printf("%d %s%s\n", tmp, buffer,tmp2.c_str());
52 printf("%d %s\n", tmp, bt_string[tmp]);
57 printf("%d %s\n", tmp, bt_string[tmp]);
65 printf("-----------------------------------------------------------\n");
66 printf("Total Unfreed: %d bytes\n", totalSize);
71 Signal2<void, int, const std::string&> logOutput;
72 int logOutputConsole=1;
74 static pthread_mutex_t DebugLock =
75 PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP;
77 void eFatal(const char* fmt, ...)
82 vsnprintf(buf, 1024, fmt, ap);
84 singleLock s(DebugLock);
85 logOutput(lvlFatal, buf);
86 fprintf(stderr, "FATAL: %s\n",buf );
91 void eDebug(const char* fmt, ...)
96 vsnprintf(buf, 1024, fmt, ap);
98 singleLock s(DebugLock);
99 logOutput(lvlDebug, std::string(buf) + "\n");
100 if (logOutputConsole)
101 fprintf(stderr, "%s\n", buf);
104 void eDebugNoNewLine(const char* fmt, ...)
109 vsnprintf(buf, 1024, fmt, ap);
111 singleLock s(DebugLock);
112 logOutput(lvlDebug, buf);
113 if (logOutputConsole)
114 fprintf(stderr, "%s", buf);
117 void eWarning(const char* fmt, ...)
122 vsnprintf(buf, 1024, fmt, ap);
124 singleLock s(DebugLock);
125 logOutput(lvlWarning, std::string(buf) + "\n");
126 if (logOutputConsole)
127 fprintf(stderr, "%s\n", buf);
131 void ePythonOutput(const char *string)
134 singleLock s(DebugLock);
135 logOutput(lvlWarning, string);
136 if (logOutputConsole)
137 fwrite(string, 1, strlen(string), stderr);
141 void eWriteCrashdump()