1 #include <lib/base/eerror.h>
2 #include <lib/base/elock.h>
13 pthread_mutex_t memLock =
14 PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
18 AllocList::iterator i;
19 unsigned int totalSize = 0;
24 FILE *f = fopen("/var/tmp/enigma2_mem.out", "w");
26 char *buffer = (char*)malloc(1024);
27 for(i = allocList->begin(); i != allocList->end(); i++)
30 fprintf(f, "%s\tLINE %d\tADDRESS %p\t%d unfreed\ttype %d (btcount %d)\n",
31 i->second.file, i->second.line, (void*)i->second.address, i->second.size, i->second.type, i->second.btcount);
32 totalSize += i->second.size;
34 char **bt_string = backtrace_symbols( i->second.backtrace, i->second.btcount );
35 for ( tmp=0; tmp < i->second.btcount; tmp++ )
39 char *beg = strchr(bt_string[tmp], '(');
42 std::string tmp1(beg+1);
43 int pos1=tmp1.find('+'), pos2=tmp1.find(')');
44 if ( pos1 != std::string::npos && pos2 != std::string::npos )
46 std::string tmp2(tmp1.substr(pos1,(pos2-pos1)));
51 abi::__cxa_demangle(tmp1.c_str(), buffer, &len, &state);
53 fprintf(f, "%d %s%s\n", tmp, buffer,tmp2.c_str());
55 fprintf(f, "%d %s\n", tmp, bt_string[tmp]);
60 fprintf(f, "%d %s\n", tmp, bt_string[tmp]);
64 if (i->second.btcount)
69 fprintf(f, "-----------------------------------------------------------\n");
70 fprintf(f, "Total Unfreed: %d bytes\n", totalSize);
75 SigC::Connection logConnection;
76 Signal2<void, int, const std::string&> logOutput;
77 int logOutputConsole=1;
79 static pthread_mutex_t DebugLock =
80 PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP;
82 extern void bsodFatal(const char *component);
84 void eFatal(const char* fmt, ...)
89 vsnprintf(buf, 1024, fmt, ap);
92 singleLock s(DebugLock);
93 logOutput(lvlFatal, "FATAL: " + std::string(buf) + "\n");
94 fprintf(stderr, "FATAL: %s\n",buf );
100 void eDebug(const char* fmt, ...)
105 vsnprintf(buf, 1024, fmt, ap);
107 if (logConnection.connected()) {
108 singleLock s(DebugLock);
109 logOutput(lvlDebug, std::string(buf) + "\n");
111 if (logOutputConsole)
112 fprintf(stderr, "%s\n", buf);
115 void eDebugNoNewLine(const char* fmt, ...)
120 vsnprintf(buf, 1024, fmt, ap);
122 if (logConnection.connected()) {
123 singleLock s(DebugLock);
124 logOutput(lvlDebug, buf);
126 if (logOutputConsole)
127 fprintf(stderr, "%s", buf);
130 void eWarning(const char* fmt, ...)
135 vsnprintf(buf, 1024, fmt, ap);
137 if (logConnection.connected()) {
138 singleLock s(DebugLock);
139 logOutput(lvlWarning, std::string(buf) + "\n");
141 if (logOutputConsole)
142 fprintf(stderr, "%s\n", buf);
146 void ePythonOutput(const char *string)
149 if (logConnection.connected()) {
150 singleLock s(DebugLock);
151 logOutput(lvlWarning, string);
153 if (logOutputConsole)
154 fwrite(string, 1, strlen(string), stderr);
158 void eWriteCrashdump()