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 extern void bsodFatal();
79 void eFatal(const char* fmt, ...)
84 vsnprintf(buf, 1024, fmt, ap);
86 singleLock s(DebugLock);
87 logOutput(lvlFatal, buf);
88 fprintf(stderr, "FATAL: %s\n",buf );
93 void eDebug(const char* fmt, ...)
98 vsnprintf(buf, 1024, fmt, ap);
100 singleLock s(DebugLock);
101 logOutput(lvlDebug, std::string(buf) + "\n");
102 if (logOutputConsole)
103 fprintf(stderr, "%s\n", buf);
106 void eDebugNoNewLine(const char* fmt, ...)
111 vsnprintf(buf, 1024, fmt, ap);
113 singleLock s(DebugLock);
114 logOutput(lvlDebug, buf);
115 if (logOutputConsole)
116 fprintf(stderr, "%s", buf);
119 void eWarning(const char* fmt, ...)
124 vsnprintf(buf, 1024, fmt, ap);
126 singleLock s(DebugLock);
127 logOutput(lvlWarning, std::string(buf) + "\n");
128 if (logOutputConsole)
129 fprintf(stderr, "%s\n", buf);
133 void ePythonOutput(const char *string)
136 singleLock s(DebugLock);
137 logOutput(lvlWarning, string);
138 if (logOutputConsole)
139 fwrite(string, 1, strlen(string), stderr);
143 void eWriteCrashdump()