2 * NOTE TO FreeBSD users. Install libexecinfo from
3 * ports/devel/libexecinfo and add -lexecinfo to LDFLAGS
4 * to add backtrace support.
12 static volatile Eina_Bool _e_x_composite_shutdown_try = 0;
15 _e_x_composite_shutdown(void)
17 // Ecore_X_Display *dpy;
20 if (_e_x_composite_shutdown_try) return; /* we failed :-( */
21 _e_x_composite_shutdown_try = 1;
23 // dpy = ecore_x_display_get();
24 root = ecore_x_window_root_first_get();
26 /* ignore errors, we really don't care at this point */
27 ecore_x_composite_unredirect_subwindows(root, ECORE_X_COMPOSITE_UPDATE_MANUAL);
28 _e_x_composite_shutdown_try = 0;
31 #define _e_write_safe(fd, buf) _e_write_safe_int(fd, buf, sizeof(buf))
34 _e_write_safe_int(int fd, const char *buf, size_t size)
38 ssize_t done = write(fd, buf, size);
46 if ((errno == EAGAIN) || (errno == EINTR))
58 _e_gdb_print_backtrace(int fd)
64 // FIXME: we are in a segv'd state. do as few function calls and things
65 // depending on a known working state as possible. this also prevents the
66 // white box allowing recovery or deeper gdbing, thus until this works
67 // properly, it's disabled (properly means always reliable, always
68 // printf bt and allows e to continue and pop up box, perferably allowing
69 // debugging in the gui etc. etc.
72 if (getenv("E_NO_GDB_BACKTRACE"))
75 size = snprintf(cmd, sizeof(cmd),
77 "-ex 'thread apply all bt' "
78 "-ex detach -ex quit", getpid());
80 if (size >= sizeof(cmd))
83 _e_write_safe(fd, "EXECUTING GDB AS: ");
84 _e_write_safe_int(fd, cmd, size);
85 _e_write_safe(fd, "\n");
86 ret = system(cmd); // TODO: use popen() or fork()+pipe()+exec() and save to 'fd'
89 #define _e_backtrace(msg) _e_backtrace_int(2, msg, sizeof(msg))
91 _e_backtrace_int(int fd, const char *msg, size_t msg_len)
97 return; // disable. causes hangs and problems
99 _e_write_safe_int(fd, msg, msg_len);
100 _e_write_safe(fd, "\nBEGIN TRACEBACK\n");
101 size = backtrace(array, 255);
102 backtrace_symbols_fd(array, size, fd);
103 _e_write_safe(fd, "END TRACEBACK\n");
105 size = snprintf(attachmsg, sizeof(attachmsg),
106 "debug with: gdb --pid=%d\n", getpid());
107 if (size < sizeof(attachmsg))
108 _e_write_safe_int(fd, attachmsg, size);
110 _e_gdb_print_backtrace(fd);
113 /* a tricky little devil, requires e and it's libs to be built
114 * with the -rdynamic flag to GCC for any sort of decent output.
117 e_sigseg_act(int x __UNUSED__, siginfo_t *info __UNUSED__, void *data __UNUSED__)
119 _e_backtrace("**** SEGMENTATION FAULT ****");
120 _e_x_composite_shutdown();
121 ecore_x_pointer_ungrab();
122 ecore_x_keyboard_ungrab();
125 e_alert_show(SIGSEGV);
129 e_sigill_act(int x __UNUSED__, siginfo_t *info __UNUSED__, void *data __UNUSED__)
131 _e_backtrace("**** ILLEGAL INSTRUCTION ****");
132 _e_x_composite_shutdown();
133 ecore_x_pointer_ungrab();
134 ecore_x_keyboard_ungrab();
137 e_alert_show(SIGILL);
141 e_sigfpe_act(int x __UNUSED__, siginfo_t *info __UNUSED__, void *data __UNUSED__)
143 _e_backtrace("**** FLOATING POINT EXCEPTION ****");
144 _e_x_composite_shutdown();
145 ecore_x_pointer_ungrab();
146 ecore_x_keyboard_ungrab();
149 e_alert_show(SIGFPE);
153 e_sigbus_act(int x __UNUSED__, siginfo_t *info __UNUSED__, void *data __UNUSED__)
155 _e_backtrace("**** BUS ERROR ****");
156 _e_x_composite_shutdown();
157 ecore_x_pointer_ungrab();
158 ecore_x_keyboard_ungrab();
161 e_alert_show(SIGBUS);
165 e_sigabrt_act(int x __UNUSED__, siginfo_t *info __UNUSED__, void *data __UNUSED__)
167 _e_backtrace("**** ABORT ****");
168 _e_x_composite_shutdown();
169 ecore_x_pointer_ungrab();
170 ecore_x_keyboard_ungrab();
173 e_alert_show(SIGABRT);