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();
68 #define INFOFILE "/maintainer.info"
70 void bsodFatal(const char *component)
73 sprintf(logfile, "/media/hdd/enigma2_crash_%u.log", (unsigned int)time(0));
74 FILE *f = fopen(logfile, "wb");
76 std::string lines = getLogBuffer();
78 /* find python-tracebacks, and extract " File "-strings */
81 char crash_emailaddr[256] = CRASH_EMAILADDR;
82 char crash_component[256] = "enigma2";
85 snprintf(crash_component, 256, component);
88 while ((start = lines.find("\n File \"", start)) != std::string::npos)
91 size_t end = lines.find("\"", start);
92 if (end == std::string::npos)
94 end = lines.rfind("/", end);
95 if (end == std::string::npos)
97 if (end - start >= (256 - strlen(INFOFILE)))
100 snprintf(filename, 256, "%s%s", lines.substr(start, end - start).c_str(), INFOFILE);
101 FILE *cf = fopen(filename, "r");
104 fgets(crash_emailaddr, sizeof crash_emailaddr, cf);
105 if (*crash_emailaddr && crash_emailaddr[strlen(crash_emailaddr)-1] == '\n')
106 crash_emailaddr[strlen(crash_emailaddr)-1] = 0;
108 fgets(crash_component, sizeof crash_component, cf);
109 if (*crash_component && crash_component[strlen(crash_component)-1] == '\n')
110 crash_component[strlen(crash_component)-1] = 0;
119 fprintf(f, "enigma2 crashed on %s", ctime(&t));
120 #ifdef ENIGMA2_CHECKOUT_TAG
121 fprintf(f, "enigma2 CVS TAG: " ENIGMA2_CHECKOUT_TAG "\n");
123 fprintf(f, "enigma2 compiled on " __DATE__ "\n");
125 #ifdef ENIGMA2_CHECKOUT_ROOT
126 fprintf(f, "enigma2 checked out from " ENIGMA2_CHECKOUT_ROOT "\n");
128 fprintf(f, "please email this file to %s\n", crash_emailaddr);
129 std::string buffer = getLogBuffer();
130 fwrite(buffer.c_str(), buffer.size(), 1, f);
134 sprintf(cmd, "find /usr/lib/enigma2/python/ -name \"*.py\" | xargs md5sum >> %s", logfile);
140 gSDLDC::getInstance(my_dc);
143 gFBDC::getInstance(my_dc);
149 p.resetClip(eRect(ePoint(0, 0), my_dc->size()));
150 #ifdef ENIGMA2_CHECKOUT_TAG
151 if (ENIGMA2_CHECKOUT_TAG[0] == 'T') /* tagged checkout (release) */
152 p.setBackgroundColor(gRGB(0x0000C0));
153 else if (ENIGMA2_CHECKOUT_TAG[0] == 'D') /* dated checkout (daily experimental build) */
157 unsigned int col = 0;
164 p.setBackgroundColor(gRGB(col));
167 p.setBackgroundColor(gRGB(0x008000));
170 p.setForegroundColor(gRGB(0xFFFFFF));
172 ePtr<gFont> font = new gFont("Regular", 20);
176 eRect usable_area = eRect(100, 70, my_dc->size().width() - 150, 100);
179 snprintf(text, 512, "We are really sorry. Your Dreambox encountered "
180 "a software problem, and needs to be restarted. "
181 "Please send the logfile created in /hdd/ to %s.\n"
182 "Your Dreambox restarts in 10 seconds!\n"
184 crash_emailaddr, crash_component);
186 p.renderText(usable_area, text, gPainter::RT_WRAP|gPainter::RT_HALIGN_LEFT);
188 usable_area = eRect(100, 170, my_dc->size().width() - 180, my_dc->size().height() - 20);
192 size_t start = std::string::npos + 1;
195 start = lines.rfind('\n', start - 1);
196 if (start == std::string::npos)
203 font = new gFont("Regular", 14);
206 p.renderText(usable_area,
207 lines.substr(start), gPainter::RT_HALIGN_LEFT);
214 #if defined(__MIPSEL__)
215 void oops(const mcontext_t &context, int dumpcode)
217 eDebug("PC: %08lx", (unsigned long)context.pc);
221 eDebugNoNewLine(" %08x", (int)context.gregs[i]);
225 /* this is temporary debug stuff. */
226 if (dumpcode && ((unsigned long)context.pc) > 0x10000) /* not a zero pointer */
228 eDebug("As a final action, i will try to dump a bit of code.");
229 eDebug("I just hope that this won't crash.");
231 eDebugNoNewLine("%08lx:", (unsigned long)context.pc);
232 for (i=0; i<0x20; ++i)
233 eDebugNoNewLine(" %02x", ((unsigned char*)context.pc)[i]);
238 #warning "no oops support!"
239 #define NO_OOPS_SUPPORT
242 void handleFatalSignal(int signum, siginfo_t *si, void *ctx)
244 ucontext_t *uc = (ucontext_t*)ctx;
245 eDebug("KILLED BY signal %d", signum);
246 #ifndef NO_OOPS_SUPPORT
247 oops(uc->uc_mcontext, signum == SIGSEGV || signum == SIGABRT);
250 bsodFatal("enigma2, signal");
253 void bsodCatchSignals()
255 struct sigaction act;
256 act.sa_handler = SIG_DFL;
257 act.sa_sigaction = handleFatalSignal;
258 act.sa_flags = SA_RESTART | SA_SIGINFO;
259 if (sigemptyset(&act.sa_mask) == -1)
260 perror("sigemptyset");
262 /* start handling segfaults etc. */
263 sigaction(SIGSEGV, &act, 0);
264 sigaction(SIGILL, &act, 0);
265 sigaction(SIGBUS, &act, 0);
266 sigaction(SIGABRT, &act, 0);
271 logOutput.connect(addToLogbuffer);