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)
69static const int _signals_to_preserve[] = { SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGBUS, SIGFPE,
70 SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGXCPU, SIGXFSZ };
76#define _NUM_SIGNALS_TO_PRESERVE (sizeof(_signals_to_preserve) / sizeof(_signals_to_preserve[0]))
79#if(defined(__FreeBSD_version) && (__FreeBSD_version < 800071)) || (defined(OpenBSD) && (OpenBSD < 201305)) \
81static int dprintf(
int fd,
const char *fmt, ...)
__attribute__((format(printf, 2, 3)))
84 FILE *
f = fdopen(fd,
"a");
86 int rc = vfprintf(
f, fmt, ap);
93#if !defined(__APPLE__) && !defined(_WIN32)
94static void _dt_sigsegv_handler(
int param)
101 _dt_sigsegv_old_handler(
param);
108 gboolean delete_file =
FALSE;
110 if((fout = g_file_open_tmp(
"ansel_bt_XXXXXX.txt", &name_used, NULL)) == -1)
111 fout = STDOUT_FILENO;
115 if(fout != STDOUT_FILENO) close(fout);
117 gchar *pid_arg = g_strdup_printf(
"%d", (
int)getpid());
118 gchar *exe_arg = g_strdup_printf(
"/proc/%s/exe", pid_arg);
119 gchar *log_file_arg = g_strdup_printf(
"set logging file %s", name_used);
120 const char *log_overwrite_arg =
"set logging overwrite on";
121 const char *log_redirect_arg =
"set logging redirect on";
122 const char *log_enabled_arg =
"set logging enabled on";
123 const char *pagination_arg =
"set pagination off";
124 const char *confirm_arg =
"set confirm off";
125 const char *where_arg =
"where";
126 const char *current_bt_arg =
"bt full";
127 const char *current_thread_arg =
"thread";
128 const char *info_registers_arg =
"info registers";
129 const char *disassemble_pc_arg =
"x/16i $pc";
130 const char *stack_words_arg =
"x/16gx $sp";
131 const char *sharedlibrary_arg =
"info sharedlibrary";
132 const char *mappings_arg =
"info proc mappings";
133 const char *info_threads_arg =
"info threads";
134 const char *thread_bt_arg =
"thread apply all bt full";
135 const char *separator_a_arg =
"echo \\n=========\\n\\n";
136 const char *separator_b_arg =
"echo \\n=========\\n";
137 const char *separator_c_arg =
"echo \\n========= current thread =========\\n";
138 const char *separator_d_arg =
"echo \\n========= registers =========\\n";
139 const char *separator_e_arg =
"echo \\n========= disassembly =========\\n";
140 const char *separator_f_arg =
"echo \\n========= stack =========\\n";
141 const char *separator_g_arg =
"echo \\n========= shared libraries =========\\n";
142 const char *separator_h_arg =
"echo \\n========= mappings =========\\n";
144 if((pid = fork()) != -1)
152 waitpid(pid, NULL, 0);
153 g_printerr(
"backtrace written to %s\n", name_used);
157 if(fout != STDOUT_FILENO)
159 const int log_fd = open(name_used, O_WRONLY | O_APPEND);
162 dup2(log_fd, STDOUT_FILENO);
163 dup2(log_fd, STDERR_FILENO);
168 if(execlp(
"gdb",
"gdb", exe_arg, pid_arg,
"-batch",
"-ex", pagination_arg,
"-ex", confirm_arg,
"-ex",
169 log_file_arg,
"-ex", log_overwrite_arg,
"-ex", log_redirect_arg,
"-ex", log_enabled_arg,
"-ex",
170 where_arg,
"-ex", separator_c_arg,
"-ex", current_thread_arg,
"-ex", current_bt_arg,
"-ex",
171 separator_d_arg,
"-ex", info_registers_arg,
"-ex", separator_e_arg,
"-ex", disassemble_pc_arg,
172 "-ex", separator_f_arg,
"-ex", stack_words_arg,
"-ex", separator_g_arg,
"-ex",
173 sharedlibrary_arg,
"-ex", separator_h_arg,
"-ex", mappings_arg,
"-ex", separator_a_arg,
"-ex",
174 info_threads_arg,
"-ex", separator_b_arg,
"-ex", thread_bt_arg, NULL))
177 g_printerr(
"an error occurred while trying to execute gdb. please check if gdb is installed on your "
185 g_printerr(
"an error occurred while trying to execute gdb.\n");
188 if(delete_file) g_unlink(name_used);
195 _dt_sigsegv_old_handler(
param);
216 if((fout = g_file_open_tmp(
"ansel_bt_XXXXXX.txt", &name_used, NULL)) == -1)
217 fout = STDOUT_FILENO;
219 FILE *fd = fdopen(fout,
"wb");
223 if(fout != STDOUT_FILENO) close(fout);
227 ok = ExcHndlSetLogFileNameA(name_used);
230 g_printerr(
"backtrace logfile cannot be set to %s\n", name_used);
234 gchar *exception_message = g_strdup_printf(
"An unhandled exception occurred.\nBacktrace will be written to: %s "
235 "after you click on the OK button.\nIf you report this issue, "
236 "please share this backtrace with the developers.\n",
238 wchar_t *wexception_message = g_utf8_to_utf16(exception_message, -1, NULL, NULL, NULL);
239 MessageBoxW(0, wexception_message,
L"Error!", MB_OK);
271 prev = signal(signum, SIG_DFL);
273 if(SIG_ERR == prev) prev = SIG_DFL;
287#if !defined(__APPLE__) && !defined(_WIN32)
290 prev = signal(SIGSEGV, &_dt_sigsegv_handler);
299 const int errsv = errno;
300 fprintf(stderr,
"[dt_set_signal_handlers] error: signal(SIGSEGV) returned SIG_ERR: %i (%s)\n", errsv,
303#elif !defined(__APPLE__)
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
const char darktable_package_string[]
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
gboolean dt_sentry_backtrace_captured(void)
float dt_aligned_pixel_simd_t __attribute__((vector_size(16), aligned(16)))
Apply one channel's tone curve to each of the three colour channels, or pass the channel through unto...
const float const float param
void dt_set_signal_handlers()
void dt_set_unhandled_exception_handler_win()
static LONG WINAPI dt_toplevel_exception_handler(PEXCEPTION_POINTERS pExceptionInfo)
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 const int _signals_to_preserve[]
static LPTOP_LEVEL_EXCEPTION_FILTER _dt_exceptionfilter_old_handler
void() dt_signal_handler_t(int)