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 Signal2<void, int, const std::string&> logOutput;
76 int logOutputConsole=1;
78 static pthread_mutex_t DebugLock =
79 PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP;
81 extern void bsodFatal(const char *component);
83 void eFatal(const char* fmt, ...)
88 vsnprintf(buf, 1024, fmt, ap);
91 singleLock s(DebugLock);
92 logOutput(lvlFatal, "FATAL: " + std::string(buf) + "\n");
93 fprintf(stderr, "FATAL: %s\n",buf );
99 void eDebug(const char* fmt, ...)
104 vsnprintf(buf, 1024, fmt, ap);
106 singleLock s(DebugLock);
107 logOutput(lvlDebug, std::string(buf) + "\n");
108 if (logOutputConsole)
109 fprintf(stderr, "%s\n", buf);
112 void eDebugNoNewLine(const char* fmt, ...)
117 vsnprintf(buf, 1024, fmt, ap);
119 singleLock s(DebugLock);
120 logOutput(lvlDebug, buf);
121 if (logOutputConsole)
122 fprintf(stderr, "%s", buf);
125 void eWarning(const char* fmt, ...)
130 vsnprintf(buf, 1024, fmt, ap);
132 singleLock s(DebugLock);
133 logOutput(lvlWarning, std::string(buf) + "\n");
134 if (logOutputConsole)
135 fprintf(stderr, "%s\n", buf);
139 void ePythonOutput(const char *string)
142 singleLock s(DebugLock);
143 logOutput(lvlWarning, string);
144 if (logOutputConsole)
145 fwrite(string, 1, strlen(string), stderr);
149 void eWriteCrashdump()