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;
23 FILE *f = fopen("/var/tmp/enigma2_mem.out", "w");
25 char *buffer = (char*)malloc(1024);
26 for(i = allocList->begin(); i != allocList->end(); i++)
29 fprintf(f, "%s\tLINE %d\tADDRESS %p\t%d unfreed\ttype %d (btcount %d)\n",
30 i->second.file, i->second.line, (void*)i->second.address, i->second.size, i->second.type, i->second.btcount);
31 totalSize += i->second.size;
33 char **bt_string = backtrace_symbols( i->second.backtrace, i->second.btcount );
34 for ( tmp=0; tmp < i->second.btcount; tmp++ )
38 char *beg = strchr(bt_string[tmp], '(');
41 std::string tmp1(beg+1);
42 int pos1=tmp1.find('+'), pos2=tmp1.find(')');
43 if ( pos1 != std::string::npos && pos2 != std::string::npos )
45 std::string tmp2(tmp1.substr(pos1,(pos2-pos1)));
50 abi::__cxa_demangle(tmp1.c_str(), buffer, &len, &state);
52 fprintf(f, "%d %s%s\n", tmp, buffer,tmp2.c_str());
54 fprintf(f, "%d %s\n", tmp, bt_string[tmp]);
59 fprintf(f, "%d %s\n", tmp, bt_string[tmp]);
63 if (i->second.btcount)
68 fprintf(f, "-----------------------------------------------------------\n");
69 fprintf(f, "Total Unfreed: %d bytes\n", totalSize);
74 Signal2<void, int, const std::string&> logOutput;
75 int logOutputConsole=1;
77 static pthread_mutex_t DebugLock =
78 PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP;
80 extern void bsodFatal();
82 void eFatal(const char* fmt, ...)
87 vsnprintf(buf, 1024, fmt, ap);
89 singleLock s(DebugLock);
90 logOutput(lvlFatal, "FATAL: " + std::string(buf) + "\n");
91 fprintf(stderr, "FATAL: %s\n",buf );
96 void eDebug(const char* fmt, ...)
101 vsnprintf(buf, 1024, fmt, ap);
103 singleLock s(DebugLock);
104 logOutput(lvlDebug, std::string(buf) + "\n");
105 if (logOutputConsole)
106 fprintf(stderr, "%s\n", buf);
109 void eDebugNoNewLine(const char* fmt, ...)
114 vsnprintf(buf, 1024, fmt, ap);
116 singleLock s(DebugLock);
117 logOutput(lvlDebug, buf);
118 if (logOutputConsole)
119 fprintf(stderr, "%s", buf);
122 void eWarning(const char* fmt, ...)
127 vsnprintf(buf, 1024, fmt, ap);
129 singleLock s(DebugLock);
130 logOutput(lvlWarning, std::string(buf) + "\n");
131 if (logOutputConsole)
132 fprintf(stderr, "%s\n", buf);
136 void ePythonOutput(const char *string)
139 singleLock s(DebugLock);
140 logOutput(lvlWarning, string);
141 if (logOutputConsole)
142 fwrite(string, 1, strlen(string), stderr);
146 void eWriteCrashdump()