X-Git-Url: http://code.vuplus.com/gitweb/?p=vuplus_dvbapp;a=blobdiff_plain;f=lib%2Fbase%2Feerror.cpp;h=e294970cffa0bb304f258e02983788b470262a10;hp=c60d5b7bd769cbec15c274e2c5aee02c5c7b0524;hb=ca63dd3bb9114ce07ba24739325036c17ad15729;hpb=06c718113b606c22f35448e2abf298e26d5d768e diff --git a/lib/base/eerror.cpp b/lib/base/eerror.cpp index c60d5b7..e294970 100644 --- a/lib/base/eerror.cpp +++ b/lib/base/eerror.cpp @@ -1,26 +1,86 @@ #include -#include -#include -#include +#include +#include +#include +#include +#include #include #include -// #include - #ifdef MEMLEAK_CHECK AllocList *allocList; pthread_mutex_t memLock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; -#else - #include -#endif -int infatal=0; +void DumpUnfreed() +{ + AllocList::iterator i; + unsigned int totalSize = 0; + + if(!allocList) + return; + + FILE *f = fopen("/var/tmp/enigma2_mem.out", "w"); + size_t len = 1024; + char *buffer = (char*)malloc(1024); + for(i = allocList->begin(); i != allocList->end(); i++) + { + unsigned int tmp; + fprintf(f, "%s\tLINE %d\tADDRESS %p\t%d unfreed\ttype %d (btcount %d)\n", + i->second.file, i->second.line, (void*)i->second.address, i->second.size, i->second.type, i->second.btcount); + totalSize += i->second.size; + + char **bt_string = backtrace_symbols( i->second.backtrace, i->second.btcount ); + for ( tmp=0; tmp < i->second.btcount; tmp++ ) + { + if ( bt_string[tmp] ) + { + char *beg = strchr(bt_string[tmp], '('); + if ( beg ) + { + std::string tmp1(beg+1); + int pos1=tmp1.find('+'), pos2=tmp1.find(')'); + if ( pos1 != std::string::npos && pos2 != std::string::npos ) + { + std::string tmp2(tmp1.substr(pos1,(pos2-pos1))); + tmp1.erase(pos1); + if (tmp1.length()) + { + int state; + abi::__cxa_demangle(tmp1.c_str(), buffer, &len, &state); + if (!state) + fprintf(f, "%d %s%s\n", tmp, buffer,tmp2.c_str()); + else + fprintf(f, "%d %s\n", tmp, bt_string[tmp]); + } + } + } + else + fprintf(f, "%d %s\n", tmp, bt_string[tmp]); + } + } + free(bt_string); + if (i->second.btcount) + fprintf(f, "\n"); + } + free(buffer); + + fprintf(f, "-----------------------------------------------------------\n"); + fprintf(f, "Total Unfreed: %d bytes\n", totalSize); + fflush(f); +}; +#endif +SigC::Connection logConnection; Signal2 logOutput; int logOutputConsole=1; +static pthread_mutex_t DebugLock = + PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP; + +extern void bsodFatal(const char *component); + void eFatal(const char* fmt, ...) { char buf[1024]; @@ -28,19 +88,12 @@ void eFatal(const char* fmt, ...) va_start(ap, fmt); vsnprintf(buf, 1024, fmt, ap); va_end(ap); - logOutput(lvlFatal, buf); - fprintf(stderr, "FATAL: %s\n",buf ); -#if 0 - if (!infatal) { - infatal=1; - eMessageBox msg(buf, "FATAL ERROR", eMessageBox::iconError|eMessageBox::btOK); - msg.show(); - msg.exec(); + singleLock s(DebugLock); + logOutput(lvlFatal, "FATAL: " + std::string(buf) + "\n"); + fprintf(stderr, "FATAL: %s\n",buf ); } -#endif - - _exit(0); + bsodFatal("enigma2"); } #ifdef DEBUG @@ -51,7 +104,10 @@ void eDebug(const char* fmt, ...) va_start(ap, fmt); vsnprintf(buf, 1024, fmt, ap); va_end(ap); - logOutput(lvlDebug, std::string(buf) + "\n"); + if (logConnection.connected()) { + singleLock s(DebugLock); + logOutput(lvlDebug, std::string(buf) + "\n"); + } if (logOutputConsole) fprintf(stderr, "%s\n", buf); } @@ -63,7 +119,10 @@ void eDebugNoNewLine(const char* fmt, ...) va_start(ap, fmt); vsnprintf(buf, 1024, fmt, ap); va_end(ap); - logOutput(lvlDebug, buf); + if (logConnection.connected()) { + singleLock s(DebugLock); + logOutput(lvlDebug, buf); + } if (logOutputConsole) fprintf(stderr, "%s", buf); } @@ -75,8 +134,28 @@ void eWarning(const char* fmt, ...) va_start(ap, fmt); vsnprintf(buf, 1024, fmt, ap); va_end(ap); - logOutput(lvlWarning, std::string(buf) + "\n"); + if (logConnection.connected()) { + singleLock s(DebugLock); + logOutput(lvlWarning, std::string(buf) + "\n"); + } if (logOutputConsole) fprintf(stderr, "%s\n", buf); } #endif // DEBUG + +void ePythonOutput(const char *string) +{ +#ifdef DEBUG + if (logConnection.connected()) { + singleLock s(DebugLock); + logOutput(lvlWarning, string); + } + if (logOutputConsole) + fwrite(string, 1, strlen(string), stderr); +#endif +} + +void eWriteCrashdump() +{ + /* implement me */ +}