diff options
author | Luminarys <kizunanohikari@gmail.com> | 2015-08-24 15:44:58 -0500 |
---|---|---|
committer | Luminarys <kizunanohikari@gmail.com> | 2015-08-24 15:44:58 -0500 |
commit | 7c5b6f8c5285c1ddb8604875a48c7798367cf8ad (patch) | |
tree | 0c193e7e81b497510e7e4927df5e105749ae8b24 | |
parent | add limit to swayc_in_direction (diff) | |
download | sway-7c5b6f8c5285c1ddb8604875a48c7798367cf8ad.tar.gz sway-7c5b6f8c5285c1ddb8604875a48c7798367cf8ad.tar.zst sway-7c5b6f8c5285c1ddb8604875a48c7798367cf8ad.zip |
Added in backtrace printing
-rw-r--r-- | include/log.h | 1 | ||||
-rw-r--r-- | sway/log.c | 25 |
2 files changed, 26 insertions, 0 deletions
diff --git a/include/log.h b/include/log.h index 3d77769c..945ad239 100644 --- a/include/log.h +++ b/include/log.h | |||
@@ -16,6 +16,7 @@ void sway_log(log_importance_t verbosity, const char* format, ...) __attribute__ | |||
16 | void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3))); | 16 | void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3))); |
17 | void sway_abort(const char* format, ...) __attribute__((format(printf,1,2))); | 17 | void sway_abort(const char* format, ...) __attribute__((format(printf,1,2))); |
18 | bool sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3))); | 18 | bool sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3))); |
19 | void error_handler(int sig); | ||
19 | 20 | ||
20 | void layout_log(const swayc_t *c, int depth); | 21 | void layout_log(const swayc_t *c, int depth); |
21 | #endif | 22 | #endif |
@@ -8,6 +8,7 @@ | |||
8 | #include <signal.h> | 8 | #include <signal.h> |
9 | #include <errno.h> | 9 | #include <errno.h> |
10 | #include <string.h> | 10 | #include <string.h> |
11 | #include <execinfo.h> | ||
11 | 12 | ||
12 | int colored = 1; | 13 | int colored = 1; |
13 | log_importance_t v = L_SILENT; | 14 | log_importance_t v = L_SILENT; |
@@ -30,6 +31,8 @@ void init_log(log_importance_t verbosity) { | |||
30 | fcntl(fd[i], F_SETFD, flag | FD_CLOEXEC); | 31 | fcntl(fd[i], F_SETFD, flag | FD_CLOEXEC); |
31 | } | 32 | } |
32 | } | 33 | } |
34 | signal(SIGSEGV, error_handler); | ||
35 | signal(SIGABRT, error_handler); | ||
33 | } | 36 | } |
34 | 37 | ||
35 | void sway_log_colors(int mode) { | 38 | void sway_log_colors(int mode) { |
@@ -114,6 +117,28 @@ bool sway_assert(bool condition, const char* format, ...) { | |||
114 | return false; | 117 | return false; |
115 | } | 118 | } |
116 | 119 | ||
120 | void error_handler(int sig) { | ||
121 | int i; | ||
122 | int max_lines = 20; | ||
123 | void *array[max_lines]; | ||
124 | char **bt; | ||
125 | size_t bt_len; | ||
126 | |||
127 | sway_log(L_ERROR, "Error: Signal %d. Printing backtrace", sig); | ||
128 | bt_len = backtrace(array, max_lines); | ||
129 | bt = backtrace_symbols(array, bt_len); | ||
130 | if (!bt) { | ||
131 | sway_log(L_ERROR, "Could not allocate sufficient memory for backtrace_symbols(), falling back to stderr"); | ||
132 | backtrace_symbols_fd(array, bt_len, STDERR_FILENO); | ||
133 | exit(1); | ||
134 | } | ||
135 | |||
136 | for (i = 0; (size_t)i < bt_len; i++) { | ||
137 | sway_log(L_ERROR, "Backtrace: %s", bt[i]); | ||
138 | } | ||
139 | exit(1); | ||
140 | } | ||
141 | |||
117 | #include "workspace.h" | 142 | #include "workspace.h" |
118 | 143 | ||
119 | /* XXX:DEBUG:XXX */ | 144 | /* XXX:DEBUG:XXX */ |