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>
12 /************************************************/
14 #define CRASH_EMAILADDR "crashlog@dream-multimedia-tv.de"
16 #define RINGBUFFER_SIZE 16384
17 static char ringbuffer[RINGBUFFER_SIZE];
18 static int ringbuffer_head;
20 static void addToLogbuffer(const char *data, int len)
24 int remaining = RINGBUFFER_SIZE - ringbuffer_head;
29 memcpy(ringbuffer + ringbuffer_head, data, remaining);
32 ringbuffer_head += remaining;
33 if (ringbuffer_head >= RINGBUFFER_SIZE)
38 static std::string getLogBuffer()
40 int begin = ringbuffer_head;
41 while (ringbuffer[begin] == 0)
44 if (begin == RINGBUFFER_SIZE)
46 if (begin == ringbuffer_head)
49 if (begin < ringbuffer_head)
50 return std::string(ringbuffer + begin, ringbuffer_head - begin);
53 return std::string(ringbuffer + begin, RINGBUFFER_SIZE - begin) + std::string(ringbuffer, ringbuffer_head);
57 static void addToLogbuffer(int level, const std::string &log)
59 addToLogbuffer(log.c_str(), log.size());
63 extern std::string getLogBuffer();
68 sprintf(logfile, "/media/hdd/enigma2_crash_%u.log", (unsigned int)time(0));
69 FILE *f = fopen(logfile, "wb");
71 std::string lines = getLogBuffer();
76 fprintf(f, "enigma2 crashed on %s", ctime(&t));
77 #ifdef ENIGMA2_CHECKOUT_TAG
78 fprintf(f, "enigma2 CVS TAG: " ENIGMA2_CHECKOUT_TAG "\n");
80 fprintf(f, "enigma2 compiled on " __DATE__ "\n");
82 #ifdef ENIGMA2_CHECKOUT_ROOT
83 fprintf(f, "enigma2 checked out from " ENIGMA2_CHECKOUT_ROOT "\n");
85 fprintf(f, "please email this file to " CRASH_EMAILADDR "\n");
86 std::string buffer = getLogBuffer();
87 fwrite(buffer.c_str(), buffer.size(), 1, f);
92 gFBDC::getInstance(my_dc);
97 p.resetClip(eRect(ePoint(0, 0), my_dc->size()));
98 p.setBackgroundColor(gRGB(0x0000C0));
99 p.setForegroundColor(gRGB(0xFFFFFF));
101 ePtr<gFont> font = new gFont("Regular", 20);
105 eRect usable_area = eRect(100, 70, my_dc->size().width() - 200, 100);
107 p.renderText(usable_area,
108 "We are really sorry. Something happened "
109 "which should not have happened, and "
110 "resulted in a crash. If you want to help "
111 "us in improving this situation, please send "
112 "the logfile created in /hdd/ to " CRASH_EMAILADDR ".", gPainter::RT_WRAP|gPainter::RT_HALIGN_LEFT);
114 usable_area = eRect(100, 170, my_dc->size().width() - 200, my_dc->size().height() - 20);
118 size_t start = std::string::npos + 1;
121 start = lines.rfind('\n', start - 1);
122 if (start == std::string::npos)
129 font = new gFont("Regular", 14);
132 p.renderText(usable_area,
133 lines.substr(start), gPainter::RT_HALIGN_LEFT);
140 #if defined(__MIPSEL__)
141 void oops(const mcontext_t &context, int dumpcode)
143 eDebug("PC: %08lx, vaddr: %08lx", (unsigned long)context.pc, (unsigned long)context.badvaddr);
146 #warning "no oops support!"
148 #define NO_OOPS_SUPPORT
151 void handleFatalSignal(int signum, siginfo_t *si, void *ctx)
153 ucontext_t *uc = (ucontext_t*)ctx;
154 eDebug("KILLED BY signal %d", signum);
155 #ifndef NO_OOPS_SUPPORT
156 oops(uc->uc_mcontext, signum == SIGSEGV);
162 void bsodCatchSignals()
164 struct sigaction act;
165 act.sa_handler = SIG_DFL;
166 act.sa_sigaction = handleFatalSignal;
168 if (sigemptyset(&act.sa_mask) == -1)
169 perror("sigemptyset");
171 /* start handling segfaults etc. */
172 sigaction(SIGSEGV, &act, 0);
173 sigaction(SIGILL, &act, 0);
174 sigaction(SIGBUS, &act, 0);
179 logOutput.connect(addToLogbuffer);