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(const char *component);
82 void eFatal(const char* fmt, ...)
87 vsnprintf(buf, 1024, fmt, ap);
90 singleLock s(DebugLock);
91 logOutput(lvlFatal, "FATAL: " + std::string(buf) + "\n");
92 fprintf(stderr, "FATAL: %s\n",buf );
98 void eDebug(const char* fmt, ...)
103 vsnprintf(buf, 1024, fmt, ap);
105 singleLock s(DebugLock);
106 logOutput(lvlDebug, std::string(buf) + "\n");
107 if (logOutputConsole)
108 fprintf(stderr, "%s\n", buf);
111 void eDebugNoNewLine(const char* fmt, ...)
116 vsnprintf(buf, 1024, fmt, ap);
118 singleLock s(DebugLock);
119 logOutput(lvlDebug, buf);
120 if (logOutputConsole)
121 fprintf(stderr, "%s", buf);
124 void eWarning(const char* fmt, ...)
129 vsnprintf(buf, 1024, fmt, ap);
131 singleLock s(DebugLock);
132 logOutput(lvlWarning, std::string(buf) + "\n");
133 if (logOutputConsole)
134 fprintf(stderr, "%s\n", buf);
138 void ePythonOutput(const char *string)
141 singleLock s(DebugLock);
142 logOutput(lvlWarning, string);
143 if (logOutputConsole)
144 fwrite(string, 1, strlen(string), stderr);
148 void eWriteCrashdump()