35#include <glib/gstdio.h>
54#if defined(__linux__) && !defined(PR_SET_PTRACER)
55#define PR_SET_PTRACER 0x59616d61
60#if !defined(__APPLE__) && !defined(_WIN32)
68 SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGXCPU, SIGXFSZ };
71static LPTOP_LEVEL_EXCEPTION_FILTER _dt_exceptionfilter_old_handler = NULL;
74#define _NUM_SIGNALS_TO_PRESERVE (sizeof(_signals_to_preserve) / sizeof(_signals_to_preserve[0]))
77#if(defined(__FreeBSD_version) && (__FreeBSD_version < 800071)) || (defined(OpenBSD) && (OpenBSD < 201305)) \
79static int dprintf(
int fd,
const char *fmt, ...)
__attribute__((format(printf, 2, 3)))
82 FILE *
f = fdopen(fd,
"a");
84 int rc = vfprintf(
f, fmt, ap);
91#if !defined(__APPLE__) && !defined(_WIN32)
106 gboolean delete_file =
FALSE;
108 if((fout = g_file_open_tmp(
"ansel_bt_XXXXXX.txt", &name_used, NULL)) == -1)
109 fout = STDOUT_FILENO;
113 if(fout != STDOUT_FILENO) close(fout);
115 gchar *pid_arg = g_strdup_printf(
"%d", (
int)getpid());
116 gchar *exe_arg = g_strdup_printf(
"/proc/%s/exe", pid_arg);
117 gchar *log_file_arg = g_strdup_printf(
"set logging file %s", name_used);
118 const char *log_overwrite_arg =
"set logging overwrite on";
119 const char *log_redirect_arg =
"set logging redirect on";
120 const char *log_enabled_arg =
"set logging enabled on";
121 const char *pagination_arg =
"set pagination off";
122 const char *confirm_arg =
"set confirm off";
123 const char *where_arg =
"where";
124 const char *current_bt_arg =
"bt full";
125 const char *current_thread_arg =
"thread";
126 const char *info_registers_arg =
"info registers";
127 const char *disassemble_pc_arg =
"x/16i $pc";
128 const char *stack_words_arg =
"x/16gx $sp";
129 const char *sharedlibrary_arg =
"info sharedlibrary";
130 const char *mappings_arg =
"info proc mappings";
131 const char *info_threads_arg =
"info threads";
132 const char *thread_bt_arg =
"thread apply all bt full";
133 const char *separator_a_arg =
"echo \\n=========\\n\\n";
134 const char *separator_b_arg =
"echo \\n=========\\n";
135 const char *separator_c_arg =
"echo \\n========= current thread =========\\n";
136 const char *separator_d_arg =
"echo \\n========= registers =========\\n";
137 const char *separator_e_arg =
"echo \\n========= disassembly =========\\n";
138 const char *separator_f_arg =
"echo \\n========= stack =========\\n";
139 const char *separator_g_arg =
"echo \\n========= shared libraries =========\\n";
140 const char *separator_h_arg =
"echo \\n========= mappings =========\\n";
142 if((pid = fork()) != -1)
148 prctl(PR_SET_PTRACER, pid, 0, 0, 0);
150 waitpid(pid, NULL, 0);
151 g_printerr(
"backtrace written to %s\n", name_used);
155 if(fout != STDOUT_FILENO)
157 const int log_fd = open(name_used, O_WRONLY | O_APPEND);
160 dup2(log_fd, STDOUT_FILENO);
161 dup2(log_fd, STDERR_FILENO);
166 if(execlp(
"gdb",
"gdb", exe_arg, pid_arg,
"-batch",
"-ex", pagination_arg,
"-ex", confirm_arg,
"-ex",
167 log_file_arg,
"-ex", log_overwrite_arg,
"-ex", log_redirect_arg,
"-ex", log_enabled_arg,
"-ex",
168 where_arg,
"-ex", separator_c_arg,
"-ex", current_thread_arg,
"-ex", current_bt_arg,
"-ex",
169 separator_d_arg,
"-ex", info_registers_arg,
"-ex", separator_e_arg,
"-ex", disassemble_pc_arg,
170 "-ex", separator_f_arg,
"-ex", stack_words_arg,
"-ex", separator_g_arg,
"-ex",
171 sharedlibrary_arg,
"-ex", separator_h_arg,
"-ex", mappings_arg,
"-ex", separator_a_arg,
"-ex",
172 info_threads_arg,
"-ex", separator_b_arg,
"-ex", thread_bt_arg, NULL))
175 g_printerr(
"an error occurred while trying to execute gdb. please check if gdb is installed on your "
183 g_printerr(
"an error occurred while trying to execute gdb.\n");
186 if(delete_file) g_unlink(name_used);
201static LONG WINAPI dt_toplevel_exception_handler(PEXCEPTION_POINTERS pExceptionInfo)
208 if((fout = g_file_open_tmp(
"ansel_bt_XXXXXX.txt", &name_used, NULL)) == -1)
209 fout = STDOUT_FILENO;
211 FILE *fd = fdopen(fout,
"wb");
215 if(fout != STDOUT_FILENO) close(fout);
219 ok = ExcHndlSetLogFileNameA(name_used);
222 g_printerr(
"backtrace logfile cannot be set to %s\n", name_used);
226 gchar *exception_message = g_strdup_printf(
"An unhandled exception occurred.\nBacktrace will be written to: %s "
227 "after you click on the OK button.\nIf you report this issue, "
228 "please share this backtrace with the developers.\n",
230 wchar_t *wexception_message = g_utf8_to_utf16(exception_message, -1, NULL, NULL, NULL);
231 MessageBoxW(0, wexception_message,
L"Error!", MB_OK);
239 return _dt_exceptionfilter_old_handler(pExceptionInfo);
242void dt_set_unhandled_exception_handler_win()
263 prev = signal(signum, SIG_DFL);
265 if(SIG_ERR == prev) prev = SIG_DFL;
279#if !defined(__APPLE__) && !defined(_WIN32)
291 const int errsv = errno;
292 fprintf(stderr,
"[dt_set_signal_handlers] error: signal(SIGSEGV) returned SIG_ERR: %i (%s)\n", errsv,
295#elif !defined(__APPLE__)
305 dt_set_unhandled_exception_handler_win();
310 _dt_exceptionfilter_old_handler = SetUnhandledExceptionFilter(dt_toplevel_exception_handler);
313 SetUnhandledExceptionFilter(dt_toplevel_exception_handler);
const dt_aligned_pixel_t f
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
const char darktable_package_string[]
float dt_aligned_pixel_simd_t __attribute__((vector_size(16), aligned(16)))
Enable aggressive floating-point arithmetic optimizations, in denormals handling. Set through user pr...
gboolean dt_sentry_backtrace_captured(void)
const float const float param
void dt_set_signal_handlers()
static int _times_handlers_were_set
static dt_signal_handler_t * _orig_sig_handlers[(sizeof(_signals_to_preserve)/sizeof(_signals_to_preserve[0]))]
#define _NUM_SIGNALS_TO_PRESERVE
defined (_WIN32)
static dt_signal_handler_t * _dt_sigsegv_old_handler
static const int _signals_to_preserve[]
static void _dt_sigsegv_handler(int param)
void() dt_signal_handler_t(int)