3 #include <asm/ptrace.h>
5 #include <lib/base/eerror.h>
6 #include <lib/base/smartptr.h>
7 #include <lib/gdi/grc.h>
8 #include <lib/gdi/gfbdc.h>
10 #include <lib/gdi/sdl.h>
15 /************************************************/
17 #define CRASH_EMAILADDR "crashlog@dream-multimedia-tv.de"
19 #define RINGBUFFER_SIZE 16384
20 static char ringbuffer[RINGBUFFER_SIZE];
21 static int ringbuffer_head;
23 static void addToLogbuffer(const char *data, int len)
27 int remaining = RINGBUFFER_SIZE - ringbuffer_head;
32 memcpy(ringbuffer + ringbuffer_head, data, remaining);
35 ringbuffer_head += remaining;
36 if (ringbuffer_head >= RINGBUFFER_SIZE)
41 static std::string getLogBuffer()
43 int begin = ringbuffer_head;
44 while (ringbuffer[begin] == 0)
47 if (begin == RINGBUFFER_SIZE)
49 if (begin == ringbuffer_head)
52 if (begin < ringbuffer_head)
53 return std::string(ringbuffer + begin, ringbuffer_head - begin);
56 return std::string(ringbuffer + begin, RINGBUFFER_SIZE - begin) + std::string(ringbuffer, ringbuffer_head);
60 static void addToLogbuffer(int level, const std::string &log)
62 addToLogbuffer(log.c_str(), log.size());
66 extern std::string getLogBuffer();
71 sprintf(logfile, "/media/hdd/enigma2_crash_%u.log", (unsigned int)time(0));
72 FILE *f = fopen(logfile, "wb");
74 std::string lines = getLogBuffer();
79 fprintf(f, "enigma2 crashed on %s", ctime(&t));
80 #ifdef ENIGMA2_CHECKOUT_TAG
81 fprintf(f, "enigma2 CVS TAG: " ENIGMA2_CHECKOUT_TAG "\n");
83 fprintf(f, "enigma2 compiled on " __DATE__ "\n");
85 #ifdef ENIGMA2_CHECKOUT_ROOT
86 fprintf(f, "enigma2 checked out from " ENIGMA2_CHECKOUT_ROOT "\n");
88 fprintf(f, "please email this file to " CRASH_EMAILADDR "\n");
89 std::string buffer = getLogBuffer();
90 fwrite(buffer.c_str(), buffer.size(), 1, f);
94 sprintf(cmd, "find /usr/lib/enigma2/python/ -name \"*.py\" | xargs md5sum >> %s", logfile);
100 gSDLDC::getInstance(my_dc);
103 gFBDC::getInstance(my_dc);
109 p.resetClip(eRect(ePoint(0, 0), my_dc->size()));
110 p.setBackgroundColor(gRGB(0x0000C0));
111 p.setForegroundColor(gRGB(0xFFFFFF));
113 ePtr<gFont> font = new gFont("Regular", 20);
117 eRect usable_area = eRect(100, 70, my_dc->size().width() - 150, 100);
119 p.renderText(usable_area,
120 "We are really sorry. Something happened "
121 "which should not have happened, and "
122 "resulted in a crash. If you want to help "
123 "us in improving this situation, please send "
124 "the logfile created in /hdd/ to " CRASH_EMAILADDR "."
125 "Your receiver restarts in 10 seconds !", gPainter::RT_WRAP|gPainter::RT_HALIGN_LEFT);
127 usable_area = eRect(100, 170, my_dc->size().width() - 180, my_dc->size().height() - 20);
131 size_t start = std::string::npos + 1;
134 start = lines.rfind('\n', start - 1);
135 if (start == std::string::npos)
142 font = new gFont("Regular", 14);
145 p.renderText(usable_area,
146 lines.substr(start), gPainter::RT_HALIGN_LEFT);
153 #if defined(__MIPSEL__)
154 void oops(const mcontext_t &context, int dumpcode)
156 eDebug("PC: %08lx, vaddr: %08lx", (unsigned long)context.pc, (unsigned long)context.badvaddr);
160 eDebugNoNewLine(" %08x", (int)context.gregs[i]);
164 /* this is temporary debug stuff. */
165 if (dumpcode && ((unsigned long)context.pc) > 0x10000) /* not a zero pointer */
167 eDebug("As a final action, i will try to dump a bit of code.");
168 eDebug("I just hope that this won't crash.");
170 eDebugNoNewLine("%08lx:", (unsigned long)context.pc);
171 for (i=0; i<0x20; ++i)
172 eDebugNoNewLine(" %02x", ((unsigned char*)context.pc)[i]);
177 #warning "no oops support!"
178 #define NO_OOPS_SUPPORT
181 void handleFatalSignal(int signum, siginfo_t *si, void *ctx)
183 ucontext_t *uc = (ucontext_t*)ctx;
184 eDebug("KILLED BY signal %d", signum);
185 #ifndef NO_OOPS_SUPPORT
186 oops(uc->uc_mcontext, signum == SIGSEGV || signum == SIGABRT);
192 void bsodCatchSignals()
194 struct sigaction act;
195 act.sa_handler = SIG_DFL;
196 act.sa_sigaction = handleFatalSignal;
197 act.sa_flags = SA_RESTART | SA_SIGINFO;
198 if (sigemptyset(&act.sa_mask) == -1)
199 perror("sigemptyset");
201 /* start handling segfaults etc. */
202 sigaction(SIGSEGV, &act, 0);
203 sigaction(SIGILL, &act, 0);
204 sigaction(SIGBUS, &act, 0);
205 sigaction(SIGABRT, &act, 0);
210 logOutput.connect(addToLogbuffer);